cvs: pecl /inclued inclued.c

From: Date: Wed, 23 Jan 2008 23:00:56 +0000
Subject: cvs: pecl /inclued inclued.c
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-9589@lists.php.net to get a copy of this message
tony2001 Wed Jan 23 23:00:56 2008 UTC Modified files: /pecl/inclued inclued.c Log: make use of DISPLAY_INI_ENTRIES() macro fix inclued.dumpdir INI option, it's not BOOLEAN bail out right away if dumpdir is not writable (fixes segfault) really destroy temporary data on request shutdown (fixes memleak) use INIT_PZVAL() after zval_copy_ctor() (fixes memleak)

http://cvs.php.net/viewvc.cgi/pecl/inclued/inclued.c?r1=1.1&r2=1.2&diff_format=u Index: pecl/inclued/inclued.c diff -u pecl/inclued/inclued.c:1.1 pecl/inclued/inclued.c:1.2 --- pecl/inclued/inclued.c:1.1 Wed Jan 23 20:05:28 2008 +++ pecl/inclued/inclued.c Wed Jan 23 23:00:56 2008 @@ -16,31 +16,27 @@ +----------------------------------------------------------------------+ */ -/* $Id: inclued.c,v 1.1 2008/01/23 20:05:28 gopalv Exp $ */ +/* $Id: inclued.c,v 1.2 2008/01/23 23:00:56 tony2001 Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "inclued.h" +#include "inclued_zend.h" + +#define INCLUED_VERSION "0.0.1" /* {{{ stupid stringifcation */ #if DEFAULT_SLASH == '/' - #define DEFAULT_SLASH_STRING "/" +# define DEFAULT_SLASH_STRING "/" #elif DEFAULT_SLASH == '\\' - #define DEFAULT_SLASH_STRING "\\" +# define DEFAULT_SLASH_STRING "\\" #else - #error "Unknown value for DEFAULT_SLASH" +# error "Unknown value for DEFAULT_SLASH" #endif /* }}} */ -/* {{{ inclued globals - * - * true globals, no need for thread safety here - */ -/* nothing for now */ -/* }}} */ - /* {{{ ZEND_DECLARE_MODULE_GLOBALS(inclued) */ ZEND_DECLARE_MODULE_GLOBALS(inclued) /* }}} */ @@ -65,43 +61,11 @@ /* {{{ ini entries */ PHP_INI_BEGIN() - STD_PHP_INI_BOOLEAN("inclued.enabled", "0", PHP_INI_SYSTEM, OnUpdateBool, enabled, zend_inclued_globals, inclued_globals) - STD_PHP_INI_BOOLEAN("inclued.dumpdir", NULL, PHP_INI_SYSTEM, OnUpdateString, dumpdir, zend_inclued_globals, inclued_globals) + STD_PHP_INI_BOOLEAN("inclued.enabled", "0", PHP_INI_SYSTEM, OnUpdateBool, enabled, zend_inclued_globals, inclued_globals) + STD_PHP_INI_ENTRY("inclued.dumpdir", NULL, PHP_INI_SYSTEM, OnUpdateString, dumpdir, zend_inclued_globals, inclued_globals) PHP_INI_END() /* }}} */ -/* {{{ PHP_FUNCTION declarations */ -PHP_FUNCTION(inclued_get_data); -/* }}} */ - -/* {{{ inclued_functions[] - * - * Every user visible function must have an entry in inclued_functions[]. - */ -zend_function_entry inclued_functions[] = { - PHP_FE(inclued_get_data, NULL) - {NULL, NULL, NULL} /* Must be the last line in inclued_functions[] */ -}; -/* }}} */ - -/* {{{ inclued_module_entry - */ -zend_module_entry inclued_module_entry = { - STANDARD_MODULE_HEADER, - "inclued", - inclued_functions, - PHP_MINIT(inclued), - PHP_MSHUTDOWN(inclued), - PHP_RINIT(inclued), - PHP_RSHUTDOWN(inclued), - PHP_MINFO(inclued), -#if ZEND_MODULE_API_NO >= 20010901 - "@PACKAGE_VERSION@", -#endif - STANDARD_MODULE_PROPERTIES -}; -/* }}} */ - #ifdef COMPILE_DL_INCLUED ZEND_GET_MODULE(inclued) #endif @@ -138,30 +102,30 @@ MAKE_STD_ZVAL(class_entry); array_init(class_entry); - add_assoc_stringl(class_entry, "name", ce->name, ce->name_length, 1); + add_assoc_stringl_ex(class_entry, "name", sizeof("name"), ce->name, ce->name_length, 1); if(ce->name[0] != key[0]) { - add_assoc_stringl(class_entry, "mangled_name", key, keylen-1, 1); + add_assoc_stringl_ex(class_entry, "mangled_name", sizeof("mangled_name"), key, keylen-1, 1); } - add_assoc_string(class_entry, "filename", ce->filename, 1); - add_assoc_long(class_entry, "line", ce->line_start); + add_assoc_string_ex(class_entry, "filename", sizeof("filename"), ce->filename, 1); + add_assoc_long_ex(class_entry, "line", sizeof("line"), ce->line_start); if(ce->parent) { MAKE_STD_ZVAL(parent_entry); array_init(parent_entry); - add_assoc_stringl(parent_entry, "name", ce->parent->name, ce->parent->name_length, 1); + add_assoc_stringl_ex(parent_entry, "name", sizeof("name"), ce->parent->name, ce->parent->name_length, 1); if(ce->parent->type == ZEND_INTERNAL_CLASS) { - add_assoc_bool(parent_entry, "internal", 1); + add_assoc_bool_ex(parent_entry, "internal", sizeof("internal"), 1); } else { - add_assoc_string(parent_entry, "filename", ce->parent->filename, 1); - add_assoc_long(parent_entry, "line", ce->parent->line_start); + add_assoc_string_ex(parent_entry, "filename", sizeof("filename"), ce->parent->filename, 1); + add_assoc_long_ex(parent_entry, "line", sizeof("line"), ce->parent->line_start); } - add_assoc_zval(class_entry, "parent", parent_entry); + add_assoc_zval_ex(class_entry, "parent", sizeof("parent"), parent_entry); } add_next_index_zval(class_table, class_entry); @@ -187,6 +151,7 @@ MAKE_STD_ZVAL(h); \ *h = *INCLUED_G(h);\ zval_copy_ctor(h); \ + INIT_PZVAL(h); \ }\ while(0) @@ -204,13 +169,14 @@ MAKE_STD_ZVAL(copy_zval);\ *copy_zval = *data[0];\ zval_copy_ctor(copy_zval);\ - add_assoc_zval(request_hash, #name, copy_zval);\ + INIT_PZVAL(copy_zval); \ + add_assoc_zval_ex(request_hash, #name, sizeof(#name), copy_zval);\ }\ } while(0); - PULL_ZVAL(&EG(symbol_table),PHP_SELF); - PULL_ZVAL(&EG(symbol_table),_REQUEST); - PULL_ZVAL(&EG(symbol_table),_COOKIE); + PULL_ZVAL(&EG(symbol_table), PHP_SELF); + PULL_ZVAL(&EG(symbol_table), _REQUEST); + PULL_ZVAL(&EG(symbol_table), _COOKIE); if (zend_hash_find((&EG(symbol_table)), "_SERVER", sizeof("_SERVER"), (void **) &data) != FAILURE) { @@ -224,10 +190,10 @@ array_init(return_value); - add_assoc_zval(return_value, "request", request_hash); - add_assoc_zval(return_value, "includes", includes_hash); - add_assoc_zval(return_value, "inheritance", inh_hash); - add_assoc_zval(return_value, "classes", class_table); + add_assoc_zval_ex(return_value, "request", sizeof("request"), request_hash); + add_assoc_zval_ex(return_value, "includes", sizeof("includes"), includes_hash); + add_assoc_zval_ex(return_value, "inheritance", sizeof("inheritance"), inh_hash); + add_assoc_zval_ex(return_value, "classes", sizeof("classes"), class_table); return; } @@ -253,7 +219,6 @@ * */ PHP_MSHUTDOWN_FUNCTION(inclued) { - if(INCLUED_G(enabled)) { inclued_zend_shutdown(TSRMLS_C); @@ -272,9 +237,7 @@ /* {{{ PHP_RINIT_FUNCTION(inclued) */ PHP_RINIT_FUNCTION(inclued) { - zval **data = NULL; - - if(INCLUED_G(enabled)) { + if(INCLUED_G(enabled)) { /* allocate new info table */ ALLOC_INIT_ZVAL(INCLUED_G(includes_hash)); array_init(INCLUED_G(includes_hash)); @@ -298,7 +261,7 @@ zval retval; zval *pretval = &retval; - if(INCLUED_G(enabled) && INCLUED_G(dumpdir)) { + if(INCLUED_G(enabled) && INCLUED_G(dumpdir) && INCLUED_G(dumpdir)[0] != '\0') { snprintf(path, MAXPATHLEN, "%s" DEFAULT_SLASH_STRING "inclued.%05d.%d", INCLUED_G(dumpdir), getpid(), INCLUED_G(counter)); @@ -306,6 +269,7 @@ if(!(dumpfile = fopen(path, "w"))) { zend_error(E_WARNING, "cannot write to %s" DEFAULT_SLASH_STRING, INCLUED_G(dumpdir)); + return SUCCESS; } pack_output(pretval); @@ -320,14 +284,14 @@ zval_dtor(pretval); } - if(INCLUED_G(enabled)) { + if(INCLUED_G(enabled)) { /* free allocated stuff */ - zval_dtor(INCLUED_G(includes_hash)); + zval_ptr_dtor(&INCLUED_G(includes_hash)); INCLUED_G(includes_hash) = NULL; - zval_dtor(INCLUED_G(inh_hash)); + zval_ptr_dtor(&INCLUED_G(inh_hash)); INCLUED_G(inh_hash) = NULL; - } - return SUCCESS; + } + return SUCCESS; } /* }}} */ @@ -335,14 +299,11 @@ */ PHP_MINFO_FUNCTION(inclued) { - const char * ini_path = NULL; - int module_number = zend_module->module_number; - php_info_print_table_start(); - php_info_print_table_row(2, "inclued support", INCLUED_G(enabled) ? "enabled" : "disabled"); - php_info_print_table_row(2, "inclued.dumpdir", \ - INCLUED_G(dumpdir) ? INCLUED_G(dumpdir) : ""); + php_info_print_table_row(2, "inclued support", "enabled"); php_info_print_table_end(); + + DISPLAY_INI_ENTRIES(); } /* }}} */ @@ -362,6 +323,32 @@ } /* }}} */ +/* {{{ inclued_functions[] + */ +zend_function_entry inclued_functions[] = { + PHP_FE(inclued_get_data, NULL) + {NULL, NULL, NULL} +}; +/* }}} */ + +/* {{{ inclued_module_entry + */ +zend_module_entry inclued_module_entry = { + STANDARD_MODULE_HEADER, + "inclued", + inclued_functions, + PHP_MINIT(inclued), + PHP_MSHUTDOWN(inclued), + PHP_RINIT(inclued), + PHP_RSHUTDOWN(inclued), + PHP_MINFO(inclued), +#if ZEND_MODULE_API_NO >= 20010901 + INCLUED_VERSION, +#endif + STANDARD_MODULE_PROPERTIES +}; +/* }}} */ + /* * Local variables: * tab-width: 4
« previous php.pecl.cvs (#9589) next »