source: svn/trunk/processor/class-helper.m4 @ 1554

Last change on this file since 1554 was 1554, checked in by Xuefer, 5 years ago

split head.m4 into multilpe helper file

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1/* {{{ xc_get_class_num
2 * return class_index + 1
3 */
4static zend_ulong xc_get_class_num(xc_processor_t *processor, zend_class_entry *ce) {
5    zend_uint i;
6    const xc_entry_data_php_t *php = processor->php_src;
7    zend_class_entry *ceptr;
8
9    if (processor->cache_ce == ce) {
10        return processor->cache_class_index + 1;
11    }
12    for (i = 0; i < php->classinfo_cnt; i ++) {
13        ceptr = CestToCePtr(php->classinfos[i].cest);
14        if (ZCEP_REFCOUNT_PTR(ceptr) == ZCEP_REFCOUNT_PTR(ce)) {
15            processor->cache_ce = ceptr;
16            processor->cache_class_index = i;
17            assert(i <= processor->active_class_index);
18            return i + 1;
19        }
20    }
21    assert(0);
22    return (zend_ulong) -1;
23}
24define(`xc_get_class_num', `IFSTORE(``xc_get_class_num'($@)',``xc_get_class_num' can be use in store only')')
25/* }}} */
26#ifdef ZEND_ENGINE_2
27static zend_class_entry *xc_get_class(xc_processor_t *processor, zend_ulong class_num) { /* {{{ */
28    /* must be parent or currrent class */
29    assert(class_num > 0);
30    assert(class_num <= processor->active_class_index + 1);
31    return CestToCePtr(processor->php_dst->classinfos[class_num - 1].cest);
32}
33define(`xc_get_class', `IFRESTORE(``xc_get_class'($@)',``xc_get_class' can be use in restore only')')
34/* }}} */
35#endif
36#ifdef ZEND_ENGINE_2
37/* fix method on store */
38static void xc_fix_method(xc_processor_t *processor, zend_op_array *dst TSRMLS_DC) /* {{{ */
39{
40    zend_function *zf = (zend_function *) dst;
41    zend_class_entry *ce = processor->active_class_entry_dst;
42    const zend_class_entry *srcce = processor->active_class_entry_src;
43
44    /* Fixing up the default functions for objects here since
45     * we need to compare with the newly allocated functions
46     *
47     * caveat: a sub-class method can have the same name as the
48     * parent~s constructor and create problems.
49     */
50
51    if (zf->common.fn_flags & ZEND_ACC_CTOR) {
52        if (!ce->constructor) {
53            ce->constructor = zf;
54        }
55    }
56    else if (zf->common.fn_flags & ZEND_ACC_DTOR) {
57        ce->destructor = zf;
58    }
59    else if (zf->common.fn_flags & ZEND_ACC_CLONE) {
60        ce->clone = zf;
61    }
62    else {
63    pushdef(`SET_IF_SAME_NAMEs', `
64        SET_IF_SAME_NAME(__get);
65        SET_IF_SAME_NAME(__set);
66#ifdef ZEND_ENGINE_2_1
67        SET_IF_SAME_NAME(__unset);
68        SET_IF_SAME_NAME(__isset);
69#endif
70        SET_IF_SAME_NAME(__call);
71#ifdef ZEND_CALLSTATIC_FUNC_NAME
72        SET_IF_SAME_NAME(__callstatic);
73#endif
74#if defined(ZEND_ENGINE_2_2) || PHP_MAJOR_VERSION >= 6
75        SET_IF_SAME_NAME(__tostring);
76#endif
77#if defined(ZEND_ENGINE_2_6)
78        SET_IF_SAME_NAME(__debugInfo);
79#endif
80    ')
81#ifdef IS_UNICODE
82        if (UG(unicode)) {
83#define SET_IF_SAME_NAME(member) \
84            do { \
85                if (srcce->member && u_strcmp(ZSTR_U(zf->common.function_name), ZSTR_U(srcce->member->common.function_name)) == 0) { \
86                    ce->member = zf; \
87                } \
88            } \
89            while(0)
90
91            SET_IF_SAME_NAMEs()
92#undef SET_IF_SAME_NAME
93        }
94        else
95#endif
96        do {
97#define SET_IF_SAME_NAME(member) \
98            do { \
99                if (srcce->member && strcmp(ZSTR_S(zf->common.function_name), ZSTR_S(srcce->member->common.function_name)) == 0) { \
100                    ce->member = zf; \
101                } \
102            } \
103            while(0)
104
105            SET_IF_SAME_NAMEs()
106#undef SET_IF_SAME_NAME
107        } while (0);
108
109    popdef(`SET_IF_SAME_NAMEs')
110
111    }
112}
113/* }}} */
114#endif
Note: See TracBrowser for help on using the repository browser.