]> granicus.if.org Git - php/commitdiff
Fix a bug in static initializers/default values/class member variables that contained
authorZeev Suraski <zeev@php.net>
Wed, 31 May 2000 19:07:09 +0000 (19:07 +0000)
committerZeev Suraski <zeev@php.net>
Wed, 31 May 2000 19:07:09 +0000 (19:07 +0000)
array values

Zend/zend-parser.y
Zend/zend.h
Zend/zend_API.c
Zend/zend_execute.c
Zend/zend_execute.h
Zend/zend_execute_API.c
Zend/zend_extensions.h
Zend/zend_variables.c

index 27fe60c3dcad8115fcc98f0537c03ee5b33e96be..9d5219b47d39529a722654e6f1a062fb0c6fdaa9 100644 (file)
@@ -530,7 +530,7 @@ static_scalar: /* compile-time evaluated scalars */
        |       T_STRING                                { do_fetch_constant(&$$, &$1, ZEND_CT CLS_CC); }
        |       '+' static_scalar       { $$ = $1; }
        |       '-' static_scalar       { zval minus_one;  minus_one.type = IS_LONG; minus_one.value.lval = -1;  mul_function(&$2.u.constant, &$2.u.constant, &minus_one);  $$ = $2; }
-       |       T_ARRAY '(' static_array_pair_list ')' { $$ = $3; }
+       |       T_ARRAY '(' static_array_pair_list ')' { $$ = $3; $$.u.constant.type = IS_CONSTANT_ARRAY; }
 ;
 
 
index 7f99fc6356543cda6bc6862d8c7086cccd698d7f..6bdc6e07d4db853537e42398593629bd8f5a3ca4 100644 (file)
@@ -267,6 +267,7 @@ typedef int (*zend_write_func_t)(const char *str, uint str_length);
 #define IS_BOOL                6
 #define IS_RESOURCE    7
 #define IS_CONSTANT    8
+#define IS_CONSTANT_ARRAY      9
 
 /* Special data type to temporarily mark large numbers */
 #define FLAG_IS_BC     9 /* for parser internal use only */
index 8cb751d066b071c65f1130db54c6b71d515ed637..c856b6672dde3190d70fd485e2c765d5e1835662 100644 (file)
@@ -202,7 +202,7 @@ ZEND_API inline int _object_init_ex(zval *arg, zend_class_entry *class_type ZEND
        zval *tmp;
 
        if (!class_type->constants_updated) {
-               zend_hash_apply(&class_type->default_properties, (int (*)(void *)) zval_update_constant);
+               zend_hash_apply_with_argument(&class_type->default_properties, (int (*)(void *,void *)) zval_update_constant, (void *) 1);
                class_type->constants_updated = 1;
        }
        
index c699b1c5eb4dfea8d1744effe642fc943d5824f7..e05ccf4a1295435f757680b7b6007854fcaabe60 100644 (file)
@@ -516,7 +516,7 @@ static void zend_fetch_var_address(znode *result, znode *op1, znode *op2, temp_v
        if (op2->u.fetch_type == ZEND_FETCH_LOCAL) {
                FREE_OP(op1, free_op1);
        } else if (op2->u.fetch_type == ZEND_FETCH_STATIC) {
-               zval_update_constant(retval);
+               zval_update_constant(retval, (void *) 1);
        }
 
        if (varname == &tmp_varname) {
@@ -1317,7 +1317,7 @@ binary_assign_op_addr: {
                                        zval *value;
                                        value = get_zval_ptr(&opline->op2, Ts, &EG(free_op2), BP_VAR_R);
 
-                                       zend_assign_to_variable(&opline->result, &opline->op1, &opline->op2, value, (EG(free_op2)?IS_TMP_VAR:opline->op2.op_type), Ts ELS_CC);
+                                       zend_assign_to_variable(&opline->result, &opline->op1, &opline->op2, value, (EG(free_op2)?IS_TMP_VAR:opline->op2.op_type), Ts ELS_CC);
                                        /* zend_assign_to_variable() always takes care of op2, never free it! */
                                }
                                NEXT_OPCODE();
@@ -1782,18 +1782,15 @@ send_by_ref:
                                        zval **param, *assignment_value;
 
                                        if (zend_ptr_stack_get_arg(opline->op1.u.constant.value.lval, (void **) &param ELS_CC)==FAILURE) {
-                                               if (opline->op2.u.constant.type == IS_CONSTANT) {
+                                               if (opline->op2.u.constant.type == IS_CONSTANT || opline->op2.u.constant.type==IS_CONSTANT_ARRAY) {
                                                        zval *default_value;
-                                                       zval tmp;
 
                                                        ALLOC_ZVAL(default_value);
                                                        *default_value = opline->op2.u.constant;
-                                                       if (!zend_get_constant(default_value->value.str.val, default_value->value.str.len, &tmp)) {
-                                                               default_value->type = IS_STRING;
+                                                       if (opline->op2.u.constant.type==IS_CONSTANT_ARRAY) {
                                                                zval_copy_ctor(default_value);
-                                                       } else {
-                                                               *default_value = tmp;
                                                        }
+                                                       zval_update_constant(&default_value, 0);
                                                        default_value->refcount=0;
                                                        default_value->is_ref=0;
                                                        param = &default_value;
index 449e4e39de8f2b62e7292a9d505b3d966b6ae7aa..2ff01f9c18774d9976582a8e9745484d44e69c0b 100644 (file)
@@ -55,7 +55,7 @@ ZEND_API int zend_is_true(zval *op);
 ZEND_API inline void safe_free_zval_ptr(zval *p);
 ZEND_API int zend_eval_string(char *str, zval *retval_ptr CLS_DC ELS_DC);
 ZEND_API inline int i_zend_is_true(zval *op);
-ZEND_API int zval_update_constant(zval **pp);
+ZEND_API int zval_update_constant(zval **pp, void *arg);
 ZEND_API inline void zend_assign_to_variable_reference(znode *result, zval **variable_ptr_ptr, zval **value_ptr_ptr, temp_variable *Ts ELS_DC);
 
 /* dedicated Zend executor functions - do not use! */
index f5916a10231b82ebedba7baf7d9d698b33be8e49..21ee9c40c0dc8135e226d8253a3d19aaf4a51cb9 100644 (file)
@@ -286,9 +286,10 @@ ZEND_API int zend_is_true(zval *op)
 }
 
 
-ZEND_API int zval_update_constant(zval **pp)
+ZEND_API int zval_update_constant(zval **pp, void *arg)
 {
        zval *p = *pp;
+       zend_bool inline_change = (zend_bool) arg;
 
        if (p->type == IS_CONSTANT) {
                zval c;
@@ -304,16 +305,22 @@ ZEND_API int zval_update_constant(zval **pp)
                                                p->value.str.val,
                                                p->value.str.val);
                        p->type = IS_STRING;
+                       if (!inline_change) {
+                               zval_copy_ctor(p);
+                       }
                } else {
-                       STR_FREE(p->value.str.val);
+                       if (inline_change) {
+                               STR_FREE(p->value.str.val);
+                       }
                        *p = c;
                }
                INIT_PZVAL(p);
                p->refcount = refcount;
-       } else if (p->type == IS_ARRAY) {
+       } else if (p->type == IS_CONSTANT_ARRAY) {
                SEPARATE_ZVAL(pp);
                p = *pp;
-               zend_hash_apply(p->value.ht, (int (*)(void *)) zval_update_constant);
+               p->type = IS_ARRAY;
+               zend_hash_apply_with_argument(p->value.ht, (int (*)(void *,void *)) zval_update_constant, (void *) 1);
        }
        return 0;
 }
index 1dff4785a9867048a840fcb65b0cc151eaec4117..51d47f13793d6bd27561268bc0dd445c839427ac 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "zend_compile.h"
 
-#define ZEND_EXTENSION_API_NO          20000521
+#define ZEND_EXTENSION_API_NO          20000531
 
 typedef struct _zend_extension_version_info {
        int zend_extension_api_no;
index 2fa87df02d027723e8e4bc0bf81007e371b3c7e8..e1639a8ad85d2f0a6fd827602250cb56b14277d2 100644 (file)
@@ -61,7 +61,8 @@ ZEND_API void _zval_dtor(zval *zvalue ZEND_FILE_LINE_DC)
                case IS_CONSTANT:
                        STR_FREE_REL(zvalue->value.str.val);
                        break;
-               case IS_ARRAY: {
+               case IS_ARRAY:
+               case IS_CONSTANT_ARRAY: {
                                ELS_FETCH();
 
                                if (zvalue->value.ht && (zvalue->value.ht != &EG(symbol_table))) {
@@ -125,7 +126,8 @@ ZEND_API int _zval_copy_ctor(zval *zvalue ZEND_FILE_LINE_DC)
                        }
                        zvalue->value.str.val = (char *) estrndup_rel(zvalue->value.str.val, zvalue->value.str.len);
                        break;
-               case IS_ARRAY: {
+               case IS_ARRAY:
+               case IS_CONSTANT_ARRAY: {
                                zval *tmp;
                                HashTable *original_ht = zvalue->value.ht;
                                ELS_FETCH();