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

LTP GCOV extension - code coverage report
Current view: directory - var/php_gcov/PHP_HEAD/Zend - zend_constants.c
Test: PHP Code Coverage
Date: 2009-11-23 Instrumented lines: 315
Code covered: 81.0 % Executed lines: 255
Legend: not executed executed

       1                 : /*
       2                 :    +----------------------------------------------------------------------+
       3                 :    | Zend Engine                                                          |
       4                 :    +----------------------------------------------------------------------+
       5                 :    | Copyright (c) 1998-2009 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: zend_constants.c 277848 2009-03-26 22:16:48Z felipe $ */
      21                 : 
      22                 : #include "zend.h"
      23                 : #include "zend_constants.h"
      24                 : #include "zend_execute.h"
      25                 : #include "zend_variables.h"
      26                 : #include "zend_operators.h"
      27                 : #include "zend_globals.h"
      28                 : 
      29                 : void free_zend_constant(zend_constant *c) /* {{{ */
      30               0 : {
      31               0 :         if (!(c->flags & CONST_PERSISTENT)) {
      32               0 :                 zval_dtor(&c->value);
      33                 :         }
      34               0 :         free(c->name.v);
      35               0 : }
      36                 : /* }}} */
      37                 : 
      38                 : void copy_zend_constant(zend_constant *c) /* {{{ */
      39               0 : {
      40               0 :         c->name.u = zend_ustrndup(c->name.u, c->name_len - 1);
      41                 : 
      42               0 :         if (!(c->flags & CONST_PERSISTENT)) {
      43               0 :                 zval_copy_ctor(&c->value);
      44                 :         }
      45               0 : }
      46                 : /* }}} */
      47                 : 
      48                 : void zend_copy_constants(HashTable *target, HashTable *source) /* {{{ */
      49               0 : {
      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                 : static int clean_non_persistent_constant(const zend_constant *c TSRMLS_DC) /* {{{ */
      57           69734 : {
      58           69734 :         return (c->flags & CONST_PERSISTENT) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
      59                 : }
      60                 : /* }}} */
      61                 : 
      62                 : static int clean_non_persistent_constant_full(const zend_constant *c TSRMLS_DC) /* {{{ */
      63               0 : {
      64               0 :         return (c->flags & CONST_PERSISTENT) ? 0 : 1;
      65                 : }
      66                 : /* }}} */
      67                 : 
      68                 : static int clean_module_constant(const zend_constant *c, int *module_number TSRMLS_DC) /* {{{ */
      69               0 : {
      70               0 :         if (c->module_number == *module_number) {
      71               0 :                 return 1;
      72                 :         } else {
      73               0 :                 return 0;
      74                 :         }
      75                 : }
      76                 : /* }}} */
      77                 : 
      78                 : void clean_module_constants(int module_number TSRMLS_DC) /* {{{ */
      79               0 : {
      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                 : int zend_startup_constants(TSRMLS_D) /* {{{ */
      85               0 : {
      86               0 :         EG(zend_constants) = (HashTable *) malloc(sizeof(HashTable));
      87                 : 
      88               0 :         if (zend_u_hash_init(EG(zend_constants), 20, NULL, ZEND_CONSTANT_DTOR, 1, UG(unicode))==FAILURE) {
      89               0 :                 return FAILURE;
      90                 :         }
      91               0 :         return SUCCESS;
      92                 : }
      93                 : /* }}} */
      94                 : 
      95                 : void zend_register_standard_constants(TSRMLS_D) /* {{{ */
      96           17007 : {
      97           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_ERROR", E_ERROR, CONST_PERSISTENT | CONST_CS);
      98           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_RECOVERABLE_ERROR", E_RECOVERABLE_ERROR, CONST_PERSISTENT | CONST_CS);
      99           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_WARNING", E_WARNING, CONST_PERSISTENT | CONST_CS);
     100           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_PARSE", E_PARSE, CONST_PERSISTENT | CONST_CS);
     101           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_NOTICE", E_NOTICE, CONST_PERSISTENT | CONST_CS);
     102           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_STRICT", E_STRICT, CONST_PERSISTENT | CONST_CS);
     103           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_DEPRECATED", E_DEPRECATED, CONST_PERSISTENT | CONST_CS);
     104           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_CORE_ERROR", E_CORE_ERROR, CONST_PERSISTENT | CONST_CS);
     105           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_CORE_WARNING", E_CORE_WARNING, CONST_PERSISTENT | CONST_CS);
     106           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_ERROR", E_COMPILE_ERROR, CONST_PERSISTENT | CONST_CS);
     107           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_WARNING", E_COMPILE_WARNING, CONST_PERSISTENT | CONST_CS);
     108           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_USER_ERROR", E_USER_ERROR, CONST_PERSISTENT | CONST_CS);
     109           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_USER_WARNING", E_USER_WARNING, CONST_PERSISTENT | CONST_CS);
     110           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_USER_NOTICE", E_USER_NOTICE, CONST_PERSISTENT | CONST_CS);
     111           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_USER_DEPRECATED", E_USER_DEPRECATED, CONST_PERSISTENT | CONST_CS);
     112                 : 
     113           17007 :         REGISTER_MAIN_LONG_CONSTANT("E_ALL", E_ALL, CONST_PERSISTENT | CONST_CS);
     114                 : 
     115           17007 :         REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_STOP", ZEND_CONV_ERROR_STOP, CONST_PERSISTENT | CONST_CS);
     116           17007 :         REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_SKIP", ZEND_CONV_ERROR_SKIP, CONST_PERSISTENT | CONST_CS);
     117           17007 :         REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_SUBST", ZEND_CONV_ERROR_SUBST, CONST_PERSISTENT | CONST_CS);
     118           17007 :         REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_ESCAPE_UNICODE", ZEND_CONV_ERROR_ESCAPE_UNICODE, CONST_PERSISTENT | CONST_CS);
     119           17007 :         REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_ESCAPE_ICU", ZEND_CONV_ERROR_ESCAPE_ICU, CONST_PERSISTENT | CONST_CS);
     120           17007 :         REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_ESCAPE_JAVA", ZEND_CONV_ERROR_ESCAPE_JAVA, CONST_PERSISTENT | CONST_CS);
     121           17007 :         REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_ESCAPE_XML_DEC", ZEND_CONV_ERROR_ESCAPE_XML_DEC, CONST_PERSISTENT | CONST_CS);
     122           17007 :         REGISTER_MAIN_LONG_CONSTANT("U_CONV_ERROR_ESCAPE_XML_HEX", ZEND_CONV_ERROR_ESCAPE_XML_HEX, CONST_PERSISTENT | CONST_CS);
     123                 : 
     124           17007 :         REGISTER_MAIN_LONG_CONSTANT("FROM_UNICODE", ZEND_FROM_UNICODE, CONST_PERSISTENT | CONST_CS);
     125           17007 :         REGISTER_MAIN_LONG_CONSTANT("TO_UNICODE", ZEND_TO_UNICODE, CONST_PERSISTENT | CONST_CS);
     126                 : 
     127                 :         /* true/false constants */
     128                 :         {
     129                 :                 zend_constant c;
     130                 : 
     131           17007 :                 Z_TYPE(c.value) = IS_BOOL;
     132           17007 :                 c.flags = CONST_PERSISTENT | CONST_CT_SUBST;
     133           17007 :                 c.module_number = 0;
     134                 : 
     135           17007 :                 c.name.s = zend_strndup(ZEND_STRL("TRUE"));
     136           17007 :                 c.name_len = sizeof("TRUE");
     137           17007 :                 Z_LVAL(c.value) = 1;
     138           17007 :                 Z_TYPE(c.value) = IS_BOOL;
     139           17007 :                 zend_register_constant(&c TSRMLS_CC);
     140                 : 
     141           17007 :                 c.name.s = zend_strndup(ZEND_STRL("FALSE"));
     142           17007 :                 c.name_len = sizeof("FALSE");
     143           17007 :                 Z_LVAL(c.value) = 0;
     144           17007 :                 Z_TYPE(c.value) = IS_BOOL;
     145           17007 :                 zend_register_constant(&c TSRMLS_CC);
     146                 : 
     147           17007 :                 c.name.s = zend_strndup(ZEND_STRL("NULL"));
     148           17007 :                 c.name_len = sizeof("NULL");
     149           17007 :                 Z_TYPE(c.value) = IS_NULL;
     150           17007 :                 zend_register_constant(&c TSRMLS_CC);
     151                 : 
     152           17007 :                 c.flags = CONST_PERSISTENT;
     153                 : 
     154           17007 :                 c.name.s = zend_strndup(ZEND_STRL("ZEND_THREAD_SAFE"));
     155           17007 :                 c.name_len = sizeof("ZEND_THREAD_SAFE");
     156           17007 :                 Z_LVAL(c.value) = ZTS_V;
     157           17007 :                 Z_TYPE(c.value) = IS_BOOL;
     158           17007 :                 zend_register_constant(&c TSRMLS_CC);
     159                 : 
     160           17007 :                 c.name.s = zend_strndup(ZEND_STRL("ZEND_DEBUG_BUILD"));
     161           17007 :                 c.name_len = sizeof("ZEND_DEBUG_BUILD");
     162           17007 :                 Z_LVAL(c.value) = ZEND_DEBUG;
     163           17007 :                 Z_TYPE(c.value) = IS_BOOL;
     164           17007 :                 zend_register_constant(&c TSRMLS_CC);
     165                 :         }
     166           17007 : }
     167                 : /* }}} */
     168                 : 
     169                 : int zend_shutdown_constants(TSRMLS_D) /* {{{ */
     170               0 : {
     171               0 :         zend_hash_destroy(EG(zend_constants));
     172               0 :         free(EG(zend_constants));
     173               0 :         return SUCCESS;
     174                 : }
     175                 : /* }}} */
     176                 : 
     177                 : void clean_non_persistent_constants(TSRMLS_D) /* {{{ */
     178           17025 : {
     179           17025 :         if (EG(full_tables_cleanup)) {
     180               0 :                 zend_hash_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant_full TSRMLS_CC);
     181                 :         } else {
     182           17025 :                 zend_hash_reverse_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant TSRMLS_CC);
     183                 :         }
     184           17025 : }
     185                 : /* }}} */
     186                 : 
     187                 : ZEND_API void zend_register_long_constant(const char *name, uint name_len, long lval, int flags, int module_number TSRMLS_DC) /* {{{ */
     188        32245542 : {
     189                 :         zend_constant c;
     190                 : 
     191        32245542 :         c.name.u = malloc(UBYTES(name_len));
     192        32245542 :         u_charsToUChars(name, c.name.u, name_len);
     193        32245542 :         c.name_len = name_len;
     194                 : 
     195        32245542 :         Z_TYPE(c.value) = IS_LONG;
     196        32245542 :         Z_LVAL(c.value) = lval;
     197        32245542 :         c.flags = flags;
     198        32245542 :         c.module_number = module_number;
     199        32245542 :         zend_u_register_constant(IS_UNICODE, &c TSRMLS_CC);
     200        32245542 : }
     201                 : /* }}} */
     202                 : 
     203                 : ZEND_API void zend_register_double_constant(const char *name, uint name_len, double dval, int flags, int module_number TSRMLS_DC) /* {{{ */
     204          323133 : {
     205                 :         zend_constant c;
     206                 : 
     207          323133 :         c.name.u = malloc(UBYTES(name_len));
     208          323133 :         u_charsToUChars(name, c.name.u, name_len);
     209          323133 :         c.name_len = name_len;
     210                 : 
     211          323133 :         Z_TYPE(c.value) = IS_DOUBLE;
     212          323133 :         Z_DVAL(c.value) = dval;
     213          323133 :         c.flags = flags;
     214          323133 :         c.module_number = module_number;
     215          323133 :         zend_u_register_constant(IS_UNICODE, &c TSRMLS_CC);
     216          323133 : }
     217                 : /* }}} */
     218                 : 
     219                 : ZEND_API void zend_register_stringl_constant(const char *name, uint name_len, char *strval, uint strlen, int flags, int module_number TSRMLS_DC) /* {{{ */
     220         1360801 : {
     221                 :         zend_constant c;
     222                 : 
     223         1360801 :         c.name.u = malloc(UBYTES(name_len));
     224         1360801 :         u_charsToUChars(name, c.name.u, name_len);
     225         1360801 :         c.name_len = name_len;
     226         1360801 :         Z_TYPE(c.value) = IS_UNICODE;
     227         1360801 :         if (flags & CONST_PERSISTENT) {
     228         1360560 :                 Z_USTRVAL(c.value) = malloc(UBYTES(strlen+1));
     229                 :         } else {
     230             241 :                 Z_USTRVAL(c.value) = emalloc(UBYTES(strlen+1));
     231                 :         }
     232         1360801 :         u_charsToUChars(strval, Z_USTRVAL(c.value), strlen+1);
     233         1360801 :         Z_USTRLEN(c.value) = strlen;
     234         1360801 :         if (!(flags & CONST_PERSISTENT)) {
     235             241 :                 efree(strval);
     236                 :         }
     237                 :         
     238         1360801 :         c.flags = flags;
     239         1360801 :         c.module_number = module_number;
     240         1360801 :         zend_u_register_constant(IS_UNICODE, &c TSRMLS_CC);
     241         1360801 : }
     242                 : /* }}} */
     243                 : 
     244                 : ZEND_API void zend_register_string_constant(const char *name, uint name_len, char *strval, int flags, int module_number TSRMLS_DC) /* {{{ */
     245         1088448 : {
     246         1088448 :         zend_register_stringl_constant(name, name_len, strval, strlen(strval), flags, module_number TSRMLS_CC);
     247         1088448 : }
     248                 : /* }}} */
     249                 : 
     250                 : ZEND_API int zend_u_get_constant(zend_uchar type, zstr name, uint name_len, zval *result TSRMLS_DC) /* {{{ */
     251           49294 : {
     252                 :         zend_constant *c;
     253           49294 :         int retval = 1;
     254                 :         zstr lookup_name;
     255                 : 
     256           49294 :         if (zend_u_hash_find(EG(zend_constants), type, name, name_len+1, (void **) &c) == FAILURE) {
     257                 :                 unsigned int lookup_name_len;
     258                 : 
     259           34967 :                 lookup_name = zend_u_str_case_fold(type, name, name_len, 1, &lookup_name_len);
     260                 : 
     261           34967 :                 if (zend_u_hash_find(EG(zend_constants), type, lookup_name, lookup_name_len+1, (void **) &c)==SUCCESS) {
     262             250 :                         if (c->flags & CONST_CS) {
     263               0 :                                 retval=0;
     264                 :                         }
     265                 :                 } else {
     266           34717 :                         if (!EG(in_execution)) {
     267           34390 :                                 retval = 0;
     268             403 :                         } else if (name_len == sizeof(ZEND_HALT_CONSTANT_NAME)-1 && ZEND_U_EQUAL(type, name, name_len, ZEND_HALT_CONSTANT_NAME, sizeof(ZEND_HALT_CONSTANT_NAME)-1)) {
     269                 :                                 char *cfilename;
     270                 :                                 zstr haltname;
     271                 :                                 int len, clen;
     272              76 :                                 cfilename = zend_get_executed_filename(TSRMLS_C);
     273              76 :                                 clen = strlen(cfilename);
     274                 :                                 /* check for __COMPILER_HALT_OFFSET__ */
     275              76 :                                 zend_mangle_property_name(&haltname.s, &len, ZEND_HALT_CONSTANT_NAME,
     276                 :                                         sizeof(ZEND_HALT_CONSTANT_NAME) - 1, cfilename, clen, 0);
     277              76 :                                 if (zend_u_hash_find(EG(zend_constants), IS_STRING, haltname, len+1, (void **) &c) == SUCCESS) {
     278              75 :                                         retval=1;
     279                 :                                 } else {
     280               1 :                                         retval=0;
     281                 :                                 }
     282              76 :                                 pefree(haltname.s, 0);
     283                 :                         } else {
     284             251 :                                 retval=0;
     285                 :                         }
     286                 :                 }
     287           34967 :                 efree(lookup_name.v);
     288                 :         }
     289                 : 
     290           49294 :         if (retval) {
     291           14652 :                 *result = c->value;
     292           14652 :                 zval_copy_ctor(result);
     293           14652 :                 Z_SET_REFCOUNT_P(result, 1);
     294           14652 :                 Z_UNSET_ISREF_P(result);
     295                 :         }
     296                 : 
     297           49294 :         return retval;
     298                 : }
     299                 : /* }}} */
     300                 : 
     301                 : ZEND_API int zend_u_get_constant_ex(zend_uchar type, zstr name, uint name_len, zval *result, zend_class_entry *scope, ulong flags TSRMLS_DC) /* {{{ */
     302           49555 : {
     303                 :         zend_constant *c;
     304           49555 :         int retval = 1;
     305                 :         zstr colon;
     306           49555 :         zend_class_entry *ce = NULL;
     307                 :         zval **ret_constant;
     308                 : 
     309                 :         /* Skip leading \ */
     310           49563 :         if (type == IS_UNICODE &&
     311                 :             name.u[0] == '\\') {
     312               8 :                 name.u += 1;
     313               8 :                 name_len -= 1;
     314           49547 :         } else if (type == IS_STRING &&
     315                 :                    name.s[0] == '\\') {
     316               0 :                 name.s += 1;
     317               0 :                 name_len -= 1;
     318                 :         }
     319                 : 
     320           49555 :         if ((type == IS_UNICODE && (colon.u = u_memrchr(name.u, ':', name_len)) && colon.u > name.u && *(colon.u-1) == ':') ||
     321                 :             (!type == IS_STRING && (colon.s = zend_memrchr(name.s, ':', name_len))&& colon.s > name.s && *(colon.s-1) == ':')) {
     322                 :                 /* compound constant name */
     323             150 :                 int class_name_len = (type == IS_UNICODE) ? colon.u-name.u-1 : colon.s-name.s-1;
     324             150 :                 int const_name_len = name_len - class_name_len - 2;
     325                 :                 zstr constant_name, class_name;
     326                 :                 zstr lcname;
     327                 :                 unsigned int lcname_len;
     328                 : 
     329             150 :                 if (type == IS_UNICODE) {
     330             150 :                         constant_name.u = colon.u + 1;
     331                 :                 } else {
     332               0 :                         constant_name.s = colon.s + 1;
     333                 :                 }
     334                 : 
     335             150 :                 if (!scope) {
     336             132 :                         if (EG(in_execution)) {
     337             132 :                                 scope = EG(scope);
     338                 :                         } else {
     339               0 :                                 scope = CG(active_class_entry);
     340                 :                         }
     341                 :                 }
     342                 : 
     343             150 :                 if (type == IS_UNICODE) {
     344             150 :                         class_name.u = eustrndup(name.u, class_name_len);
     345                 :                 } else {
     346               0 :                         class_name.s = estrndup(name.s, class_name_len);
     347                 :                 }
     348                 : 
     349             150 :                 lcname = zend_u_str_case_fold(type, class_name, class_name_len, 0, &lcname_len);
     350                 : 
     351             199 :                 if (lcname_len == sizeof("self")-1 &&
     352                 :                     ZEND_U_EQUAL(type, lcname, lcname_len, "self", sizeof("self")-1)) {
     353              49 :                         if (scope) {
     354              49 :                                 ce = scope;
     355                 :                         } else {
     356               0 :                                 zend_error(E_ERROR, "Cannot access self:: when no class scope is active");
     357               0 :                                 retval = 0;
     358                 :                         }
     359              49 :                         efree(lcname.v);
     360             107 :                 } else if (lcname_len == sizeof("parent")-1 &&
     361                 :                            ZEND_U_EQUAL(type, lcname, lcname_len, "parent", sizeof("parent")-1)) {
     362               6 :                         efree(lcname.v);
     363               6 :                         if (!scope) {
     364               0 :                                 zend_error(E_ERROR, "Cannot access parent:: when no class scope is active");
     365               6 :                         } else if (!scope->parent) {
     366               0 :                                 zend_error(E_ERROR, "Cannot access parent:: when current class scope has no parent");
     367                 :                         } else {
     368               6 :                                 ce = scope->parent;
     369                 :                         }
     370             100 :                 } else if (lcname_len == sizeof("static")-1 &&
     371                 :                            ZEND_U_EQUAL(type, lcname, lcname_len, "static", sizeof("static")-1)) {
     372               5 :                         efree(lcname.v);
     373               5 :                         if (EG(called_scope)) {
     374               5 :                                 ce = EG(called_scope);
     375                 :                         } else {
     376               0 :                                 zend_error(E_ERROR, "Cannot access static:: when no class scope is active");
     377                 :                         }
     378                 :                 } else {
     379              90 :                         efree(lcname.v);
     380              90 :                         ce = zend_u_fetch_class(type, class_name, class_name_len, flags TSRMLS_CC);
     381                 :                 }
     382                 : 
     383             283 :                 if (retval && ce) {
     384             141 :                         if (zend_u_hash_find(&ce->constants_table, type, constant_name, const_name_len+1, (void **) &ret_constant) != SUCCESS) {
     385               5 :                                 retval = 0;
     386               5 :                                 if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
     387               1 :                                         zend_error(E_ERROR, "Undefined class constant '%R::%R'", type, class_name, type, constant_name);
     388                 :                                 }
     389                 :                         }
     390               2 :                 } else if (!ce) {
     391               2 :                         retval = 0;
     392                 :                 }
     393             142 :                 efree(class_name.v);
     394             142 :                 goto finish;
     395                 :         }
     396                 :         /* non-class constant */
     397           49405 :         if(type == IS_UNICODE) {
     398           49247 :                 colon.u = u_memrchr(name.u, '\\', name_len);
     399                 :         } else {
     400             158 :                 colon.s = zend_memrchr(name.s, '\\', name_len);
     401                 :         }
     402           49405 :         if(colon.v != NULL) {
     403                 :                 /* compound constant name */
     404                 :                 zstr lcname, constant_name;
     405                 :                 unsigned int lcname_len, prefix_len, const_name_len;
     406             148 :                 int found_const = 0;
     407                 : 
     408             148 :                 if(type == IS_UNICODE) {
     409             148 :                         prefix_len = colon.u - name.u;
     410             148 :                         constant_name.u = colon.u+1;
     411                 :                 } else {
     412               0 :                         prefix_len = colon.s - name.s;
     413               0 :                         constant_name.s = colon.s+1;
     414                 :                 }
     415             148 :                 const_name_len = name_len - prefix_len - 1;
     416                 : 
     417             148 :                 lcname = zend_u_str_case_fold(type, name, prefix_len, 0, &lcname_len);
     418                 : 
     419             148 :                 if(type == IS_UNICODE) {
     420             148 :                         lcname.u = erealloc(lcname.u, UBYTES(const_name_len + 1 + lcname_len + 1));
     421             148 :                         lcname.u[lcname_len] = '\\';
     422             148 :                         memcpy(lcname.u+lcname_len+1, constant_name.u, UBYTES(const_name_len + 1));
     423                 :                 } else {
     424               0 :                         lcname.s = erealloc(lcname.s, const_name_len + 1 + lcname_len + 1);
     425               0 :                         lcname.s[lcname_len] = '\\';
     426               0 :                         memcpy(lcname.s+lcname_len+1, constant_name.s, const_name_len + 1);
     427                 :                 }
     428                 : 
     429             148 :                 if (zend_u_hash_find(EG(zend_constants), type, lcname, const_name_len + 1 + lcname_len + 1, (void **) &c) == SUCCESS) {
     430              97 :                         found_const = 1;
     431                 :                 } else {
     432                 :                         /* try lowercase */
     433              51 :                         efree(lcname.v);
     434              51 :                         lcname = zend_u_str_case_fold(type, name, name_len, 0, &lcname_len);
     435              51 :                         if (zend_u_hash_find(EG(zend_constants), type, lcname, lcname_len + 1, (void **) &c) == SUCCESS) {
     436               4 :                                 if ((c->flags & CONST_CS) == 0) {
     437               3 :                                         found_const = 1;
     438                 :                                 }
     439                 :                         }
     440                 :                 }
     441             148 :                 efree(lcname.v);
     442             148 :                 if(found_const) {
     443             100 :                         *result = c->value;
     444             100 :                         zval_update_constant_ex(&result, (void*)1, NULL TSRMLS_CC);
     445             100 :                         zval_copy_ctor(result);
     446             100 :                         Z_SET_REFCOUNT_P(result, 1);
     447             100 :                         Z_UNSET_ISREF_P(result);
     448             100 :                         return 1;
     449                 :                 }
     450                 :                 /* name requires runtime resolution, need to check non-namespaced name */
     451              48 :                 if ((flags & IS_CONSTANT_UNQUALIFIED) != 0) {
     452              37 :                         name = constant_name;
     453              37 :                         name_len = const_name_len;
     454              37 :                         return zend_u_get_constant(type, name, name_len, result TSRMLS_CC);
     455                 :                 }
     456              11 :                 retval = 0;
     457             153 : finish:
     458             153 :                 if (retval) {
     459             136 :                         zval_update_constant_ex(ret_constant, (void*)1, ce TSRMLS_CC);
     460             134 :                         *result = **ret_constant;
     461             134 :                         zval_copy_ctor(result);
     462             134 :                         INIT_PZVAL(result);
     463                 :                 }
     464                 : 
     465             151 :                 return retval;
     466                 :         }
     467                 : 
     468           49257 :         return zend_u_get_constant(type, name, name_len, result TSRMLS_CC);
     469                 : }
     470                 : /* }}} */
     471                 : 
     472                 : ZEND_API int zend_get_constant(const char *name, uint name_len, zval *result TSRMLS_DC) /* {{{ */
     473             158 : {
     474             158 :         return zend_u_get_constant_ex(IS_STRING, ZSTR(name), name_len, result, NULL, 0 TSRMLS_CC);
     475                 : }
     476                 : /* }}} */
     477                 : 
     478                 : ZEND_API int zend_u_register_constant(zend_uchar type, zend_constant *c TSRMLS_DC) /* {{{ */
     479        34066722 : {
     480                 :         unsigned int  lookup_name_len;
     481                 :         zstr lookup_name;
     482                 :         zstr name;
     483        34066722 :         int ret = SUCCESS;
     484                 : 
     485                 : #if 0
     486                 :         printf("Registering constant for module %d\n", c->module_number);
     487                 : #endif
     488                 : 
     489        34066722 :         if (!(c->flags & CONST_CS)) {
     490                 :                 /* keep in mind that c->name_len already contains the '\0' */
     491          782689 :                 name = lookup_name = zend_u_str_case_fold(type, c->name, c->name_len-1, 1, &lookup_name_len);
     492          782689 :                 lookup_name_len++;
     493                 :         } else {
     494                 :                 zstr slash, const_name;
     495                 :                 unsigned int lcname_len, prefix_len, const_name_len;
     496                 : 
     497        33284033 :                 if(type == IS_UNICODE) {
     498        33284033 :                         slash.u = u_memrchr(c->name.u, '\\', c->name_len-1);
     499                 :                 } else {
     500               0 :                         slash.s = zend_memrchr(c->name.s, '\\', c->name_len-1);
     501                 :                 }
     502        33284033 :                 if(slash.v != NULL) {
     503              29 :                         name = c->name;
     504              29 :                         if(type == IS_UNICODE) {
     505              29 :                                 prefix_len = slash.u - name.u;
     506              29 :                                 const_name.u = slash.u+1;
     507                 :                         } else {
     508               0 :                                 prefix_len = slash.s - name.s;
     509               0 :                                 const_name.s = slash.s+1;
     510                 :                         }
     511              29 :                         const_name_len = c->name_len - 1 - prefix_len - 1;
     512                 : 
     513              29 :                         lookup_name = zend_u_str_case_fold(type, name, prefix_len, 0, &lcname_len);
     514              29 :                         lookup_name_len = const_name_len + 1 + lcname_len + 1;
     515                 : 
     516              29 :                         if(type == IS_UNICODE) {
     517              29 :                                 lookup_name.u = erealloc(lookup_name.u, UBYTES(lookup_name_len));
     518              29 :                                 lookup_name.u[lcname_len] = '\\';
     519              29 :                                 memcpy(lookup_name.u+lcname_len+1, const_name.u, UBYTES(const_name_len + 1));
     520                 :                         } else {
     521               0 :                                 lookup_name.s = erealloc(lookup_name.s, lookup_name_len);
     522               0 :                                 lookup_name.s[lcname_len] = '\\';
     523               0 :                                 memcpy(lookup_name.s+lcname_len+1, const_name.s, const_name_len + 1);
     524                 :                         }
     525              29 :                         name = lookup_name;
     526                 :                 } else {
     527        33284004 :                         lookup_name_len = c->name_len;
     528        33284004 :                         name = c->name;
     529        33284004 :                         lookup_name = NULL_ZSTR;
     530                 :                 }
     531                 :         }
     532                 : 
     533        34066722 :         if (EG(in_execution) && lookup_name_len == sizeof(ZEND_HALT_CONSTANT_NAME) && ZEND_U_EQUAL(type, name, lookup_name_len-1, ZEND_HALT_CONSTANT_NAME, sizeof(ZEND_HALT_CONSTANT_NAME)-1)) {
     534               2 :                 zend_error(E_NOTICE,"Constant %R already defined", type, name);
     535               2 :                 if (lookup_name.v) {
     536               0 :                         efree(lookup_name.v);
     537                 :                 }
     538               2 :                 ret = FAILURE;
     539                 :         }
     540        34066722 :         if (zend_u_hash_add(EG(zend_constants), type, name, lookup_name_len, (void *) c, sizeof(zend_constant), NULL)==FAILURE) {
     541               5 :                 zend_error(E_NOTICE,"Constant %R already defined", type, name);
     542               5 :                 free(c->name.v);
     543               5 :                 if (!(c->flags & CONST_PERSISTENT)) {
     544               5 :                         zval_dtor(&c->value);
     545                 :                 }
     546               5 :                 ret = FAILURE;
     547                 :         }
     548        34066722 :         if (lookup_name.v) {
     549          782718 :                 efree(lookup_name.v);
     550                 :         }
     551        34066722 :         return ret;
     552                 : }
     553                 : /* }}} */
     554                 : 
     555                 : ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC) /* {{{ */
     556          134877 : {
     557                 :         UChar *ustr;
     558                 : 
     559          134877 :         if (c->name.s) {
     560          134877 :                 ustr = malloc(UBYTES(c->name_len));
     561          134877 :                 u_charsToUChars(c->name.s, ustr, c->name_len);
     562          134877 :                 free(c->name.s);
     563          134877 :                 c->name.u = ustr;
     564                 :         }
     565          134877 :         if (Z_TYPE(c->value) == IS_STRING || (Z_TYPE(c->value) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
     566               0 :                 ustr = pemalloc(UBYTES(Z_STRLEN(c->value)+1), c->flags & CONST_PERSISTENT);
     567               0 :                 u_charsToUChars(Z_STRVAL(c->value), ustr, Z_STRLEN(c->value)+1);
     568               0 :                 pefree(Z_STRVAL(c->value), c->flags & CONST_PERSISTENT);
     569               0 :                 Z_USTRVAL(c->value) = ustr;
     570               0 :                 if (Z_TYPE(c->value) == IS_STRING) Z_TYPE(c->value) = IS_UNICODE;
     571                 :         }
     572          134877 :         return zend_u_register_constant(IS_UNICODE, c TSRMLS_CC);
     573                 : }
     574                 : /* }}} */
     575                 : 
     576                 : /*
     577                 :  * Local variables:
     578                 :  * tab-width: 4
     579                 :  * c-basic-offset: 4
     580                 :  * indent-tabs-mode: t
     581                 :  * End:
     582                 :  */

Generated by: LTP GCOV extension version 1.5

Generated at Mon, 23 Nov 2009 17:39:26 +0000 (34 hours ago)

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