]> granicus.if.org Git - php/commitdiff
Reimplemented support for namespaces in indexes id constant arrays (removed zval...
authorDmitry Stogov <dmitry@php.net>
Fri, 2 Nov 2007 10:11:59 +0000 (10:11 +0000)
committerDmitry Stogov <dmitry@php.net>
Fri, 2 Nov 2007 10:11:59 +0000 (10:11 +0000)
Zend/zend.h
Zend/zend_compile.c
Zend/zend_execute_API.c

index 8f922e15724bbba8d6bf36beeeb053ffcd9f8963..58327d2a0031a1a1047854f6e1763e893957152f 100644 (file)
@@ -336,7 +336,6 @@ struct _zval_struct {
        zend_uint refcount__gc;
        zend_uchar type;        /* active type */
        zend_uchar is_ref__gc;
-       zend_uchar idx_type;    /* type of element's index in constant array */
 };
 
 #define Z_REFCOUNT_PP(ppz)             Z_REFCOUNT_P(*(ppz))
index f8c956664fd0798fa977c7ad854aa04c0c8683ae..9e880bb36c30ec19cdc06030579a623d2ae7e54e 100644 (file)
@@ -3946,9 +3946,18 @@ void zend_do_add_static_array_element(znode *result, znode *offset, znode *expr)
                        case IS_CONSTANT:
                                /* Ugly hack to denote that this value has a constant index */
                                Z_TYPE_P(element) |= IS_CONSTANT_INDEX;
-                               element->idx_type = Z_TYPE(offset->u.constant);
-                               /* break missing intentionally */
-                               utype = UG(unicode)?IS_UNICODE:IS_STRING;
+                               if (UG(unicode)) {
+                                       Z_USTRVAL(offset->u.constant) = eurealloc(Z_USTRVAL(offset->u.constant), Z_USTRLEN(offset->u.constant)+3);
+                                       Z_USTRVAL(offset->u.constant)[Z_USTRLEN(offset->u.constant)+1] = Z_TYPE(offset->u.constant);
+                                       Z_USTRVAL(offset->u.constant)[Z_USTRLEN(offset->u.constant)+2] = 0;
+                               } else {
+                                       Z_STRVAL(offset->u.constant) = erealloc(Z_STRVAL(offset->u.constant), Z_STRLEN(offset->u.constant)+3);
+                                       Z_STRVAL(offset->u.constant)[Z_STRLEN(offset->u.constant)+1] = Z_TYPE(offset->u.constant);
+                                       Z_STRVAL(offset->u.constant)[Z_STRLEN(offset->u.constant)+2] = 0;
+                               }
+                               zend_u_symtable_update(result->u.constant.value.ht, ZEND_STR_TYPE, Z_UNIVAL(offset->u.constant), Z_UNILEN(offset->u.constant)+3, &element, sizeof(zval *), NULL);
+                               zval_dtor(&offset->u.constant);
+                               break;
                        case IS_STRING:
                        case IS_UNICODE:
                                zend_u_symtable_update(Z_ARRVAL(result->u.constant), utype, Z_UNIVAL(offset->u.constant), Z_UNILEN(offset->u.constant)+1, &element, sizeof(zval *), NULL);
index 7145517464ba42a2be566cb8f45d64674d9415e0..f3a549d39bd7c346ce4c961abb5e0c02e86ac712 100644 (file)
@@ -549,50 +549,29 @@ ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *sco
                                zend_hash_move_forward(Z_ARRVAL_P(p));
                                continue;
                        }
-                       if (!zend_u_get_constant_ex(ZEND_STR_TYPE, str_index, str_index_len - 1, &const_value, scope, (*element)->idx_type TSRMLS_CC)) {
-                               if ((UG(unicode) && (colon.u = u_memchr(str_index.u, ':', str_index_len - 1)) && colon.u[1] == ':') ||
-                                       (!UG(unicode) && (colon.s = memchr(str_index.s, ':', str_index_len - 1)) && colon.s[1] == ':')
+                       if (!zend_u_get_constant_ex(ZEND_STR_TYPE, str_index, str_index_len - 3, &const_value, scope, (UG(unicode) ? str_index.u[str_index_len-2] : str_index.s[str_index_len-2]) TSRMLS_CC)) {
+                               if ((UG(unicode) && (colon.u = u_memchr(str_index.u, ':', str_index_len - 3)) && colon.u[1] == ':') ||
+                                       (!UG(unicode) && (colon.s = memchr(str_index.s, ':', str_index_len - 3)) && colon.s[1] == ':')
                                ) {
                                        zend_error(E_ERROR, "Undefined class constant '%v'", str_index);
                                }
                                zend_error(E_NOTICE, "Use of undefined constant %v - assumed '%v'",     str_index, str_index);
-                               zend_hash_move_forward(Z_ARRVAL_P(p));
-                               continue;
+                               ZVAL_TEXTL(&const_value, str_index, str_index_len-3, 1);
                        }
 
-                       if (UG(unicode)) {
-                               if (Z_TYPE(const_value) == IS_UNICODE &&
-                                       Z_USTRLEN(const_value) == str_index_len - 1 &&
-                                       !u_strncmp(Z_USTRVAL(const_value), str_index.u, str_index_len)
-                               ) {
-                                       /* constant value is the same as its name */
-                                       zval_dtor(&const_value);
-                                       zend_hash_move_forward(Z_ARRVAL_P(p));
-                                       continue;
-                               }
-                       } else {
-                               if (Z_TYPE(const_value) == IS_STRING &&
-                                       Z_STRLEN(const_value) == str_index_len - 1 &&
-                                       !strncmp(Z_STRVAL(const_value), str_index.s, str_index_len)
-                               ) {
-                                       /* constant value is the same as its name */
-                                       zval_dtor(&const_value);
-                                       zend_hash_move_forward(Z_ARRVAL_P(p));
-                                       continue;
-                               }
+                       if (Z_REFCOUNT_PP(element) > 1) {
+                               ALLOC_ZVAL(new_val);
+                               *new_val = **element;
+                               zval_copy_ctor(new_val);
+                               Z_SET_REFCOUNT_P(new_val, 1);
+                               Z_UNSET_ISREF_P(new_val);
+
+                               /* preserve this bit for inheritance */
+                               Z_TYPE_PP(element) |= IS_CONSTANT_INDEX;
+                               zval_ptr_dtor(element);
+                               *element = new_val;
                        }
 
-                       ALLOC_ZVAL(new_val);
-                       *new_val = **element;
-                       zval_copy_ctor(new_val);
-                       Z_SET_REFCOUNT_P(new_val, 1);
-                       Z_UNSET_ISREF_P(new_val);
-
-                       /* preserve this bit for inheritance */
-                       Z_TYPE_PP(element) |= IS_CONSTANT_INDEX;
-                       zval_ptr_dtor(element);
-                       *element = new_val;
-
                        switch (Z_TYPE(const_value)) {
                                case IS_STRING:
                                case IS_UNICODE: