From: Rob Richards Date: Tue, 9 Dec 2003 21:55:02 +0000 (+0000) Subject: buffer error messages until newline is hit X-Git-Tag: php-5.0.0b3RC1~162 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1f33239c919006d7b927b80d6fff1836279656b4;p=php buffer error messages until newline is hit --- diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index 49500d88aa..f9e6ded171 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -221,6 +221,7 @@ static void php_libxml_node_free_list(xmlNodePtr node TSRMLS_DC) static void php_libxml_init_globals(php_libxml_globals *libxml_globals_p TSRMLS_DC) { LIBXML(stream_context) = NULL; + LIBXML(error_buffer) = NULL; } #endif @@ -297,19 +298,31 @@ static void php_libxml_error_handler(void *ctx, const char *msg, ...) { va_list ap; char *buf; - int len; + int len, len_iter, output = 0; + + TSRMLS_FETCH(); va_start(ap, msg); len = vspprintf(&buf, 0, msg, ap); va_end(ap); - + + len_iter = len; + /* remove any trailing \n */ - while (len && buf[--len] == '\n') { - buf[len] = '\0'; + while (len && buf[--len_iter] == '\n') { + buf[len_iter] = '\0'; + output = 1; } - php_error(E_WARNING, "%s", buf); + smart_str_appendl(&LIBXML(error_buffer), buf, len); + efree(buf); + + if (output == 1) { + php_error(E_WARNING, "%s", (char *) LIBXML(error_buffer)); + smart_str_free(&LIBXML(error_buffer)); + LIBXML(error_buffer) = NULL; + } } PHP_LIBXML_API void php_libxml_initialize() { @@ -357,6 +370,7 @@ PHP_MINIT_FUNCTION(libxml) ts_allocate_id(&libxml_globals_id, sizeof(php_libxml_globals), (ts_allocate_ctor) php_libxml_init_globals, NULL); #else LIBXML(stream_context) = NULL; + LIBXML(error_buffer) = NULL; #endif return SUCCESS; @@ -378,6 +392,10 @@ PHP_MSHUTDOWN_FUNCTION(libxml) PHP_RSHUTDOWN_FUNCTION(libxml) { + if (LIBXML(error_buffer)) { + smart_str_free(&LIBXML(error_buffer)); + LIBXML(error_buffer) = NULL; + } return SUCCESS; } diff --git a/ext/libxml/php_libxml.h b/ext/libxml/php_libxml.h index 6ed39f88ef..11a63609e9 100644 --- a/ext/libxml/php_libxml.h +++ b/ext/libxml/php_libxml.h @@ -37,10 +37,12 @@ extern zend_module_entry libxml_module_entry; #define PHP_LIBXML_API #endif +#include "ext/standard/php_smart_str.h" #include typedef struct { zval *stream_context; + smart_str *error_buffer; } php_libxml_globals; typedef struct _php_libxml_ref_obj {