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

Generated by: LCOV version 1.10

Generated at Sat, 13 Dec 2014 06:16:10 +0000 (6 days ago)

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