From 689e78da7660350b0a7ec94f69381cb19e273c9b Mon Sep 17 00:00:00 2001 From: Xuefer Date: Wed, 18 Jul 2012 08:27:29 +0000 Subject: [PATCH] refactor: move functions to module git-svn-id: svn://svn.lighttpd.net/xcache/trunk@993 c26eb9a1-5813-0410-bd6c-c2e55f420ca7 --- submodules/xc_coverager.h | 5 +++ submodules/xc_disassembler.c | 33 +++++++++++++++++-- submodules/xc_disassembler.h | 7 ++-- submodules/xc_optimizer.h | 1 + xcache.c | 62 ++++++++++++------------------------ 5 files changed, 61 insertions(+), 47 deletions(-) diff --git a/submodules/xc_coverager.h b/submodules/xc_coverager.h index fceab75..584817e 100644 --- a/submodules/xc_coverager.h +++ b/submodules/xc_coverager.h @@ -10,3 +10,8 @@ PHP_FUNCTION(xcache_coverager_decode); PHP_FUNCTION(xcache_coverager_start); PHP_FUNCTION(xcache_coverager_stop); PHP_FUNCTION(xcache_coverager_get); +#define XCACHE_COVERAGER_FUNCTIONS() \ + PHP_FE(xcache_coverager_decode, NULL) \ + PHP_FE(xcache_coverager_start, NULL) \ + PHP_FE(xcache_coverager_stop, NULL) \ + PHP_FE(xcache_coverager_get, NULL) diff --git a/submodules/xc_disassembler.c b/submodules/xc_disassembler.c index 3e50a59..25dbf6d 100644 --- a/submodules/xc_disassembler.c +++ b/submodules/xc_disassembler.c @@ -118,9 +118,8 @@ typedef struct xc_dasm_sandboxed_t { /* {{{ */ } input; zval *output; -} xc_dasm_sandboxed_t; /* {{{ */ - -zend_op_array *xc_dasm_sandboxed(void *data TSRMLS_DC) +} xc_dasm_sandboxed_t; /* }}} */ +zend_op_array *xc_dasm_sandboxed(void *data TSRMLS_DC) /* {{{ */ { zend_bool catched = 0; zend_op_array *op_array = NULL; @@ -188,3 +187,31 @@ void xc_dasm_file(zval *output, const char *filename TSRMLS_DC) /* {{{ */ FREE_ZVAL(zfilename); } /* }}} */ + +/* {{{ proto array xcache_dasm_file(string filename) + Disassemble file into opcode array by filename */ +PHP_FUNCTION(xcache_dasm_file) +{ + char *filename; + int filename_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { + return; + } + if (!filename_len) RETURN_FALSE; + + xc_dasm_file(return_value, filename TSRMLS_CC); +} +/* }}} */ +/* {{{ proto array xcache_dasm_string(string code) + Disassemble php code into opcode array */ +PHP_FUNCTION(xcache_dasm_string) +{ + zval *code; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &code) == FAILURE) { + return; + } + xc_dasm_string(return_value, code TSRMLS_CC); +} +/* }}} */ diff --git a/submodules/xc_disassembler.h b/submodules/xc_disassembler.h index 19e62ea..1e28634 100644 --- a/submodules/xc_disassembler.h +++ b/submodules/xc_disassembler.h @@ -1,4 +1,7 @@ #include "php.h" -void xc_dasm_string(zval *return_value, zval *code TSRMLS_DC); -void xc_dasm_file(zval *return_value, const char *filename TSRMLS_DC); +PHP_FUNCTION(xcache_dasm_file); +PHP_FUNCTION(xcache_dasm_string); +#define XCACHE_DISASSEMBLER_FUNCTIONS() \ + PHP_FE(xcache_dasm_file, NULL) \ + PHP_FE(xcache_dasm_string, NULL) diff --git a/submodules/xc_optimizer.h b/submodules/xc_optimizer.h index 5be0716..dcec650 100644 --- a/submodules/xc_optimizer.h +++ b/submodules/xc_optimizer.h @@ -2,3 +2,4 @@ #include "xcache.h" void xc_optimizer_op_array_handler(zend_op_array *op_array); +#define XCACHE_OPTIMIZER_FUNCTIONS() diff --git a/xcache.c b/xcache.c index 2314848..c587f62 100644 --- a/xcache.c +++ b/xcache.c @@ -26,9 +26,23 @@ #ifdef ZEND_ENGINE_2_1 #include "ext/date/php_date.h" #endif -#include "submodules/xc_optimizer.h" -#include "submodules/xc_coverager.h" -#include "submodules/xc_disassembler.h" + +#ifdef HAVE_XCACHE_OPTIMIZER +# include "submodules/xc_optimizer.h" +#else +# define XCACHE_OPTIMIZER_FUNCTIONS() +#endif +#ifdef HAVE_XCACHE_COVERAGER +# include "submodules/xc_coverager.h" +#else +# define XCACHE_COVERAGER_FUNCTIONS() +#endif +#ifdef HAVE_XCACHE_DISASSEMBLER +# include "submodules/xc_disassembler.h" +#else +# define XCACHE_DISASSEMBLER_FUNCTIONS() +#endif + #include "xcache_globals.h" #include "xc_processor.h" #include "xcache/xc_const_string.h" @@ -3172,35 +3186,6 @@ PHP_FUNCTION(xcache_asm) } #endif /* }}} */ -#ifdef HAVE_XCACHE_DISASSEMBLER -/* {{{ proto array xcache_dasm_file(string filename) - Disassemble file into opcode array by filename */ -PHP_FUNCTION(xcache_dasm_file) -{ - char *filename; - int filename_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { - return; - } - if (!filename_len) RETURN_FALSE; - - xc_dasm_file(return_value, filename TSRMLS_CC); -} -/* }}} */ -/* {{{ proto array xcache_dasm_string(string code) - Disassemble php code into opcode array */ -PHP_FUNCTION(xcache_dasm_string) -{ - zval *code; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &code) == FAILURE) { - return; - } - xc_dasm_string(return_value, code TSRMLS_CC); -} -/* }}} */ -#endif /* {{{ proto string xcache_encode(string filename) Encode php file into XCache opcode encoded format */ #ifdef HAVE_XCACHE_ENCODER @@ -3373,13 +3358,11 @@ static zend_function_entry xcache_functions[] = /* {{{ */ PHP_FE(xcache_list, NULL) PHP_FE(xcache_clear_cache, NULL) PHP_FE(xcache_coredump, NULL) + XCACHE_OPTIMIZER_FUNCTIONS() #ifdef HAVE_XCACHE_ASSEMBLER PHP_FE(xcache_asm, NULL) #endif -#ifdef HAVE_XCACHE_DISASSEMBLER - PHP_FE(xcache_dasm_file, NULL) - PHP_FE(xcache_dasm_string, NULL) -#endif + XCACHE_DISASSEMBLER_FUNCTIONS() #ifdef HAVE_XCACHE_ENCODER PHP_FE(xcache_encode, NULL) #endif @@ -3387,12 +3370,7 @@ static zend_function_entry xcache_functions[] = /* {{{ */ PHP_FE(xcache_decode_file, NULL) PHP_FE(xcache_decode_string, NULL) #endif -#ifdef HAVE_XCACHE_COVERAGER - PHP_FE(xcache_coverager_decode, NULL) - PHP_FE(xcache_coverager_start, NULL) - PHP_FE(xcache_coverager_stop, NULL) - PHP_FE(xcache_coverager_get, NULL) -#endif + XCACHE_COVERAGER_FUNCTIONS() PHP_FE(xcache_get_special_value, NULL) PHP_FE(xcache_get_type, NULL) PHP_FE(xcache_get_op_type, NULL)