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: 223 274 81.4 %
Date: 2015-08-25 Functions: 17 24 70.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2015 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_exceptions.h"
      25             : #include "zend_execute.h"
      26             : #include "zend_variables.h"
      27             : #include "zend_operators.h"
      28             : #include "zend_globals.h"
      29             : #include "zend_API.h"
      30             : 
      31    52644116 : void free_zend_constant(zval *zv)
      32             : {
      33    52644116 :         zend_constant *c = Z_PTR_P(zv);
      34             : 
      35    52644116 :         if (!(c->flags & CONST_PERSISTENT)) {
      36       66530 :                 zval_dtor(&c->value);
      37             :         } else {
      38    52577586 :                 zval_internal_dtor(&c->value);
      39             :         }
      40    52644116 :         if (c->name) {
      41    52644116 :                 zend_string_release(c->name);
      42             :         }
      43    52644116 :         pefree(c, c->flags & CONST_PERSISTENT);
      44    52644116 : }
      45             : 
      46             : 
      47           0 : static void copy_zend_constant(zval *zv)
      48             : {
      49           0 :         zend_constant *c = Z_PTR_P(zv);
      50             : 
      51           0 :         Z_PTR_P(zv) = pemalloc(sizeof(zend_constant), c->flags & CONST_PERSISTENT);
      52           0 :         memcpy(Z_PTR_P(zv), c, sizeof(zend_constant));
      53             : 
      54           0 :         c = Z_PTR_P(zv);
      55           0 :         c->name = zend_string_copy(c->name);
      56           0 :         if (!(c->flags & CONST_PERSISTENT)) {
      57           0 :                 zval_copy_ctor(&c->value);
      58             :         } else {
      59           0 :                 if (Z_TYPE(c->value) == IS_STRING) {
      60           0 :                         Z_STR(c->value) = zend_string_dup(Z_STR(c->value), 1);
      61             :                 }
      62             :         }
      63           0 : }
      64             : 
      65             : 
      66           0 : void zend_copy_constants(HashTable *target, HashTable *source)
      67             : {
      68           0 :         zend_hash_copy(target, source, copy_zend_constant);
      69           0 : }
      70             : 
      71             : 
      72       87810 : static int clean_non_persistent_constant(zval *zv)
      73             : {
      74       87810 :         zend_constant *c = Z_PTR_P(zv);
      75       87810 :         return (c->flags & CONST_PERSISTENT) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
      76             : }
      77             : 
      78             : 
      79           0 : static int clean_non_persistent_constant_full(zval *zv)
      80             : {
      81           0 :         zend_constant *c = Z_PTR_P(zv);
      82           0 :         return (c->flags & CONST_PERSISTENT) ? 0 : 1;
      83             : }
      84             : 
      85             : 
      86           0 : static int clean_module_constant(zval *el, void *arg)
      87             : {
      88           0 :         zend_constant *c = (zend_constant *)Z_PTR_P(el);
      89           0 :         int module_number = *(int *)arg;
      90             : 
      91           0 :         if (c->module_number == module_number) {
      92           0 :                 return 1;
      93             :         } else {
      94           0 :                 return 0;
      95             :         }
      96             : }
      97             : 
      98             : 
      99           0 : void clean_module_constants(int module_number)
     100             : {
     101           0 :         zend_hash_apply_with_argument(EG(zend_constants), clean_module_constant, (void *) &module_number);
     102           0 : }
     103             : 
     104             : 
     105           0 : int zend_startup_constants(void)
     106             : {
     107           0 :         EG(zend_constants) = (HashTable *) malloc(sizeof(HashTable));
     108             : 
     109           0 :         zend_hash_init(EG(zend_constants), 128, NULL, ZEND_CONSTANT_DTOR, 1);
     110           0 :         return SUCCESS;
     111             : }
     112             : 
     113             : 
     114             : 
     115       21285 : void zend_register_standard_constants(void)
     116             : {
     117       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_ERROR", E_ERROR, CONST_PERSISTENT | CONST_CS);
     118       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_RECOVERABLE_ERROR", E_RECOVERABLE_ERROR, CONST_PERSISTENT | CONST_CS);
     119       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_WARNING", E_WARNING, CONST_PERSISTENT | CONST_CS);
     120       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_PARSE", E_PARSE, CONST_PERSISTENT | CONST_CS);
     121       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_NOTICE", E_NOTICE, CONST_PERSISTENT | CONST_CS);
     122       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_STRICT", E_STRICT, CONST_PERSISTENT | CONST_CS);
     123       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_DEPRECATED", E_DEPRECATED, CONST_PERSISTENT | CONST_CS);
     124       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_CORE_ERROR", E_CORE_ERROR, CONST_PERSISTENT | CONST_CS);
     125       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_CORE_WARNING", E_CORE_WARNING, CONST_PERSISTENT | CONST_CS);
     126       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_ERROR", E_COMPILE_ERROR, CONST_PERSISTENT | CONST_CS);
     127       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_WARNING", E_COMPILE_WARNING, CONST_PERSISTENT | CONST_CS);
     128       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_USER_ERROR", E_USER_ERROR, CONST_PERSISTENT | CONST_CS);
     129       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_USER_WARNING", E_USER_WARNING, CONST_PERSISTENT | CONST_CS);
     130       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_USER_NOTICE", E_USER_NOTICE, CONST_PERSISTENT | CONST_CS);
     131       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_USER_DEPRECATED", E_USER_DEPRECATED, CONST_PERSISTENT | CONST_CS);
     132             : 
     133       21285 :         REGISTER_MAIN_LONG_CONSTANT("E_ALL", E_ALL, CONST_PERSISTENT | CONST_CS);
     134             : 
     135       21285 :         REGISTER_MAIN_LONG_CONSTANT("DEBUG_BACKTRACE_PROVIDE_OBJECT", DEBUG_BACKTRACE_PROVIDE_OBJECT, CONST_PERSISTENT | CONST_CS);
     136       21285 :         REGISTER_MAIN_LONG_CONSTANT("DEBUG_BACKTRACE_IGNORE_ARGS", DEBUG_BACKTRACE_IGNORE_ARGS, CONST_PERSISTENT | CONST_CS);
     137             :         /* true/false constants */
     138             :         {
     139       21285 :                 REGISTER_MAIN_BOOL_CONSTANT("TRUE", 1, CONST_PERSISTENT | CONST_CT_SUBST);
     140       21285 :                 REGISTER_MAIN_BOOL_CONSTANT("FALSE", 0, CONST_PERSISTENT | CONST_CT_SUBST);
     141       21285 :                 REGISTER_MAIN_BOOL_CONSTANT("ZEND_THREAD_SAFE", ZTS_V, CONST_PERSISTENT | CONST_CS);
     142       21285 :                 REGISTER_MAIN_BOOL_CONSTANT("ZEND_DEBUG_BUILD", ZEND_DEBUG, CONST_PERSISTENT | CONST_CS);
     143             :         }
     144       21285 :         REGISTER_MAIN_NULL_CONSTANT("NULL", CONST_PERSISTENT | CONST_CT_SUBST);
     145       21285 : }
     146             : 
     147             : 
     148           0 : int zend_shutdown_constants(void)
     149             : {
     150           0 :         zend_hash_destroy(EG(zend_constants));
     151           0 :         free(EG(zend_constants));
     152           0 :         return SUCCESS;
     153             : }
     154             : 
     155             : 
     156       21280 : void clean_non_persistent_constants(void)
     157             : {
     158       21280 :         if (EG(full_tables_cleanup)) {
     159           0 :                 zend_hash_apply(EG(zend_constants), clean_non_persistent_constant_full);
     160             :         } else {
     161       21280 :                 zend_hash_reverse_apply(EG(zend_constants), clean_non_persistent_constant);
     162             :         }
     163       21280 : }
     164             : 
     165       21285 : ZEND_API void zend_register_null_constant(const char *name, size_t name_len, int flags, int module_number)
     166             : {
     167             :         zend_constant c;
     168             : 
     169       21285 :         ZVAL_NULL(&c.value);
     170       21285 :         c.flags = flags;
     171       42570 :         c.name = zend_string_init(name, name_len, flags & CONST_PERSISTENT);
     172       21285 :         c.module_number = module_number;
     173       21285 :         zend_register_constant(&c);
     174       21285 : }
     175             : 
     176       85140 : ZEND_API void zend_register_bool_constant(const char *name, size_t name_len, zend_bool bval, int flags, int module_number)
     177             : {
     178             :         zend_constant c;
     179             : 
     180       85140 :         ZVAL_BOOL(&c.value, bval);
     181       85140 :         c.flags = flags;
     182      170280 :         c.name = zend_string_init(name, name_len, flags & CONST_PERSISTENT);
     183       85140 :         c.module_number = module_number;
     184       85140 :         zend_register_constant(&c);
     185       85140 : }
     186             : 
     187    49977456 : ZEND_API void zend_register_long_constant(const char *name, size_t name_len, zend_long lval, int flags, int module_number)
     188             : {
     189             :         zend_constant c;
     190             : 
     191    49977456 :         ZVAL_LONG(&c.value, lval);
     192    49977456 :         c.flags = flags;
     193    99954912 :         c.name = zend_string_init(name, name_len, flags & CONST_PERSISTENT);
     194    49977456 :         c.module_number = module_number;
     195    49977456 :         zend_register_constant(&c);
     196    49977456 : }
     197             : 
     198             : 
     199      404415 : ZEND_API void zend_register_double_constant(const char *name, size_t name_len, double dval, int flags, int module_number)
     200             : {
     201             :         zend_constant c;
     202             : 
     203      404415 :         ZVAL_DOUBLE(&c.value, dval);
     204      404415 :         c.flags = flags;
     205      808830 :         c.name = zend_string_init(name, name_len, flags & CONST_PERSISTENT);
     206      404415 :         c.module_number = module_number;
     207      404415 :         zend_register_constant(&c);
     208      404415 : }
     209             : 
     210             : 
     211     2000976 : ZEND_API void zend_register_stringl_constant(const char *name, size_t name_len, char *strval, size_t strlen, int flags, int module_number)
     212             : {
     213             :         zend_constant c;
     214             : 
     215     4001952 :         ZVAL_NEW_STR(&c.value, zend_string_init(strval, strlen, flags & CONST_PERSISTENT));
     216     2000976 :         c.flags = flags;
     217     4001952 :         c.name = zend_string_init(name, name_len, flags & CONST_PERSISTENT);
     218     2000976 :         c.module_number = module_number;
     219     2000976 :         zend_register_constant(&c);
     220     2000976 : }
     221             : 
     222             : 
     223     1575090 : ZEND_API void zend_register_string_constant(const char *name, size_t name_len, char *strval, int flags, int module_number)
     224             : {
     225     1575090 :         zend_register_stringl_constant(name, name_len, strval, strlen(strval), flags, module_number);
     226     1575090 : }
     227             : 
     228        1749 : static zend_constant *zend_get_special_constant(const char *name, size_t name_len)
     229             : {
     230             :         zend_constant *c;
     231             :         static char haltoff[] = "__COMPILER_HALT_OFFSET__";
     232             : 
     233        1749 :         if (!EG(current_execute_data)) {
     234         955 :                 return NULL;
     235        1294 :         } else if (name_len == sizeof("__COMPILER_HALT_OFFSET__")-1 &&
     236         500 :                   !memcmp(name, "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1)) {
     237             :                 const char *cfilename;
     238             :                 zend_string *haltname;
     239             :                 size_t clen;
     240             : 
     241         500 :                 cfilename = zend_get_executed_filename();
     242         500 :                 clen = strlen(cfilename);
     243             :                 /* check for __COMPILER_HALT_OFFSET__ */
     244         500 :                 haltname = zend_mangle_property_name(haltoff,
     245             :                         sizeof("__COMPILER_HALT_OFFSET__") - 1, cfilename, clen, 0);
     246        1000 :                 c = zend_hash_find_ptr(EG(zend_constants), haltname);
     247             :                 zend_string_free(haltname);
     248         500 :                 return c;
     249             :         } else {
     250         294 :                 return NULL;
     251             :         }
     252             : }
     253             : 
     254             : 
     255        1158 : ZEND_API zval *zend_get_constant_str(const char *name, size_t name_len)
     256             : {
     257             :         zend_constant *c;
     258             :         ALLOCA_FLAG(use_heap)
     259             : 
     260        2316 :         if ((c = zend_hash_str_find_ptr(EG(zend_constants), name, name_len)) == NULL) {
     261         859 :                 char *lcname = do_alloca(name_len + 1, use_heap);
     262         859 :                 zend_str_tolower_copy(lcname, name, name_len);
     263        1718 :                 if ((c = zend_hash_str_find_ptr(EG(zend_constants), lcname, name_len)) != NULL) {
     264         170 :                         if (c->flags & CONST_CS) {
     265           0 :                                 c = NULL;
     266             :                         }
     267             :                 } else {
     268         689 :                         c = zend_get_special_constant(name, name_len);
     269             :                 }
     270         859 :                 free_alloca(lcname, use_heap);
     271             :         }
     272             : 
     273        1158 :         return c ? &c->value : NULL;
     274             : }
     275             : 
     276        1566 : ZEND_API zval *zend_get_constant(zend_string *name)
     277             : {
     278             :         zend_constant *c;
     279             :         ALLOCA_FLAG(use_heap)
     280             : 
     281        3132 :         if ((c = zend_hash_find_ptr(EG(zend_constants), name)) == NULL) {
     282        1060 :                 char *lcname = do_alloca(ZSTR_LEN(name) + 1, use_heap);
     283        1060 :                 zend_str_tolower_copy(lcname, ZSTR_VAL(name), ZSTR_LEN(name));
     284        2120 :                 if ((c = zend_hash_str_find_ptr(EG(zend_constants), lcname, ZSTR_LEN(name))) != NULL) {
     285           0 :                         if (c->flags & CONST_CS) {
     286           0 :                                 c = NULL;
     287             :                         }
     288             :                 } else {
     289        1060 :                         c = zend_get_special_constant(ZSTR_VAL(name), ZSTR_LEN(name));
     290             :                 }
     291        1060 :                 free_alloca(lcname, use_heap);
     292             :         }
     293             : 
     294        1566 :         return c ? &c->value : NULL;
     295             : }
     296             : 
     297         407 : ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope, zend_ulong flags)
     298             : {
     299             :         zend_constant *c;
     300             :         const char *colon;
     301         407 :         zend_class_entry *ce = NULL;
     302             :         zend_string *class_name;
     303         407 :         const char *name = ZSTR_VAL(cname);
     304         407 :         size_t name_len = ZSTR_LEN(cname);
     305             : 
     306             :         /* Skip leading \\ */
     307         407 :         if (name[0] == '\\') {
     308           8 :                 name += 1;
     309           8 :                 name_len -= 1;
     310           8 :                 cname = NULL;
     311             :         }
     312             : 
     313         546 :         if ((colon = zend_memrchr(name, ':', name_len)) &&
     314         139 :             colon > name && (*(colon - 1) == ':')) {
     315         139 :                 int class_name_len = colon - name - 1;
     316         139 :                 size_t const_name_len = name_len - class_name_len - 2;
     317         278 :                 zend_string *constant_name = zend_string_init(colon + 1, const_name_len, 0);
     318             :                 char *lcname;
     319         139 :                 zval *ret_constant = NULL;
     320             :                 ALLOCA_FLAG(use_heap)
     321             : 
     322         278 :                 class_name = zend_string_init(name, class_name_len, 0);
     323         139 :                 lcname = do_alloca(class_name_len + 1, use_heap);
     324         139 :                 zend_str_tolower_copy(lcname, name, class_name_len);
     325         139 :                 if (!scope) {
     326         130 :                         if (EG(current_execute_data)) {
     327         130 :                                 scope = EG(scope);
     328             :                         } else {
     329           0 :                                 scope = CG(active_class_entry);
     330             :                         }
     331             :                 }
     332             : 
     333         208 :                 if (class_name_len == sizeof("self")-1 &&
     334          36 :                     !memcmp(lcname, "self", sizeof("self")-1)) {
     335          33 :                         if (UNEXPECTED(!scope)) {
     336           0 :                                 zend_throw_error(NULL, "Cannot access self:: when no class scope is active");
     337           0 :                                 return NULL;
     338             :                         }
     339          33 :                         ce = scope;
     340         139 :                 } else if (class_name_len == sizeof("parent")-1 &&
     341          23 :                            !memcmp(lcname, "parent", sizeof("parent")-1)) {
     342          10 :                         if (UNEXPECTED(!scope)) {
     343           0 :                                 zend_throw_error(NULL, "Cannot access parent:: when no class scope is active");
     344           0 :                                 return NULL;
     345          10 :                         } else if (UNEXPECTED(!scope->parent)) {
     346           0 :                                 zend_throw_error(NULL, "Cannot access parent:: when current class scope has no parent");
     347           0 :                                 return NULL;
     348             :                         } else {
     349          10 :                                 ce = scope->parent;
     350             :                         }
     351         114 :                 } else if (class_name_len == sizeof("static")-1 &&
     352          13 :                            !memcmp(lcname, "static", sizeof("static")-1)) {
     353           5 :                         ce = zend_get_called_scope(EG(current_execute_data));
     354           5 :                         if (UNEXPECTED(!ce)) {
     355           0 :                                 zend_throw_error(NULL, "Cannot access static:: when no class scope is active");
     356           0 :                                 return NULL;
     357             :                         }
     358             :                 } else {
     359          91 :                         ce = zend_fetch_class(class_name, flags);
     360             :                 }
     361         133 :                 free_alloca(lcname, use_heap);
     362         133 :                 if (ce) {
     363         130 :                         ret_constant = zend_hash_find(&ce->constants_table, constant_name);
     364         130 :                         if (ret_constant == NULL) {
     365           6 :                                 if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
     366           1 :                                         zend_throw_error(NULL, "Undefined class constant '%s::%s'", ZSTR_VAL(class_name), ZSTR_VAL(constant_name));
     367             :                                         zend_string_release(class_name);
     368             :                                         zend_string_free(constant_name);
     369           1 :                                         return NULL;
     370             :                                 }
     371         124 :                         } else if (Z_ISREF_P(ret_constant)) {
     372          37 :                                 ret_constant = Z_REFVAL_P(ret_constant);
     373             :                         }
     374             :                 }
     375             :                 zend_string_release(class_name);
     376             :                 zend_string_free(constant_name);
     377         132 :                 if (ret_constant && Z_CONSTANT_P(ret_constant)) {
     378           8 :                         if (UNEXPECTED(zval_update_constant_ex(ret_constant, 1, ce) != SUCCESS)) {
     379           5 :                                 return NULL;
     380             :                         }
     381             :                 }
     382         127 :                 return ret_constant;
     383             :         }
     384             : 
     385             :         /* non-class constant */
     386         268 :         if ((colon = zend_memrchr(name, '\\', name_len)) != NULL) {
     387             :                 /* compound constant name */
     388          77 :                 int prefix_len = colon - name;
     389          77 :                 size_t const_name_len = name_len - prefix_len - 1;
     390          77 :                 const char *constant_name = colon + 1;
     391             :                 char *lcname;
     392             :                 size_t lcname_len;
     393             :                 ALLOCA_FLAG(use_heap)
     394             : 
     395          77 :                 lcname_len = prefix_len + 1 + const_name_len;
     396          77 :                 lcname = do_alloca(lcname_len + 1, use_heap);
     397          77 :                 zend_str_tolower_copy(lcname, name, prefix_len);
     398             :                 /* Check for namespace constant */
     399             : 
     400          77 :                 lcname[prefix_len] = '\\';
     401          77 :                 memcpy(lcname + prefix_len + 1, constant_name, const_name_len + 1);
     402             : 
     403         154 :                 if ((c = zend_hash_str_find_ptr(EG(zend_constants), lcname, lcname_len)) == NULL) {
     404             :                         /* try lowercase */
     405          25 :                         zend_str_tolower(lcname + prefix_len + 1, const_name_len);
     406          50 :                         if ((c = zend_hash_str_find_ptr(EG(zend_constants), lcname, lcname_len)) != NULL) {
     407           0 :                                 if ((c->flags & CONST_CS) != 0) {
     408           0 :                                         c = NULL;
     409             :                                 }
     410             :                         }
     411             :                 }
     412          77 :                 free_alloca(lcname, use_heap);
     413          77 :                 if (c) {
     414          52 :                         return &c->value;
     415             :                 }
     416             :                 /* name requires runtime resolution, need to check non-namespaced name */
     417          25 :                 if ((flags & IS_CONSTANT_UNQUALIFIED) != 0) {
     418          17 :                         return zend_get_constant_str(constant_name, const_name_len);
     419             :                 }
     420           8 :                 return NULL;
     421             :         }
     422             : 
     423         191 :         if (cname) {
     424         190 :                 return zend_get_constant(cname);
     425             :         } else {
     426           1 :                 return zend_get_constant_str(name, name_len);
     427             :         }
     428             : }
     429             : 
     430        3468 : zend_constant *zend_quick_get_constant(const zval *key, zend_ulong flags)
     431             : {
     432             :         zend_constant *c;
     433             : 
     434        6936 :         if ((c = zend_hash_find_ptr(EG(zend_constants), Z_STR_P(key))) == NULL) {
     435         305 :                 key++;
     436         832 :                 if ((c = zend_hash_find_ptr(EG(zend_constants), Z_STR_P(key))) == NULL ||
     437         222 :                     (c->flags & CONST_CS) != 0) {
     438          84 :                         if ((flags & (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) == (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) {
     439          14 :                                 key++;
     440          28 :                                 if ((c = zend_hash_find_ptr(EG(zend_constants), Z_STR_P(key))) == NULL) {
     441           5 :                                     key++;
     442          10 :                                         if ((c = zend_hash_find_ptr(EG(zend_constants), Z_STR_P(key))) == NULL ||
     443           0 :                                             (c->flags & CONST_CS) != 0) {
     444             : 
     445           5 :                                                 key--;
     446           5 :                                                 c = NULL;
     447             :                                         }
     448             :                                 }
     449             :                         } else {
     450          70 :                                 key--;
     451          70 :                                 c = NULL;
     452             :                         }
     453             :                 }
     454             :         }
     455        3468 :         return c;
     456             : }
     457             : 
     458    52555222 : static void* zend_hash_add_constant(HashTable *ht, zend_string *key, zend_constant *c)
     459             : {
     460             :         void *ret;
     461   105110444 :         zend_constant *copy = pemalloc(sizeof(zend_constant), c->flags & CONST_PERSISTENT);
     462             : 
     463    52555222 :         memcpy(copy, c, sizeof(zend_constant));
     464    52555222 :         ret = zend_hash_add_ptr(ht, key, copy);
     465    52555222 :         if (!ret) {
     466           5 :                 pefree(copy, c->flags & CONST_PERSISTENT);
     467             :         }
     468    52555222 :         return ret;
     469             : }
     470             : 
     471    52555225 : ZEND_API int zend_register_constant(zend_constant *c)
     472             : {
     473    52555225 :         zend_string *lowercase_name = NULL;
     474             :         zend_string *name;
     475    52555225 :         int ret = SUCCESS;
     476             : 
     477             : #if 0
     478             :         printf("Registering constant for module %d\n", c->module_number);
     479             : #endif
     480             : 
     481    52555225 :         if (!(c->flags & CONST_CS)) {
     482     1873706 :                 lowercase_name = zend_string_alloc(ZSTR_LEN(c->name), c->flags & CONST_PERSISTENT);
     483      936853 :                 zend_str_tolower_copy(ZSTR_VAL(lowercase_name), ZSTR_VAL(c->name), ZSTR_LEN(c->name));
     484      936853 :                 lowercase_name = zend_new_interned_string(lowercase_name);
     485      936853 :                 name = lowercase_name;
     486             :         } else {
     487    51618372 :                 char *slash = strrchr(ZSTR_VAL(c->name), '\\');
     488    51618372 :                 if (slash) {
     489          98 :                         lowercase_name = zend_string_init(ZSTR_VAL(c->name), ZSTR_LEN(c->name), c->flags & CONST_PERSISTENT);
     490          49 :                         zend_str_tolower(ZSTR_VAL(lowercase_name), slash - ZSTR_VAL(c->name));
     491          49 :                         lowercase_name = zend_new_interned_string(lowercase_name);
     492          49 :                         name = lowercase_name;
     493             :                 } else {
     494    51618323 :                         name = c->name;
     495             :                 }
     496             :         }
     497             : 
     498             :         /* Check if the user is trying to define the internal pseudo constant name __COMPILER_HALT_OFFSET__ */
     499   159134379 :         if ((ZSTR_LEN(c->name) == sizeof("__COMPILER_HALT_OFFSET__")-1
     500    54023932 :                 && !memcmp(ZSTR_VAL(name), "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1))
     501    52555222 :                 || zend_hash_add_constant(EG(zend_constants), name, c) == NULL) {
     502             : 
     503             :                 /* The internal __COMPILER_HALT_OFFSET__ is prefixed by NULL byte */
     504           8 :                 if (ZSTR_VAL(c->name)[0] == '\0' && ZSTR_LEN(c->name) > sizeof("\0__COMPILER_HALT_OFFSET__")-1
     505           0 :                         && memcmp(ZSTR_VAL(name), "\0__COMPILER_HALT_OFFSET__", sizeof("\0__COMPILER_HALT_OFFSET__")) == 0) {
     506             :                 }
     507           8 :                 zend_error(E_NOTICE,"Constant %s already defined", ZSTR_VAL(name));
     508           8 :                 zend_string_release(c->name);
     509           8 :                 if (!(c->flags & CONST_PERSISTENT)) {
     510           8 :                         zval_dtor(&c->value);
     511             :                 }
     512           8 :                 ret = FAILURE;
     513             :         }
     514    52555225 :         if (lowercase_name) {
     515             :                 zend_string_release(lowercase_name);
     516             :         }
     517    52555225 :         return ret;
     518             : }
     519             : 
     520             : 
     521             : /*
     522             :  * Local variables:
     523             :  * tab-width: 4
     524             :  * c-basic-offset: 4
     525             :  * indent-tabs-mode: t
     526             :  * End:
     527             :  */

Generated by: LCOV version 1.10

Generated at Tue, 25 Aug 2015 07:24:15 +0000 (4 days ago)

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