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