diff options
author | Marcus Boerger <helly@php.net> | 2003-08-31 09:35:54 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2003-08-31 09:35:54 +0000 |
commit | d45fd8a1b102ed18dc417132df846f4c7cd80ae5 (patch) | |
tree | 4a22a598e2efd936b11567307af6b9b23bfe3040 | |
parent | c4b0b8c26237fb1e533446ff78878cb8c0be5810 (diff) | |
download | php-git-d45fd8a1b102ed18dc417132df846f4c7cd80ae5.tar.gz |
Make vspprintf available as zend utility function. Use it in exception output.
-rw-r--r-- | Zend/zend.c | 2 | ||||
-rw-r--r-- | Zend/zend.h | 2 | ||||
-rw-r--r-- | Zend/zend_default_classes.c | 17 | ||||
-rw-r--r-- | Zend/zend_exceptions.c | 17 | ||||
-rw-r--r-- | main/main.c | 1 |
5 files changed, 13 insertions, 26 deletions
diff --git a/Zend/zend.c b/Zend/zend.c index b9e125073d..46a24d3226 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -54,6 +54,7 @@ ZEND_API void (*zend_block_interruptions)(void); ZEND_API void (*zend_unblock_interruptions)(void); ZEND_API void (*zend_ticks_function)(int ticks); ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args); +int (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap); void (*zend_on_timeout)(int seconds TSRMLS_DC); @@ -567,6 +568,7 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i zend_get_configuration_directive_p = utility_functions->get_configuration_directive; zend_ticks_function = utility_functions->ticks_function; zend_on_timeout = utility_functions->on_timeout; + zend_vspprintf = utility_functions->vspprintf_function; zend_compile_file = compile_file; zend_execute = execute; diff --git a/Zend/zend.h b/Zend/zend.h index 71b8d14871..31d6f18f01 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -365,6 +365,7 @@ typedef struct _zend_utility_functions { void (*ticks_function)(int ticks); void (*on_timeout)(int seconds TSRMLS_DC); int (*stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC); + int (*vspprintf_function)(char **pbuf, size_t max_len, const char *format, va_list ap); } zend_utility_functions; @@ -501,6 +502,7 @@ extern ZEND_API void (*zend_ticks_function)(int ticks); extern ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 4, 0); extern void (*zend_on_timeout)(int seconds TSRMLS_DC); extern ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC); +extern int (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap); ZEND_API void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); diff --git a/Zend/zend_default_classes.c b/Zend/zend_default_classes.c index 3083fe77c8..a57ab4a2d2 100644 --- a/Zend/zend_default_classes.c +++ b/Zend/zend_default_classes.c @@ -232,7 +232,7 @@ static int _build_trace_string(zval **frame, int num_args, va_list args, zend_ha len = va_arg(args, int*); num = va_arg(args, int*); - s_tmp = emalloc(Z_STRLEN_PP(file) + MAX_LENGTH_OF_LONG + 2 + 1); + s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 1 + 1); sprintf(s_tmp, "#%d ", (*num)++); TRACE_APPEND_STRL(s_tmp, strlen(s_tmp)); efree(s_tmp); @@ -358,18 +358,11 @@ ZEND_API void zend_throw_exception_ex(zend_class_entry *exception_ce, long code { zval *ex; va_list arg; - -#ifdef _GNU_SOURCE char *message; + va_start(arg, format); - vasprintf(message, format, arg); - va_end(arg); -#else - char message[1024]; - va_start(arg, format); - vsnprintf(message, sizeof(message), format, arg); + zend_vspprintf(&message, 0, format, arg); va_end(arg); -#endif MAKE_STD_ZVAL(ex); if (exception_ce) { @@ -390,9 +383,7 @@ ZEND_API void zend_throw_exception_ex(zend_class_entry *exception_ce, long code zend_update_property_long(exception_ce, ex, "code", sizeof("code")-1, code TSRMLS_CC); } -#ifdef _GNU_SOURCE - free(message); -#endif + efree(message); EG(exception) = ex; } diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 3083fe77c8..a57ab4a2d2 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -232,7 +232,7 @@ static int _build_trace_string(zval **frame, int num_args, va_list args, zend_ha len = va_arg(args, int*); num = va_arg(args, int*); - s_tmp = emalloc(Z_STRLEN_PP(file) + MAX_LENGTH_OF_LONG + 2 + 1); + s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 1 + 1); sprintf(s_tmp, "#%d ", (*num)++); TRACE_APPEND_STRL(s_tmp, strlen(s_tmp)); efree(s_tmp); @@ -358,18 +358,11 @@ ZEND_API void zend_throw_exception_ex(zend_class_entry *exception_ce, long code { zval *ex; va_list arg; - -#ifdef _GNU_SOURCE char *message; + va_start(arg, format); - vasprintf(message, format, arg); - va_end(arg); -#else - char message[1024]; - va_start(arg, format); - vsnprintf(message, sizeof(message), format, arg); + zend_vspprintf(&message, 0, format, arg); va_end(arg); -#endif MAKE_STD_ZVAL(ex); if (exception_ce) { @@ -390,9 +383,7 @@ ZEND_API void zend_throw_exception_ex(zend_class_entry *exception_ce, long code zend_update_property_long(exception_ce, ex, "code", sizeof("code")-1, code TSRMLS_CC); } -#ifdef _GNU_SOURCE - free(message); -#endif + efree(message); EG(exception) = ex; } diff --git a/main/main.c b/main/main.c index 87ebf66194..6294c64f85 100644 --- a/main/main.c +++ b/main/main.c @@ -1313,6 +1313,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod zuf.ticks_function = php_run_ticks; zuf.on_timeout = php_on_timeout; zuf.stream_open_function = php_stream_open_for_zend; + zuf.vspprintf_function = vspprintf; zend_startup(&zuf, NULL, 1); #ifdef ZTS |