7
7
void ZendFunction::freehash (zval *zval_ptr)
8
8
{
9
9
10
- // if(Z_TYPE_P(zval_ptr) == IS_NULL){
11
- // cout << "该变量为 null" <<endl;
12
- // return;
13
- // }
10
+ Debug (" zend_hash_destory: zval:%x type:%d" ,zval_ptr,Z_TYPE_P (zval_ptr));
11
+ if (Z_TYPE_P (zval_ptr) == IS_NULL) {
12
+ return ;
13
+ }
14
+ if (Z_TYPE_P (zval_ptr) == IS_REFERENCE) {
15
+ int gccount = GC_REFCOUNT (Z_REF_P (zval_ptr));
16
+ Debug (" reference gc count:%d" ,gccount);
17
+ return ;
18
+ }
14
19
zval_ptr_dtor (zval_ptr);
15
20
}
16
21
/* *
@@ -60,15 +65,15 @@ void ZendFunction::prepare_functions(Coroutine *co) {
60
65
void *value = NULL ,*prepared = NULL ;
61
66
// TODO: need handle it,could crash
62
67
zend_compiler_globals* cg = ((zend_compiler_globals *) (*((void ***) co->creator ))[TSRM_UNSHUFFLE_RSRC_ID (compiler_globals_id)]);
63
- Debug (" creator:%ld cgid:%ld cg:%ld null:%d" ,co->creator ,compiler_globals_id,cg,cg== nullptr );
68
+ Debug (" creator:%x cgid:%ld cg:%x null:%d" ,co->creator ,compiler_globals_id,cg,cg== nullptr );
64
69
if (cg == nullptr ){
65
70
cg = ((zend_compiler_globals *) (*((void ***) co->creator ))[TSRM_UNSHUFFLE_RSRC_ID (compiler_globals_id)]);
66
- Error (" creator thread local not exist cg:%ld " ,cg);
71
+ Error (" creator thread local not exist cg:%x " ,cg);
67
72
return ;
68
73
}
69
74
HashTable *function_table = cg->function_table ;
70
75
HashTable *local_table = CG (function_table);
71
- Debug (" origin:%ld local:%ld " ,function_table,local_table)
76
+ Debug (" origin:%x local:%x " ,function_table,local_table)
72
77
ZEND_HASH_FOREACH_STR_KEY_PTR (function_table, key, value)
73
78
{
74
79
if (((zend_function*)value)->type == ZEND_INTERNAL_FUNCTION ||
@@ -77,7 +82,7 @@ void ZendFunction::prepare_functions(Coroutine *co) {
77
82
name = zend_string_new (key);
78
83
prepared = copy_function ((zend_function*)value);
79
84
if (!zend_hash_add_ptr (local_table, name, prepared)) {
80
- Debug (" function table add failed: %ld " ,local_table)
85
+ Debug (" function table add failed: %x " ,local_table)
81
86
destroy_op_array ((zend_op_array*)prepared);
82
87
}
83
88
@@ -109,6 +114,7 @@ zend_function* ZendFunction::copy_user_function(zend_function *function)
109
114
{
110
115
zend_function *copy;
111
116
zend_op_array *op_array;
117
+ zend_op_array *old_op_array;
112
118
zend_string **variables, *filename_copy;
113
119
zval *literals;
114
120
zend_arg_info *arg_info;
@@ -120,6 +126,7 @@ zend_function* ZendFunction::copy_user_function(zend_function *function)
120
126
variables = op_array->vars ;
121
127
literals = op_array->literals ;
122
128
arg_info = op_array->arg_info ;
129
+ old_op_array = (zend_op_array*)function;
123
130
124
131
// op_array->function_name = zend_string_new(op_array->function_name);
125
132
op_array->function_name = ZendString::copy_string (op_array->function_name ,is_new);
@@ -154,7 +161,9 @@ zend_function* ZendFunction::copy_user_function(zend_function *function)
154
161
if (op_array->live_range ) op_array->live_range = copy_live (op_array->live_range , op_array->last_live_range );
155
162
if (op_array->try_catch_array ) op_array->try_catch_array = copy_try (op_array->try_catch_array , op_array->last_try_catch );
156
163
if (op_array->vars ) op_array->vars = copy_variables (variables, op_array->last_var );
157
- if (op_array->static_variables ) op_array->static_variables = copy_statics (op_array->static_variables );
164
+ // if (op_array->static_variables) op_array->static_variables = copy_statics(op_array->static_variables);
165
+ if (op_array->static_variables ) op_array->static_variables = copy_statics (old_op_array->static_variables );
166
+ // op_array->static_variables = old_op_array->static_variables;
158
167
159
168
return copy;
160
169
}
@@ -201,8 +210,12 @@ HashTable* ZendFunction::copy_statics(HashTable *old) {
201
210
ZEND_HASH_FOREACH_STR_KEY_VAL (old, key, value) {
202
211
zend_string *name = zend_string_new (key);
203
212
zval *next = value;
204
- while (Z_TYPE_P (next) == IS_REFERENCE)
205
- next = &Z_REF_P (next)->val ;
213
+ // while (Z_TYPE_P(next) == IS_REFERENCE)
214
+ // next = &Z_REF_P(next)->val;
215
+ if (Z_TYPE_P (next) == IS_REFERENCE){
216
+ zend_hash_add (statics, name, next);
217
+ continue ;
218
+ }
206
219
207
220
if (Z_REFCOUNTED_P (next)) {
208
221
zval copy;
0 commit comments