summaryrefslogtreecommitdiff
path: root/processor
diff options
context:
space:
mode:
authorXuefer <xuefer@gmail.com>2014-11-09 06:49:44 +0000
committerXuefer <xuefer@gmail.com>2014-11-09 06:49:44 +0000
commit977ff39373429681d4bf43a1d7b61b64cd30993a (patch)
tree5125063fbbc6a51eeb29683c78b99daec4470595 /processor
parenteefebd8773e8f29f5d00f6c03b0b10eb5661f34c (diff)
downloadxcache-977ff39373429681d4bf43a1d7b61b64cd30993a.tar.gz
xcache-977ff39373429681d4bf43a1d7b61b64cd30993a.zip
separate plain c code to .h files
git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1555 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
Diffstat (limited to 'processor')
-rw-r--r--processor/debug.h (renamed from processor/debug-helper.m4)49
-rw-r--r--processor/head.m472
-rw-r--r--processor/main.m426
-rw-r--r--processor/processor-t.h31
-rw-r--r--processor/string-helper-t.h1
-rw-r--r--processor/string-helper.m429
-rw-r--r--processor/types.h20
-rw-r--r--processor/types.m4 (renamed from processor/type-helper.m4)21
8 files changed, 113 insertions, 136 deletions
diff --git a/processor/debug-helper.m4 b/processor/debug.h
index cca6e69..751f774 100644
--- a/processor/debug-helper.m4
+++ b/processor/debug.h
@@ -1,19 +1,15 @@
-IFAUTOCHECK(`
-#define RELAYLINE_DC , int relayline
-#define RELAYLINE_CC , __LINE__
-', `
-#define RELAYLINE_DC
-#define RELAYLINE_CC
-')
+#ifdef HAVE_XCACHE_TEST
+# define RELAYLINE_DC , int relayline
+# define RELAYLINE_CC , __LINE__
+#else
+# define RELAYLINE_DC
+# define RELAYLINE_CC
+#endif
-ifdef(`XCACHE_ENABLE_TEST', `
-#undef NDEBUG
-#include <assert.h>
-m4_errprint(`AUTOCHECK INFO: runtime autocheck Enabled (debug build)')
-', `
-m4_errprint(`AUTOCHECK INFO: runtime autocheck Disabled (optimized build)')
-')
-ifdef(`DEBUG_SIZE', `static int xc_totalsize = 0;')
+#ifdef HAVE_XCACHE_TEST
+# undef NDEBUG
+# include <assert.h>
+#endif
#ifndef NDEBUG
# undef inline
@@ -54,9 +50,8 @@ static void xc_dprint_str_len(const char *str, int len) /* {{{ */
}
/* }}} */
#endif
-/* {{{ field name checker */
-IFAUTOCHECK(`dnl
-static int xc_check_names(const char *file, int line, const char *functionName, const char **assert_names, size_t assert_names_count, HashTable *done_names)
+#ifdef HAVE_XCACHE_TEST
+static int xc_check_names(const char *file, int line, const char *functionName, const char **assert_names, size_t assert_names_count, HashTable *done_names) /* {{{ field name checker */
{
int errors = 0;
if (assert_names_count) {
@@ -94,5 +89,21 @@ static int xc_check_names(const char *file, int line, const char *functionName,
}
return errors;
}
-')
/* }}} */
+#endif
+#ifdef HAVE_XCACHE_TEST
+static void *xc_memsetptr(void *mem, void *content, size_t n) /* {{{ */
+{
+ void **p = (void **) mem;
+ void **end = (void **) ((char *) mem + n);
+ while (p < end - sizeof(content)) {
+ *p = content;
+ p += sizeof(content);
+ }
+ if (p < end) {
+ memset(p, -1, end - p);
+ }
+ return mem;
+}
+/* }}} */
+#endif
diff --git a/processor/head.m4 b/processor/head.m4
index ad0b1d3..c727698 100644
--- a/processor/head.m4
+++ b/processor/head.m4
@@ -1,5 +1,11 @@
-dnl {{{ === program start ========================================
+dnl === program start ========================================
divert(0)
+ifdef(`XCACHE_ENABLE_TEST', `
+m4_errprint(`AUTOCHECK INFO: runtime autocheck Enabled (debug build)')
+', `
+m4_errprint(`AUTOCHECK INFO: runtime autocheck Disabled (optimized build)')
+')
+
#include <string.h>
#include <stdio.h>
@@ -25,11 +31,15 @@ EXPORT(`#include "xcache/xc_allocator.h"')
#if defined(HARDENING_PATCH_HASH_PROTECT) && HARDENING_PATCH_HASH_PROTECT
extern unsigned int zend_hash_canary;
#endif
-dnl }}}
+dnl
-include(__dir__`/debug-helper.m4')
-include(__dir__`/type-helper.m4')
-include(__dir__`/string-helper.m4')
+#ifdef DEBUG_SIZE
+static int xc_totalsize = 0;
+#endif
+
+#include "processor/debug.h"
+#include "processor/types.h"
+include(__dir__`/types.m4')
/* {{{ call op_array ctor handler */
extern zend_bool xc_have_op_array_ctor;
@@ -40,54 +50,8 @@ static void xc_zend_extension_op_array_ctor_handler(zend_extension *extension, z
}
}
/* }}} */
-/* {{{ memsetptr */
-IFAUTOCHECK(`dnl
-static void *memsetptr(void *mem, void *content, size_t n)
-{
- void **p = (void **) mem;
- void **end = (void **) ((char *) mem + n);
- while (p < end - sizeof(content)) {
- *p = content;
- p += sizeof(content);
- }
- if (p < end) {
- memset(p, -1, end - p);
- }
- return mem;
-}
-')
-/* }}} */
-dnl {{{ _xc_processor_t
-typedef struct _xc_processor_t {
- char *p;
- size_t size;
- HashTable zvalptrs;
- zend_bool handle_reference; /* enable if to deal with reference */
- zend_bool have_references;
- ptrdiff_t relocatediff;
-
- const xc_entry_php_t *entry_php_src;
- const xc_entry_php_t *entry_php_dst;
- const xc_entry_data_php_t *php_src;
- const xc_entry_data_php_t *php_dst;
- const zend_class_entry *cache_ce;
- zend_ulong cache_class_index;
-
- const zend_op_array *active_op_array_src;
- zend_op_array *active_op_array_dst;
- const zend_class_entry *active_class_entry_src;
- zend_class_entry *active_class_entry_dst;
- zend_uint active_class_index;
- zend_uint active_op_array_index;
- const xc_op_array_info_t *active_op_array_infos_src;
-
- zend_bool readonly_protection; /* wheather it's present */
-
- STRING_HELPER_T
-
- IFAUTOCHECK(xc_vector_t allocsizes;)
-} xc_processor_t;
-dnl }}}
-STRING_HELPERS()
+#include "processor/processor-t.h"
+#include "processor/string-helper.h"
+include(__dir__`/string-helper.m4')
include(__dir__`/class-helper.m4')
diff --git a/processor/main.m4 b/processor/main.m4
index 5a9ba25..83d9c88 100644
--- a/processor/main.m4
+++ b/processor/main.m4
@@ -1,6 +1,6 @@
divert(-1)
dnl ================ start ======================
-dnl define(`XCACHE_ENABLE_TEST')
+dnl #define HAVE_XCACHE_TEST
dnl define(`DEBUG_SIZE')
define(`USEMEMCPY')
@@ -71,7 +71,7 @@ define(`ALLOC', `
')
$1 = (REALTYPE *) (processor->p = (char *) ALIGN(processor->p));
ifelse(`$4', `', `
- IFAUTOCHECK(`memsetptr($1, (void *) (unsigned long) __LINE__, SIZE);')
+ IFAUTOCHECK(`xc_memsetptr($1, (void *) (unsigned long) __LINE__, SIZE);')
', `
memset($1, 0, SIZE);
')
@@ -88,7 +88,7 @@ define(`ALLOC', `
REALTYPE*COUNT, `zval*1', `ALLOC_ZVAL($1);',
REALTYPE*COUNT, `HashTable*1', `ALLOC_HASHTABLE($1);',
`', `', `$1 = (REALTYPE *) emalloc(SIZE);')
- IFAUTOCHECK(`memsetptr($1, (void *) __LINE__, SIZE);')
+ IFAUTOCHECK(`xc_memsetptr($1, (void *) __LINE__, SIZE);')
', `
$1 = (REALTYPE *) ecalloc(COUNT, sizeof($2));
')
@@ -118,20 +118,20 @@ define(`PROC_CLASS_ENTRY_P_EX', `
}
')
dnl }}}
-dnl {{{ IFAUTOCHECKEX
-define(`IFAUTOCHECKEX', `ifdef(`XCACHE_ENABLE_TEST', `$1', `$2')')
-dnl }}}
dnl {{{ IFAUTOCHECK
-define(`IFAUTOCHECK', `IFAUTOCHECKEX(`
-#ifndef NDEBUG
- $1
+define(`IFAUTOCHECK', `
+#ifdef HAVE_XCACHE_TEST
+ $1
+ifelse(`$2', `', `
+#else
+ $2
+')
#endif
-')')
+')
dnl }}}
dnl {{{ DBG
-define(`DBG', `ifdef(`XCACHE_ENABLE_TEST', `
- /* `$1' */
-')')
+define(`DBG', `/* `$1' */
+')
dnl }}}
dnl {{{ EXPORT(1:code)
define(`EXPORT', `/* export: $1 :export */')
diff --git a/processor/processor-t.h b/processor/processor-t.h
new file mode 100644
index 0000000..ee0a0a4
--- /dev/null
+++ b/processor/processor-t.h
@@ -0,0 +1,31 @@
+typedef struct _xc_processor_t {
+ char *p;
+ size_t size;
+ HashTable zvalptrs;
+ zend_bool handle_reference; /* enable if to deal with reference */
+ zend_bool have_references;
+ ptrdiff_t relocatediff;
+
+ const xc_entry_php_t *entry_php_src;
+ const xc_entry_php_t *entry_php_dst;
+ const xc_entry_data_php_t *php_src;
+ const xc_entry_data_php_t *php_dst;
+ const zend_class_entry *cache_ce;
+ zend_ulong cache_class_index;
+
+ const zend_op_array *active_op_array_src;
+ zend_op_array *active_op_array_dst;
+ const zend_class_entry *active_class_entry_src;
+ zend_class_entry *active_class_entry_dst;
+ zend_uint active_class_index;
+ zend_uint active_op_array_index;
+ const xc_op_array_info_t *active_op_array_infos_src;
+
+ zend_bool readonly_protection; /* wheather it's present */
+
+ #include "processor/string-helper-t.h"
+
+#ifdef HAVE_XCACHE_TEST
+ xc_vector_t allocsizes;
+#endif
+} xc_processor_t;
diff --git a/processor/string-helper-t.h b/processor/string-helper-t.h
new file mode 100644
index 0000000..43747bc
--- /dev/null
+++ b/processor/string-helper-t.h
@@ -0,0 +1 @@
+HashTable strings;
diff --git a/processor/string-helper.m4 b/processor/string-helper.m4
index d559ffb..9c19cbb 100644
--- a/processor/string-helper.m4
+++ b/processor/string-helper.m4
@@ -1,31 +1,3 @@
-#define MAX_DUP_STR_LEN 256
-
-define(`STRING_HELPER_T', `
-HashTable strings;
-')
-
-define(`STRING_HELPERS', `
-static inline size_t xc_zstrlen_char(const_zstr s) /* {{{ */
-{
- return strlen(ZSTR_S(s));
-}
-/* }}} */
-#ifdef IS_UNICODE
-static inline size_t xc_zstrlen_uchar(zstr s) /* {{{ */
-{
- return u_strlen(ZSTR_U(s));
-}
-/* }}} */
-static inline size_t xc_zstrlen(int type, const_zstr s) /* {{{ */
-{
- return type == IS_UNICODE ? xc_zstrlen_uchar(s) : xc_zstrlen_char(s);
-}
-/* }}} */
-#else
-/* {{{ xc_zstrlen */
-#define xc_zstrlen(dummy, s) xc_zstrlen_char(s)
-/* }}} */
-#endif
static inline void xc_calc_string_n(xc_processor_t *processor, zend_uchar type, const_zstr str, long size RELAYLINE_DC TSRMLS_DC) { /* {{{ */
pushdef(`PROCESSOR_TYPE', `calc')
pushdef(`__LINE__', `relayline')
@@ -76,4 +48,3 @@ static inline zstr xc_store_string_n(xc_processor_t *processor, zend_uchar type,
popdef(`PROCESSOR_TYPE')
}
/* }}} */
-')
diff --git a/processor/types.h b/processor/types.h
new file mode 100644
index 0000000..db464b7
--- /dev/null
+++ b/processor/types.h
@@ -0,0 +1,20 @@
+typedef zval *zval_ptr;
+typedef zval *zval_ptr_nullable;
+typedef char *xc_ztstring;
+#ifdef ZEND_ENGINE_2_4
+typedef zend_trait_alias *zend_trait_alias_ptr;
+typedef zend_trait_precedence *zend_trait_precedence_ptr;
+#endif
+#ifdef ZEND_ENGINE_2_3
+typedef int last_brk_cont_t;
+#else
+typedef zend_uint last_brk_cont_t;
+#endif
+
+typedef zend_uchar xc_zval_type_t;
+typedef int xc_op_type;
+typedef zend_uchar xc_opcode;
+#ifdef IS_UNICODE
+typedef UChar zstr_uchar;
+#endif
+typedef char zstr_char;
diff --git a/processor/type-helper.m4 b/processor/types.m4
index 98b1316..9b8150c 100644
--- a/processor/type-helper.m4
+++ b/processor/types.m4
@@ -17,26 +17,5 @@ define(`COUNTOF_xc_entry_name_t', `1')
define(`SIZEOF_xc_ztstring', `sizeof(xc_ztstring)')
define(`COUNTOF_xc_ztstring', `1')
-typedef zval *zval_ptr;
-typedef zval *zval_ptr_nullable;
-typedef char *xc_ztstring;
-#ifdef ZEND_ENGINE_2_4
-typedef zend_trait_alias *zend_trait_alias_ptr;
-typedef zend_trait_precedence *zend_trait_precedence_ptr;
-#endif
-#ifdef ZEND_ENGINE_2_3
-typedef int last_brk_cont_t;
-#else
-typedef zend_uint last_brk_cont_t;
-#endif
-
-typedef zend_uchar xc_zval_type_t;
-typedef int xc_op_type;
-typedef zend_uchar xc_opcode;
-#ifdef IS_UNICODE
-typedef UChar zstr_uchar;
-#endif
-typedef char zstr_char;
-
EXPORT(`typedef struct _xc_dasm_t { const zend_op_array *active_op_array_src; } xc_dasm_t;')