1
0
Fork 0

separate plain c code to .h files

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1555 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
master
Xuefer 2014-11-09 06:49:44 +00:00
parent eefebd8773
commit 977ff39373
12 changed files with 120 additions and 140 deletions

View File

@ -15,7 +15,7 @@ $(XCACHE_STRUCTINFO_OUT): $(XCACHE_INCLUDES_I) $(srcdir)/gen_structinfo.awk
mv $(XCACHE_STRUCTINFO_OUT).tmp $(XCACHE_STRUCTINFO_OUT)
$(XCACHE_PROC_OUT): $(XCACHE_PROC_SRC) $(XCACHE_STRUCTINFO_OUT) $(XCACHE_PROC_SOURCES)
$(M4) $(XCACHE_ENABLE_TEST) $(XCACHE_STRUCTINFO_OUT) $(XCACHE_PROC_SRC) > $(XCACHE_PROC_OUT).tmp
$(M4) $(XCACHE_STRUCTINFO_OUT) $(XCACHE_PROC_SRC) > $(XCACHE_PROC_OUT).tmp
mv $(XCACHE_PROC_OUT).tmp $(XCACHE_PROC_OUT)
$(XCACHE_PROC_H): $(XCACHE_PROC_OUT)

View File

@ -18,7 +18,7 @@ xcache/xc_ini.lo $(builddir)/xcache/xc_ini.lo: $(srcdir)/xcache/xc_ini.h
xcache/xc_malloc.lo $(builddir)/xcache/xc_malloc.lo: $(srcdir)/util/xc_align.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_mutex.lo $(builddir)/xcache/xc_mutex.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_opcode_spec.lo $(builddir)/xcache/xc_opcode_spec.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_opcode_spec_def.h $(srcdir)/xcache/xc_shm.h
xcache/xc_processor.lo $(builddir)/xcache/xc_processor.lo: $(XCACHE_PROC_C)
xcache/xc_processor.lo $(builddir)/xcache/xc_processor.lo: $(XCACHE_PROC_C) $(XCACHE_PROC_H) $(srcdir)/util/xc_align.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_util.h $(srcdir)/util/xc_vector.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
xcache/xc_sandbox.lo $(builddir)/xcache/xc_sandbox.lo: $(srcdir)/util/xc_vector.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
xcache/xc_shm.lo $(builddir)/xcache/xc_shm.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_shm_mmap.lo $(builddir)/xcache/xc_shm_mmap.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h

View File

@ -135,6 +135,6 @@ done
PHP_SUBST([XCACHE_INDENT])
dnl $ac_srcdir etc require PHP_NEW_EXTENSION
XCACHE_PROC_SOURCES=`ls $ac_srcdir/processor/*.m4`
XCACHE_PROC_SOURCES=`ls $ac_srcdir/processor/*.m4 $ac_srcdir/processor/*.h`
PHP_SUBST([XCACHE_PROC_SOURCES])
fi

View File

@ -139,6 +139,9 @@ xc_cacher.c \
MFO.WriteLine(frag);
ADD_FLAG("CFLAGS_XCACHE", "/I " + builddir);
/// }}}
XCACHE_PROC_SOURCES=glob(srcdir + "\\processor\\*.m4").join(' ');
XCACHE_PROC_SOURCES = [];
XCACHE_PROC_SOURCES.concat(glob(srcdir + "\\processor\\*.m4"));
XCACHE_PROC_SOURCES.concat(glob(srcdir + "\\processor\\*.h"));
XCACHE_PROC_SOURCES = XCACHE_PROC_SOURCES.join(' ');
ADD_FLAG("XCACHE_PROC_SOURCES", XCACHE_PROC_SOURCES);
}

View File

@ -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

View File

@ -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')

View File

@ -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 */')

31
processor/processor-t.h Normal file
View File

@ -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;

View File

@ -0,0 +1 @@
HashTable strings;

View File

@ -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')
}
/* }}} */
')

20
processor/types.h Normal file
View File

@ -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;

View File

@ -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;')