source: trunk/processor/processor.m4

Last change on this file was 1578, checked in by moo, 5 weeks ago

cacher: fix more var caching leaks

  • Property svn:eol-style set to native
File size: 37.5 KB
Line 
1dnl ================
2/* {{{ Pre-declare */
3DECL_STRUCT_P_FUNC(`zval')
4DECL_STRUCT_P_FUNC(`zval_ptr')
5DECL_STRUCT_P_FUNC(`zval_ptr_nullable')
6DECL_STRUCT_P_FUNC(`zend_op_array')
7DECL_STRUCT_P_FUNC(`zend_class_entry')
8#ifdef HAVE_XCACHE_CONSTANT
9DECL_STRUCT_P_FUNC(`zend_constant')
10#endif
11DECL_STRUCT_P_FUNC(`zend_function')
12DECL_STRUCT_P_FUNC(`xc_entry_var_t')
13DECL_STRUCT_P_FUNC(`xc_entry_php_t')
14#ifdef ZEND_ENGINE_2
15DECL_STRUCT_P_FUNC(`zend_property_info')
16#endif
17/* }}} */
18dnl ====================================================
19#ifdef IS_CV
20DEF_STRUCT_P_FUNC(`zend_compiled_variable', , `dnl {{{
21    PROCESS(int, name_len)
22    PROC_ZSTRING_L(, name, name_len)
23    PROCESS(ulong, hash_value)
24')
25dnl }}}
26#endif
27DEF_STRUCT_P_FUNC(`zend_uint', , `dnl {{{
28    IFCOPY(`DST()[0] = SRC()[0];')
29    IFDPRINT(`
30        INDENT()
31        fprintf(stderr, "%u\n", SRC()[0]);
32    ')
33    DONE_SIZE(sizeof(SRC()[0]))
34')
35dnl }}}
36#ifndef ZEND_ENGINE_2
37DEF_STRUCT_P_FUNC(`int', , `dnl {{{
38    IFCOPY(`*DST() = *SRC();')
39    IFDPRINT(`
40        INDENT()
41        fprintf(stderr, "%d\n", SRC()[0]);
42    ')
43    DONE_SIZE(sizeof(SRC()[0]))
44')
45dnl }}}
46#endif
47#ifdef ZEND_ENGINE_2
48DEF_STRUCT_P_FUNC(`zend_try_catch_element', , `dnl {{{
49    PROCESS(zend_uint, try_op)
50    PROCESS(zend_uint, catch_op)
51#ifdef ZEND_ENGINE_2_5
52    PROCESS(zend_uint, finally_op)
53    PROCESS(zend_uint, finally_end)
54#endif
55')
56dnl }}}
57#endif
58DEF_STRUCT_P_FUNC(`zend_brk_cont_element', , `dnl {{{
59#ifdef ZEND_ENGINE_2_2
60    PROCESS(int, start)
61#endif
62    PROCESS(int, cont)
63    PROCESS(int, brk)
64    PROCESS(int, parent)
65')
66dnl }}}
67DEF_HASH_TABLE_FUNC(`HashTable_zval_ptr',           `zval_ptr')
68DEF_HASH_TABLE_FUNC(`HashTable_zend_function',      `zend_function')
69#ifdef ZEND_ENGINE_2
70DEF_HASH_TABLE_FUNC(`HashTable_zend_property_info', `zend_property_info')
71#endif
72#ifdef IS_CONSTANT_AST
73define(`ZEND_AST_HELPER', `dnl {{{
74{
75    IFCALCCOPY(`
76        size_t zend_ast_size = ($1->kind == ZEND_CONST)
77         ? sizeof(zend_ast) + sizeof(zval)
78         : sizeof(zend_ast) + sizeof(zend_ast *) * ($1->children - 1);
79    ')
80
81    pushdef(`ALLOC_SIZE_HELPER', `zend_ast_size')
82    $2
83    popdef(`ALLOC_SIZE_HELPER')
84}
85')
86dnl }}}
87DEF_STRUCT_P_FUNC(`zend_ast', , `dnl {{{
88        zend_ushort i;
89        PROCESS(zend_ushort, kind)
90        PROCESS(zend_ushort, children)
91        DONE(u)
92        DISABLECHECK(`
93            if (SRC()->kind == ZEND_CONST) {
94                assert(SRC()->u.val);
95                IFCOPY(`
96                    DST()->u.val = (zval *) (DST() + 1);
97                    memcpy(DST()->u.val, SRC()->u.val, sizeof(zval));
98                ')
99                STRUCT_P_EX(zval, DST()->u.val, SRC()->u.val, `[]', `', ` ')
100                RELOCATE_EX(zval, DST()->u.val)
101            }
102            else {
103                for (i = 0; i < SRC()->children; ++i) {
104                    zend_ast *src_ast = (&SRC()->u.child)[i];
105                    if (src_ast) {
106                        ZEND_AST_HELPER(`src_ast', `
107                            ALLOC(`(&DST()->u.child)[i]', zend_ast)
108                            STRUCT_P_EX(zend_ast, (&DST()->u.child)[i], src_ast, `[]', `', ` ')
109                        ')
110                        RELOCATE_EX(zend_ast, (&DST()->u.child)[i])
111                    }
112                    else {
113                        SETNULL_EX(`(&DST()->u.child)[i]', `[]')
114                    }
115                }
116            }
117        ')
118')
119dnl }}}
120#endif
121DEF_STRUCT_P_FUNC(`zend_object', , `dnl {{{
122    IFCALC(`
123        xc_var_collect_class(processor, SRC(ce) TSRMLS_CC);
124        DONE(ce)
125    ', `IFSTORE(`
126        DST(ce) = (zend_class_entry *) xc_var_store_ce(processor, SRC(ce) TSRMLS_CC);
127        DONE(ce)
128    ', `IFRESTORE(`
129        assert(processor->index_to_ce);
130        DST(ce) = processor->index_to_ce[(size_t) SRC(ce)];
131        DONE(ce)
132    ', `
133        PROCESS_SCALAR(ce, lu, unsigned long)
134    ')')')
135
136    STRUCT_P(HashTable, properties, HashTable_zval_ptr)
137#ifdef ZEND_ENGINE_2_4
138    dnl TODO: how to rebuild properties_table
139    STRUCT_ARRAY(int, ce->default_properties_count, zval_ptr, properties_table)
140#endif
141#ifdef ZEND_ENGINE_2
142    COPYNULL(`guards')
143#endif
144')
145dnl }}}
146#ifdef ZEND_ENGINE_2
147DEF_STRUCT_P_FUNC(`zend_object_value', , `dnl {{{
148    IFCALC(`
149        xc_var_collect_object(processor, SRC(handle) TSRMLS_CC);
150        DONE(handle)
151    ', `IFSTORE(`
152        DST(handle) = (zend_object_handle) xc_var_store_handle(processor, SRC(handle) TSRMLS_CC);
153        DONE(handle)
154    ', `IFRESTORE(`
155        DST(handle) = xc_var_restore_handle(processor, (size_t) SRC(handle) TSRMLS_CC);
156        DONE(handle)
157    ', `
158        PROCESS(zend_object_handle, handle)
159    ')')')
160    COPY(handlers)
161')
162dnl }}}
163#endif
164DEF_STRUCT_P_FUNC(`zval', , `dnl {{{
165    IFDASM(`do {
166        zval_dtor(DST());
167        *DST() = *SRC();
168        zval_copy_ctor(DST());
169        Z_SET_REFCOUNT(*DST(), 1);
170        DONE(value)
171        DONE(type)
172#ifdef ZEND_ENGINE_2_3
173        DONE(is_ref__gc)
174        DONE(refcount__gc)
175#else
176        DONE(is_ref)
177        DONE(refcount)
178#endif
179    } while(0);
180    ', `
181        dnl IFDASM else
182        /* Variable information */
183dnl {{{ zvalue_value
184        DISABLECHECK(`
185        switch ((Z_TYPE_P(SRC()) & IS_CONSTANT_TYPE_MASK)) {
186            case IS_LONG:
187            case IS_BOOL:
188                PROCESS(long, value.lval)
189                break;
190            case IS_DOUBLE:
191                PROCESS(double, value.dval)
192                break;
193            case IS_NULL:
194                IFDPRINT(`INDENT()`'fprintf(stderr, "\tNULL\n");')
195                break;
196
197            case IS_CONSTANT:
198#ifdef IS_UNICODE
199                if (UG(unicode)) {
200                    goto proc_unicode;
201                }
202#endif
203            case IS_STRING:
204#ifdef FLAG_IS_BC
205            case FLAG_IS_BC:
206#endif
207                PROCESS(int, value.str.len)
208                IFRESTORE(`
209                    TRACE("%p, %p, %d", src->value.str.val, processor->entry_php_src->filepath.str, src->value.str.val == processor->entry_php_src->filepath.str);
210                ')
211                PROC_STRING_L(value.str.val, value.str.len)
212                dnl IFSTORE(`
213                dnl     TRACE("%s, %d", dst->value.str.val, dst->value.str.val == processor->entry_php_dst->filepath.str);
214                dnl ')
215                break;
216#ifdef IS_UNICODE
217            case IS_UNICODE:
218proc_unicode:
219                PROCESS(int32_t, value.uni.len)
220                PROC_ZSTRING_L(1, value.uni.val, value.uni.len)
221                break;
222#endif
223
224            case IS_ARRAY:
225#ifdef IS_CONSTANT_ARRAY
226            case IS_CONSTANT_ARRAY:
227#endif
228                assert(SRC()->value.ht);
229                STRUCT_P(HashTable, value.ht, HashTable_zval_ptr)
230                break;
231
232#ifdef IS_CONSTANT_AST
233            case IS_CONSTANT_AST:
234                assert(SRC()->value.ast);
235                ZEND_AST_HELPER(`SRC()->value.ast', `STRUCT_P(zend_ast, value.ast)')
236                break;
237#endif
238
239            case IS_OBJECT:
240#ifdef ZEND_ENGINE_2
241                STRUCT(zend_object_value, value.obj)
242#else
243                STRUCT(zend_object, value.obj)
244#endif
245                break;
246
247            default:
248                /* IS_RESOURCE */
249                IFCOPY(`Z_TYPE_P(DST()) = IS_LONG;')
250                PROCESS(long, value.lval)
251                break;
252        }
253        ')
254dnl }}}
255        DONE(value)
256        PROCESS(xc_zval_type_t, type)
257#ifdef ZEND_ENGINE_2_3
258        PROCESS(zend_uchar, is_ref__gc)
259#else
260        PROCESS(zend_uchar, is_ref)
261#endif
262
263#ifdef ZEND_ENGINE_2_3
264        PROCESS(zend_uint, refcount__gc)
265#elif defined(ZEND_ENGINE_2)
266        PROCESS(zend_uint, refcount)
267#else
268        PROCESS(zend_ushort, refcount)
269#endif
270    ')dnl IFDASM
271')
272dnl }}}
273DEF_STRUCT_P_FUNC(`zval_ptr', , `dnl {{{
274    IFDASM(`
275        pushdefFUNC_NAME(`zval')
276        FUNC_NAME (dasm, DST(), SRC()[0] TSRMLS_CC);
277        popdef(`FUNC_NAME')
278    ', `
279        do {
280            IFCALCCOPY(`
281                if (processor->handle_reference) {
282                    zval_ptr *ppzv;
283                    if (zend_hash_find(&processor->zvalptrs, (char *) &SRC()[0], sizeof(SRC()[0]), (void **) &ppzv) == SUCCESS) {
284                        IFCOPY(`
285                            DST()[0] = *ppzv;
286                            IFSTORE(`
287                                Z_ADDREF(**DST());
288                                TRACE("add refcount to %d", Z_REFCOUNT(**DST()));
289                            ')
290                            /* *DST() is updated */
291                            TRACE("*DST() is set to %p, PROCESSOR_TYPE is_shm %d", (void *) DST()[0], xc_is_shm(DST()[0]));
292                        ')
293                        IFCALCSTORE(`processor->have_references = 1;')
294                        IFSTORE(`assert(xc_is_shm(DST()[0]));')
295                        IFRESTORE(`assert(!xc_is_shm(DST()[0]));')
296                        break;
297                    }
298                }
299            ')
300           
301            ALLOC(DST()[0], zval)
302            IFCALCCOPY(`
303                if (processor->handle_reference) {
304                    IFCALC(`
305                        /* make dummy */
306                        zval_ptr pzv = (zval_ptr)-1;
307                    ', `
308                        zval_ptr pzv = DST()[0];
309                        RELOCATE_EX(zval, pzv)
310                    ')
311                    if (zend_hash_add(&processor->zvalptrs, (char *) &SRC()[0], sizeof(SRC()[0]), (void *) &pzv, sizeof(pzv), NULL) == SUCCESS) { /* first add, go on */
312                        dnl IFSTORE(`fprintf(stderr, "mark[%p] = %p\n", (void *) SRC()[0], (void *) pzv);')
313                    }
314                    else {
315                        assert(0);
316                    }
317                }
318            ')
319            IFCOPY(`
320                TRACE("copy from %p to %p", SRC()[0], DST()[0]);
321            ')
322            IFDPRINT(`INDENT()`'fprintf(stderr, "[%p] ", (void *) SRC()[0]);')
323            STRUCT_P_EX(zval, DST()[0], SRC()[0], `[0]', `', ` ')
324            dnl set refcount here instead of struct zval?
325            IFSTORE(`
326                Z_SET_REFCOUNT(**DST(), 1);
327                TRACE("set refcount to %d", Z_REFCOUNT(**DST()));
328            ')
329            RELOCATE_EX(zval, DST()[0])
330        } while (0);
331    ')
332    DONE_SIZE(sizeof(zval_ptr))
333')
334dnl }}}
335DEF_STRUCT_P_FUNC(`zval_ptr_nullable', , `dnl {{{
336    if (SRC()[0]) {
337        pushdef(`DASM_STRUCT_DIRECT')
338        STRUCT_P_EX(zval_ptr, DST(), SRC(), `', `', ` ')
339        popdef(`DASM_STRUCT_DIRECT')
340    }
341    else {
342        IFCOPY(`COPYNULL_EX(DST()[0], SRC())')
343    }
344    DONE_SIZE(sizeof(zval_ptr_nullable))
345')
346dnl }}}
347#ifdef ZEND_ENGINE_2
348DEF_STRUCT_P_FUNC(`zend_arg_info', , `dnl {{{
349    PROCESS(zend_uint, name_len)
350    PROC_ZSTRING_L(, name, name_len)
351    PROCESS(zend_uint, class_name_len)
352    PROC_ZSTRING_L(, class_name, class_name_len)
353#ifdef ZEND_ENGINE_2_4
354    PROCESS(zend_uchar, type_hint)
355#elif defined(ZEND_ENGINE_2_1)
356    PROCESS(zend_bool, array_type_hint)
357#endif
358#ifdef ZEND_ENGINE_2_6
359    PROCESS(zend_uchar, pass_by_reference)
360#endif
361    PROCESS(zend_bool, allow_null)
362
363#ifdef ZEND_ENGINE_2_6
364    PROCESS(zend_bool, is_variadic)
365#else
366    PROCESS(zend_bool, pass_by_reference)
367#endif
368
369#ifndef ZEND_ENGINE_2_4
370    PROCESS(zend_bool, return_reference)
371    PROCESS(int, required_num_args)
372#endif
373')
374dnl }}}
375#endif
376#ifdef HAVE_XCACHE_CONSTANT
377DEF_STRUCT_P_FUNC(`zend_constant', , `dnl {{{
378    STRUCT(zval, value)
379    PROCESS(int, flags)
380    PROCESS(uint, name_len)
381    pushdef(`estrndup', `zend_strndup')
382    PROC_ZSTRING_N(, name, name_len)
383    popdef(`estrndup')
384    PROCESS(int, module_number)
385')
386dnl }}}
387#endif
388DEF_STRUCT_P_FUNC(`zend_function', , `dnl {{{
389    DISABLECHECK(`
390    switch (SRC(`type')) {
391    case ZEND_INTERNAL_FUNCTION:
392    case ZEND_OVERLOADED_FUNCTION:
393        IFNOTMEMCPY(`IFCOPY(`memcpy(DST(), SRC(), sizeof(SRC()[0]));')')
394        break;
395
396    case ZEND_USER_FUNCTION:
397    case ZEND_EVAL_CODE:
398        DONE(type)
399        STRUCT(zend_op_array, op_array)
400        break;
401
402    default:
403        assert(0);
404    }
405    ')
406    DONE_SIZE(sizeof(SRC()[0]))
407')
408dnl }}}
409#ifdef ZEND_ENGINE_2
410DEF_STRUCT_P_FUNC(`zend_property_info', , `dnl {{{
411    PROCESS(zend_uint, flags)
412    PROCESS(int, name_length)
413    PROC_ZSTRING_L(, name, name_length)
414    PROCESS(ulong, h)
415#ifdef ZEND_ENGINE_2_4
416    PROCESS(int, offset)
417#endif
418#ifdef ZEND_ENGINE_2_1
419    PROCESS(int, doc_comment_len)
420    PROC_ZSTRING_L(, doc_comment, doc_comment_len)
421#endif
422    dnl isnt in php6 yet
423#if defined(ZEND_ENGINE_2_2)
424    PROC_CLASS_ENTRY_P(ce)
425#endif
426')
427dnl }}}
428#endif
429#ifdef ZEND_ENGINE_2_4
430DEF_STRUCT_P_FUNC(`zend_trait_method_reference', , `dnl {{{
431    PROCESS(unsigned int, mname_len)
432    PROC_STRING_L(method_name, mname_len)
433    COPYNULL(ce)
434    PROCESS(unsigned int, cname_len)
435    PROC_STRING_L(class_name, cname_len)
436')
437dnl }}}
438DEF_STRUCT_P_FUNC(`zend_trait_alias', , `dnl {{{
439    STRUCT_P(zend_trait_method_reference, trait_method)
440    PROCESS(unsigned int, alias_len)
441    PROC_STRING_L(alias, alias_len)
442    PROCESS(zend_uint, modifiers)
443#ifndef ZEND_ENGINE_2_5
444    COPYNULL(function)
445#endif
446')
447dnl }}}
448DEF_STRUCT_P_FUNC(`zend_trait_precedence', , `dnl {{{
449    STRUCT_P(zend_trait_method_reference, trait_method)
450    PROCESS_ARRAY(, xc_ztstring, exclude_from_classes, zend_class_entry*)
451#ifndef ZEND_ENGINE_2_5
452    COPYNULL(function)
453#endif
454')
455dnl }}}
456DEF_STRUCT_P_FUNC(`zend_trait_alias_ptr', , `dnl {{{
457    IFDASM(`
458        pushdefFUNC_NAME(`zend_trait_alias')
459        FUNC_NAME (dasm, DST(), SRC()[0] TSRMLS_CC);
460        popdef(`FUNC_NAME')
461    ', `
462        ALLOC(DST()[0], zend_trait_alias)
463        STRUCT_P_EX(zend_trait_alias, DST()[0], SRC()[0], `[0]', `', ` ')
464        RELOCATE_EX(zend_trait_alias, DST()[0])
465    ')
466    DONE_SIZE(sizeof(zend_trait_alias))
467')
468dnl }}}
469DEF_STRUCT_P_FUNC(`zend_trait_precedence_ptr', , `dnl {{{
470    IFDASM(`
471        pushdefFUNC_NAME(`zend_trait_precedence')
472        FUNC_NAME (dasm, DST(), SRC()[0] TSRMLS_CC);
473        popdef(`FUNC_NAME')
474    ', `
475        ALLOC(DST()[0], zend_trait_precedence)
476        STRUCT_P_EX(zend_trait_precedence, DST()[0], SRC()[0], `[0]', `', ` ')
477        RELOCATE_EX(zend_trait_precedence, DST()[0])
478    ')
479    DONE_SIZE(sizeof(zend_trait_precedence))
480')
481dnl }}}
482#endif
483DEF_STRUCT_P_FUNC(`zend_class_entry', , `dnl {{{
484    IFCALCCOPY(`
485        processor->active_class_entry_src = SRC();
486        IFCOPY(`processor->active_class_entry_dst = DST();')
487    ')
488    PROCESS(char, type)
489    PROCESS(zend_uint, name_length)
490    PROC_ZSTRING_L(, name, name_length)
491    IFRESTORE(`
492#ifndef ZEND_ENGINE_2
493        /* just copy parent and resolve on install_class */
494        COPYPOINTER(parent)
495#else
496        PROC_CLASS_ENTRY_P(parent)
497#endif
498    ', `
499        PROC_CLASS_ENTRY_P(parent)
500    ')
501#ifdef ZEND_ENGINE_2
502    PROCESS(int, refcount)
503#else
504    STRUCT_P(int, refcount)
505#endif
506#ifndef ZEND_ENGINE_2_4
507    PROCESS(zend_bool, constants_updated)
508#endif
509#ifdef ZEND_ENGINE_2
510    PROCESS(zend_uint, ce_flags)
511#endif
512
513#ifdef ZEND_ENGINE_2
514    STRUCT(HashTable, properties_info, HashTable_zend_property_info)
515#endif
516
517#ifdef ZEND_ENGINE_2_4
518    STRUCT_ARRAY(int, default_properties_count, zval_ptr_nullable, default_properties_table)
519    PROCESS(int, default_properties_count)
520    STRUCT_ARRAY(int, default_static_members_count, zval_ptr_nullable, default_static_members_table)
521    PROCESS(int, default_static_members_count)
522    IFCOPY(`DST(`static_members_table') = DST(`default_static_members_table');')
523    DONE(static_members_table)
524#else
525    IFCOPY(`DST(`builtin_functions') = SRC(`builtin_functions');')
526    DONE(builtin_functions)
527    STRUCT(HashTable, default_properties, HashTable_zval_ptr)
528#   ifdef ZEND_ENGINE_2_1
529    STRUCT(HashTable, default_static_members, HashTable_zval_ptr)
530    IFCOPY(`DST(`static_members') = &DST(`default_static_members');')
531    DONE(static_members)
532#   elif defined(ZEND_ENGINE_2)
533    STRUCT_P(HashTable, static_members, HashTable_zval_ptr)
534#   endif
535#endif /* ZEND_ENGINE_2_4 */
536
537#ifdef ZEND_ENGINE_2
538    STRUCT(HashTable, constants_table, HashTable_zval_ptr)
539
540#ifdef ZEND_ENGINE_2_2
541    dnl runtime binding: ADD_INTERFACE will deal with it
542    COPYNULL(`interfaces')
543    COPYZERO(`num_interfaces')
544
545#   ifdef ZEND_ENGINE_2_4
546    dnl runtime binding: ADD_TRAIT will deal with it
547    COPYNULL(traits)
548    COPYZERO(num_traits)
549    STRUCT_ARRAY(, , zend_trait_alias_ptr, trait_aliases)
550    STRUCT_ARRAY(, , zend_trait_precedence_ptr, trait_precedences)
551#   endif
552#else
553    IFRESTORE(`
554        if (SRC(`num_interfaces')) {
555            CALLOC(DST(`interfaces'), zend_class_entry*, SRC(`num_interfaces'))
556            DONE(`interfaces')
557        }
558        else {
559            COPYNULL(`interfaces')
560        }
561    ', `
562        DONE(`interfaces')
563    ')
564    PROCESS(zend_uint, num_interfaces)
565#endif
566
567#   ifdef ZEND_ENGINE_2_4
568    DISABLECHECK(`
569    IFRESTORE(`DST(`info.user.filename') = processor->entry_php_src->filepath.str;', `PROC_STRING(info.user.filename)')
570    PROCESS(zend_uint, info.user.line_start)
571    PROCESS(zend_uint, info.user.line_end)
572    PROCESS(zend_uint, info.user.doc_comment_len)
573    PROC_ZSTRING_L(, info.user.doc_comment, info.user.doc_comment_len)
574    ')
575    DONE(info)
576#   else
577    IFRESTORE(`DST(`filename') = processor->entry_php_src->filepath.str;DONE(filename)', `PROC_STRING(filename)')
578    PROCESS(zend_uint, line_start)
579    PROCESS(zend_uint, line_end)
580    PROCESS(zend_uint, doc_comment_len)
581    PROC_ZSTRING_L(, doc_comment, doc_comment_len)
582#   endif
583
584    /* # NOT DONE */
585#   ifdef ZEND_ENGINE_2_1
586    PROCESS_CTEXTPOINTER(serialize_func)
587    PROCESS_CTEXTPOINTER(unserialize_func)
588#   endif
589    PROCESS_CTEXTPOINTER(iterator_funcs)
590    PROCESS_CTEXTPOINTER(create_object)
591    PROCESS_CTEXTPOINTER(get_iterator)
592    PROCESS_CTEXTPOINTER(interface_gets_implemented)
593#   ifdef ZEND_ENGINE_2_3
594    PROCESS_CTEXTPOINTER(get_static_method)
595#   endif
596#   ifdef ZEND_ENGINE_2_1
597    PROCESS_CTEXTPOINTER(serialize)
598    PROCESS_CTEXTPOINTER(unserialize)
599#   endif
600    /* deal with it inside xc_fix_method */
601    SETNULL(constructor)
602    PROCESS_CTEXTPOINTER(destructor)
603    PROCESS_CTEXTPOINTER(clone)
604    PROCESS_CTEXTPOINTER(__get)
605    PROCESS_CTEXTPOINTER(__set)
606/* should be >5.1 */
607#   ifdef ZEND_ENGINE_2_1
608    PROCESS_CTEXTPOINTER(__unset)
609    PROCESS_CTEXTPOINTER(__isset)
610#   endif
611    PROCESS_CTEXTPOINTER(__call)
612#   ifdef ZEND_CALLSTATIC_FUNC_NAME
613    PROCESS_CTEXTPOINTER(__callstatic)
614#   endif
615# if defined(ZEND_ENGINE_2_2) || PHP_MAJOR_VERSION >= 6
616    PROCESS_CTEXTPOINTER(__tostring)
617# endif
618# if defined(ZEND_ENGINE_2_6)
619    PROCESS_CTEXTPOINTER(__debugInfo)
620# endif
621#   ifndef ZEND_ENGINE_2_4
622    /* # NOT DONE */
623    PROCESS_CTEXTPOINTER(module)
624#   endif
625#else /* ZEND_ENGINE_2 */
626    PROCESS_CTEXTPOINTER(handle_function_call)
627    PROCESS_CTEXTPOINTER(handle_property_get)
628    PROCESS_CTEXTPOINTER(handle_property_set)
629#endif
630    dnl must do after SETNULL(constructor) and DST()->parent
631    STRUCT(HashTable, function_table, HashTable_zend_function)
632    IFRESTORE(`DST(`function_table.pDestructor') = ZEND_FUNCTION_DTOR;')
633    IFCALCCOPY(`
634        processor->active_class_entry_src = NULL;
635        IFCOPY(`processor->active_class_entry_dst = NULL;')
636    ')
637')
638dnl }}}
639#ifdef ZEND_ENGINE_2_4
640undefine(`UNION_znode_op')
641define(`UNION_znode_op', `dnl {{{
642#ifndef NDEBUG
643    switch ((SRC(`$1_type') ifelse($1, `result', & ~EXT_TYPE_UNUSED))) {
644    case IS_CONST:
645    case IS_VAR:
646    case IS_CV:
647    case IS_TMP_VAR:
648    case IS_UNUSED:
649        break;
650
651    default:
652        assert(0);
653    }
654#endif
655
656    dnl dirty dispatch
657    DISABLECHECK(`
658    switch ((SRC(`$1_type') ifelse($1, `result', & ~EXT_TYPE_UNUSED))) {
659        case IS_CONST:
660            ifelse($1, `result', `
661                PROCESS(zend_uint, $1.constant)
662            ', `
663                IFDASM(`{
664                    zval *zv;
665                    zval *srczv = &dasm->active_op_array_src->literals[SRC(`$1.constant')].constant;
666                    ALLOC_ZVAL(zv);
667                    MAKE_COPY_ZVAL(&srczv, zv);
668                    add_assoc_zval_ex(DST(), XCACHE_STRS("$1.constant"), zv);
669                }
670                ', `
671                    IFCOPY(`
672                        DST(`$1') = SRC(`$1');
673                    ', `
674                        PROCESS(zend_uint, $1.constant)
675                    ')
676                ')
677            ')
678            break;
679        IFCOPY(`
680            IFNOTMEMCPY(`
681                default:
682                    DST(`$1') = SRC(`$1');
683            ')
684        ', `
685        case IS_VAR:
686        case IS_TMP_VAR:
687        case IS_CV:
688            PROCESS(zend_uint, $1.var)
689            break;
690        case IS_UNUSED:
691            IFDASM(`PROCESS(zend_uint, $1.var)')
692            PROCESS(zend_uint, $1.opline_num)
693            break;
694        ')
695    }
696    ')
697    DONE($1)
698')
699dnl }}}
700#else
701DEF_STRUCT_P_FUNC(`znode', , `dnl {{{
702    PROCESS(xc_op_type, op_type)
703
704#ifdef IS_CV
705#   define XCACHE_IS_CV IS_CV
706#else
707/* compatible with zend optimizer */
708#   define XCACHE_IS_CV 16
709#endif
710    assert(SRC(`op_type') == IS_CONST ||
711        SRC(`op_type') == IS_VAR ||
712        SRC(`op_type') == XCACHE_IS_CV ||
713        SRC(`op_type') == IS_TMP_VAR ||
714        SRC(`op_type') == IS_UNUSED);
715    dnl dirty dispatch
716    DISABLECHECK(`
717    switch (SRC(`op_type')) {
718        case IS_CONST:
719            STRUCT(zval, u.constant)
720            break;
721        IFCOPY(`
722            IFNOTMEMCPY(`
723                default:
724                    DST(`u') = SRC(`u');
725            ')
726        ', `
727        case IS_VAR:
728        case IS_TMP_VAR:
729        case XCACHE_IS_CV:
730            PROCESS(zend_uint, u.var)
731            PROCESS(zend_uint, u.EA.type)
732            break;
733        case IS_UNUSED:
734            IFDASM(`PROCESS(zend_uint, u.var)')
735            PROCESS(zend_uint, u.opline_num)
736#ifndef ZEND_ENGINE_2
737            PROCESS(zend_uint, u.fetch_type)
738#endif
739            PROCESS(zend_uint, u.EA.type)
740            break;
741        ')
742    }
743    ')
744    DONE(u)
745#if 0
746    DONE(EA)
747#endif
748#undef XCACHE_IS_CV
749')
750dnl }}}
751#endif
752DEF_STRUCT_P_FUNC(`zend_op', , `dnl {{{
753    PROCESS(xc_opcode, opcode)
754#ifdef ZEND_ENGINE_2_4
755    IFRESTORE(`', `
756    switch (SRC(`opcode')) {
757    case ZEND_BIND_TRAITS:
758        ((zend_op *) SRC())->op2_type = IS_UNUSED;
759        break;
760    }
761    ')
762    UNION_znode_op(result)
763    UNION_znode_op(op1)
764    UNION_znode_op(op2)
765#else
766    STRUCT(znode, result)
767    STRUCT(znode, op1)
768    STRUCT(znode, op2)
769#endif
770    PROCESS(ulong, extended_value)
771    PROCESS(uint, lineno)
772#ifdef ZEND_ENGINE_2_4
773    PROCESS(zend_uchar, op1_type)
774    PROCESS(zend_uchar, op2_type)
775    PROCESS(zend_uchar, result_type)
776#endif
777    IFCOPY(`
778        assert(processor->active_op_array_src);
779        assert(processor->active_op_array_dst);
780#ifdef ZEND_ENGINE_2_4
781        pushdef(`UNION_znode_op_literal', `
782            if (SRC(`$1_type') == IS_CONST) {
783                DST(`$1').constant = SRC(`$1.literal') - processor->active_op_array_src->literals;
784                DST(`$1').literal = &processor->active_op_array_dst->literals[DST(`$1').constant];
785            }
786        ')
787        UNION_znode_op_literal(op1)
788        UNION_znode_op_literal(op2)
789#endif
790        popdef(`UNION_znode_op_literal')
791#ifdef ZEND_ENGINE_2
792        switch (SRC(`opcode')) {
793#   ifdef ZEND_GOTO
794            case ZEND_GOTO:
795#   endif
796            case ZEND_JMP:
797#   ifdef ZEND_FAST_CALL
798            case ZEND_FAST_CALL:
799#   endif
800                assert(Z_OP(SRC(`op1')).jmp_addr >= processor->active_op_array_src->opcodes);
801                assert(Z_OP(SRC(`op1')).jmp_addr - processor->active_op_array_src->opcodes < processor->active_op_array_src->last);
802                Z_OP(DST(`op1')).jmp_addr = processor->active_op_array_dst->opcodes + (Z_OP(SRC(`op1')).jmp_addr - processor->active_op_array_src->opcodes);
803                assert(Z_OP(DST(`op1')).jmp_addr >= processor->active_op_array_dst->opcodes);
804                assert(Z_OP(DST(`op1')).jmp_addr - processor->active_op_array_dst->opcodes < processor->active_op_array_dst->last);
805                RELOCATE_EX(zend_op, `Z_OP(DST(`op1')).jmp_addr')
806                break;
807
808            case ZEND_JMPZ:
809            case ZEND_JMPNZ:
810            case ZEND_JMPZ_EX:
811            case ZEND_JMPNZ_EX:
812#   ifdef ZEND_JMP_SET
813            case ZEND_JMP_SET:
814#   endif
815#   ifdef ZEND_JMP_SET_VAR
816            case ZEND_JMP_SET_VAR:
817#   endif
818                assert(Z_OP(SRC(`op2')).jmp_addr >= processor->active_op_array_src->opcodes);
819                assert(Z_OP(SRC(`op2')).jmp_addr - processor->active_op_array_src->opcodes < processor->active_op_array_src->last);
820                Z_OP(DST(`op2')).jmp_addr = processor->active_op_array_dst->opcodes + (Z_OP(SRC(`op2')).jmp_addr - processor->active_op_array_src->opcodes);
821                assert(Z_OP(DST(`op2')).jmp_addr >= processor->active_op_array_dst->opcodes);
822                assert(Z_OP(DST(`op2')).jmp_addr - processor->active_op_array_dst->opcodes < processor->active_op_array_dst->last);
823                RELOCATE_EX(zend_op, `Z_OP(DST(`op2')).jmp_addr')
824                break;
825
826            default:
827                break;
828        }
829#   endif
830    ')
831#ifdef ZEND_ENGINE_2
832    PROCESS(opcode_handler_t, handler)
833#endif
834')
835dnl }}}
836#ifdef ZEND_ENGINE_2_4
837DEF_STRUCT_P_FUNC(`zend_literal', , `dnl {{{
838    STRUCT(zval, constant)
839    PROCESS(zend_ulong, hash_value)
840    PROCESS(zend_uint,  cache_slot)
841')
842dnl }}}
843#endif
844DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
845    IFCOPY(`
846        processor->active_op_array_dst = DST();
847        processor->active_op_array_src = SRC();
848    ')
849    IFDASM(`
850        dasm->active_op_array_src = SRC();
851    ')
852    {
853    IFRESTORE(`
854    const xc_op_array_info_t *op_array_info = &processor->active_op_array_infos_src[processor->active_op_array_index++];
855    dnl shadow copy must NOT meet:
856    dnl readonly_protection=on
857    dnl main op_array && have early binding
858#ifdef ZEND_COMPILE_DELAYED_BINDING
859    zend_bool need_early_binding = 0;
860#else
861    zend_bool need_early_binding = processor->php_src->have_early_binding;
862#endif
863    zend_bool shallow_copy = !processor->readonly_protection && !(SRC() == processor->php_src->op_array && need_early_binding);
864    if (shallow_copy) {
865        zend_bool gc_arg_info = 0;
866        zend_bool gc_opcodes  = 0;
867#ifdef ZEND_ENGINE_2_4
868        zend_bool gc_literals = 0;
869#endif
870        /* really fast shallow copy */
871        memcpy(DST(), SRC(), sizeof(SRC()[0]));
872        DST(`refcount') = &XG(op_array_dummy_refcount_holder);
873        XG(op_array_dummy_refcount_holder) = ((zend_uint) -1) / 2;
874#ifdef ZEND_ACC_ALIAS
875        if ((processor->active_class_entry_src && (processor->active_class_entry_src->ce_flags & ZEND_ACC_TRAIT))) {
876            PROC_ZSTRING(, function_name)
877        }
878#endif
879        /* deep */
880        STRUCT_P(HashTable, static_variables, HashTable_zval_ptr)
881#ifdef ZEND_ENGINE_2
882        if (SRC(`arg_info')) {
883            gc_arg_info = 1;
884            STRUCT_ARRAY(zend_uint, num_args, zend_arg_info, arg_info)
885        }
886#endif
887        DST(`filename') = processor->entry_php_src->filepath.str;
888
889#ifdef ZEND_ENGINE_2_4
890        if (SRC(`literals') && op_array_info->constantinfo_cnt) {
891            gc_opcodes = 1;
892            gc_literals = 1;
893        }
894#else
895        if (op_array_info->constantinfo_cnt) {
896            gc_opcodes = 1;
897        }
898#endif
899
900#ifdef ZEND_ENGINE_2_4
901        if (gc_literals) {
902            dnl used when copying opcodes
903            COPY_N_EX(last_literal, zend_literal, literals)
904        }
905#endif
906        if (gc_opcodes) {
907            zend_op *opline, *end;
908            COPY_N_EX(last, zend_op, opcodes)
909
910            for (opline = DST(`opcodes'), end = opline + SRC(`last'); opline < end; ++opline) {
911#ifdef ZEND_ENGINE_2_4
912                pushdef(`UNION_znode_op_literal', `
913                    if (opline->$1_type == IS_CONST) {
914                        opline->$1.literal = &DST(`literals[opline->$1.literal - SRC(`literals')]');
915                    }
916                ')
917                UNION_znode_op_literal(op1)
918                UNION_znode_op_literal(op2)
919                popdef(`UNION_znode_op_literal')
920#endif
921
922                switch (opline->opcode) {
923#ifdef ZEND_GOTO
924                    case ZEND_GOTO:
925#endif
926                    case ZEND_JMP:
927#ifdef ZEND_FAST_CALL
928                    case ZEND_FAST_CALL:
929#endif
930#ifdef ZEND_ENGINE_2
931                        Z_OP(opline->op1).jmp_addr = &DST(`opcodes[Z_OP(opline->op1).jmp_addr') - SRC(`opcodes')];
932#endif
933                        break;
934
935                    case ZEND_JMPZ:
936                    case ZEND_JMPNZ:
937                    case ZEND_JMPZ_EX:
938                    case ZEND_JMPNZ_EX:
939#ifdef ZEND_JMP_SET
940                    case ZEND_JMP_SET:
941#endif
942#ifdef ZEND_JMP_SET_VAR
943            case ZEND_JMP_SET_VAR:
944#endif
945#ifdef ZEND_ENGINE_2
946                        Z_OP(opline->op2).jmp_addr = &DST(`opcodes[Z_OP(opline->op2).jmp_addr') - SRC(`opcodes')];
947#endif
948                        break;
949
950                    default:
951                        break;
952                }
953            }
954        }
955        if (gc_arg_info || gc_opcodes
956#ifdef ZEND_ENGINE_2_4
957         || gc_literals
958#endif
959        ) {
960            xc_gc_op_array_t gc_op_array;
961#ifdef ZEND_ENGINE_2
962            gc_op_array.num_args = gc_arg_info ? DST(`num_args') : 0;
963            gc_op_array.arg_info = gc_arg_info ? DST(`arg_info') : NULL;
964#endif
965            gc_op_array.opcodes  = gc_opcodes ? DST(`opcodes') : NULL;
966#ifdef ZEND_ENGINE_2_4
967            gc_op_array.literals = gc_literals ? DST(`literals') : NULL;
968#endif
969            xc_gc_add_op_array(&gc_op_array TSRMLS_CC);
970        }
971        IFAUTOCHECK(`xc_autocheck_skip = 1;')
972    }
973    else
974    ')
975    do {
976    dnl RESTORE is done above!
977
978    /* Common elements */
979    PROCESS(zend_uchar, type)
980    PROC_ZSTRING(, function_name)
981#ifdef ZEND_ENGINE_2
982    PROCESS(zend_uint, fn_flags)
983    STRUCT_ARRAY(zend_uint, num_args, zend_arg_info, arg_info)
984    PROCESS(zend_uint, num_args)
985    PROCESS(zend_uint, required_num_args)
986#   ifndef ZEND_ENGINE_2_4
987    PROCESS(zend_bool, pass_rest_by_reference)
988#   endif
989#else
990    if (SRC(`arg_types')) {
991        ALLOC(`DST(`arg_types')', zend_uchar, SRC(`arg_types[0]') + 1)
992        IFCOPY(`memcpy(DST(`arg_types'), SRC(`arg_types'), sizeof(SRC(`arg_types[0]')) * (SRC(`arg_types[0]')+1));')
993        IFDASM(`do {
994            int i;
995            zval *zv;
996            ALLOC_INIT_ZVAL(zv);
997            array_init(zv);
998            for (i = 0; i < SRC(`arg_types[0]'); i ++) {
999                add_next_index_long(zv, SRC(`arg_types[i + 1]'));
1000            }
1001            add_assoc_zval_ex(DST(), ZEND_STRS("arg_types"), zv);
1002        } while (0);')
1003        DONE(arg_types)
1004    }
1005    else {
1006        COPYNULL(arg_types)
1007    }
1008#endif
1009#ifndef ZEND_ENGINE_2_4
1010    PROCESS(unsigned char, return_reference)
1011#endif
1012    /* END of common elements */
1013#ifdef IS_UNICODE
1014    dnl SETNULL(u_twin)
1015#endif
1016
1017    IFSTORE(`pushdef(`RELOCATE_EX')')
1018    STRUCT_P(zend_uint, refcount)
1019    IFSTORE(`
1020        popdef(`RELOCATE_EX')
1021        DST(`refcount[0]') = 1;
1022        RELOCATE(zend_uint, refcount)
1023    ')
1024
1025#ifdef ZEND_ENGINE_2_4
1026    dnl used when copying opcodes
1027    STRUCT_ARRAY(int, last_literal, zend_literal, literals)
1028    PROCESS(int, last_literal)
1029#endif
1030
1031    dnl uses literals
1032    STRUCT_ARRAY(zend_uint, last, zend_op, opcodes)
1033    PROCESS(zend_uint, last)
1034#ifndef ZEND_ENGINE_2_4
1035    IFCOPY(`DST(`size') = SRC(`last');DONE(size)', `PROCESS(zend_uint, size)')
1036#endif
1037
1038#ifdef IS_CV
1039    STRUCT_ARRAY(int, last_var, zend_compiled_variable, vars)
1040    PROCESS(int, last_var)
1041#   ifndef ZEND_ENGINE_2_4
1042    IFCOPY(`DST(`size_var') = SRC(`last_var');DONE(size_var)', `PROCESS(zend_uint, size_var)')
1043#   endif
1044#else
1045    dnl zend_cv.m4 is illegal to be made public, don not ask me for it
1046    IFDASM(`
1047        sinclude(__dir__`/zend_cv.m4')
1048        ')
1049#endif
1050
1051    PROCESS(zend_uint, T)
1052
1053#ifdef ZEND_ENGINE_2_5
1054    PROCESS(zend_uint, nested_calls)
1055    PROCESS(zend_uint, used_stack)
1056#endif
1057
1058    STRUCT_ARRAY(last_brk_cont_t, last_brk_cont, zend_brk_cont_element, brk_cont_array)
1059    PROCESS(last_brk_cont_t, last_brk_cont)
1060#ifndef ZEND_ENGINE_2_4
1061    PROCESS(zend_uint, current_brk_cont)
1062#endif
1063#ifndef ZEND_ENGINE_2
1064    PROCESS(zend_bool, uses_globals)
1065#endif
1066
1067#ifdef ZEND_ENGINE_2
1068    STRUCT_ARRAY(int, last_try_catch, zend_try_catch_element, try_catch_array)
1069    PROCESS(int, last_try_catch)
1070#endif
1071#ifdef ZEND_ENGINE_2_5
1072    PROCESS(zend_bool, has_finally_block)
1073#endif
1074
1075    STRUCT_P(HashTable, static_variables, HashTable_zval_ptr)
1076
1077#ifndef ZEND_ENGINE_2_4
1078    COPYPOINTER(start_op)
1079    PROCESS(int, backpatch_count)
1080#endif
1081#ifdef ZEND_ENGINE_2_3
1082    PROCESS(zend_uint, this_var)
1083#endif
1084
1085#ifndef ZEND_ENGINE_2_4
1086    PROCESS(zend_bool, done_pass_two)
1087#endif
1088    /* 5.0 <= ver < 5.3 */
1089#if defined(ZEND_ENGINE_2) && !defined(ZEND_ENGINE_2_3)
1090    PROCESS(zend_bool, uses_this)
1091#endif
1092
1093    IFRESTORE(`DST(`filename') = processor->entry_php_src->filepath.str; DONE(filename)', `PROC_STRING(filename)')
1094#ifdef IS_UNICODE
1095    IFRESTORE(`
1096        COPYPOINTER(script_encoding)
1097    ', `
1098        PROC_STRING(script_encoding)
1099    ')
1100#endif
1101#ifdef ZEND_ENGINE_2
1102    PROCESS(zend_uint, line_start)
1103    PROCESS(zend_uint, line_end)
1104    PROCESS(int, doc_comment_len)
1105    PROC_ZSTRING_L(, doc_comment, doc_comment_len)
1106#endif
1107#ifdef ZEND_COMPILE_DELAYED_BINDING
1108    PROCESS(zend_uint, early_binding);
1109#endif
1110
1111    /* reserved */
1112    DONE(reserved)
1113#if defined(HARDENING_PATCH) && HARDENING_PATCH
1114    PROCESS(zend_bool, created_by_eval)
1115#endif
1116#ifdef ZEND_ENGINE_2_4
1117    SETNULL(run_time_cache)
1118    PROCESS(int, last_cache_slot)
1119#endif
1120    } while (0);
1121    IFRESTORE(`xc_fix_op_array_info(processor->entry_php_src, DST(), shallow_copy, op_array_info TSRMLS_CC);')
1122
1123#ifdef ZEND_ENGINE_2
1124    dnl mark it as -1 on store, and lookup parent on restore
1125    IFSTORE(`DST(`prototype') = (processor->active_class_entry_src && SRC(`prototype')) ? (zend_function *) -1 : NULL;', `
1126        IFRESTORE(`do {
1127            zend_function *parent;
1128            if (SRC(`prototype') != NULL
1129             && zend_u_hash_find(&(processor->active_class_entry_dst->parent->function_table),
1130                    UG(unicode) ? IS_UNICODE : IS_STRING,
1131                    SRC(`function_name'), xc_zstrlen(UG(unicode) ? IS_UNICODE : IS_STRING, SRC(`function_name')) + 1,
1132                    (void **) &parent) == SUCCESS) {
1133                /* see do_inherit_method_check() */
1134                if ((parent->common.fn_flags & ZEND_ACC_ABSTRACT)) {
1135                    DST(`prototype') = parent;
1136                } else if (!(parent->common.fn_flags & ZEND_ACC_CTOR) || (parent->common.prototype && (parent->common.prototype->common.scope->ce_flags & ZEND_ACC_INTERFACE))) {
1137                    /* ctors only have a prototype if it comes from an interface */
1138                    DST(`prototype') = parent->common.prototype ? parent->common.prototype : parent;
1139                }
1140                else {
1141                    DST(`prototype') = NULL;
1142                }
1143            }
1144            else {
1145                DST(`prototype') = NULL;
1146            }
1147        } while (0);
1148        ')
1149    ')
1150    DONE(prototype)
1151
1152#endif
1153
1154#ifdef ZEND_ENGINE_2
1155    PROC_CLASS_ENTRY_P(scope)
1156    IFCOPY(`
1157        if (SRC(`scope')) {
1158            xc_fix_method(processor, DST() TSRMLS_CC);
1159        }
1160    ')
1161#endif
1162
1163    IFRESTORE(`
1164        if (xc_have_op_array_ctor) {
1165            zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) xc_zend_extension_op_array_ctor_handler, DST() TSRMLS_CC);
1166        }
1167    ')
1168    }
1169    IFCOPY(`
1170        processor->active_op_array_dst = NULL;
1171        processor->active_op_array_src = NULL;
1172    ')
1173    IFDASM(`
1174        dasm->active_op_array_src = NULL;
1175    ')
1176')
1177dnl }}}
1178
1179#ifdef HAVE_XCACHE_CONSTANT
1180DEF_STRUCT_P_FUNC(`xc_constinfo_t', , `dnl {{{
1181    PROCESS(zend_uint, key_size)
1182#ifdef IS_UNICODE
1183    PROCESS(zend_uchar, type)
1184#endif
1185    IFRESTORE(`COPYPOINTER(key)', `
1186        PROC_ZSTRING_N(type, key, key_size)
1187    ')
1188    PROCESS(ulong, h)
1189    STRUCT(zend_constant, constant)
1190')
1191dnl }}}
1192#endif
1193IFRESTORE(`', `
1194DEF_STRUCT_P_FUNC(`xc_constant_info_t', , `dnl {{{
1195    PROCESS(zend_uint, index)
1196    PROCESS(zend_uint, info)
1197')
1198dnl }}}
1199DEF_STRUCT_P_FUNC(`xc_op_array_info_t', , `dnl {{{
1200    PROCESS(zend_uint, constantinfo_cnt)
1201    STRUCT_ARRAY(zend_uint, constantinfo_cnt, xc_constant_info_t, constantinfos)
1202')
1203dnl }}}
1204')
1205DEF_STRUCT_P_FUNC(`xc_funcinfo_t', , `dnl {{{
1206    PROCESS(zend_uint, key_size)
1207#ifdef IS_UNICODE
1208    PROCESS(zend_uchar, type)
1209#endif
1210    IFRESTORE(`COPYPOINTER(key)', `
1211        PROC_ZSTRING_N(type, key, key_size)
1212    ')
1213    PROCESS(ulong, h)
1214    IFRESTORE(`COPYPOINTER(op_array_info)', `
1215        STRUCT(xc_op_array_info_t, op_array_info)
1216    ')
1217    IFRESTORE(`
1218        processor->active_op_array_infos_src = &SRC(`op_array_info');
1219        processor->active_op_array_index = 0;
1220    ')
1221    STRUCT(zend_function, func)
1222')
1223dnl }}}
1224DEF_STRUCT_P_FUNC(`xc_classinfo_t', , `dnl {{{
1225    PROCESS(zend_uint, key_size)
1226#ifdef IS_UNICODE
1227    PROCESS(zend_uchar, type)
1228#endif
1229    IFRESTORE(`COPYPOINTER(key)', `
1230        PROC_ZSTRING_N(type, key, key_size)
1231    ')
1232    PROCESS(ulong, h)
1233    PROCESS(zend_uint, methodinfo_cnt)
1234    IFRESTORE(`COPYPOINTER(methodinfos)', `
1235        STRUCT_ARRAY(zend_uint, methodinfo_cnt, xc_op_array_info_t, methodinfos)
1236    ')
1237#ifdef ZEND_ENGINE_2
1238    PROCESS(zend_uint, constantinfo_cnt)
1239    IFRESTORE(`COPYPOINTER(constantinfos)', `
1240        STRUCT_ARRAY(zend_uint, constantinfo_cnt, xc_constant_info_t, constantinfos)
1241    ')
1242#endif
1243    IFRESTORE(`
1244        processor->active_op_array_infos_src = SRC(`methodinfos');
1245        processor->active_op_array_index = 0;
1246    ')
1247#ifdef ZEND_ENGINE_2
1248    STRUCT_P(zend_class_entry, cest)
1249#else
1250    STRUCT(zend_class_entry, cest)
1251#endif
1252#ifdef ZEND_ENGINE_2
1253    IFRESTORE(`xc_fix_class_info(processor->entry_php_src, DST(), 0 TSRMLS_CC);')
1254#endif
1255#ifndef ZEND_COMPILE_DELAYED_BINDING
1256    PROCESS(int, oplineno)
1257#endif
1258')
1259dnl }}}
1260IFRESTORE(`', `
1261#ifdef ZEND_ENGINE_2_1
1262DEF_STRUCT_P_FUNC(`xc_autoglobal_t', , `dnl {{{
1263    PROCESS(zend_uint, key_len)
1264#ifdef IS_UNICODE
1265    PROCESS(zend_uchar, type)
1266#endif
1267    IFRESTORE(`COPYPOINTER(key)', `
1268        PROC_ZSTRING_L(type, key, key_len)
1269    ')
1270    PROCESS(ulong, h)
1271')
1272dnl }}}
1273#endif
1274')
1275IFRESTORE(`', `
1276#ifdef XCACHE_ERROR_CACHING
1277DEF_STRUCT_P_FUNC(`xc_compilererror_t', , `dnl {{{
1278    PROCESS(int, type)
1279    PROCESS(uint, lineno)
1280    PROCESS(int, error_len)
1281    PROC_STRING_L(error, error_len)
1282')
1283dnl }}}
1284#endif
1285')
1286DEF_STRUCT_P_FUNC(`xc_entry_data_php_t', , `dnl {{{
1287    IFCOPY(`
1288        processor->php_dst = DST();
1289        processor->php_src = SRC();
1290    ')
1291
1292    /* skip */
1293    DONE(next)
1294    PROCESS(xc_hash_value_t, hvalue)
1295    PROCESS(xc_md5sum_t, md5)
1296    PROCESS(zend_ulong, refcount)
1297
1298    PROCESS(zend_ulong, hits)
1299    PROCESS(size_t, size)
1300
1301    IFRESTORE(`COPYPOINTER(op_array_info)', `
1302        STRUCT(xc_op_array_info_t, op_array_info)
1303    ')
1304    IFRESTORE(`
1305        processor->active_op_array_infos_src = &DST(`op_array_info');
1306        processor->active_op_array_index = 0;
1307    ')
1308    STRUCT_P(zend_op_array, op_array)
1309
1310#ifdef HAVE_XCACHE_CONSTANT
1311    PROCESS(zend_uint, constinfo_cnt)
1312    STRUCT_ARRAY(zend_uint, constinfo_cnt, xc_constinfo_t, constinfos)
1313#endif
1314
1315    PROCESS(zend_uint, funcinfo_cnt)
1316    STRUCT_ARRAY(zend_uint, funcinfo_cnt, xc_funcinfo_t, funcinfos)
1317
1318    PROCESS(zend_uint, classinfo_cnt)
1319    STRUCT_ARRAY(zend_uint, classinfo_cnt, xc_classinfo_t, classinfos, , IFCOPY(`processor->active_class_index'))
1320#ifdef ZEND_ENGINE_2_1
1321    PROCESS(zend_uint, autoglobal_cnt)
1322    IFRESTORE(`
1323        COPYPOINTER(autoglobals)
1324    ', `
1325        STRUCT_ARRAY(zend_uint, autoglobal_cnt, xc_autoglobal_t, autoglobals)
1326    ')
1327#endif
1328#ifdef XCACHE_ERROR_CACHING
1329    PROCESS(zend_uint, compilererror_cnt)
1330    IFRESTORE(`
1331        COPYPOINTER(compilererrors)
1332    ', `
1333        STRUCT_ARRAY(zend_uint, compilererror_cnt, xc_compilererror_t, compilererrors)
1334    ')
1335#endif
1336#ifndef ZEND_COMPILE_DELAYED_BINDING
1337    PROCESS(zend_bool, have_early_binding)
1338#endif
1339    PROCESS(zend_bool, have_references)
1340')
1341dnl }}}
1342DEF_STRUCT_P_FUNC(`xc_entry_t', , `dnl {{{
1343    /* skip */
1344    DONE(next)
1345    PROCESS(size_t, size)
1346
1347    PROCESS(time_t, ctime)
1348    PROCESS(time_t, atime)
1349    PROCESS(time_t, dtime)
1350    PROCESS(long, ttl)
1351    PROCESS(zend_ulong, hits)
1352    DONE(name) dnl handle in xc_entry_php_t and xc_entry_var_t
1353')
1354dnl }}}
1355DEF_STRUCT_P_FUNC(`xc_constant_string_t', , `dnl {{{
1356    PROCESS(size_t, len)
1357    IFRESTORE(`COPYPOINTER(str)', `PROC_STRING_L(str, len)')
1358')
1359dnl }}}
1360#ifdef IS_UNICODE
1361DEF_STRUCT_P_FUNC(`xc_constant_u_string_t', , `dnl {{{
1362    PROCESS(size_t, len)
1363    IFRESTORE(`COPYPOINTER(str)', `PROC_USTRING_L(str, len)')
1364')
1365dnl }}}
1366#endif
1367DEF_STRUCT_P_FUNC(`xc_entry_php_t', , `dnl {{{
1368    STRUCT(xc_entry_t, entry)
1369    DISABLECHECK(`
1370        PROCESS(int, entry.name.str.len)
1371        IFRESTORE(`COPYPOINTER(entry.name.str.val)', `
1372            PROC_STRING_L(entry.name.str.val, entry.name.str.len)
1373        ')
1374    ')
1375
1376    IFCALCCOPY(`COPYPOINTER(php)', `STRUCT_P(xc_entry_data_php_t, php)')
1377
1378    IFSTORE(`DST(`refcount') = 0; DONE(refcount)', `PROCESS(long, refcount)')
1379    PROCESS(time_t, file_mtime)
1380    PROCESS(size_t, file_size)
1381    PROCESS(size_t, file_device)
1382    PROCESS(size_t, file_inode)
1383
1384    STRUCT(xc_constant_string_t, filepath)
1385#ifdef ZEND_ENGINE_2_3
1386    STRUCT(xc_constant_string_t, dirpath)
1387#endif
1388#ifdef IS_UNICODE
1389    STRUCT(xc_constant_u_string_t, u_filepath)
1390    STRUCT(xc_constant_u_string_t, u_dirpath)
1391#endif
1392')
1393dnl }}}
1394DEF_STRUCT_P_FUNC(`xc_entry_var_t', , `dnl {{{
1395    IFCALCSTORE(`xc_entry_var_t *vsrc = /* const_cast */ (xc_entry_var_t *) src;')
1396    IFRESTORE(`processor->entry_var_src = src;')
1397
1398    dnl restore is done in foot.m4
1399    STRUCT(xc_entry_t, entry)
1400
1401#ifdef IS_UNICODE
1402    PROCESS(zend_uchar, name_type)
1403#endif
1404    dnl {{{ entry.name
1405    DISABLECHECK(`
1406#ifdef IS_UNICODE
1407        if (SRC(`name_type') == IS_UNICODE) {
1408            PROCESS(int32_t, entry.name.ustr.len)
1409        }
1410        else {
1411            PROCESS(int, entry.name.str.len)
1412        }
1413#else
1414        PROCESS(int, entry.name.str.len)
1415#endif
1416        IFRESTORE(`COPYPOINTER(entry.name.str.val)', `
1417#ifdef IS_UNICODE
1418            PROC_ZSTRING_L(name_type, entry.name.uni.val, entry.name.uni.len)
1419#else
1420            PROC_STRING_L(entry.name.str.val, entry.name.str.len)
1421#endif
1422        ')
1423    ')
1424    dnl }}}
1425
1426    IFDPRINT(`INDENT()`'fprintf(stderr, "zval:value");')
1427    STRUCT_P_EX(zval_ptr, DST(`value'), SRC(`value'), `value', `', `&')
1428    DONE(value)
1429#if 0
1430    IFSTORE(`
1431    {
1432        HashTable *ht;
1433        zval **zv;
1434
1435        assert(Z_TYPE_P(DST(`value')) == IS_ARRAY);
1436        ht = Z_ARRVAL_P(DST(`value'));
1437        assert(ht->nNumOfElements == 1);
1438        fprintf(stderr, "key %s\n", ht->pListHead->arKey);
1439
1440        zv = (zval **) ht->pListHead->pData;
1441        assert(Z_TYPE_PP(zv) == IS_ARRAY);
1442        assert(Z_ARRVAL_PP(zv) == ht);
1443        fprintf(stderr, "refcount=%d\n", Z_REFCOUNT(*DST(`value')));
1444        fprintf(stderr, "refcount=%d\n", Z_REFCOUNT(**zv));
1445    }
1446    ')
1447#endif
1448
1449#ifdef ZEND_ENGINE_2
1450    IFCALC(`
1451        dnl objects = collect_from(value + objects);
1452        pushdef(`src', `vsrc')
1453        SRC(objects_count) = xc_vector_size(&processor->objects);
1454        SRC(objects) = xc_vector_detach(zend_object, &processor->objects);
1455        popdef(`src')
1456        xc_vector_destroy(&processor->objects);
1457    ')
1458    dnl must be after calc .value
1459    PROCESS(zend_uint, objects_count)
1460    STRUCT_ARRAY(zend_uint, objects_count, zend_object, objects)
1461    IFSTORE(`{
1462        /* no longer needed */
1463        if (vsrc->objects_count) {
1464            efree(vsrc->objects);
1465            vsrc->objects_count = 0;
1466            vsrc->objects = NULL;
1467            zend_hash_destroy(&processor->handle_to_index);
1468        }
1469    }')
1470#endif
1471
1472    dnl classe_
1473    IFCALC(`
1474        dnl class_names = collect_from(objects);
1475        pushdef(`src', `vsrc')
1476        SRC(class_names_count) = xc_vector_size(&processor->class_names);
1477        SRC(class_names) = xc_vector_detach(xc_constant_string_t, &processor->class_names);
1478        popdef(`src')
1479        xc_vector_destroy(&processor->class_names);
1480    ')
1481    PROCESS(zend_uint, class_names_count)
1482    STRUCT_ARRAY(zend_uint, class_names_count, xc_constant_string_t, class_names)
1483    IFSTORE(`
1484        /* no longer needed */
1485        if (vsrc->class_names_count) {
1486            efree(vsrc->class_names);
1487            vsrc->class_names_count = 0;
1488            vsrc->class_names = NULL;
1489            zend_hash_destroy(&processor->class_name_to_index);
1490        }
1491    ')
1492
1493    PROCESS(zend_bool, have_references)
1494')
1495dnl }}}
1496dnl ====================================================
Note: See TracBrowser for help on using the repository browser.