source: trunk/processor/main.m4 @ 843

Last change on this file since 843 was 843, checked in by moo, 2 years ago

PHP_5_4: handle exclude_from_classes

  • Property svn:eol-style set to native
File size: 8.2 KB
Line 
1divert(-1)
2dnl ================ start ======================
3dnl define(`XCACHE_ENABLE_TEST')
4dnl define(`DEBUG_SIZE')
5define(`USEMEMCPY')
6
7dnl ================ main
8
9dnl {{{ basic
10define(`REDEF', `ifdef(`$1', `undefine(`$1')') define(`$1', `$2')')
11define(`MAKE_MACRONAME', `translit(`$1', ` ():
12', `_____')')
13define(`ONCE', `ifdef(MAKE_MACRONAME(`ONCE $1'), `', `define(MAKE_MACRONAME(`ONCE $1'))$1')')
14define(`m4_errprint', `ONCE(`errprint(`$1
15')')')
16ifdef(`len', `
17define(`m4_len', defn(`len'))
18undefine(`len')
19')
20define(`ZEND_STRS', `($1), (sizeof($1))')
21define(`ZEND_STRL', `($1), (sizeof($1) - 1)')
22define(`DST', `dst->$1')
23define(`SRC', `src->$1')
24dnl ============
25define(`INDENT', `xc_dprint_indent(indent);')
26dnl }}}
27dnl {{{ ALLOC(1:dst, 2:type, 3:count=1, 4:clean=false, 5:forcetype=$2)
28define(`ALLOC', `
29    pushdef(`COUNT', `ifelse(`$3', `', `1', `$3')')
30    pushdef(`SIZE', `sizeof($2)ifelse(`$3', `', `', ` * $3')')
31    pushdef(`FORCETYPE', `ifelse(`$5', , `$2', `$5')')
32    /* allocate */
33    IFCALC(`
34        IFASSERT(`
35            xc_stack_push(&processor->allocsizes, (void *) (long) (SIZE));
36            xc_stack_push(&processor->allocsizes, (void *) (long) (__LINE__));
37        ')
38        processor->size = (size_t) ALIGN(processor->size);
39        processor->size += SIZE;
40    ')
41    IFSTORE(`
42        IFASSERT(`{
43            if (!xc_stack_count(&processor->allocsizes)) {
44                fprintf(stderr, "mismatch `$@' at line %d\n", __LINE__);
45            }
46            else {
47                unsigned long expect = (unsigned long) xc_stack_pop(&processor->allocsizes);
48                unsigned long atline = (unsigned long) xc_stack_pop(&processor->allocsizes);
49                unsigned long real = SIZE;
50                if (expect != real) {
51                    fprintf(stderr, "mismatch `$@' at line %d(was %lu): real %lu - expect %lu = %lu\n", __LINE__, atline, real, expect, real - expect);
52                }
53            }
54        }')
55        ifdef(`DEBUG_SIZE', ` {
56            void *oldp = processor->p;
57        ')
58        $1 = (FORCETYPE *) (processor->p = (char *) ALIGN(processor->p));
59        ifelse(`$4', `', `
60                IFASSERT(`memsetptr($1, (void *) __LINE__, SIZE);')
61            ', `
62                memset($1, 0, SIZE);
63        ')
64        processor->p += SIZE;
65
66        ifdef(`DEBUG_SIZE', `
67            xc_totalsize += (char *) processor->p - (char *) oldp;
68            fprintf(stderr, "%d\t%d\t`'SIZE()\n", (char *) processor->p - (char *) oldp, xc_totalsize);
69        }
70        ')
71    ')
72    IFRESTORE(`ifelse(`$4', `', `
73            ifelse(
74                FORCETYPE*COUNT, `zval*1', `ALLOC_ZVAL($1);',
75                FORCETYPE*COUNT, `HashTable*1', `ALLOC_HASHTABLE($1);',
76                `', `', `$1 = (FORCETYPE *) emalloc(SIZE);')
77            IFASSERT(`memsetptr($1, (void *) __LINE__, SIZE);')
78        ', `
79            $1 = (FORCETYPE *) ecalloc(COUNT, sizeof($2));
80        ')
81    ')
82    popdef(`COUNT')
83    popdef(`SIZE')
84')
85dnl CALLOC(1:dst, 2:type [, 3:count=1, 4:forcetype=$2 ])
86define(`CALLOC', `ALLOC(`$1', `$2', `$3', `1', `$4')')
87dnl }}}
88dnl {{{ PROC_CLASS_ENTRY_P(1:elm)
89define(`PROC_CLASS_ENTRY_P', `PROC_CLASS_ENTRY_P_EX(`dst->$1', `SRC(`$1')', `$1')`'DONE(`$1')')
90dnl PROC_CLASS_ENTRY_P_EX(1:dst, 2:src, 3:elm-name)
91define(`PROC_CLASS_ENTRY_P_EX', `
92    if ($2) {
93        IFSTORE(`$1 = (zend_class_entry *) xc_get_class_num(processor, $2);')
94        IFRESTORE(`$1 = xc_get_class(processor, (zend_ulong) $2);')
95#ifdef IS_UNICODE
96        IFDASM(`add_assoc_unicodel_ex(dst, ZEND_STRS("$3"), ZSTR_U($2->name), $2->name_length, 1);')
97#else
98        IFDASM(`add_assoc_stringl_ex(dst, ZEND_STRS("$3"), $2->name, $2->name_length, 1);')
99#endif
100    }
101    else {
102        COPYNULL_EX(`$1', `$3')
103    }
104')
105dnl }}}
106dnl {{{ IFASSERTEX
107define(`IFASSERTEX', `ifdef(`XCACHE_ENABLE_TEST', `$1', `$2')')
108dnl }}}
109dnl {{{ IFASSERT
110define(`IFASSERT', `IFASSERTEX(`
111#ifndef NDEBUG
112        $1
113#endif
114')')
115dnl }}}
116dnl {{{ DBG
117define(`DBG', `ifdef(`XCACHE_ENABLE_TEST', `
118    /* `$1' */
119')')
120dnl }}}
121dnl {{{ EXPORT
122define(`EXPORT', `define(`EXPORT_$1')')
123dnl }}}
124dnl {{{ FIXPOINTER
125define(`FIXPOINTER', `FIXPOINTER_EX(`$1', `dst->$2')')
126define(`FIXPOINTER_EX', `IFSTORE(`
127    $2 = ($1 *) processor->cache->shm->handlers->to_readonly(processor->cache->shm, (char *)$2);
128')')
129define(`UNFIXPOINTER', `UNFIXPOINTER_EX(`$1', `dst->$2')')
130define(`UNFIXPOINTER_EX', `IFSTORE(`
131    $2 = ($1 *) processor->cache->shm->handlers->to_readwrite(processor->cache->shm, (char *)$2);
132')')
133dnl }}}
134dnl {{{ COPY
135define(`COPY', `IFNOTMEMCPY(`IFCOPY(`dst->$1 = SRC(`$1');')')DONE(`$1')')
136dnl }}}
137dnl {{{ COPY_N_EX
138define(`COPY_N_EX', `
139    ALLOC(`dst->$3', `$2', `SRC(`$1')')
140    IFCOPY(`
141        memcpy(dst->$3, SRC(`$3'), sizeof(dst->$3[0]) * SRC(`$1'));
142        ')
143')
144dnl }}}
145dnl {{{ COPY_N
146define(`COPY_N', `COPY_N_EX(`$1',`$2')DONE(`$1')')
147dnl }}}
148dnl {{{ COPYPOINTER
149define(`COPYPOINTER', `COPY(`$1')')
150dnl }}}
151dnl {{{ COPYARRAY_EX
152define(`COPYARRAY_EX', `IFNOTMEMCPY(`IFCOPY(`memcpy(dst->$1, SRC(`$1'), sizeof(dst->$1));')')')
153dnl }}}
154dnl {{{ COPYARRAY
155define(`COPYARRAY', `COPYARRAY_EX(`$1',`$2')DONE(`$1')')
156dnl }}}
157dnl {{{ SETNULL_EX
158define(`SETNULL_EX', `IFCOPY(`$1 = NULL;')')
159define(`SETNULL', `SETNULL_EX(`dst->$1')DONE(`$1')')
160dnl }}}
161dnl {{{ COPYNULL_EX(1:dst, 2:elm-name)
162define(`COPYNULL_EX', `
163    IFDASM(`add_assoc_null_ex(dst, ZEND_STRS("$2"));')
164    IFNOTMEMCPY(`IFCOPY(`$1 = NULL;')')
165    assert(patsubst($1, dst, src) == NULL);
166')
167dnl }}}
168dnl {{{ COPYNULL(1:elm)
169define(`COPYNULL', `
170    COPYNULL_EX(`dst->$1', `$1')DONE(`$1')
171')
172dnl }}}
173dnl {{{ LIST_DIFF(1:left-list, 2:right-list)
174define(`foreach',
175       `pushdef(`$1')_foreach(`$1', `$2', `$3')popdef(`$1')')
176define(`_arg1', `$1')
177define(`_foreach',                             
178       `ifelse(`$2', `()', ,                       
179       `define(`$1', _arg1$2)$3`'_foreach(`$1',
180                                                       (shift$2),
181                                                       `$3')')')
182define(`LIST_DIFF', `dnl
183foreach(`i', `($1)', `pushdef(`item_'defn(`i'))')dnl allocate variable for items in $1
184foreach(`i', `($2)', `pushdef(`item_'defn(`i'))undefine(`item_'defn(`i'))')dnl allocate variable for items in $2, and undefine it
185foreach(`i', `($1)', `ifdef(`item_'defn(`i'), `defn(`i') ')')dnl see what is still defined
186foreach(`i', `($2)', `define(`item_'defn(`i'))popdef(`item_'defn(`i'))')dnl
187foreach(`i', `($1)', `popdef(`item_'defn(`i'))')dnl
188')
189dnl }}}
190dnl {{{ DONE_*
191define(`DONE_SIZE', `IFASSERT(`dnl
192    done_size += $1`';
193    done_count ++;
194')')
195define(`DONE', `
196    define(`ELEMENTS_DONE', defn(`ELEMENTS_DONE')`,"$1"')
197    IFASSERT(`dnl
198        if (zend_hash_exists(&done_names, "$1", sizeof("$1"))) {
199            fprintf(stderr
200                , "duplicate field at %s `#'%d FUNC_NAME`' : %s\n"
201                , __FILE__, __LINE__
202                , "$1"
203                );
204        }
205        else {
206            zend_uchar b = 1;
207            zend_hash_add(&done_names, "$1", sizeof("$1"), (void*)&b, sizeof(b), NULL);
208        }
209    ')
210    DONE_SIZE(`sizeof(SRC(`$1'))')
211')
212define(`DISABLECHECK', `
213    pushdef(`DONE_SIZE')
214    pushdef(`DONE')
215$1
216    popdef(`DONE_SIZE')
217    popdef(`DONE')
218')
219dnl }}}
220dnl {{{ IF**
221define(`IFCALC', `ifelse(KIND, `calc', `$1', `$2')')
222define(`IFSTORE', `ifelse(KIND, `store', `$1', `$2')')
223define(`IFCALCSTORE', `IFSTORE(`$1', `IFCALC(`$1', `$2')')')
224define(`IFRESTORE', `ifelse(KIND, `restore', `$1', `$2')')
225define(`IFCOPY', `IFSTORE(`$1', `IFRESTORE(`$1', `$2')')')
226define(`IFCALCCOPY', `IFCALC(`$1', `IFCOPY(`$1', `$2')')')
227define(`IFDPRINT', `ifelse(KIND, `dprint', `$1', `$2')')
228define(`IFASM', `ifelse(KIND, `asm', `$1', `$2')')
229define(`IFDASM', `ifelse(KIND, `dasm', `$1', `$2')')
230dnl }}}
231EXPORT(`zend_op')
232EXPORT(`zend_op_array')
233EXPORT(`zend_function')
234EXPORT(`HashTable_zend_function')
235EXPORT(`zend_class_entry')
236EXPORT(`xc_classinfo_t')
237EXPORT(`xc_funcinfo_t')
238EXPORT(`xc_entry_t')
239EXPORT(`xc_entry_data_php_t')
240EXPORT(`zval')
241
242include(srcdir`/processor/hashtable.m4')
243include(srcdir`/processor/string.m4')
244include(srcdir`/processor/struct.m4')
245include(srcdir`/processor/process.m4')
246include(srcdir`/processor/head.m4')
247
248define(`IFNOTMEMCPY', `ifdef(`USEMEMCPY', `', `$1')')
249REDEF(`KIND', `calc') include(srcdir`/processor/processor.m4')
250pushdef(`xc_get_class_num', ``xc_get_class_num'($@)')
251REDEF(`KIND', `store') include(srcdir`/processor/processor.m4')
252popdef(`xc_get_class_num')
253pushdef(`xc_get_class', ``xc_get_class'($@)')
254REDEF(`KIND', `restore') include(srcdir`/processor/processor.m4')
255popdef(`xc_get_class')
256
257REDEF(`IFNOTMEMCPY', `$1')
258#ifdef HAVE_XCACHE_DPRINT
259REDEF(`KIND', `dprint') include(srcdir`/processor/processor.m4')
260#endif /* HAVE_XCACHE_DPRINT */
261#ifdef HAVE_XCACHE_DISASSEMBLER
262REDEF(`KIND', `dasm') include(srcdir`/processor/processor.m4')
263#endif /* HAVE_XCACHE_DISASSEMBLER */
264#ifdef HAVE_XCACHE_ASSEMBLER
265REDEF(`KIND', `asm') include(srcdir`/processor/processor.m4')
266#endif /* HAVE_XCACHE_ASSEMBLER */
267
268ifdef(`EXIT_PENDING', `m4exit(EXIT_PENDING)')
Note: See TracBrowser for help on using the repository browser.