PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - Zend - zend_constants.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 251 298 84.2 %
Date: 2014-11-25 Functions: 13 20 65.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        | 
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #include "zend.h"
      23             : #include "zend_constants.h"
      24             : #include "zend_execute.h"
      25             : #include "zend_variables.h"
      26             : #include "zend_operators.h"
      27             : #include "zend_globals.h"
      28             : 
      29             : 
      30    48000728 : void free_zend_constant(zend_constant *c)
      31             : {
      32    48000728 :         if (!(c->flags & CONST_PERSISTENT)) {
      33     2980786 :                 zval_dtor(&c->value);
      34             :         }
      35    48000728 :         str_free(c->name);
      36    48000728 : }
      37             : 
      38             : 
      39           0 : void copy_zend_constant(zend_constant *c)
      40             : {
      41           0 :         if (!IS_INTERNED(c->name)) {
      42           0 :                 c->name = zend_strndup(c->name, c->name_len - 1);
      43             :         }
      44           0 :         if (!(c->flags & CONST_PERSISTENT)) {
      45           0 :                 zval_copy_ctor(&c->value);
      46             :         }
      47           0 : }
      48             : 
      49             : 
      50           0 : void zend_copy_constants(HashTable *target, HashTable *source)
      51             : {
      52             :         zend_constant tmp_constant;
      53             : 
      54           0 :         zend_hash_copy(target, source, (copy_ctor_func_t) copy_zend_constant, &tmp_constant, sizeof(zend_constant));
      55           0 : }
      56             : 
      57             : 
      58       83282 : static int clean_non_persistent_constant(const zend_constant *c TSRMLS_DC)
      59             : {
      60       83282 :         return (c->flags & CONST_PERSISTENT) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
      61             : }
      62             : 
      63             : 
      64           0 : static int clean_non_persistent_constant_full(const zend_constant *c TSRMLS_DC)
      65             : {
      66           0 :         return (c->flags & CONST_PERSISTENT) ? 0 : 1;
      67             : }
      68             : 
      69             : 
      70           0 : static int clean_module_constant(const zend_constant *c, int *module_number TSRMLS_DC)
      71             : {
      72           0 :         if (c->module_number == *module_number) {
      73           0 :                 return 1;
      74             :         } else {
      75           0 :                 return 0;
      76             :         }
      77             : }
      78             : 
      79             : 
      80           0 : void clean_module_constants(int module_number TSRMLS_DC)
      81             : {
      82           0 :         zend_hash_apply_with_argument(EG(zend_constants), (apply_func_arg_t) clean_module_constant, (void *) &module_number TSRMLS_CC);
      83           0 : }
      84             : 
      85             : 
      86           0 : int zend_startup_constants(TSRMLS_D)
      87             : {
      88           0 :         EG(zend_constants) = (HashTable *) malloc(sizeof(HashTable));
      89             : 
      90           0 :         if (zend_hash_init(EG(zend_constants), 20, NULL, ZEND_CONSTANT_DTOR, 1)==FAILURE) {
      91           0 :                 return FAILURE;
      92             :         }
      93           0 :         return SUCCESS;
      94             : }
      95             : 
      96             : 
      97             : 
      98       20225 : void zend_register_standard_constants(TSRMLS_D)
      99             : {
     100       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_ERROR", E_ERROR, CONST_PERSISTENT | CONST_CS);
     101       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_RECOVERABLE_ERROR", E_RECOVERABLE_ERROR, CONST_PERSISTENT | CONST_CS);
     102       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_WARNING", E_WARNING, CONST_PERSISTENT | CONST_CS);
     103       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_PARSE", E_PARSE, CONST_PERSISTENT | CONST_CS);
     104       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_NOTICE", E_NOTICE, CONST_PERSISTENT | CONST_CS);
     105       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_STRICT", E_STRICT, CONST_PERSISTENT | CONST_CS);
     106       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_DEPRECATED", E_DEPRECATED, CONST_PERSISTENT | CONST_CS);
     107       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_CORE_ERROR", E_CORE_ERROR, CONST_PERSISTENT | CONST_CS);
     108       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_CORE_WARNING", E_CORE_WARNING, CONST_PERSISTENT | CONST_CS);
     109       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_ERROR", E_COMPILE_ERROR, CONST_PERSISTENT | CONST_CS);
     110       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_WARNING", E_COMPILE_WARNING, CONST_PERSISTENT | CONST_CS);
     111       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_USER_ERROR", E_USER_ERROR, CONST_PERSISTENT | CONST_CS);
     112       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_USER_WARNING", E_USER_WARNING, CONST_PERSISTENT | CONST_CS);
     113       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_USER_NOTICE", E_USER_NOTICE, CONST_PERSISTENT | CONST_CS);
     114       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_USER_DEPRECATED", E_USER_DEPRECATED, CONST_PERSISTENT | CONST_CS);
     115             : 
     116       20225 :         REGISTER_MAIN_LONG_CONSTANT("E_ALL", E_ALL, CONST_PERSISTENT | CONST_CS);
     117             : 
     118       20225 :         REGISTER_MAIN_LONG_CONSTANT("DEBUG_BACKTRACE_PROVIDE_OBJECT", DEBUG_BACKTRACE_PROVIDE_OBJECT, CONST_PERSISTENT | CONST_CS);
     119       20225 :         REGISTER_MAIN_LONG_CONSTANT("DEBUG_BACKTRACE_IGNORE_ARGS", DEBUG_BACKTRACE_IGNORE_ARGS, CONST_PERSISTENT | CONST_CS);
     120             :         /* true/false constants */
     121             :         {
     122             :                 zend_constant c;
     123             :         
     124       20225 :                 c.flags = CONST_PERSISTENT | CONST_CT_SUBST;
     125       20225 :                 c.module_number = 0;
     126             : 
     127       20225 :                 c.name = zend_strndup(ZEND_STRL("TRUE"));
     128       20225 :                 c.name_len = sizeof("TRUE");
     129       20225 :                 c.value.value.lval = 1;
     130       20225 :                 c.value.type = IS_BOOL;
     131       20225 :                 zend_register_constant(&c TSRMLS_CC);
     132             :                 
     133       20225 :                 c.name = zend_strndup(ZEND_STRL("FALSE"));
     134       20225 :                 c.name_len = sizeof("FALSE");
     135       20225 :                 c.value.value.lval = 0;
     136       20225 :                 c.value.type = IS_BOOL;
     137       20225 :                 zend_register_constant(&c TSRMLS_CC);
     138             : 
     139       20225 :                 c.name = zend_strndup(ZEND_STRL("NULL"));
     140       20225 :                 c.name_len = sizeof("NULL");
     141       20225 :                 c.value.type = IS_NULL;
     142       20225 :                 zend_register_constant(&c TSRMLS_CC);
     143             : 
     144       20225 :                 c.flags = CONST_PERSISTENT | CONST_CS;
     145             : 
     146       20225 :                 c.name = zend_strndup(ZEND_STRL("ZEND_THREAD_SAFE"));
     147       20225 :                 c.name_len = sizeof("ZEND_THREAD_SAFE");
     148       20225 :                 c.value.value.lval = ZTS_V;
     149       20225 :                 c.value.type = IS_BOOL;
     150       20225 :                 zend_register_constant(&c TSRMLS_CC);
     151             : 
     152       20225 :                 c.name = zend_strndup(ZEND_STRL("ZEND_DEBUG_BUILD"));
     153       20225 :                 c.name_len = sizeof("ZEND_DEBUG_BUILD");
     154       20225 :                 c.value.value.lval = ZEND_DEBUG;
     155       20225 :                 c.value.type = IS_BOOL;
     156       20225 :                 zend_register_constant(&c TSRMLS_CC);
     157             :         }
     158       20225 : }
     159             : 
     160             : 
     161           0 : int zend_shutdown_constants(TSRMLS_D)
     162             : {
     163           0 :         zend_hash_destroy(EG(zend_constants));
     164           0 :         free(EG(zend_constants));
     165           0 :         return SUCCESS;
     166             : }
     167             : 
     168             : 
     169       20220 : void clean_non_persistent_constants(TSRMLS_D)
     170             : {
     171       20220 :         if (EG(full_tables_cleanup)) {
     172           0 :                 zend_hash_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant_full TSRMLS_CC);
     173             :         } else {
     174       20220 :                 zend_hash_reverse_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant TSRMLS_CC);
     175             :         }
     176       20220 : }
     177             : 
     178             : 
     179    45506524 : ZEND_API void zend_register_long_constant(const char *name, uint name_len, long lval, int flags, int module_number TSRMLS_DC)
     180             : {
     181             :         zend_constant c;
     182             :         
     183    45506524 :         c.value.type = IS_LONG;
     184    45506524 :         c.value.value.lval = lval;
     185    45506524 :         c.flags = flags;
     186    45506524 :         c.name = zend_strndup(name, name_len-1);
     187    45506524 :         c.name_len = name_len;
     188    45506524 :         c.module_number = module_number;
     189    45506524 :         zend_register_constant(&c TSRMLS_CC);
     190    45506524 : }
     191             : 
     192             : 
     193      384275 : ZEND_API void zend_register_double_constant(const char *name, uint name_len, double dval, int flags, int module_number TSRMLS_DC)
     194             : {
     195             :         zend_constant c;
     196             :         
     197      384275 :         c.value.type = IS_DOUBLE;
     198      384275 :         c.value.value.dval = dval;
     199      384275 :         c.flags = flags;
     200      384275 :         c.name = zend_strndup(name, name_len-1);
     201      384275 :         c.name_len = name_len;
     202      384275 :         c.module_number = module_number;
     203      384275 :         zend_register_constant(&c TSRMLS_CC);
     204      384275 : }
     205             : 
     206             : 
     207     1861009 : ZEND_API void zend_register_stringl_constant(const char *name, uint name_len, char *strval, uint strlen, int flags, int module_number TSRMLS_DC)
     208             : {
     209             :         zend_constant c;
     210             :         
     211     1861009 :         c.value.type = IS_STRING;
     212     1861009 :         c.value.value.str.val = strval;
     213     1861009 :         c.value.value.str.len = strlen;
     214     1861009 :         c.flags = flags;
     215     1861009 :         c.name = zend_strndup(name, name_len-1);
     216     1861009 :         c.name_len = name_len;
     217     1861009 :         c.module_number = module_number;
     218     1861009 :         zend_register_constant(&c TSRMLS_CC);
     219     1861009 : }
     220             : 
     221             : 
     222     1456200 : ZEND_API void zend_register_string_constant(const char *name, uint name_len, char *strval, int flags, int module_number TSRMLS_DC)
     223             : {
     224     1456200 :         zend_register_stringl_constant(name, name_len, strval, strlen(strval), flags, module_number TSRMLS_CC);
     225     1456200 : }
     226             : 
     227        1144 : static int zend_get_special_constant(const char *name, uint name_len, zend_constant **c TSRMLS_DC)
     228             : {
     229             :         int ret;
     230             :         static char haltoff[] = "__COMPILER_HALT_OFFSET__";
     231             : 
     232        1144 :         if (!EG(in_execution)) {
     233         854 :                 return 0;
     234         316 :         } else if (name_len == sizeof("__CLASS__")-1 &&
     235          26 :                   !memcmp(name, "__CLASS__", sizeof("__CLASS__")-1)) {
     236             :                 zend_constant tmp;
     237             : 
     238             :                 /* Returned constants may be cached, so they have to be stored */
     239          18 :                 if (EG(scope) && EG(scope)->name) {
     240             :                         int const_name_len;
     241             :                         char *const_name;
     242             :                         ALLOCA_FLAG(use_heap)
     243             :                         
     244           9 :                         const_name_len = sizeof("\0__CLASS__") + EG(scope)->name_length;
     245           9 :                         const_name = do_alloca(const_name_len, use_heap);
     246           9 :                         memcpy(const_name, "\0__CLASS__", sizeof("\0__CLASS__")-1);
     247           9 :                         zend_str_tolower_copy(const_name + sizeof("\0__CLASS__")-1, EG(scope)->name, EG(scope)->name_length);
     248           9 :                         if (zend_hash_find(EG(zend_constants), const_name, const_name_len, (void**)c) == FAILURE) {
     249           3 :                                 zend_hash_add(EG(zend_constants), const_name, const_name_len, (void*)&tmp, sizeof(zend_constant), (void**)c);
     250           3 :                                 memset(*c, 0, sizeof(zend_constant));
     251           3 :                                 Z_STRVAL((**c).value) = estrndup(EG(scope)->name, EG(scope)->name_length);
     252           3 :                                 Z_STRLEN((**c).value) = EG(scope)->name_length;
     253           3 :                                 Z_TYPE((**c).value) = IS_STRING;
     254             :                         }
     255           9 :                         free_alloca(const_name, use_heap);
     256             :                 } else {
     257           0 :                         if (zend_hash_find(EG(zend_constants), "\0__CLASS__", sizeof("\0__CLASS__"), (void**)c) == FAILURE) {
     258           0 :                                 zend_hash_add(EG(zend_constants), "\0__CLASS__", sizeof("\0__CLASS__"), (void*)&tmp, sizeof(zend_constant), (void**)c);
     259           0 :                                 memset(*c, 0, sizeof(zend_constant));
     260           0 :                                 Z_STRVAL((**c).value) = estrndup("", 0);
     261           0 :                                 Z_STRLEN((**c).value) = 0;
     262           0 :                                 Z_TYPE((**c).value) = IS_STRING;
     263             :                         }
     264             :                 }
     265           9 :                 return 1;
     266         361 :         } else if (name_len == sizeof("__COMPILER_HALT_OFFSET__")-1 &&
     267          80 :                   !memcmp(name, "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1)) {
     268             :                 const char *cfilename;
     269             :                 char *haltname;
     270             :                 int len, clen;
     271             : 
     272          80 :                 cfilename = zend_get_executed_filename(TSRMLS_C);
     273          80 :                 clen = strlen(cfilename);
     274             :                 /* check for __COMPILER_HALT_OFFSET__ */
     275          80 :                 zend_mangle_property_name(&haltname, &len, haltoff,
     276             :                         sizeof("__COMPILER_HALT_OFFSET__") - 1, cfilename, clen, 0);
     277          80 :                 ret = zend_hash_find(EG(zend_constants), haltname, len+1, (void **) c);
     278          80 :                 efree(haltname);
     279          80 :                 return (ret == SUCCESS);
     280             :         } else {
     281         201 :                 return 0;
     282             :         }
     283             : }
     284             : 
     285             : 
     286        1944 : ZEND_API int zend_get_constant(const char *name, uint name_len, zval *result TSRMLS_DC)
     287             : {
     288             :         zend_constant *c;
     289        1944 :         int retval = 1;
     290             :         char *lookup_name;
     291             : 
     292        1944 :         if (zend_hash_find(EG(zend_constants), name, name_len+1, (void **) &c) == FAILURE) {
     293        1075 :                 lookup_name = zend_str_tolower_dup(name, name_len);
     294             : 
     295        1075 :                 if (zend_hash_find(EG(zend_constants), lookup_name, name_len+1, (void **) &c)==SUCCESS) {
     296           0 :                         if (c->flags & CONST_CS) {
     297           0 :                                 retval=0;
     298             :                         }
     299             :                 } else {
     300        1075 :                         retval = zend_get_special_constant(name, name_len, &c TSRMLS_CC);
     301             :                 }
     302        1075 :                 efree(lookup_name);
     303             :         }
     304             : 
     305        1944 :         if (retval) {
     306         945 :                 *result = c->value;
     307             :                 zval_copy_ctor(result);
     308             :                 Z_SET_REFCOUNT_P(result, 1);
     309             :                 Z_UNSET_ISREF_P(result);
     310             :         }
     311             : 
     312        1944 :         return retval;
     313             : }
     314             : 
     315         570 : ZEND_API int zend_get_constant_ex(const char *name, uint name_len, zval *result, zend_class_entry *scope, ulong flags TSRMLS_DC)
     316             : {
     317             :         zend_constant *c;
     318         570 :         int retval = 1;
     319             :         const char *colon;
     320         570 :         zend_class_entry *ce = NULL;
     321             :         char *class_name;
     322             :         zval **ret_constant;
     323             : 
     324             :         /* Skip leading \\ */
     325         570 :         if (name[0] == '\\') {
     326           8 :                 name += 1;
     327           8 :                 name_len -= 1;
     328             :         }
     329             : 
     330             : 
     331         761 :         if ((colon = zend_memrchr(name, ':', name_len)) &&
     332         191 :             colon > name && (*(colon - 1) == ':')) {
     333         191 :                 int class_name_len = colon - name - 1;
     334         191 :                 int const_name_len = name_len - class_name_len - 2;
     335         191 :                 const char *constant_name = colon + 1;
     336             :                 char *lcname;
     337             : 
     338         191 :                 class_name = estrndup(name, class_name_len);
     339         191 :                 lcname = zend_str_tolower_dup(class_name, class_name_len);
     340         191 :                 if (!scope) {
     341         172 :                         if (EG(in_execution)) {
     342         172 :                                 scope = EG(scope);
     343             :                         } else {
     344           0 :                                 scope = CG(active_class_entry);
     345             :                         }
     346             :                 }
     347             : 
     348         306 :                 if (class_name_len == sizeof("self")-1 &&
     349          59 :                     !memcmp(lcname, "self", sizeof("self")-1)) {
     350          56 :                         if (scope) {
     351          56 :                                 ce = scope;
     352             :                         } else {
     353           0 :                                 zend_error(E_ERROR, "Cannot access self:: when no class scope is active");
     354           0 :                                 retval = 0;
     355             :                         }
     356          56 :                         efree(lcname);
     357         163 :                 } else if (class_name_len == sizeof("parent")-1 &&
     358          21 :                            !memcmp(lcname, "parent", sizeof("parent")-1)) {
     359           7 :                         if (!scope) {
     360           0 :                                 zend_error(E_ERROR, "Cannot access parent:: when no class scope is active");
     361           7 :                         } else if (!scope->parent) {
     362           0 :                                 zend_error(E_ERROR, "Cannot access parent:: when current class scope has no parent");
     363             :                         } else {
     364           7 :                                 ce = scope->parent;
     365             :                         }
     366           7 :                         efree(lcname);
     367         147 :                 } else if (class_name_len == sizeof("static")-1 &&
     368          14 :                            !memcmp(lcname, "static", sizeof("static")-1)) {
     369           5 :                         if (EG(called_scope)) {
     370           5 :                                 ce = EG(called_scope);
     371             :                         } else {
     372           0 :                                 zend_error(E_ERROR, "Cannot access static:: when no class scope is active");
     373             :                         }
     374           5 :                         efree(lcname);
     375             :                 } else {
     376         123 :                         efree(lcname);
     377         123 :                         ce = zend_fetch_class(class_name, class_name_len, flags TSRMLS_CC);
     378             :                 }
     379         366 :                 if (retval && ce) {
     380         182 :                         if (zend_hash_find(&ce->constants_table, constant_name, const_name_len+1, (void **) &ret_constant) != SUCCESS) {
     381           6 :                                 retval = 0;
     382           6 :                                 if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
     383           1 :                                         zend_error(E_ERROR, "Undefined class constant '%s::%s'", class_name, constant_name);
     384             :                                 }
     385             :                         }
     386           3 :                 } else if (!ce) {
     387           3 :                         retval = 0;
     388             :                 }
     389         184 :                 efree(class_name);
     390         184 :                 goto finish;
     391             :         }
     392             : 
     393             :         /* non-class constant */
     394         379 :         if ((colon = zend_memrchr(name, '\\', name_len)) != NULL) {
     395             :                 /* compound constant name */
     396          77 :                 int prefix_len = colon - name;
     397          77 :                 int const_name_len = name_len - prefix_len - 1;
     398          77 :                 const char *constant_name = colon + 1;
     399             :                 char *lcname;
     400          77 :                 int found_const = 0;
     401             : 
     402          77 :                 lcname = zend_str_tolower_dup(name, prefix_len);
     403             :                 /* Check for namespace constant */
     404             : 
     405             :                 /* Concatenate lowercase namespace name and constant name */
     406          77 :                 lcname = erealloc(lcname, prefix_len + 1 + const_name_len + 1);
     407          77 :                 lcname[prefix_len] = '\\';
     408          77 :                 memcpy(lcname + prefix_len + 1, constant_name, const_name_len + 1);
     409             : 
     410          77 :                 if (zend_hash_find(EG(zend_constants), lcname, prefix_len + 1 + const_name_len + 1, (void **) &c) == SUCCESS) {
     411          52 :                         found_const = 1;
     412             :                 } else {
     413             :                         /* try lowercase */
     414          25 :                         zend_str_tolower(lcname + prefix_len + 1, const_name_len);
     415          25 :                         if (zend_hash_find(EG(zend_constants), lcname, prefix_len + 1 + const_name_len + 1, (void **) &c) == SUCCESS) {
     416           0 :                                 if ((c->flags & CONST_CS) == 0) {
     417           0 :                                         found_const = 1;
     418             :                                 }
     419             :                         }
     420             :                 }
     421          77 :                 efree(lcname);
     422          77 :                 if(found_const) {
     423          52 :                         *result = c->value;
     424          52 :                         zval_update_constant_ex(&result, (void*)1, NULL TSRMLS_CC);
     425          52 :                         zval_copy_ctor(result);
     426          52 :                         Z_SET_REFCOUNT_P(result, 1);
     427          52 :                         Z_UNSET_ISREF_P(result);
     428          52 :                         return 1;
     429             :                 }
     430             :                 /* name requires runtime resolution, need to check non-namespaced name */
     431          25 :                 if ((flags & IS_CONSTANT_UNQUALIFIED) != 0) {
     432          17 :                         name = constant_name;
     433          17 :                         name_len = const_name_len;
     434          17 :                         return zend_get_constant(name, name_len, result TSRMLS_CC);
     435             :                 }
     436           8 :                 retval = 0;
     437             : finish:
     438         192 :                 if (retval) {
     439         176 :                         zval_update_constant_ex(ret_constant, (void*)1, ce TSRMLS_CC);
     440         174 :                         *result = **ret_constant;
     441         174 :                         zval_copy_ctor(result);
     442         174 :                         INIT_PZVAL(result);
     443             :                 }
     444             : 
     445         190 :                 return retval;
     446             :         }
     447             : 
     448         302 :         return zend_get_constant(name, name_len, result TSRMLS_CC);
     449             : }
     450             : 
     451        3139 : zend_constant *zend_quick_get_constant(const zend_literal *key, ulong flags TSRMLS_DC)
     452             : {
     453             :         zend_constant *c;
     454             : 
     455        3139 :         if (zend_hash_quick_find(EG(zend_constants), Z_STRVAL(key->constant), Z_STRLEN(key->constant) + 1, key->hash_value, (void **) &c) == FAILURE) {
     456         386 :                 key++;
     457         690 :                 if (zend_hash_quick_find(EG(zend_constants), Z_STRVAL(key->constant), Z_STRLEN(key->constant) + 1, key->hash_value, (void **) &c) == FAILURE ||
     458         304 :                     (c->flags & CONST_CS) != 0) {
     459          83 :                         if ((flags & (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) == (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) {
     460          19 :                                 key++;
     461          19 :                                 if (zend_hash_quick_find(EG(zend_constants), Z_STRVAL(key->constant), Z_STRLEN(key->constant) + 1, key->hash_value, (void **) &c) == FAILURE) {
     462           7 :                                     key++;
     463           9 :                                         if (zend_hash_quick_find(EG(zend_constants), Z_STRVAL(key->constant), Z_STRLEN(key->constant) + 1, key->hash_value, (void **) &c) == FAILURE ||
     464           2 :                                             (c->flags & CONST_CS) != 0) {
     465             : 
     466           5 :                                                 key--;
     467           5 :                                                 if (!zend_get_special_constant(Z_STRVAL(key->constant), Z_STRLEN(key->constant), &c TSRMLS_CC)) {
     468           5 :                                                         return NULL;
     469             :                                                 }
     470             :                                         }
     471             :                                 }
     472             :                         } else {
     473          64 :                                 key--;
     474          64 :                                 if (!zend_get_special_constant(Z_STRVAL(key->constant), Z_STRLEN(key->constant), &c TSRMLS_CC)) {
     475          52 :                                         return NULL;
     476             :                                 }
     477             :                         }
     478             :                 }
     479             :         }
     480        3082 :         return c;
     481             : }
     482             : 
     483    47915434 : ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC)
     484             : {
     485    47915434 :         char *lowercase_name = NULL;
     486             :         char *name;
     487    47915434 :         int ret = SUCCESS;
     488    47915434 :         ulong chash = 0;
     489             : 
     490             : #if 0
     491             :         printf("Registering constant for module %d\n", c->module_number);
     492             : #endif
     493             : 
     494    47915434 :         if (!(c->flags & CONST_CS)) {
     495             :                 /* keep in mind that c->name_len already contains the '\0' */
     496     2225186 :                 lowercase_name = estrndup(c->name, c->name_len-1);
     497     2225186 :                 zend_str_tolower(lowercase_name, c->name_len-1);
     498     2225186 :                 lowercase_name = (char*)zend_new_interned_string(lowercase_name, c->name_len, 1 TSRMLS_CC);
     499     2225186 :                 name = lowercase_name;
     500     2225186 :                 chash = IS_INTERNED(lowercase_name) ? INTERNED_HASH(lowercase_name) : 0;
     501             :         } else {
     502    45690248 :                 char *slash = strrchr(c->name, '\\');
     503    45690248 :                 if(slash) {
     504          30 :                         lowercase_name = estrndup(c->name, c->name_len-1);
     505          30 :                         zend_str_tolower(lowercase_name, slash-c->name);
     506          30 :                         lowercase_name = (char*)zend_new_interned_string(lowercase_name, c->name_len, 1 TSRMLS_CC);
     507          30 :                         name = lowercase_name;
     508             :                         
     509          30 :                         chash = IS_INTERNED(lowercase_name) ? INTERNED_HASH(lowercase_name) : 0;
     510             :                 } else {
     511    45690218 :                         name = c->name;
     512             :                 }
     513             :         }
     514    47915434 :         if (chash == 0) {
     515    45690218 :                 chash = zend_hash_func(name, c->name_len);
     516             :         }
     517             : 
     518             :         /* Check if the user is trying to define the internal pseudo constant name __COMPILER_HALT_OFFSET__ */
     519    97185943 :         if ((c->name_len == sizeof("__COMPILER_HALT_OFFSET__")
     520    49270512 :                 && !memcmp(name, "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1))
     521    47915431 :                 || zend_hash_quick_add(EG(zend_constants), name, c->name_len, chash, (void *) c, sizeof(zend_constant), NULL)==FAILURE) {
     522             :                 
     523             :                 /* The internal __COMPILER_HALT_OFFSET__ is prefixed by NULL byte */
     524           8 :                 if (c->name[0] == '\0' && c->name_len > sizeof("\0__COMPILER_HALT_OFFSET__")
     525           0 :                         && memcmp(name, "\0__COMPILER_HALT_OFFSET__", sizeof("\0__COMPILER_HALT_OFFSET__")) == 0) {
     526           0 :                         name++;
     527             :                 }
     528           8 :                 zend_error(E_NOTICE,"Constant %s already defined", name);
     529           8 :                 str_free(c->name);
     530           8 :                 if (!(c->flags & CONST_PERSISTENT)) {
     531           8 :                         zval_dtor(&c->value);
     532             :                 }
     533           8 :                 ret = FAILURE;
     534             :         }
     535    47915434 :         if (lowercase_name && !IS_INTERNED(lowercase_name)) {
     536           0 :                 efree(lowercase_name);
     537             :         }
     538    47915434 :         return ret;
     539             : }
     540             : 
     541             : 
     542             : /*
     543             :  * Local variables:
     544             :  * tab-width: 4
     545             :  * c-basic-offset: 4
     546             :  * indent-tabs-mode: t
     547             :  * End:
     548             :  */

Generated by: LCOV version 1.10

Generated at Tue, 25 Nov 2014 09:10:51 +0000 (2 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.