From: Marcus Boerger Date: Sat, 4 Nov 2006 20:22:29 +0000 (+0000) Subject: - Store length of autoload file exts X-Git-Tag: RELEASE_1_0_0RC1~1129 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=50514b8202b8b7bc2c60303fe810dec8b9f54195;p=php - Store length of autoload file exts --- diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 0105565b53..f3b36fd277 100755 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -55,9 +55,10 @@ zend_function_entry spl_functions_none[] = { */ static PHP_GINIT_FUNCTION(spl) { - spl_globals->autoload_extensions = NULL; - spl_globals->autoload_functions = NULL; - spl_globals->autoload_running = 0; + spl_globals->autoload_extensions = NULL; + spl_globals->autoload_extensions_len = 0; + spl_globals->autoload_functions = NULL; + spl_globals->autoload_running = 0; } /* }}} */ @@ -267,8 +268,8 @@ int spl_autoload(const char *class_name, const char * lc_name, int class_name_le Default implementation for __autoload() */ PHP_FUNCTION(spl_autoload) { - char *class_name, *lc_name, *file_exts; - int class_name_len, file_exts_len, found = 0; + char *class_name, *lc_name, *file_exts = SPL_G(autoload_extensions); + int class_name_len, file_exts_len = SPL_G(autoload_extensions_len), found = 0; char *copy, *pos1, *pos2; zval **original_return_value = EG(return_value_ptr_ptr); zend_op **original_opline_ptr = EG(opline_ptr); @@ -279,7 +280,7 @@ PHP_FUNCTION(spl_autoload) RETURN_FALSE; } - copy = pos1 = estrdup(ZEND_NUM_ARGS() > 1 ? file_exts : SPL_G(autoload_extensions)); + copy = pos1 = estrndup(file_exts, file_exts_len); lc_name = zend_str_tolower_dup(class_name, class_name_len); while(pos1 && *pos1 && !EG(exception)) { EG(return_value_ptr_ptr) = original_return_value; @@ -324,10 +325,11 @@ PHP_FUNCTION(spl_autoload_extensions) if (SPL_G(autoload_extensions)) { efree(SPL_G(autoload_extensions)); } - SPL_G(autoload_extensions) = estrdup(file_exts); + SPL_G(autoload_extensions) = estrndup(file_exts, file_exts_len); + SPL_G(autoload_extensions_len) = file_exts_len; } - RETURN_STRING(SPL_G(autoload_extensions), 1); + RETURN_STRINGL(SPL_G(autoload_extensions), SPL_G(autoload_extensions_len), 1); } /* }}} */ typedef struct { @@ -707,7 +709,9 @@ PHP_MINIT_FUNCTION(spl) PHP_RINIT_FUNCTION(spl) /* {{{ */ { SPL_G(autoload_extensions) = estrndup(".inc,.php", sizeof(".inc,.php")-1); + SPL_G(autoload_extensions_len) = sizeof(".inc,.php")-1; SPL_G(autoload_functions) = NULL; + SPL_G(autoload_running) = 0; return SUCCESS; } /* }}} */ @@ -716,6 +720,7 @@ PHP_RSHUTDOWN_FUNCTION(spl) /* {{{ */ if (SPL_G(autoload_extensions)) { efree(SPL_G(autoload_extensions)); SPL_G(autoload_extensions) = NULL; + SPL_G(autoload_extensions_len) = 0; } if (SPL_G(autoload_functions)) { zend_hash_destroy(SPL_G(autoload_functions)); diff --git a/ext/spl/php_spl.h b/ext/spl/php_spl.h index fd8e5cb8b9..e1be44546c 100755 --- a/ext/spl/php_spl.h +++ b/ext/spl/php_spl.h @@ -57,6 +57,7 @@ PHP_MINFO_FUNCTION(spl); ZEND_BEGIN_MODULE_GLOBALS(spl) char * autoload_extensions; + int autoload_extensions_len; HashTable * autoload_functions; int autoload_running; ZEND_END_MODULE_GLOBALS(spl)