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

Generated by: LCOV version 1.10

Generated at Mon, 04 Aug 2014 15:49:01 +0000 (45 days ago)

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