source: trunk/processor/processor.m4 @ 880

Last change on this file since 880 was 880, checked in by moo, 3 years ago

fix release build

  • Property svn:eol-style set to native
File size: 29.6 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')
52dnl }}}
53#endif
54DEF_STRUCT_P_FUNC(`zend_brk_cont_element', , `dnl {{{
55#ifdef ZEND_ENGINE_2_2
56    PROCESS(int, start)
57#endif
58    PROCESS(int, cont)
59    PROCESS(int, brk)
60    PROCESS(int, parent)
61')
62dnl }}}
63DEF_HASH_TABLE_FUNC(`HashTable_zval_ptr',           `zval_ptr')
64DEF_HASH_TABLE_FUNC(`HashTable_zend_function',      `zend_function')
65#ifdef ZEND_ENGINE_2
66DEF_HASH_TABLE_FUNC(`HashTable_zend_property_info', `zend_property_info')
67#endif
68DEF_STRUCT_P_FUNC(`zval', , `dnl {{{
69    IFDASM(`do {
70        zval_dtor(dst);
71        *dst = *src;
72        zval_copy_ctor(dst);
73        Z_SET_REFCOUNT(*dst, 1);
74        DONE(value)
75        DONE(type)
76#ifdef ZEND_ENGINE_2_3
77        DONE(is_ref__gc)
78        DONE(refcount__gc)
79#else
80        DONE(is_ref)
81        DONE(refcount)
82#endif
83    } while(0);
84    ', `
85        dnl IFDASM else
86        /* Variable information */
87dnl {{{ zvalue_value
88        DISABLECHECK(`
89        switch ((Z_TYPE_P(src) & IS_CONSTANT_TYPE_MASK)) {
90            case IS_LONG:
91            case IS_RESOURCE:
92            case IS_BOOL:
93                PROCESS(long, value.lval)
94                break;
95            case IS_DOUBLE:
96                PROCESS(double, value.dval)
97                break;
98            case IS_NULL:
99                IFDPRINT(`INDENT()`'fprintf(stderr, "\tNULL\n");')
100                break;
101
102            case IS_CONSTANT:
103#ifdef IS_UNICODE
104                if (UG(unicode)) {
105                    goto proc_unicode;
106                }
107#endif
108            case IS_STRING:
109#ifdef FLAG_IS_BC
110            case FLAG_IS_BC:
111#endif
112                PROCESS(int, value.str.len)
113                PROC_STRING_L(value.str.val, value.str.len)
114                break;
115#ifdef IS_UNICODE
116            case IS_UNICODE:
117proc_unicode:
118                PROCESS(int32_t, value.uni.len)
119                PROC_ZSTRING_L(1, value.uni.val, value.uni.len)
120                break;
121#endif
122
123            case IS_ARRAY:
124            case IS_CONSTANT_ARRAY:
125                STRUCT_P(HashTable, value.ht, HashTable_zval_ptr)
126                break;
127
128            case IS_OBJECT:
129                IFNOTMEMCPY(`IFCOPY(`memcpy(dst, src, sizeof(src[0]));')')
130                dnl STRUCT(value.obj)
131#ifndef ZEND_ENGINE_2
132                STRUCT_P(zend_class_entry, value.obj.ce)
133                STRUCT_P(HashTable, value.obj.properties, HashTable_zval_ptr)
134#endif
135                break;
136
137            default:
138                assert(0);
139        }
140        ')
141dnl }}}
142        DONE(value)
143        PROCESS(xc_zval_data_type, type)
144#ifdef ZEND_ENGINE_2_3
145        PROCESS(zend_uchar, is_ref__gc)
146#else
147        PROCESS(zend_uchar, is_ref)
148#endif
149
150#ifdef ZEND_ENGINE_2_3
151        PROCESS(zend_uint, refcount__gc)
152#elif defined(ZEND_ENGINE_2)
153        PROCESS(zend_uint, refcount)
154#else
155        PROCESS(zend_ushort, refcount)
156#endif
157    ')dnl IFDASM
158')
159dnl }}}
160DEF_STRUCT_P_FUNC(`zval_ptr', , `dnl {{{
161    IFDASM(`
162        pushdefFUNC_NAME(`zval')
163        FUNC_NAME (dst, src[0] TSRMLS_CC);
164        popdef(`FUNC_NAME')
165    ', `
166        do {
167            IFCALCCOPY(`
168                if (processor->reference) {
169                    zval_ptr *ppzv;
170                    if (zend_hash_find(&processor->zvalptrs, (char *) &src[0], sizeof(src[0]), (void **) &ppzv) == SUCCESS) {
171                        IFCOPY(`
172                            dst[0] = *ppzv;
173                            /* *dst is updated */
174                            dnl fprintf(stderr, "*dst is set to %p, PROCESSOR_TYPE is_shm %d\n", dst[0], xc_is_shm(dst[0]));
175                        ')
176                        IFCALCSTORE(`processor->have_references = 1;')
177                        IFSTORE(`assert(xc_is_shm(dst[0]));')
178                        IFRESTORE(`assert(!xc_is_shm(dst[0]));')
179                        break;
180                    }
181                }
182            ')
183           
184            ALLOC(dst[0], zval)
185            IFCALCCOPY(`
186                if (processor->reference) {
187                    IFCALC(`
188                        /* make dummy */
189                        zval_ptr pzv = (zval_ptr)-1;
190                    ', `
191                        zval_ptr pzv = dst[0];
192                        FIXPOINTER_EX(zval, pzv)
193                    ')
194                    if (zend_hash_add(&processor->zvalptrs, (char *) &src[0], sizeof(src[0]), (void *) &pzv, sizeof(pzv), NULL) == SUCCESS) {
195                        /* first add, go on */
196                        dnl fprintf(stderr, "mark[%p] = %p\n", src[0], pzv);
197                    }
198                    else {
199                        assert(0);
200                    }
201                }
202            ')
203            IFCOPY(`
204                dnl fprintf(stderr, "copy from %p to %p\n", src[0], dst[0]);
205            ')
206            IFDPRINT(`INDENT()`'fprintf(stderr, "[%p] ", src[0]);')
207            STRUCT_P_EX(zval, dst[0], src[0], `[0]', `', ` ')
208            FIXPOINTER_EX(zval, dst[0])
209        } while (0);
210    ')
211    DONE_SIZE(sizeof(zval_ptr))
212')
213dnl }}}
214DEF_STRUCT_P_FUNC(`zval_ptr_nullable', , `dnl {{{
215    if (src[0]) {
216        STRUCT_P_EX(zval_ptr, dst, src, `', `', ` ')
217    }
218    else {
219        IFCOPY(`COPYNULL_EX(src[0], src)')
220    }
221    DONE_SIZE(sizeof(zval_ptr_nullable))
222')
223dnl }}}
224#ifdef ZEND_ENGINE_2
225DEF_STRUCT_P_FUNC(`zend_arg_info', , `dnl {{{
226    PROCESS(zend_uint, name_len)
227    PROC_ZSTRING_L(, name, name_len)
228    PROCESS(zend_uint, class_name_len)
229    PROC_ZSTRING_L(, class_name, class_name_len)
230#ifdef ZEND_ENGINE_2_4
231    PROCESS(zend_uchar, type_hint)
232#else
233    PROCESS(zend_bool, array_type_hint)
234#endif
235    PROCESS(zend_bool, allow_null)
236    PROCESS(zend_bool, pass_by_reference)
237#ifndef ZEND_ENGINE_2_4
238    PROCESS(zend_bool, return_reference)
239    PROCESS(int, required_num_args)
240#endif
241')
242dnl }}}
243#endif
244#ifdef HAVE_XCACHE_CONSTANT
245DEF_STRUCT_P_FUNC(`zend_constant', , `dnl {{{
246    STRUCT(zval, value)
247    PROCESS(int, flags)
248    PROCESS(uint, name_len)
249    pushdef(`estrndup', `zend_strndup')
250    PROC_ZSTRING_N(, name, name_len)
251    popdef(`estrndup')
252    PROCESS(int, module_number)
253')
254dnl }}}
255#endif
256DEF_STRUCT_P_FUNC(`zend_function', , `dnl {{{
257    DISABLECHECK(`
258    switch (src->type) {
259    case ZEND_INTERNAL_FUNCTION:
260    case ZEND_OVERLOADED_FUNCTION:
261        IFNOTMEMCPY(`IFCOPY(`memcpy(dst, src, sizeof(src[0]));')')
262        break;
263
264    case ZEND_USER_FUNCTION:
265    case ZEND_EVAL_CODE:
266        DONE(type)
267        STRUCT(zend_op_array, op_array)
268        break;
269
270    default:
271        assert(0);
272    }
273    ')
274    DONE_SIZE(sizeof(src[0]))
275')
276dnl }}}
277#ifdef ZEND_ENGINE_2
278DEF_STRUCT_P_FUNC(`zend_property_info', , `dnl {{{
279    PROCESS(zend_uint, flags)
280    PROCESS(int, name_length)
281    PROC_ZSTRING_L(, name, name_length)
282    PROCESS(ulong, h)
283#ifdef ZEND_ENGINE_2_4
284    PROCESS(int, offset)
285#endif
286#ifdef ZEND_ENGINE_2_1
287    PROCESS(int, doc_comment_len)
288    PROC_ZSTRING_L(, doc_comment, doc_comment_len)
289#endif
290    dnl isnt in php6 yet
291#if defined(ZEND_ENGINE_2_2)
292    PROC_CLASS_ENTRY_P(ce)
293#endif
294')
295dnl }}}
296#endif
297#ifdef ZEND_ENGINE_2_4
298DEF_STRUCT_P_FUNC(`zend_trait_method_reference', , `dnl {{{
299    PROCESS(unsigned int, mname_len)
300    PROC_STRING_L(method_name, mname_len)
301    COPYNULL(ce)
302    PROCESS(unsigned int, cname_len)
303    PROC_STRING_L(class_name, cname_len)
304')
305dnl }}}
306DEF_STRUCT_P_FUNC(`zend_trait_alias', , `dnl {{{
307    STRUCT_P(zend_trait_method_reference, trait_method)
308    PROCESS(unsigned int, alias_len)
309    PROC_STRING_L(alias, alias_len)
310    PROCESS(zend_uint, modifiers)
311    COPYNULL(function)
312')
313dnl }}}
314DEF_STRUCT_P_FUNC(`zend_trait_precedence', , `dnl {{{
315    STRUCT_P(zend_trait_method_reference, trait_method)
316    PROCESS_ARRAY(, xc_ztstring, exclude_from_classes, zend_class_entry*)
317    COPYNULL(function)
318')
319dnl }}}
320DEF_STRUCT_P_FUNC(`zend_trait_alias_ptr', , `dnl {{{
321    IFDASM(`
322        pushdefFUNC_NAME(`zend_trait_alias')
323        FUNC_NAME (dst, src[0] TSRMLS_CC);
324        popdef(`FUNC_NAME')
325    ', `
326        ALLOC(dst[0], zend_trait_alias)
327        STRUCT_P_EX(zend_trait_alias, dst[0], src[0], `[0]', `', ` ')
328        FIXPOINTER_EX(zend_trait_alias, dst[0])
329    ')
330    DONE_SIZE(sizeof(zend_trait_alias))
331')
332dnl }}}
333DEF_STRUCT_P_FUNC(`zend_trait_precedence_ptr', , `dnl {{{
334    IFDASM(`
335        pushdefFUNC_NAME(`zend_trait_precedence')
336        FUNC_NAME (dst, src[0] TSRMLS_CC);
337        popdef(`FUNC_NAME')
338    ', `
339        ALLOC(dst[0], zend_trait_precedence)
340        STRUCT_P_EX(zend_trait_precedence, dst[0], src[0], `[0]', `', ` ')
341        FIXPOINTER_EX(zend_trait_precedence, dst[0])
342    ')
343    DONE_SIZE(sizeof(zend_trait_precedence))
344')
345dnl }}}
346#endif
347DEF_STRUCT_P_FUNC(`zend_class_entry', , `dnl {{{
348    IFCALCCOPY(`
349        processor->active_class_entry_src = src;
350        IFCOPY(`processor->active_class_entry_dst = dst;')
351    ')
352    PROCESS(char, type)
353    PROCESS(zend_uint, name_length)
354    PROC_ZSTRING_L(, name, name_length)
355    IFRESTORE(`
356#ifndef ZEND_ENGINE_2
357        /* just copy parent and resolve on install_class */
358        COPY(parent)
359#else
360        PROC_CLASS_ENTRY_P(parent)
361#endif
362    ', `
363        PROC_CLASS_ENTRY_P(parent)
364    ')
365#ifdef ZEND_ENGINE_2
366    PROCESS(int, refcount)
367#else
368    STRUCT_P(int, refcount)
369#endif
370#ifndef ZEND_ENGINE_2_4
371    PROCESS(zend_bool, constants_updated)
372#endif
373#ifdef ZEND_ENGINE_2
374    PROCESS(zend_uint, ce_flags)
375#endif
376
377#ifdef ZEND_ENGINE_2
378    STRUCT(HashTable, properties_info, HashTable_zend_property_info)
379#endif
380
381#ifdef ZEND_ENGINE_2_4
382    STRUCT_ARRAY(default_properties_count, zval_ptr_nullable, default_properties_table)
383    PROCESS(int, default_properties_count)
384    STRUCT_ARRAY(default_static_members_count, zval_ptr_nullable, default_static_members_table)
385    PROCESS(int, default_static_members_count)
386    IFCOPY(`dst->static_members_table = dst->default_static_members_table;')
387    DONE(static_members_table)
388#else
389    IFCOPY(`dst->builtin_functions = src->builtin_functions;')
390    DONE(builtin_functions)
391    STRUCT(HashTable, default_properties, HashTable_zval_ptr)
392#   ifdef ZEND_ENGINE_2_1
393    STRUCT(HashTable, default_static_members, HashTable_zval_ptr)
394    IFCOPY(`dst->static_members = &dst->default_static_members;')
395    DONE(static_members)
396#   elif defined(ZEND_ENGINE_2)
397    STRUCT_P(HashTable, static_members, HashTable_zval_ptr)
398#   endif
399#endif /* ZEND_ENGINE_2_4 */
400
401#ifdef ZEND_ENGINE_2
402    STRUCT(HashTable, constants_table, HashTable_zval_ptr)
403
404#ifdef ZEND_ENGINE_2_2
405    dnl runtime binding: ADD_INTERFACE will deal with it
406    COPYNULL(`interfaces')
407    COPYZERO(`num_interfaces')
408
409#   ifdef ZEND_ENGINE_2_4
410    dnl runtime binding: ADD_TRAIT will deal with it
411    COPYNULL(traits)
412    COPYZERO(num_traits)
413    STRUCT_ARRAY(, zend_trait_alias_ptr, trait_aliases)
414    STRUCT_ARRAY(, zend_trait_precedence_ptr, trait_precedences)
415#   endif
416#else
417    IFRESTORE(`
418        if (src->num_interfaces) {
419            CALLOC(dst->interfaces, zend_class_entry*, src->num_interfaces)
420            DONE(`interfaces')
421        }
422        else {
423            COPYNULL(`interfaces')
424        }
425    ', `
426        DONE(`interfaces')
427    ')
428    PROCESS(zend_uint, num_interfaces)
429#endif
430
431#   ifdef ZEND_ENGINE_2_4
432    DISABLECHECK(`
433    IFRESTORE(`dst->info.user.filename = processor->entry_php_src->filepath;', `PROC_STRING(info.user.filename)')
434    PROCESS(zend_uint, info.user.line_start)
435    PROCESS(zend_uint, info.user.line_end)
436    PROCESS(zend_uint, info.user.doc_comment_len)
437    PROC_ZSTRING_L(, info.user.doc_comment, info.user.doc_comment_len)
438    ')
439    DONE(info)
440#   else
441    IFRESTORE(`dst->filename = processor->entry_php_src->filepath;DONE(filename)', `PROC_STRING(filename)')
442    PROCESS(zend_uint, line_start)
443    PROCESS(zend_uint, line_end)
444#       ifdef ZEND_ENGINE_2_1
445    PROCESS(zend_uint, doc_comment_len)
446    PROC_ZSTRING_L(, doc_comment, doc_comment_len)
447#       endif
448#   endif
449
450    /* # NOT DONE */
451    COPY(serialize_func)
452    COPY(unserialize_func)
453    COPY(iterator_funcs)
454    COPY(create_object)
455    COPY(get_iterator)
456    COPY(interface_gets_implemented)
457#   ifdef ZEND_ENGINE_2_3
458    COPY(get_static_method)
459#   endif
460    COPY(serialize)
461    COPY(unserialize)
462    /* deal with it inside xc_fix_method */
463    SETNULL(constructor)
464    COPY(destructor)
465    COPY(clone)
466    COPY(__get)
467    COPY(__set)
468/* should be >5.1 */
469#   ifdef ZEND_ENGINE_2_1
470    COPY(__unset)
471    COPY(__isset)
472#    if defined(ZEND_ENGINE_2_2) || PHP_MAJOR_VERSION >= 6
473    COPY(__tostring)
474#    endif
475#   endif
476    COPY(__call)
477#   ifdef ZEND_CALLSTATIC_FUNC_NAME
478    COPY(__callstatic)
479#   endif
480#   ifndef ZEND_ENGINE_2_4
481    /* # NOT DONE */
482    COPY(module)
483#   endif
484#else /* ZEND_ENGINE_2 */
485    COPY(handle_function_call)
486    COPY(handle_property_get)
487    COPY(handle_property_set)
488#endif
489    dnl must do after SETNULL(constructor) and dst->parent
490    STRUCT(HashTable, function_table, HashTable_zend_function)
491    IFRESTORE(`dst->function_table.pDestructor = ZEND_FUNCTION_DTOR;')
492    IFCALCCOPY(`
493        processor->active_class_entry_src = NULL;
494        IFCOPY(`processor->active_class_entry_dst = NULL;')
495    ')
496')
497dnl }}}
498#ifdef ZEND_ENGINE_2_4
499undefine(`UNION_znode_op')
500define(`UNION_znode_op', `dnl {{{
501#ifndef NDEBUG
502    switch ((src->$1_type ifelse($1, `result', & ~EXT_TYPE_UNUSED))) {
503    case IS_CONST:
504    case IS_VAR:
505    case IS_CV:
506    case IS_TMP_VAR:
507    case IS_UNUSED:
508        break;
509
510    default:
511        assert(0);
512    }
513#endif
514
515    dnl dirty dispatch
516    DISABLECHECK(`
517    switch ((src->$1_type ifelse($1, `result', & ~EXT_TYPE_UNUSED))) {
518        case IS_CONST:
519            ifelse($1, `result', `
520                PROCESS(zend_uint, $1.constant)
521            ', `
522                IFDASM(`{
523                    zval *zv;
524                    ALLOC_INIT_ZVAL(zv);
525                    *zv = src->$1.literal->constant;
526                    zval_copy_ctor(zv);
527                    add_assoc_zval_ex(dst, ZEND_STRS("$1.constant"), zv);
528                }
529                ', `
530                    IFCOPY(`
531                        dst->$1 = src->$1;
532                    ', `
533                        PROCESS(zend_uint, $1.constant)
534                    ')
535                ')
536            ')
537            break;
538        IFCOPY(`
539            IFNOTMEMCPY(`
540                default:
541                    $1 = $2;
542            ')
543        ', `
544        case IS_VAR:
545        case IS_TMP_VAR:
546        case IS_CV:
547            PROCESS(zend_uint, $1.var)
548            break;
549        case IS_UNUSED:
550            IFDASM(`PROCESS(zend_uint, $1.var)')
551            PROCESS(zend_uint, $1.opline_num)
552            break;
553        ')
554    }
555    ')
556    DONE($1)
557')
558dnl }}}
559#else
560DEF_STRUCT_P_FUNC(`znode', , `dnl {{{
561    PROCESS(xc_op_type, op_type)
562
563#ifdef IS_CV
564#   define XCACHE_IS_CV IS_CV
565#else
566/* compatible with zend optimizer */
567#   define XCACHE_IS_CV 16
568#endif
569    assert(src->op_type == IS_CONST ||
570        src->op_type == IS_VAR ||
571        src->op_type == XCACHE_IS_CV ||
572        src->op_type == IS_TMP_VAR ||
573        src->op_type == IS_UNUSED);
574    dnl dirty dispatch
575    DISABLECHECK(`
576    switch (src->op_type) {
577        case IS_CONST:
578            STRUCT(zval, u.constant)
579            break;
580        IFCOPY(`
581            IFNOTMEMCPY(`
582                default:
583                    memcpy(&dst->u, &src->u, sizeof(src->u));
584            ')
585        ', `
586        case IS_VAR:
587        case IS_TMP_VAR:
588        case XCACHE_IS_CV:
589            PROCESS(zend_uint, u.var)
590            PROCESS(zend_uint, u.EA.type)
591            break;
592        case IS_UNUSED:
593            IFDASM(`PROCESS(zend_uint, u.var)')
594            PROCESS(zend_uint, u.opline_num)
595#ifndef ZEND_ENGINE_2
596            PROCESS(zend_uint, u.fetch_type)
597#endif
598            PROCESS(zend_uint, u.EA.type)
599            break;
600        ')
601    }
602    ')
603    DONE(u)
604#if 0
605    DONE(EA)
606#endif
607#undef XCACHE_IS_CV
608')
609dnl }}}
610#endif
611DEF_STRUCT_P_FUNC(`zend_op', , `dnl {{{
612    PROCESS(xc_opcode, opcode)
613#ifdef ZEND_ENGINE_2_4
614    IFRESTORE(`', `
615    switch (src->opcode) {
616    case ZEND_BIND_TRAITS:
617        ((zend_op *) src)->op2_type = IS_UNUSED;
618        break;
619    }
620    ')
621    UNION_znode_op(result)
622    UNION_znode_op(op1)
623    UNION_znode_op(op2)
624#else
625    STRUCT(znode, result)
626    STRUCT(znode, op1)
627    STRUCT(znode, op2)
628#endif
629    PROCESS(ulong, extended_value)
630    PROCESS(uint, lineno)
631#ifdef ZEND_ENGINE_2_1
632#ifdef ZEND_ENGINE_2_4
633    PROCESS(zend_uchar, op1_type)
634    PROCESS(zend_uchar, op2_type)
635    PROCESS(zend_uchar, result_type)
636#endif
637    IFCOPY(`
638        assert(processor->active_op_array_src);
639        assert(processor->active_op_array_dst);
640#ifdef ZEND_ENGINE_2_4
641        pushdef(`UNION_znode_op_literal', `
642            if (src->$1_type == IS_CONST) {
643                dst->$1.constant = src->$1.literal - processor->active_op_array_src->literals;
644                dst->$1.literal = &processor->active_op_array_dst->literals[dst->$1.constant];
645            }
646        ')
647        UNION_znode_op_literal(op1)
648        UNION_znode_op_literal(op2)
649#endif
650        popdef(`UNION_znode_op_literal')
651        switch (src->opcode) {
652#ifdef ZEND_GOTO
653            case ZEND_GOTO:
654#endif
655            case ZEND_JMP:
656                assert(Z_OP(src->op1).jmp_addr >= processor->active_op_array_src->opcodes && Z_OP(src->op1).jmp_addr - processor->active_op_array_src->opcodes < processor->active_op_array_src->last);
657                Z_OP(dst->op1).jmp_addr = processor->active_op_array_dst->opcodes + (Z_OP(src->op1).jmp_addr - processor->active_op_array_src->opcodes);
658                assert(Z_OP(dst->op1).jmp_addr >= processor->active_op_array_dst->opcodes && Z_OP(dst->op1).jmp_addr - processor->active_op_array_dst->opcodes < processor->active_op_array_dst->last);
659                break;
660
661            case ZEND_JMPZ:
662            case ZEND_JMPNZ:
663            case ZEND_JMPZ_EX:
664            case ZEND_JMPNZ_EX:
665#ifdef ZEND_JMP_SET
666            case ZEND_JMP_SET:
667#endif
668#ifdef ZEND_JMP_SET_VAR
669            case ZEND_JMP_SET_VAR:
670#endif
671                assert(Z_OP(src->op2).jmp_addr >= processor->active_op_array_src->opcodes && Z_OP(src->op2).jmp_addr - processor->active_op_array_src->opcodes < processor->active_op_array_src->last);
672                Z_OP(dst->op2).jmp_addr = processor->active_op_array_dst->opcodes + (Z_OP(src->op2).jmp_addr - processor->active_op_array_src->opcodes);
673                assert(Z_OP(dst->op2).jmp_addr >= processor->active_op_array_dst->opcodes && Z_OP(dst->op2).jmp_addr - processor->active_op_array_dst->opcodes < processor->active_op_array_dst->last);
674                break;
675
676            default:
677                break;
678        }
679    ')
680    PROCESS(opcode_handler_t, handler)
681#endif
682')
683dnl }}}
684#ifdef ZEND_ENGINE_2_4
685DEF_STRUCT_P_FUNC(`zend_literal', , `dnl {{{
686    STRUCT(zval, constant)
687    PROCESS(zend_ulong, hash_value)
688    PROCESS(zend_uint,  cache_slot)
689')
690dnl }}}
691#endif
692DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
693    IFCOPY(`
694        processor->active_op_array_dst = dst;
695        processor->active_op_array_src = src;
696    ')
697    {
698    IFRESTORE(`
699    const xc_op_array_info_t *op_array_info = &processor->active_op_array_infos_src[processor->active_op_array_index++];
700    dnl shadow copy must NOT meet:
701    dnl readonly_protection=on
702    dnl main op_array && have early binding
703#ifdef ZEND_COMPILE_DELAYED_BINDING
704    zend_bool need_early_binding = 0;
705#else
706    zend_bool need_early_binding = processor->php_src->have_early_binding;
707#endif
708    zend_bool shallow_copy = !processor->readonly_protection && !(src == processor->php_src->op_array && need_early_binding);
709    if (shallow_copy) {
710        zend_bool gc_arg_info = 0;
711        zend_bool gc_opcodes  = 0;
712        /* really fast shallow copy */
713        memcpy(dst, src, sizeof(src[0]));
714        dst->refcount[0] = 1000;
715        /* deep */
716        STRUCT_P(HashTable, static_variables, HashTable_zval_ptr)
717#ifdef ZEND_ENGINE_2
718        STRUCT_ARRAY(num_args, zend_arg_info, arg_info)
719        gc_arg_info = 1;
720#endif
721        dst->filename = processor->entry_php_src->filepath;
722#ifdef ZEND_ENGINE_2_4
723        if (src->literals /* || op_array_info->literalsinfo_cnt */) {
724            gc_opcodes = 1;
725        }
726#else
727        if (op_array_info->oplineinfo_cnt) {
728            gc_opcodes = 1;
729        }
730#endif
731        if (gc_opcodes) {
732            zend_op *opline, *end;
733            COPY_N_EX(last, zend_op, opcodes)
734
735            for (opline = dst->opcodes, end = opline + src->last; opline < end; ++opline) {
736#ifdef ZEND_ENGINE_2_4
737                pushdef(`UNION_znode_op_literal', `
738                    if (opline->$1_type == IS_CONST) {
739                        opline->$1.constant = opline->$1.literal - src->literals;
740                        opline->$1.literal = &dst->literals[opline->$1.constant];
741                    }
742                ')
743                UNION_znode_op_literal(op1)
744                UNION_znode_op_literal(op2)
745                popdef(`UNION_znode_op_literal')
746#endif
747
748                switch (opline->opcode) {
749#ifdef ZEND_GOTO
750                    case ZEND_GOTO:
751#endif
752                    case ZEND_JMP:
753                        Z_OP(opline->op1).jmp_addr = dst->opcodes + (Z_OP(opline->op1).jmp_addr - src->opcodes);
754                        break;
755
756                    case ZEND_JMPZ:
757                    case ZEND_JMPNZ:
758                    case ZEND_JMPZ_EX:
759                    case ZEND_JMPNZ_EX:
760#ifdef ZEND_JMP_SET
761                    case ZEND_JMP_SET:
762#endif
763#ifdef ZEND_JMP_SET_VAR
764            case ZEND_JMP_SET_VAR:
765#endif
766                        Z_OP(opline->op2).jmp_addr = dst->opcodes + (Z_OP(opline->op2).jmp_addr - src->opcodes);
767                        break;
768
769                    default:
770                        break;
771                }
772            }
773        }
774        if (gc_arg_info || gc_opcodes) {
775            xc_gc_op_array_t gc_op_array;
776#ifdef ZEND_ENGINE_2
777            gc_op_array.num_args = gc_arg_info ? dst->num_args : 0;
778            gc_op_array.arg_info = gc_arg_info ? dst->arg_info : NULL;
779#endif
780            gc_op_array.opcodes  = gc_opcodes ? dst->opcodes : NULL;
781            xc_gc_add_op_array(&gc_op_array TSRMLS_CC);
782        }
783        IFAUTOCHECK(`xc_autocheck_skip = 1;')
784    }
785    else
786    ')
787    do {
788    dnl RESTORE is done above!
789
790    /* Common elements */
791    PROCESS(zend_uchar, type)
792    PROC_ZSTRING(, function_name)
793#ifdef ZEND_ENGINE_2
794    PROCESS(zend_uint, fn_flags)
795    STRUCT_ARRAY(num_args, zend_arg_info, arg_info)
796    PROCESS(zend_uint, num_args)
797    PROCESS(zend_uint, required_num_args)
798#   ifndef ZEND_ENGINE_2_4
799    PROCESS(zend_bool, pass_rest_by_reference)
800#   endif
801#else
802    if (src->arg_types) {
803        ALLOC(dst->arg_types, zend_uchar, src->arg_types[0] + 1)
804        IFCOPY(`memcpy(dst->arg_types, src->arg_types, sizeof(src->arg_types[0]) * (src->arg_types[0]+1));')
805        IFDASM(`do {
806            int i;
807            zval *zv;
808            ALLOC_INIT_ZVAL(zv);
809            array_init(zv);
810            for (i = 0; i < src->arg_types[0]; i ++) {
811                add_next_index_long(zv, src->arg_types[i + 1]);
812            }
813            add_assoc_zval_ex(dst, ZEND_STRS("arg_types"), zv);
814        } while (0);')
815        DONE(arg_types)
816    }
817    else {
818        COPYNULL(arg_types)
819    }
820#endif
821#ifndef ZEND_ENGINE_2_4
822    PROCESS(unsigned char, return_reference)
823#endif
824    /* END of common elements */
825#ifdef IS_UNICODE
826    dnl SETNULL(u_twin)
827#endif
828
829    STRUCT_P(zend_uint, refcount)
830    UNFIXPOINTER(zend_uint, refcount)
831    IFSTORE(`dst->refcount[0] = 1;')
832
833#ifdef ZEND_ENGINE_2_4
834    dnl used when copying opcodes
835    STRUCT_ARRAY(last_literal, zend_literal, literals)
836    PROCESS(int, last_literal)
837#endif
838
839    dnl uses literals
840    STRUCT_ARRAY(last, zend_op, opcodes)
841    PROCESS(zend_uint, last)
842#ifndef ZEND_ENGINE_2_4
843    IFCOPY(`dst->size = src->last;DONE(size)', `PROCESS(zend_uint, size)')
844#endif
845
846#ifdef IS_CV
847    STRUCT_ARRAY(last_var, zend_compiled_variable, vars)
848    PROCESS(int, last_var)
849#   ifndef ZEND_ENGINE_2_4
850    IFCOPY(`dst->size_var = src->last_var;DONE(size_var)', `PROCESS(zend_uint, size_var)')
851#   endif
852#else
853    dnl zend_cv.m4 is illegal to be made public, don not ask me for it
854    IFDASM(`
855        sinclude(srcdir`/processor/zend_cv.m4')
856        ')
857#endif
858
859    PROCESS(zend_uint, T)
860
861    STRUCT_ARRAY(last_brk_cont, zend_brk_cont_element, brk_cont_array)
862    PROCESS(zend_uint, last_brk_cont)
863#ifndef ZEND_ENGINE_2_4
864    PROCESS(zend_uint, current_brk_cont)
865#endif
866#ifndef ZEND_ENGINE_2
867    PROCESS(zend_bool, uses_globals)
868#endif
869
870#ifdef ZEND_ENGINE_2
871    STRUCT_ARRAY(last_try_catch, zend_try_catch_element, try_catch_array)
872    PROCESS(int, last_try_catch)
873#endif
874
875    STRUCT_P(HashTable, static_variables, HashTable_zval_ptr)
876
877#ifndef ZEND_ENGINE_2_4
878    COPY(start_op)
879    PROCESS(int, backpatch_count)
880#endif
881#ifdef ZEND_ENGINE_2_3
882    PROCESS(zend_uint, this_var)
883#endif
884
885#ifndef ZEND_ENGINE_2_4
886    PROCESS(zend_bool, done_pass_two)
887#endif
888    /* 5.0 <= ver < 5.3 */
889#if defined(ZEND_ENGINE_2) && !defined(ZEND_ENGINE_2_3)
890    PROCESS(zend_bool, uses_this)
891#endif
892
893    IFRESTORE(`dst->filename = processor->entry_php_src->filepath;DONE(filename)', `PROC_STRING(filename)')
894#ifdef IS_UNICODE
895    IFRESTORE(`
896        COPY(script_encoding)
897    ', `
898        PROC_STRING(script_encoding)
899    ')
900#endif
901#ifdef ZEND_ENGINE_2
902    PROCESS(zend_uint, line_start)
903    PROCESS(zend_uint, line_end)
904    PROCESS(int, doc_comment_len)
905    PROC_ZSTRING_L(, doc_comment, doc_comment_len)
906#endif
907#ifdef ZEND_COMPILE_DELAYED_BINDING
908    PROCESS(zend_uint, early_binding);
909#endif
910
911    /* reserved */
912    DONE(reserved)
913#if defined(HARDENING_PATCH) && HARDENING_PATCH
914    PROCESS(zend_bool, created_by_eval)
915#endif
916#ifdef ZEND_ENGINE_2_4
917    SETNULL(run_time_cache)
918    PROCESS(int, last_cache_slot)
919#endif
920    } while (0);
921    IFRESTORE(`xc_fix_op_array_info(processor->entry_php_src, processor->php_src, dst, shallow_copy, op_array_info TSRMLS_CC);')
922
923#ifdef ZEND_ENGINE_2
924    dnl mark it as -1 on store, and lookup parent on restore
925    IFSTORE(`dst->prototype = (processor->active_class_entry_src && src->prototype) ? (zend_function *) -1 : NULL;', `
926        IFRESTORE(`do {
927            zend_function *parent;
928            if (src->prototype != NULL
929             && zend_u_hash_find(&(processor->active_class_entry_dst->parent->function_table),
930                    UG(unicode) ? IS_UNICODE : IS_STRING,
931                    src->function_name, xc_zstrlen(UG(unicode) ? IS_UNICODE : IS_STRING, src->function_name) + 1,
932                    (void **) &parent) == SUCCESS) {
933                /* see do_inherit_method_check() */
934                if ((parent->common.fn_flags & ZEND_ACC_ABSTRACT)) {
935                    dst->prototype = parent;
936                } else if (!(parent->common.fn_flags & ZEND_ACC_CTOR) || (parent->common.prototype && (parent->common.prototype->common.scope->ce_flags & ZEND_ACC_INTERFACE))) {
937                    /* ctors only have a prototype if it comes from an interface */
938                    dst->prototype = parent->common.prototype ? parent->common.prototype : parent;
939                }
940                else {
941                    dst->prototype = NULL;
942                }
943            }
944            else {
945                dst->prototype = NULL;
946            }
947        } while (0);
948        ')
949    ')
950    DONE(prototype)
951
952#endif
953
954#ifdef ZEND_ENGINE_2
955    PROC_CLASS_ENTRY_P(scope)
956    IFCOPY(`
957        if (src->scope) {
958            xc_fix_method(processor, dst TSRMLS_CC);
959        }
960    ')
961#endif
962
963    IFRESTORE(`
964        if (xc_have_op_array_ctor) {
965            zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) xc_zend_extension_op_array_ctor_handler, dst TSRMLS_CC);
966        }
967    ')
968    }
969    IFCOPY(`
970        processor->active_op_array_dst = NULL;
971        processor->active_op_array_src = NULL;
972    ')
973')
974dnl }}}
975
976#ifdef HAVE_XCACHE_CONSTANT
977DEF_STRUCT_P_FUNC(`xc_constinfo_t', , `dnl {{{
978    PROCESS(zend_uint, key_size)
979#ifdef IS_UNICODE
980    PROCESS(zend_uchar, type)
981#endif
982    IFRESTORE(`COPY(key)', `
983        PROC_ZSTRING_N(type, key, key_size)
984    ')
985    PROCESS(ulong, h)
986    STRUCT(zend_constant, constant)
987')
988dnl }}}
989#endif
990IFRESTORE(`', `
991DEF_STRUCT_P_FUNC(`xc_op_array_info_detail_t', , `dnl {{{
992    PROCESS(zend_uint, index)
993    PROCESS(zend_uint, info)
994')
995dnl }}}
996DEF_STRUCT_P_FUNC(`xc_op_array_info_t', , `dnl {{{
997#ifdef ZEND_ENGINE_2_4
998    PROCESS(zend_uint, literalinfo_cnt)
999    STRUCT_ARRAY(literalinfo_cnt, xc_op_array_info_detail_t, literalinfos)
1000#else
1001    PROCESS(zend_uint, oplineinfo_cnt)
1002    STRUCT_ARRAY(oplineinfo_cnt, xc_op_array_info_detail_t, oplineinfos)
1003#endif
1004')
1005dnl }}}
1006')
1007DEF_STRUCT_P_FUNC(`xc_funcinfo_t', , `dnl {{{
1008    PROCESS(zend_uint, key_size)
1009#ifdef IS_UNICODE
1010    PROCESS(zend_uchar, type)
1011#endif
1012    IFRESTORE(`COPY(key)', `
1013        PROC_ZSTRING_N(type, key, key_size)
1014    ')
1015    PROCESS(ulong, h)
1016    IFRESTORE(`COPY(op_array_info)', `
1017        STRUCT(xc_op_array_info_t, op_array_info)
1018    ')
1019    IFRESTORE(`
1020        processor->active_op_array_infos_src = &src->op_array_info;
1021        processor->active_op_array_index = 0;
1022    ')
1023    STRUCT(zend_function, func)
1024')
1025dnl }}}
1026DEF_STRUCT_P_FUNC(`xc_classinfo_t', , `dnl {{{
1027    PROCESS(zend_uint, key_size)
1028#ifdef IS_UNICODE
1029    PROCESS(zend_uchar, type)
1030#endif
1031    IFRESTORE(`COPY(key)', `
1032        PROC_ZSTRING_N(type, key, key_size)
1033    ')
1034    PROCESS(ulong, h)
1035    PROCESS(zend_uint, methodinfo_cnt)
1036    IFRESTORE(`COPY(methodinfos)', `
1037        STRUCT_ARRAY(methodinfo_cnt, xc_op_array_info_t, methodinfos)
1038    ')
1039    IFRESTORE(`
1040        processor->active_op_array_infos_src = src->methodinfos;
1041        processor->active_op_array_index = 0;
1042    ')
1043#ifdef ZEND_ENGINE_2
1044    STRUCT_P(zend_class_entry, cest)
1045#else
1046    STRUCT(zend_class_entry, cest)
1047#endif
1048#ifndef ZEND_COMPILE_DELAYED_BINDING
1049    PROCESS(int, oplineno)
1050#endif
1051')
1052dnl }}}
1053IFRESTORE(`', `
1054#ifdef ZEND_ENGINE_2_1
1055DEF_STRUCT_P_FUNC(`xc_autoglobal_t', , `dnl {{{
1056    PROCESS(zend_uint, key_len)
1057#ifdef IS_UNICODE
1058    PROCESS(zend_uchar, type)
1059#endif
1060    IFRESTORE(`COPY(key)', `
1061        PROC_ZSTRING_L(type, key, key_len)
1062    ')
1063    PROCESS(ulong, h)
1064')
1065dnl }}}
1066#endif
1067')
1068IFRESTORE(`', `
1069#ifdef E_STRICT
1070DEF_STRUCT_P_FUNC(`xc_compilererror_t', , `dnl {{{
1071    PROCESS(int, type)
1072    PROCESS(uint, lineno)
1073    PROCESS(int, error_len)
1074    PROC_STRING_L(error, error_len)
1075')
1076dnl }}}
1077#endif
1078')
1079DEF_STRUCT_P_FUNC(`xc_entry_data_php_t', , `dnl {{{
1080    IFCOPY(`
1081        processor->php_dst = dst;
1082        processor->php_src = src;
1083    ')
1084
1085    /* skip */
1086    DONE(next)
1087    PROCESS(xc_hash_value_t, hvalue)
1088    PROCESS(xc_md5sum_t, md5)
1089    PROCESS(zend_ulong, refcount)
1090
1091    PROCESS(zend_ulong, hits)
1092    PROCESS(size_t, size)
1093
1094    IFRESTORE(`COPY(op_array_info)', `
1095        STRUCT(xc_op_array_info_t, op_array_info)
1096    ')
1097    IFRESTORE(`
1098        processor->active_op_array_infos_src = &dst->op_array_info;
1099        processor->active_op_array_index = 0;
1100    ')
1101    STRUCT_P(zend_op_array, op_array)
1102
1103#ifdef HAVE_XCACHE_CONSTANT
1104    PROCESS(zend_uint, constinfo_cnt)
1105    STRUCT_ARRAY(constinfo_cnt, xc_constinfo_t, constinfos)
1106#endif
1107
1108    PROCESS(zend_uint, funcinfo_cnt)
1109    STRUCT_ARRAY(funcinfo_cnt, xc_funcinfo_t, funcinfos)
1110
1111    PROCESS(zend_uint, classinfo_cnt)
1112    STRUCT_ARRAY(classinfo_cnt, xc_classinfo_t, classinfos, , IFRESTORE(`processor->active_class_index'))
1113#ifdef ZEND_ENGINE_2_1
1114    PROCESS(zend_uint, autoglobal_cnt)
1115    IFRESTORE(`
1116        COPY(autoglobals)
1117    ', `
1118        STRUCT_ARRAY(autoglobal_cnt, xc_autoglobal_t, autoglobals)
1119    ')
1120#endif
1121#ifdef E_STRICT
1122    PROCESS(zend_uint, compilererror_cnt)
1123    IFRESTORE(`
1124        COPY(compilererrors)
1125    ', `
1126        STRUCT_ARRAY(compilererror_cnt, xc_compilererror_t, compilererrors)
1127    ')
1128#endif
1129#ifndef ZEND_COMPILE_DELAYED_BINDING
1130    PROCESS(zend_bool, have_early_binding)
1131#endif
1132    PROCESS(zend_bool, have_references)
1133')
1134dnl }}}
1135DEF_STRUCT_P_FUNC(`xc_entry_t', , `dnl {{{
1136    /* skip */
1137    DONE(next)
1138    PROCESS(size_t, size)
1139
1140    PROCESS(time_t, ctime)
1141    PROCESS(time_t, atime)
1142    PROCESS(time_t, dtime)
1143    PROCESS(long, ttl)
1144    PROCESS(zend_ulong, hits)
1145    DONE(name) dnl handle in xc_entry_php_t and xc_entry_var_t
1146')
1147dnl }}}
1148DEF_STRUCT_P_FUNC(`xc_entry_php_t', , `dnl {{{
1149    STRUCT(xc_entry_t, entry)
1150    DISABLECHECK(`
1151        PROCESS(int, entry.name.str.len)
1152        IFRESTORE(`COPY(entry.name.str.val)', `
1153            PROC_STRING_L(entry.name.str.val, entry.name.str.len)
1154        ')
1155    ')
1156
1157    IFCALCCOPY(`COPY(php)', `STRUCT_P(xc_entry_data_php_t, php)')
1158
1159    IFSTORE(`dst->refcount = 0; DONE(refcount)', `PROCESS(long, refcount)')
1160    PROCESS(time_t, file_mtime)
1161    PROCESS(size_t, file_size)
1162#ifdef HAVE_INODE
1163    PROCESS(int, file_device)
1164    PROCESS(int, file_inode)
1165#endif
1166
1167    PROCESS(int, filepath_len)
1168    IFRESTORE(`COPY(filepath)', `PROC_STRING_L(filepath, filepath_len)')
1169    PROCESS(int, dirpath_len)
1170    IFRESTORE(`COPY(dirpath)', `PROC_STRING_L(dirpath, dirpath_len)')
1171#ifdef IS_UNICODE
1172    PROCESS(int, ufilepath_len)
1173    IFRESTORE(`COPY(ufilepath)', `PROC_USTRING_L(ufilepath, ufilepath_len)')
1174    PROCESS(int, udirpath_len)
1175    IFRESTORE(`COPY(udirpath)', `PROC_USTRING_L(udirpath, udirpath_len)')
1176#endif
1177')
1178dnl }}}
1179DEF_STRUCT_P_FUNC(`xc_entry_var_t', , `dnl {{{
1180    STRUCT(xc_entry_t, entry)
1181
1182#ifdef IS_UNICODE
1183    PROCESS(zend_uchar, name_type)
1184#endif
1185    dnl {{{ entry.name
1186    DISABLECHECK(`
1187#ifdef IS_UNICODE
1188        if (src->name_type == IS_UNICODE) {
1189            PROCESS(int32_t, entry.name.ustr.len)
1190        }
1191        else {
1192            PROCESS(int, entry.name.str.len)
1193        }
1194#else
1195        PROCESS(int, entry.name.str.len)
1196#endif
1197        IFRESTORE(`COPY(entry.name.str.val)', `
1198#ifdef IS_UNICODE
1199            PROC_ZSTRING_L(name_type, entry.name.uni.val, entry.name.uni.len)
1200#else
1201            PROC_STRING_L(entry.name.str.val, entry.name.str.len)
1202#endif
1203        ')
1204    ')
1205    dnl }}}
1206
1207    IFDPRINT(`INDENT()`'fprintf(stderr, "zval:value");')
1208    STRUCT_P_EX(zval_ptr, dst->value, src->value, `value', `', `&')
1209    PROCESS(zend_bool, have_references)
1210    DONE(value)
1211')
1212dnl }}}
1213dnl ====================================================
Note: See TracBrowser for help on using the repository browser.