| 1 | define(`pushdefFUNC_NAME', ` |
|---|
| 2 | pushdef(`FUNC_NAME', `xc_`'PROCESSOR_TYPE`'_`'ifelse(`$2', `', `$1', `$2')') |
|---|
| 3 | ') |
|---|
| 4 | dnl {{{ DECL_STRUCT_P_FUNC(1:type, 2:name, 3:comma=;) |
|---|
| 5 | define(`DECL_STRUCT_P_FUNC', `translit( |
|---|
| 6 | pushdefFUNC_NAME(`$1', `$2') |
|---|
| 7 | define(`DEFINED_'ifelse(`$2', `', `$1', `$2'), `') |
|---|
| 8 | ifdef(`EXPORT_'ifelse(`$2', `', `$1', `$2'), `void', `static void inline') |
|---|
| 9 | FUNC_NAME`'( |
|---|
| 10 | IFDPRINT( `const $1 * const src, int indent') |
|---|
| 11 | IFCALC( `xc_processor_t *processor, const $1 * const src') |
|---|
| 12 | IFSTORE( `xc_processor_t *processor, $1 *dst, const $1 * const src') |
|---|
| 13 | IFRESTORE(`xc_processor_t *processor, $1 *dst, const $1 * const src') |
|---|
| 14 | IFDASM( `zval *dst, const $1 * const src') |
|---|
| 15 | IFASM( `$1 *dst, const $1 * const src') |
|---|
| 16 | TSRMLS_DC |
|---|
| 17 | )ifelse(`$3', `', `;') |
|---|
| 18 | popdef(`FUNC_NAME')dnl |
|---|
| 19 | , ` |
|---|
| 20 | ', ` ')') |
|---|
| 21 | dnl }}} |
|---|
| 22 | dnl {{{ DEF_STRUCT_P_FUNC(1:type, 2:name, 3:body) |
|---|
| 23 | define(`DEF_STRUCT_P_FUNC', ` |
|---|
| 24 | pushdefFUNC_NAME(`$1', `$2') |
|---|
| 25 | /* {`{'{ FUNC_NAME */ |
|---|
| 26 | ifdef(`EXPORT_'ifelse(`$2', `', `$1', `$2'), ` |
|---|
| 27 | /* export: DECL_STRUCT_P_FUNC(`$1', `$2') :export */ |
|---|
| 28 | ') |
|---|
| 29 | DECL_STRUCT_P_FUNC(`$1', `$2', 1) |
|---|
| 30 | { |
|---|
| 31 | pushdef(`ELEMENTS_DONE') |
|---|
| 32 | IFAUTOCHECK(` |
|---|
| 33 | /* {{{ init assert */ |
|---|
| 34 | ifdef(`SIZEOF_$1', , `m4_errprint(`missing SIZEOF_$1, safe to ignore')') |
|---|
| 35 | ifdef(`COUNTOF_$1', , `m4_errprint(`missing COUNTOF_$1, safe to ignore')') |
|---|
| 36 | dnl SIZEOF_x COUNTOF_x can be both defined or both not |
|---|
| 37 | ifdef(`SIZEOF_$1', ` |
|---|
| 38 | ifdef(`COUNTOF_$1', , `m4_errprint(`AUTOCHECK WARN: missing COUNTOF_$1')') |
|---|
| 39 | ', ` |
|---|
| 40 | define(`SIZEOF_$1', 0) |
|---|
| 41 | ') |
|---|
| 42 | ifdef(`COUNTOF_$1', ` |
|---|
| 43 | ifdef(`SIZEOF_$1', , `m4_errprint(`AUTOCHECK WARN: missing SIZEOF_$1')') |
|---|
| 44 | ', ` |
|---|
| 45 | define(`COUNTOF_$1', 0) |
|---|
| 46 | ') |
|---|
| 47 | int xc_autocheck_assert_size = SIZEOF_$1, assert_count = COUNTOF_$1; |
|---|
| 48 | int xc_autocheck_done_size = 0, xc_autocheck_done_count = 0; |
|---|
| 49 | const char *xc_autocheck_assert_names[] = { ifdef(`ELEMENTSOF_$1', `ELEMENTSOF_$1') }; |
|---|
| 50 | zend_bool xc_autocheck_skip = 0; |
|---|
| 51 | HashTable xc_autocheck_done_names; |
|---|
| 52 | zend_hash_init(&xc_autocheck_done_names, 0, NULL, NULL, 0); |
|---|
| 53 | /* }}} */ |
|---|
| 54 | IFRESTORE(`assert(xc_is_shm(src));') |
|---|
| 55 | IFCALCSTORE(`assert(!xc_is_shm(src));') |
|---|
| 56 | do { |
|---|
| 57 | ') |
|---|
| 58 | ifdef(`SIZEOF_$1', , `m4_errprint(`AUTOCHECK WARN: $1: missing structinfo, dont panic')') |
|---|
| 59 | |
|---|
| 60 | ifdef(`USEMEMCPY', `IFCOPY(` |
|---|
| 61 | memcpy(dst, src, sizeof($1)); |
|---|
| 62 | do { |
|---|
| 63 | ')') |
|---|
| 64 | |
|---|
| 65 | IFDPRINT(` |
|---|
| 66 | fprintf(stderr, "%s", "{\n"); |
|---|
| 67 | indent ++; |
|---|
| 68 | ') |
|---|
| 69 | $3`' |
|---|
| 70 | IFDPRINT(` |
|---|
| 71 | indent --; |
|---|
| 72 | INDENT()fprintf(stderr, "}\n"); |
|---|
| 73 | ') |
|---|
| 74 | IFAUTOCHECK(` |
|---|
| 75 | /* {{{ autocheck */ |
|---|
| 76 | if (!xc_autocheck_skip) { |
|---|
| 77 | int name_check_errors = xc_check_names(__FILE__, __LINE__, "FUNC_NAME", xc_autocheck_assert_names, sizeof(xc_autocheck_assert_names) / sizeof(xc_autocheck_assert_names[0]), &xc_autocheck_done_names); |
|---|
| 78 | |
|---|
| 79 | if (xc_autocheck_done_count != assert_count) { |
|---|
| 80 | fprintf(stderr |
|---|
| 81 | , "count assertion failed at %s `#'%d FUNC_NAME`' : unexpected:%d - expecting:%d = %d != 0\n" |
|---|
| 82 | , __FILE__, __LINE__ |
|---|
| 83 | , xc_autocheck_done_count, assert_count, xc_autocheck_done_count - assert_count |
|---|
| 84 | ); |
|---|
| 85 | } |
|---|
| 86 | if (xc_autocheck_done_size != xc_autocheck_assert_size) { |
|---|
| 87 | fprintf(stderr |
|---|
| 88 | , "size assertion failed at %s `#'%d FUNC_NAME`' : unexpected:%d - expecting:%d = %d != 0\n" |
|---|
| 89 | , __FILE__, __LINE__ |
|---|
| 90 | , xc_autocheck_done_size, xc_autocheck_assert_size, xc_autocheck_done_size - xc_autocheck_assert_size |
|---|
| 91 | ); |
|---|
| 92 | } |
|---|
| 93 | if (name_check_errors || xc_autocheck_done_count != assert_count || xc_autocheck_done_size != xc_autocheck_assert_size) { |
|---|
| 94 | assert(0); |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | zend_hash_destroy(&xc_autocheck_done_names); |
|---|
| 98 | /* }}} */ |
|---|
| 99 | ') |
|---|
| 100 | ifdef(`ELEMENTSOF_$1', ` |
|---|
| 101 | pushdef(`ELEMENTS_UNDONE', LIST_DIFF(defn(`ELEMENTSOF_$1'), defn(`ELEMENTS_DONE'))) |
|---|
| 102 | ifelse(defn(`ELEMENTS_UNDONE'), , `m4_errprint(`AUTOCHECK INFO: $1: processor looks good')', ` |
|---|
| 103 | m4_errprint(`AUTOCHECK ERROR: ====' PROCESSOR_TYPE `$1 =================') |
|---|
| 104 | m4_errprint(`AUTOCHECK expected:' defn(`ELEMENTSOF_$1')) |
|---|
| 105 | m4_errprint(`AUTOCHECK missing :' defn(`ELEMENTS_UNDONE')) |
|---|
| 106 | define(`EXIT_PENDING', 1) |
|---|
| 107 | ') |
|---|
| 108 | popdef(`ELEMENTS_UNDONE') |
|---|
| 109 | ') |
|---|
| 110 | ifdef(`USEMEMCPY', `IFCOPY(` |
|---|
| 111 | } while (0); |
|---|
| 112 | ')') |
|---|
| 113 | IFAUTOCHECK(` |
|---|
| 114 | } while (0); |
|---|
| 115 | ') |
|---|
| 116 | popdef(`ELEMENTS_DONE') |
|---|
| 117 | } |
|---|
| 118 | /* }`}'} */ |
|---|
| 119 | popdef(`FUNC_NAME') |
|---|
| 120 | ') |
|---|
| 121 | dnl }}} |
|---|
| 122 | dnl {{{ STRUCT_P_EX(1:type, 2:dst, 3:src, 4:elm-name, 5:name=type, 6:&) |
|---|
| 123 | define(`STRUCT_P_EX', ` |
|---|
| 124 | DBG(`$0($*)') |
|---|
| 125 | pushdefFUNC_NAME(`$1', `$5') |
|---|
| 126 | ifdef(`DEFINED_'ifelse(`$5', `', `$1', `$5'), `', `m4_errprint(`AUTOCHECK ERROR: Unknown struct "'ifelse(`$5', `', `$1', `$5')`"')define(`EXIT_PENDING', 1)') |
|---|
| 127 | assert(sizeof($1) == sizeof(($6 $3)[0])); |
|---|
| 128 | ifelse(`$6', `', `ALLOC(`$2', `$1')') |
|---|
| 129 | IFDASM(`do { |
|---|
| 130 | zval *zv; |
|---|
| 131 | ALLOC_INIT_ZVAL(zv); |
|---|
| 132 | array_init(zv); |
|---|
| 133 | ') |
|---|
| 134 | FUNC_NAME`'( |
|---|
| 135 | IFDPRINT( ` $6 $3, indent') |
|---|
| 136 | IFCALC( `processor, $6 $3') |
|---|
| 137 | IFSTORE( `processor, $6 $2, $6 $3') |
|---|
| 138 | IFRESTORE(`processor, $6 $2, $6 $3') |
|---|
| 139 | IFDASM( `zv, $6 $3') |
|---|
| 140 | IFASM( `$6 $2, $6 $3') |
|---|
| 141 | TSRMLS_CC |
|---|
| 142 | ); |
|---|
| 143 | IFDASM(` |
|---|
| 144 | add_assoc_zval_ex(dst, ZEND_STRS("$4"), zv); |
|---|
| 145 | } while (0); |
|---|
| 146 | ') |
|---|
| 147 | popdef(`FUNC_NAME') |
|---|
| 148 | ifelse(`$6', , `FIXPOINTER_EX(`$1', `$2')') |
|---|
| 149 | ') |
|---|
| 150 | dnl }}} |
|---|
| 151 | dnl {{{ STRUCT_P(1:type, 2:elm, 3:name=type) |
|---|
| 152 | define(`STRUCT_P', ` |
|---|
| 153 | DBG(`$0($*)') |
|---|
| 154 | if (SRC(`$2')) { |
|---|
| 155 | IFDPRINT(`INDENT()`'fprintf(stderr, "$1:$2 ");') |
|---|
| 156 | STRUCT_P_EX(`$1', `dst->$2', `SRC(`$2')', `$2', `$3') |
|---|
| 157 | } |
|---|
| 158 | else { |
|---|
| 159 | IFDPRINT(`INDENT()`'fprintf(stderr, "$1:$2:\tNULL\n");') |
|---|
| 160 | COPYNULL_EX(`dst->$2', `$2') |
|---|
| 161 | } |
|---|
| 162 | DONE(`$2') |
|---|
| 163 | ') |
|---|
| 164 | dnl }}} |
|---|
| 165 | dnl {{{ STRUCT(1:type, 2:elm, 3:name=type) |
|---|
| 166 | define(`STRUCT', ` |
|---|
| 167 | DBG(`$0($*)') |
|---|
| 168 | assert(sizeof($1) == sizeof(SRC(`$2'))); |
|---|
| 169 | IFDPRINT(`INDENT()`'fprintf(stderr, "$1:$2 ");') |
|---|
| 170 | STRUCT_P_EX(`$1', `dst->$2', `SRC(`$2')', `$2', `$3', `&') |
|---|
| 171 | DONE(`$2') |
|---|
| 172 | ') |
|---|
| 173 | dnl }}} |
|---|
| 174 | dnl {{{ STRUCT_ARRAY(1:count, 2:type, 3:elm, 4:name=type, 5:loopcounter) |
|---|
| 175 | define(`STRUCT_ARRAY', ` |
|---|
| 176 | if (SRC(`$3')) { |
|---|
| 177 | ifelse( |
|---|
| 178 | `$5', `', `int i; pushdef(`LOOPCOUNTER', `i')', |
|---|
| 179 | `', `', `pushdef(`LOOPCOUNTER', `$5')') |
|---|
| 180 | pushdefFUNC_NAME(`$2', `$4') |
|---|
| 181 | IFDASM(` |
|---|
| 182 | zval *arr; |
|---|
| 183 | ALLOC_INIT_ZVAL(arr); |
|---|
| 184 | array_init(arr); |
|---|
| 185 | |
|---|
| 186 | for (LOOPCOUNTER = 0; |
|---|
| 187 | ifelse(`$1', `', `SRC(`$3[LOOPCOUNTER]')', |
|---|
| 188 | `', `', `LOOPCOUNTER < SRC(`$1')'); |
|---|
| 189 | ++LOOPCOUNTER) { |
|---|
| 190 | zval *zv; |
|---|
| 191 | |
|---|
| 192 | ALLOC_INIT_ZVAL(zv); |
|---|
| 193 | array_init(zv); |
|---|
| 194 | FUNC_NAME (zv, &(SRC(`$3[LOOPCOUNTER]')) TSRMLS_CC); |
|---|
| 195 | add_next_index_zval(arr, zv); |
|---|
| 196 | } |
|---|
| 197 | add_assoc_zval_ex(dst, ZEND_STRS("$3"), arr); |
|---|
| 198 | ', ` |
|---|
| 199 | dnl find count with NULL |
|---|
| 200 | ifelse(`$1', `', ` |
|---|
| 201 | size_t count = 0; |
|---|
| 202 | while (SRC(`$3[count]')) { |
|---|
| 203 | ++count; |
|---|
| 204 | } |
|---|
| 205 | ++count; |
|---|
| 206 | pushdef(`ARRAY_ELEMENT_COUNT', `count') |
|---|
| 207 | ', |
|---|
| 208 | `', `', `pushdef(`ARRAY_ELEMENT_COUNT', `SRC(`$1')')') |
|---|
| 209 | ALLOC(`dst->$3', `$2', `ARRAY_ELEMENT_COUNT') |
|---|
| 210 | popdef(`ARRAY_ELEMENT_COUNT') |
|---|
| 211 | |
|---|
| 212 | for (LOOPCOUNTER = 0; |
|---|
| 213 | ifelse(`$1', `', `SRC(`$3[LOOPCOUNTER]')', |
|---|
| 214 | `', `', `LOOPCOUNTER < SRC(`$1')'); |
|---|
| 215 | ++LOOPCOUNTER) { |
|---|
| 216 | DISABLECHECK(` |
|---|
| 217 | STRUCT(`$2', `$3[LOOPCOUNTER]', `$4') |
|---|
| 218 | ') |
|---|
| 219 | } |
|---|
| 220 | dnl the end marker |
|---|
| 221 | ifelse(`$1', `', `IFCOPY(`DST(`$3[LOOPCOUNTER]') = NULL;')') |
|---|
| 222 | ')dnl IFDASM |
|---|
| 223 | DONE(`$3') |
|---|
| 224 | popdef(`FUNC_NAME') |
|---|
| 225 | popdef(`LOOPCOUNTER') |
|---|
| 226 | } |
|---|
| 227 | else { |
|---|
| 228 | COPYNULL(`$3') |
|---|
| 229 | } |
|---|
| 230 | ') |
|---|
| 231 | dnl }}} |
|---|