source: trunk/processor/processor.m4 @ 1313

Last change on this file since 1313 was 1313, checked in by moo, 14 months ago

ZEND_STRS ZEND_STRL is inconsist between PHP5.0- and PHP5.0+

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