XCache is a fast, stable PHP opcode cacher that has been proven and is now running on production servers under high load. https://xcache.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
4.9 KiB

  1. define(`pushdefFUNC_NAME', `
  2. pushdef(`FUNC_NAME', `xc_`'KIND`'_`'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( `processor_t *processor, const $1 * const src')
  12. IFSTORE( `processor_t *processor, $1 *dst, const $1 * const src')
  13. IFRESTORE(`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. IFASSERT(`
  32. /* {{{ init assert */
  33. ifdef(`SIZEOF_$1', , `m4_errprint(`missing SIZEOF_$1, safe to ignore')define(`SIZEOF_$1', 0)')
  34. ifdef(`COUNTOF_$1', , `m4_errprint(`missing COUNTOF_$1, safe to ignore')define(`COUNTOF_$1', 0)')
  35. int assert_size = SIZEOF_$1, assert_count = COUNTOF_$1;
  36. int done_size = 0, done_count = 0;
  37. pushdef(`ELEMENTS_DONE')
  38. /* }}} */
  39. IFRESTORE(`assert(xc_is_shm(src));')
  40. IFCALCSTORE(`assert(!xc_is_shm(src));')
  41. ')
  42. ifdef(`USEMEMCPY', `IFCOPY(`
  43. memcpy(dst, src, sizeof($1));
  44. ')')
  45. IFDPRINT(`
  46. fprintf(stderr, "%s", " {\n");
  47. indent ++;
  48. ')
  49. $3`'
  50. IFDPRINT(`
  51. indent --;
  52. INDENT()fprintf(stderr, "}\n");
  53. ')
  54. ifdef(`SKIPASSERT_ONCE', `undefine(`SKIPASSERT_ONCE')', `IFASSERT(`
  55. /* {{{ check assert */
  56. if (done_count != assert_count) {
  57. fprintf(stderr
  58. , "count assertion failed at %s `#'%d FUNC_NAME`' : unexpected %d - expected %d = %d != 0\n"
  59. , __FILE__, __LINE__
  60. , done_count, assert_count, done_count - assert_count
  61. );
  62. abort();
  63. }
  64. if (done_size != assert_size) {
  65. fprintf(stderr
  66. , "size assertion failed at %s `#'%d FUNC_NAME`' : %d - %d = %d != 0\n"
  67. , __FILE__, __LINE__
  68. , done_size, assert_size, done_size - assert_size
  69. );
  70. abort();
  71. }
  72. ifdef(`ELEMENTSOF_$1', `
  73. pushdef(`ELEMENTS_UNDONE', LIST_DIFF(defn(`ELEMENTSOF_$1'), defn(`ELEMENTS_DONE')))
  74. ifelse(defn(`ELEMENTS_UNDONE'), , , `
  75. m4_errprint(`====' KIND `$1 =================')
  76. m4_errprint(`expected:' defn(`ELEMENTSOF_$1'))
  77. m4_errprint(`missing :' defn(`ELEMENTS_UNDONE'))
  78. define(`EXIT_PENDING', 1)
  79. ')
  80. popdef(`ELEMENTS_UNDONE')
  81. ')
  82. /* }}} */
  83. ')')
  84. IFASSERT(`
  85. undefine(`ELEMENTS_DONE')
  86. ')
  87. }
  88. /* }`}'} */
  89. popdef(`FUNC_NAME')
  90. ')
  91. dnl }}}
  92. dnl {{{ STRUCT_P_EX(1:type, 2:dst, 3:src, 4:elm-name, 5:name=type, 6:&)
  93. define(`STRUCT_P_EX', `
  94. DBG(`$0($*)')
  95. pushdefFUNC_NAME(`$1', `$5')
  96. ifdef(`DEFINED_'ifelse(`$5', `', `$1', `$5'), `', `m4_errprint(`Unknown struct "'ifelse(`$5', `', `$1', `$5')`"')')
  97. assert(sizeof($1) == sizeof(($6 $3)[0]));
  98. ifelse(`$6', `', `ALLOC(`$2', `$1')')
  99. IFDASM(`do {
  100. zval *zv;
  101. ALLOC_INIT_ZVAL(zv);
  102. array_init(zv);
  103. ')
  104. FUNC_NAME`'(
  105. IFDPRINT( ` $6 $3, indent')
  106. IFCALC( `processor, $6 $3')
  107. IFSTORE( `processor, $6 $2, $6 $3')
  108. IFRESTORE(`processor, $6 $2, $6 $3')
  109. IFDASM( `zv, $6 $3')
  110. IFASM( `$6 $2, $6 $3')
  111. TSRMLS_CC
  112. );
  113. IFDASM(`
  114. add_assoc_zval_ex(dst, ZEND_STRS("$4"), zv);
  115. } while (0);
  116. ')
  117. popdef(`FUNC_NAME')
  118. ifelse(`$6', , `FIXPOINTER_EX(`$1', `$2')')
  119. ')
  120. dnl }}}
  121. dnl {{{ STRUCT_P(1:type, 2:elm, 3:name=type)
  122. define(`STRUCT_P', `
  123. DBG(`$0($*)')
  124. if (src->$2) {
  125. STRUCT_P_EX(`$1', `dst->$2', `src->$2', `$2', `$3')
  126. IFDPRINT(`INDENT()`'fprintf(stderr, "$1:$2");')
  127. }
  128. else {
  129. COPYNULL_EX(`dst->$2', `$2')
  130. IFDPRINT(`INDENT()`'fprintf(stderr, "$1:$2:\tNULL\n");')
  131. }
  132. DONE(`$2')
  133. ')
  134. dnl }}}
  135. dnl {{{ STRUCT(1:type, 2:elm, 3:name=type)
  136. define(`STRUCT', `
  137. DBG(`$0($*)')
  138. assert(sizeof($1) == sizeof(src->$2));
  139. IFDPRINT(`INDENT()`'fprintf(stderr, "$1:$2");')
  140. STRUCT_P_EX(`$1', `dst->$2', `src->$2', `$2', `$3', `&')
  141. DONE(`$2')
  142. ')
  143. dnl }}}
  144. dnl {{{ STRUCT_ARRAY(1:count, 2:type, 3:elm, 4:name=type)
  145. define(`STRUCT_ARRAY', `
  146. if (src->$3) {
  147. pushdefFUNC_NAME(`$2', `$4')
  148. IFDASM(`
  149. zval *arr;
  150. ALLOC_INIT_ZVAL(arr);
  151. array_init(arr);
  152. for (i = 0; i < src->$1; i ++) {
  153. zval *zv;
  154. ALLOC_INIT_ZVAL(zv);
  155. array_init(zv);
  156. FUNC_NAME (zv, &(src->$3[i]) TSRMLS_CC);
  157. add_next_index_zval(arr, zv);
  158. }
  159. add_assoc_zval_ex(dst, ZEND_STRS("$3"), arr);
  160. ', `
  161. ALLOC(`dst->$3', `$2', `src->$1')
  162. ifdef(`AFTER_ALLOC', AFTER_ALLOC)
  163. for (i = 0; i < src->$1; i ++) {
  164. DISABLECHECK(`
  165. ifdef(`BEFORE_LOOP', `BEFORE_LOOP')
  166. STRUCT(`$2', `$3[i]', `$4')
  167. ')
  168. }
  169. ')dnl IFDASM
  170. DONE(`$3')
  171. popdef(`FUNC_NAME')
  172. }
  173. else {
  174. COPYNULL(`$3')
  175. ifdef(`AFTER_ALLOC', AFTER_ALLOC)
  176. }
  177. ')
  178. dnl }}}