Index: Zend/zend_compile.c =================================================================== RCS file: /repository/ZendEngine2/zend_compile.c,v retrieving revision 1.829 diff -u -r1.829 zend_compile.c --- Zend/zend_compile.c 14 Jul 2008 12:17:16 -0000 1.829 +++ Zend/zend_compile.c 17 Jul 2008 14:30:30 -0000 @@ -3985,49 +3985,31 @@ } /* }}} */ -static zend_constant* zend_get_ct_const(zval *const_name TSRMLS_DC) /* {{{ */ +static int zend_constant_ct_subst(znode *result, zval *const_name, zend_bool from_namespace TSRMLS_DC) /* {{{ */ { - zend_constant *c = NULL; + zend_constant *c; - if (zend_u_hash_find(EG(zend_constants), Z_TYPE_P(const_name), Z_UNIVAL_P(const_name), Z_UNILEN_P(const_name)+1, (void **) &c) == FAILURE) { - unsigned int lookup_name_len; - zstr lookup_name = zend_u_str_case_fold(Z_TYPE_P(const_name), Z_UNIVAL_P(const_name), Z_UNILEN_P(const_name), 1, &lookup_name_len); - - if (zend_u_hash_find(EG(zend_constants), Z_TYPE_P(const_name), lookup_name, lookup_name_len+1, (void **) &c)==SUCCESS) { - if ((c->flags & CONST_CS) && memcmp(c->name.v, Z_UNIVAL_P(const_name).v, UG(unicode)?UBYTES(Z_USTRLEN_P(const_name)):Z_STRLEN_P(const_name))!=0) { - efree(lookup_name.v); - return NULL; - } - } else { - efree(lookup_name.v); - return NULL; + if (CG(is_basic_const)) { + result->u.constant = CG(basic_const_value); + goto done; + } + + if (!from_namespace && zend_u_hash_find(EG(zend_constants), Z_TYPE_P(const_name), Z_UNIVAL_P(const_name), Z_UNILEN_P(const_name)+1, (void **) &c) == SUCCESS) { + if (c->flags & CONST_PERSISTENT) { + result->u.constant = c->value; +done: + zval_dtor(const_name); + result->op_type = IS_CONST; + zval_copy_ctor(&result->u.constant); + INIT_PZVAL(&result->u.constant); + return 1; } - efree(lookup_name.v); - } - if (c->flags & CONST_CT_SUBST) { - return c; - } - return NULL; -} -/* }}} */ - -static int zend_constant_ct_subst(znode *result, zval *const_name TSRMLS_DC) /* {{{ */ -{ - zend_constant *c = zend_get_ct_const(const_name TSRMLS_CC); - - if (c) { - zval_dtor(const_name); - result->op_type = IS_CONST; - result->u.constant = c->value; - zval_copy_ctor(&result->u.constant); - INIT_PZVAL(&result->u.constant); - return 1; } return 0; } /* }}} */ -void zend_do_fetch_constant(znode *result, znode *constant_container, znode *constant_name, int mode, zend_bool check_namespace TSRMLS_DC) /* {{{ */ +void zend_do_fetch_constant(znode *result, znode *constant_container, znode *constant_name, int mode, zend_bool from_namespace TSRMLS_DC) /* {{{ */ { ulong fetch_type = 0; znode tmp; @@ -4038,9 +4020,13 @@ Z_UNILEN(constant_container->u.constant) == 0) { /* namespace::const */ zval_dtor(&constant_container->u.constant); - check_namespace = 1; + from_namespace = 1; constant_container = NULL; - fetch_type = ZEND_FETCH_CLASS_RT_NS_CHECK | IS_CONSTANT_RT_NS_CHECK;; + fetch_type = ZEND_FETCH_CLASS_RT_NS_CHECK | IS_CONSTANT_RT_NS_CHECK; + } + + if (!CG(current_namespace)) { + from_namespace = 0; } switch (mode) { @@ -4056,8 +4042,8 @@ zend_do_build_full_name(NULL, constant_container, constant_name TSRMLS_CC); *result = *constant_container; result->u.constant.type = IS_CONSTANT | fetch_type; - } else if (fetch_type || !zend_constant_ct_subst(result, &constant_name->u.constant TSRMLS_CC)) { - if (check_namespace && CG(current_namespace)) { + } else if (fetch_type || !zend_constant_ct_subst(result, &constant_name->u.constant, from_namespace TSRMLS_CC)) { + if (from_namespace) { /* We assume we use constant from the current namespace if it is not prefixed. */ tmp.op_type = IS_CONST; @@ -4073,7 +4059,7 @@ break; case ZEND_RT: if (constant_container || - !zend_constant_ct_subst(result, &constant_name->u.constant TSRMLS_CC)) { + !zend_constant_ct_subst(result, &constant_name->u.constant, from_namespace TSRMLS_CC)) { zend_op *opline; if (constant_container) { @@ -4084,7 +4070,7 @@ zend_do_fetch_class(&tmp, constant_container TSRMLS_CC); constant_container = &tmp; } - } else if (check_namespace && CG(current_namespace)) { + } else if (from_namespace) { /* We assume we use constant from the current namespace if it is not prefixed. */ tmp.op_type = IS_CONST; @@ -5541,7 +5527,7 @@ } /* }}} */ -void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC) /* {{{ */ +void zend_do_declare_constant(znode *name, znode *value, int is_basic_const TSRMLS_DC) /* {{{ */ { zend_op *opline; @@ -5549,7 +5535,7 @@ zend_error(E_COMPILE_ERROR, "Arrays are not allowed as constants"); } - if (zend_get_ct_const(&name->u.constant TSRMLS_CC)) { + if (is_basic_const) { zend_error(E_COMPILE_ERROR, "Cannot redeclare constant '%R'", Z_TYPE(name->u.constant), Z_UNIVAL(name->u.constant)); } Index: Zend/zend_compile.h =================================================================== RCS file: /repository/ZendEngine2/zend_compile.h,v retrieving revision 1.383 diff -u -r1.383 zend_compile.h --- Zend/zend_compile.h 8 Jul 2008 07:05:03 -0000 1.383 +++ Zend/zend_compile.h 17 Jul 2008 14:30:30 -0000 @@ -491,7 +491,7 @@ void zend_do_begin_new_object(znode *new_token, znode *class_type TSRMLS_DC); void zend_do_end_new_object(znode *result, znode *new_token, znode *argument_list TSRMLS_DC); -void zend_do_fetch_constant(znode *result, znode *constant_container, znode *constant_name, int mode, zend_bool check_namespace TSRMLS_DC); +void zend_do_fetch_constant(znode *result, znode *constant_container, znode *constant_name, int mode, zend_bool from_namespace TSRMLS_DC); void zend_do_shell_exec(znode *result, znode *cmd TSRMLS_DC); @@ -540,7 +540,7 @@ void zend_do_abstract_method(znode *function_name, znode *modifiers, znode *body TSRMLS_DC); -void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC); +void zend_do_declare_constant(znode *name, znode *value, int is_basic_const TSRMLS_DC); void zend_do_build_namespace_name(znode *result, znode *prefix, znode *name TSRMLS_DC); void zend_do_namespace(znode *name TSRMLS_DC); void zend_do_use(znode *name, znode *new_name, int is_global TSRMLS_DC); Index: Zend/zend_constants.c =================================================================== RCS file: /repository/ZendEngine2/zend_constants.c,v retrieving revision 1.111 diff -u -r1.111 zend_constants.c --- Zend/zend_constants.c 21 Jul 2008 09:36:21 -0000 1.111 +++ Zend/zend_constants.c 23 Jul 2008 13:49:37 -0000 @@ -132,8 +132,7 @@ { zend_constant c; - Z_TYPE(c.value) = IS_BOOL; - c.flags = CONST_PERSISTENT | CONST_CT_SUBST; + c.flags = CONST_PERSISTENT; c.module_number = 0; c.name.s = zend_strndup(ZEND_STRL("TRUE")); @@ -153,8 +152,6 @@ Z_TYPE(c.value) = IS_NULL; zend_register_constant(&c TSRMLS_CC); - c.flags = CONST_PERSISTENT; - c.name.s = zend_strndup(ZEND_STRL("ZEND_THREAD_SAFE")); c.name_len = sizeof("ZEND_THREAD_SAFE"); Z_LVAL(c.value) = ZTS_V; @@ -278,7 +275,7 @@ lookup_name = zend_u_str_case_fold(type, name, name_len, 1, &lookup_name_len); if (zend_u_hash_find(EG(zend_constants), type, lookup_name, lookup_name_len+1, (void **) &c)==SUCCESS) { - if ((c->flags & CONST_CS) && memcmp(c->name.v, name.v, UG(unicode)?UBYTES(name_len):name_len)!=0) { + if (c->flags & CONST_CS) { retval=0; } } else { Index: Zend/zend_constants.h =================================================================== RCS file: /repository/ZendEngine2/zend_constants.h,v retrieving revision 1.43 diff -u -r1.43 zend_constants.h --- Zend/zend_constants.h 12 May 2008 07:13:47 -0000 1.43 +++ Zend/zend_constants.h 17 Jul 2008 14:30:30 -0000 @@ -26,7 +26,6 @@ #define CONST_CS (1<<0) /* Case Sensitive */ #define CONST_PERSISTENT (1<<1) /* Persistent */ -#define CONST_CT_SUBST (1<<2) /* Allow compile-time substitution */ #define PHP_USER_CONSTANT INT_MAX /* a constant defined in user space */ Index: Zend/zend_globals.h =================================================================== RCS file: /repository/ZendEngine2/zend_globals.h,v retrieving revision 1.179 diff -u -r1.179 zend_globals.h --- Zend/zend_globals.h 9 Apr 2008 21:07:45 -0000 1.179 +++ Zend/zend_globals.h 18 Apr 2008 11:46:40 -0000 @@ -140,6 +140,9 @@ zval *current_namespace; HashTable *current_import; + zend_bool is_basic_const; + zval basic_const_value; + #ifdef ZTS HashTable **static_members; int last_static_member; Index: Zend/zend_language_parser.y =================================================================== RCS file: /repository/ZendEngine2/zend_language_parser.y,v retrieving revision 1.207 diff -u -r1.207 zend_language_parser.y --- Zend/zend_language_parser.y 8 Jul 2008 07:05:03 -0000 1.207 +++ Zend/zend_language_parser.y 17 Jul 2008 14:30:30 -0000 @@ -190,8 +190,8 @@ constant_declaration: - constant_declaration ',' T_STRING '=' static_scalar { zend_do_declare_constant(&$3, &$5 TSRMLS_CC); } - | T_CONST T_STRING '=' static_scalar { zend_do_declare_constant(&$2, &$4 TSRMLS_CC); } + constant_declaration ',' T_STRING { Z_LVAL($2.u.constant) = CG(is_basic_const); } '=' static_scalar { zend_do_declare_constant(&$3, &$6, (int) Z_LVAL($2.u.constant) TSRMLS_CC); } + | T_CONST T_STRING { Z_LVAL($1.u.constant) = CG(is_basic_const); } '=' static_scalar { zend_do_declare_constant(&$2, &$5, (int) Z_LVAL($1.u.constant) TSRMLS_CC); } ; inner_statement_list: Index: Zend/zend_language_scanner.l =================================================================== RCS file: /repository/ZendEngine2/zend_language_scanner.l,v retrieving revision 1.188 diff -u -r1.188 zend_language_scanner.l --- Zend/zend_language_scanner.l 8 Jul 2008 15:24:25 -0000 1.188 +++ Zend/zend_language_scanner.l 17 Jul 2008 14:30:31 -0000 @@ -2250,18 +2250,38 @@ return T_ENCAPSED_AND_WHITESPACE; } -{LABEL} { - if (!zend_copy_scanner_string(zendlval, yytext, yyleng, UG(unicode)?IS_UNICODE:IS_STRING, SCNG(output_conv) TSRMLS_CC)) { - return 0; - } - if (UG(unicode) && !zend_check_and_normalize_identifier(zendlval)) { +{LABEL} { + if (!zend_copy_scanner_string(zendlval, yytext, yyleng, CG(literal_type), SCNG(output_conv) TSRMLS_CC)) { return 0; } return T_STRING; } -{LABEL} { - if (!zend_copy_scanner_string(zendlval, yytext, yyleng, CG(literal_type), SCNG(output_conv) TSRMLS_CC)) { +"TRUE" { + CG(is_basic_const) = 1; + ZVAL_BOOL(&CG(basic_const_value), 1); + goto return_string; +} + +"FALSE" { + CG(is_basic_const) = 1; + ZVAL_BOOL(&CG(basic_const_value), 0); + goto return_string; +} + +"NULL" { + CG(is_basic_const) = 1; + ZVAL_NULL(&CG(basic_const_value)); + goto return_string; +} + +{LABEL} { + CG(is_basic_const) = 0; +return_string: + if (!zend_copy_scanner_string(zendlval, yytext, yyleng, UG(unicode)?IS_UNICODE:IS_STRING, SCNG(output_conv) TSRMLS_CC)) { + return 0; + } + if (UG(unicode) && !zend_check_and_normalize_identifier(zendlval)) { return 0; } return T_STRING;