]> granicus.if.org Git - php/commitdiff
Make vspprintf available as zend utility function. Use it in exception output.
authorMarcus Boerger <helly@php.net>
Sun, 31 Aug 2003 09:35:54 +0000 (09:35 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 31 Aug 2003 09:35:54 +0000 (09:35 +0000)
Zend/zend.c
Zend/zend.h
Zend/zend_default_classes.c
Zend/zend_exceptions.c
main/main.c

index b9e125073d380d5e7b2edee25df87dcdddc42e51..46a24d3226c6997e67b6b45656ebe0ef5ec9861c 100644 (file)
@@ -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;
index 71b8d148719a1effe17e692ff76272f946b4d1a6..31d6f18f017b541aebbb2dffccf1c483afc6a542 100644 (file)
@@ -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);
index 3083fe77c83a931e3544f4dcd57ded79a7e4e140..a57ab4a2d27a5ffbb94972c714007daf245e4084 100644 (file)
@@ -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;
 }
index 3083fe77c83a931e3544f4dcd57ded79a7e4e140..a57ab4a2d27a5ffbb94972c714007daf245e4084 100644 (file)
@@ -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;
 }
index 87ebf6619438d2af3683ab0ddc634f0b366dcb08..6294c64f856bf3482f366916e4f6cd74bc41b724 100644 (file)
@@ -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