diff options
30 files changed, 562 insertions, 767 deletions
diff --git a/Zend/zend.c b/Zend/zend.c index 5858fb3ac8..dc0f1e9c75 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -32,6 +32,7 @@ #include "zend_dtrace.h" #include "zend_virtual_cwd.h" #include "zend_smart_str.h" +#include "zend_smart_string.h" #ifdef ZTS # define GLOBAL_FUNCTION_TABLE global_function_table @@ -54,8 +55,8 @@ ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle ZEND_API void (*zend_ticks_function)(int ticks); ZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data); ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args); -size_t (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap); -zend_string *(*zend_vstrpprintf)(size_t max_len, const char *format, va_list ap); +void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap); +void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap); ZEND_API char *(*zend_getenv)(char *name, size_t name_len); ZEND_API zend_string *(*zend_resolve_path)(const char *filename, int filename_len); @@ -159,6 +160,77 @@ static uint32_t zend_version_info_length; #define ZEND_CORE_VERSION_INFO "Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2016 Zend Technologies\n" #define PRINT_ZVAL_INDENT 4 +ZEND_API size_t zend_vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) /* {{{ */ +{ + smart_string buf = {0}; + + /* since there are places where (v)spprintf called without checking for null, + a bit of defensive coding here */ + if (!pbuf) { + return 0; + } + + zend_printf_to_smart_string(&buf, format, ap); + + if (max_len && buf.len > max_len) { + buf.len = max_len; + } + + smart_string_0(&buf); + + if (buf.c) { + *pbuf = buf.c; + return buf.len; + } else { + *pbuf = estrndup("", 0); + return 0; + } +} +/* }}} */ + +ZEND_API size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) /* {{{ */ +{ + va_list arg; + size_t len; + + va_start(arg, format); + len = zend_vspprintf(message, max_len, format, arg); + va_end(arg); + return len; +} +/* }}} */ + +ZEND_API zend_string *zend_vstrpprintf(size_t max_len, const char *format, va_list ap) /* {{{ */ +{ + smart_str buf = {0}; + + zend_printf_to_smart_str(&buf, format, ap); + + if (!buf.s) { + return ZSTR_EMPTY_ALLOC(); + } + + if (max_len && ZSTR_LEN(buf.s) > max_len) { + ZSTR_LEN(buf.s) = max_len; + } + + smart_str_0(&buf); + return buf.s; +} +/* }}} */ + +ZEND_API zend_string *zend_strpprintf(size_t max_len, const char *format, ...) /* {{{ */ +{ + va_list arg; + zend_string *str; + + va_start(arg, format); + str = zend_vstrpprintf(max_len, format, arg); + va_end(arg); + return str; +} +/* }}} */ + static void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent); static void print_hash(smart_str *buf, HashTable *ht, int indent, zend_bool is_object) /* {{{ */ @@ -684,8 +756,8 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions) / 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_vstrpprintf = utility_functions->vstrpprintf_function; + zend_printf_to_smart_string = utility_functions->printf_to_smart_string_function; + zend_printf_to_smart_str = utility_functions->printf_to_smart_str_function; zend_getenv = utility_functions->getenv_function; zend_resolve_path = utility_functions->resolve_path_function; diff --git a/Zend/zend.h b/Zend/zend.h index 59d906d24a..7ed61d5bee 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -38,6 +38,7 @@ #include "zend_iterators.h" #include "zend_stream.h" #include "zend_smart_str_public.h" +#include "zend_smart_string_public.h" #include "zend_signal.h" #define HANDLE_BLOCK_INTERRUPTIONS() ZEND_SIGNAL_BLOCK_INTERRUPTIONS() @@ -185,8 +186,8 @@ typedef struct _zend_utility_functions { void (*ticks_function)(int ticks); void (*on_timeout)(int seconds); int (*stream_open_function)(const char *filename, zend_file_handle *handle); - size_t (*vspprintf_function)(char **pbuf, size_t max_len, const char *format, va_list ap); - zend_string *(*vstrpprintf_function)(size_t max_len, const char *format, va_list ap); + void (*printf_to_smart_string_function)(smart_string *buf, const char *format, va_list ap); + void (*printf_to_smart_str_function)(smart_str *buf, const char *format, va_list ap); char *(*getenv_function)(char *name, size_t name_len); zend_string *(*resolve_path_function)(const char *filename, int filename_len); } zend_utility_functions; @@ -226,6 +227,11 @@ void zend_set_utility_values(zend_utility_values *utility_values); ZEND_API ZEND_COLD void _zend_bailout(char *filename, uint32_t lineno); +ZEND_API size_t zend_vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap); +ZEND_API size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 3, 4); +ZEND_API zend_string *zend_vstrpprintf(size_t max_len, const char *format, va_list ap); +ZEND_API zend_string *zend_strpprintf(size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); + ZEND_API char *get_zend_version(void); ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy); ZEND_API size_t zend_print_zval(zval *expr, int indent); @@ -260,8 +266,8 @@ extern ZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data) extern ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 4, 0); extern ZEND_API void (*zend_on_timeout)(int seconds); extern ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle); -extern size_t (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap); -extern zend_string *(*zend_vstrpprintf)(size_t max_len, const char *format, va_list ap); +extern void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap); +extern void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap); extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len); extern ZEND_API zend_string *(*zend_resolve_path)(const char *filename, int filename_len); diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 0aaca540fb..3072b182ce 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -651,30 +651,6 @@ ZEND_METHOD(exception, getPrevious) ZVAL_COPY(return_value, GET_PROPERTY_SILENT(getThis(), ZEND_STR_PREVIOUS)); } /* }}} */ -size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) /* {{{ */ -{ - va_list arg; - size_t len; - - va_start(arg, format); - len = zend_vspprintf(message, max_len, format, arg); - va_end(arg); - return len; -} -/* }}} */ - -zend_string *zend_strpprintf(size_t max_len, const char *format, ...) /* {{{ */ -{ - va_list arg; - zend_string *str; - - va_start(arg, format); - str = zend_vstrpprintf(max_len, format, arg); - va_end(arg); - return str; -} -/* }}} */ - /* {{{ proto string Exception|Error::__toString() Obtain the string representation of the Exception object */ ZEND_METHOD(exception, __toString) diff --git a/Zend/zend_exceptions.h b/Zend/zend_exceptions.h index e88b5e1db7..61f9500506 100644 --- a/Zend/zend_exceptions.h +++ b/Zend/zend_exceptions.h @@ -68,10 +68,6 @@ extern ZEND_API void (*zend_throw_exception_hook)(zval *ex); /* show an exception using zend_error(severity,...), severity should be E_ERROR */ ZEND_API ZEND_COLD void zend_exception_error(zend_object *exception, int severity); -/* do not export, in php it's available thru spprintf directly */ -size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 3, 4); -zend_string *zend_strpprintf(size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); - #include "zend_globals.h" static zend_always_inline void zend_rethrow_exception(zend_execute_data *execute_data) diff --git a/Zend/zend_smart_str.c b/Zend/zend_smart_str.c index c9b97acd1d..a42c9f0af4 100644 --- a/Zend/zend_smart_str.c +++ b/Zend/zend_smart_str.c @@ -117,3 +117,10 @@ ZEND_API void ZEND_FASTCALL smart_str_append_escaped(smart_str *str, const char } } } + +ZEND_API void ZEND_FASTCALL smart_str_append_printf(smart_str *dest, const char *format, ...) { + va_list arg; + va_start(arg, format); + zend_printf_to_smart_str(dest, format, arg); + va_end(arg); +} diff --git a/Zend/zend_smart_str.h b/Zend/zend_smart_str.h index f31d53e019..0d61b56a67 100644 --- a/Zend/zend_smart_str.h +++ b/Zend/zend_smart_str.h @@ -20,6 +20,7 @@ #define ZEND_SMART_STR_H #include <zend.h> +#include "zend_globals.h" #include "zend_smart_str_public.h" #define smart_str_appends_ex(dest, src, what) \ @@ -46,6 +47,8 @@ BEGIN_EXTERN_C() ZEND_API void ZEND_FASTCALL smart_str_erealloc(smart_str *str, size_t len); ZEND_API void ZEND_FASTCALL smart_str_realloc(smart_str *str, size_t len); ZEND_API void ZEND_FASTCALL smart_str_append_escaped(smart_str *str, const char *s, size_t l); +ZEND_API void ZEND_FASTCALL smart_str_append_printf(smart_str *dest, const char *format, ...) + ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); END_EXTERN_C() @@ -80,6 +83,22 @@ static zend_always_inline void smart_str_0(smart_str *str) { } } +static zend_always_inline size_t smart_str_get_len(smart_str *str) { + return str->s ? ZSTR_LEN(str->s) : 0; +} + +static zend_always_inline zend_string *smart_str_extract(smart_str *str) { + if (str->s) { + zend_string *res; + smart_str_0(str); + res = str->s; + str->s = NULL; + return res; + } else { + return ZSTR_EMPTY_ALLOC(); + } +} + static zend_always_inline void smart_str_appendc_ex(smart_str *dest, char ch, zend_bool persistent) { size_t new_len = smart_str_alloc(dest, 1, persistent); ZSTR_VAL(dest->s)[new_len - 1] = ch; diff --git a/Zend/zend_smart_string.h b/Zend/zend_smart_string.h new file mode 100644 index 0000000000..7325c80796 --- /dev/null +++ b/Zend/zend_smart_string.h @@ -0,0 +1,139 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2016 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Sascha Schumann <sascha@schumann.cx> | + | Xinchen Hui <laruence@php.net> | + +----------------------------------------------------------------------+ + */ + +/* $Id$ */ + +#ifndef PHP_SMART_STRING_H +#define PHP_SMART_STRING_H + +#include "zend_smart_string_public.h" + +#include <stdlib.h> +#ifndef SMART_STR_USE_REALLOC +#include <zend.h> +#endif + +#ifndef SMART_STRING_PREALLOC +#define SMART_STRING_PREALLOC 128 +#endif + +#ifndef SMART_STRING_START_SIZE +#define SMART_STRING_START_SIZE 78 +#endif + +#ifdef SMART_STRING_USE_REALLOC +#define SMART_STRING_REALLOC(a,b,c) realloc((a),(b)) +#else +#define SMART_STRING_REALLOC(a,b,c) perealloc((a),(b),(c)) +#endif + +#define SMART_STRING_DO_REALLOC(d, what) \ + (d)->c = SMART_STRING_REALLOC((d)->c, (d)->a + 1, (what)) + +/* wrapper */ + +#define smart_string_appends_ex(str, src, what) \ + smart_string_appendl_ex((str), (src), strlen(src), (what)) +#define smart_string_appends(str, src) \ + smart_string_appendl((str), (src), strlen(src)) +#define smart_string_append_ex(str, src, what) \ + smart_string_appendl_ex((str), ((smart_string *)(src))->c, \ + ((smart_string *)(src))->len, (what)); +#define smart_string_sets(str, src) \ + smart_string_setl((str), (src), strlen(src)); + +#define smart_string_appendc(str, c) \ + smart_string_appendc_ex((str), (c), 0) +#define smart_string_free(s) \ + smart_string_free_ex((s), 0) +#define smart_string_appendl(str, src, len) \ + smart_string_appendl_ex((str), (src), (len), 0) +#define smart_string_append(str, src) \ + smart_string_append_ex((str), (src), 0) +#define smart_string_append_long(str, val) \ + smart_string_append_long_ex((str), (val), 0) +#define smart_string_append_unsigned(str, val) \ + smart_string_append_unsigned_ex((str), (val), 0) + +static zend_always_inline size_t smart_string_alloc(smart_string *str, size_t len, zend_bool persistent) { + if (!str->c) { + str->len = 0; + str->a = len < SMART_STRING_START_SIZE + ? SMART_STRING_START_SIZE + : len + SMART_STRING_PREALLOC; + SMART_STRING_DO_REALLOC(str, persistent); + return len; + } else { + if (UNEXPECTED((size_t) len > SIZE_MAX - str->len)) { + zend_error(E_ERROR, "String size overflow"); + } + len += str->len; + if (UNEXPECTED(len >= str->a)) { + str->a = len + SMART_STRING_PREALLOC; + SMART_STRING_DO_REALLOC(str, persistent); + } + } + return len; +} + +static zend_always_inline void smart_string_free_ex(smart_string *str, zend_bool persistent) { + if (str->c) { + pefree(str->c, persistent); + str->c = NULL; + } + str->a = str->len = 0; +} + +static zend_always_inline void smart_string_0(smart_string *str) { + if (str->c) { + str->c[str->len] = '\0'; + } +} + +static zend_always_inline void smart_string_appendc_ex(smart_string *dest, char ch, zend_bool persistent) { + dest->len = smart_string_alloc(dest, 1, persistent); + dest->c[dest->len - 1] = ch; +} + +static zend_always_inline void smart_string_appendl_ex(smart_string *dest, const char *str, size_t len, zend_bool persistent) { + size_t new_len = smart_string_alloc(dest, len, persistent); + memcpy(dest->c + dest->len, str, len); + dest->len = new_len; + +} + +static zend_always_inline void smart_string_append_long_ex(smart_string *dest, zend_long num, zend_bool persistent) { + char buf[32]; + char *result = zend_print_long_to_buf(buf + sizeof(buf) - 1, num); + smart_string_appendl_ex(dest, result, buf + sizeof(buf) - 1 - result, persistent); +} + +static zend_always_inline void smart_string_append_unsigned_ex(smart_string *dest, zend_ulong num, zend_bool persistent) { + char buf[32]; + char *result = zend_print_ulong_to_buf(buf + sizeof(buf) - 1, num); + smart_string_appendl_ex(dest, result, buf + sizeof(buf) - 1 - result, persistent); +} + +static zend_always_inline void smart_string_setl(smart_string *dest, char *src, size_t len) { + dest->len = len; + dest->a = len + 1; + dest->c = src; +} + +#endif diff --git a/Zend/zend_smart_string_public.h b/Zend/zend_smart_string_public.h new file mode 100644 index 0000000000..dabc359676 --- /dev/null +++ b/Zend/zend_smart_string_public.h @@ -0,0 +1,33 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2016 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Sascha Schumann <sascha@schumann.cx> | + | Xinchen Hui <laruence@php.net> | + +----------------------------------------------------------------------+ + */ + +/* $Id$ */ + +#ifndef PHP_SMART_STRING_PUBLIC_H +#define PHP_SMART_STRING_PUBLIC_H + +#include <sys/types.h> + +typedef struct { + char *c; + size_t len; + size_t a; +} smart_string; + +#endif diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index e89293ecfc..cbe76d2cac 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -42,6 +42,7 @@ #include "zend_generators.h" #include "zend_extensions.h" #include "zend_builtin_functions.h" +#include "zend_smart_str.h" #define reflection_update_property(object, name, value) do { \ zval member; \ @@ -103,75 +104,6 @@ PHPAPI zend_class_entry *reflection_zend_extension_ptr; #define REGISTER_REFLECTION_CLASS_CONST_LONG(class_name, const_name, value) \ zend_declare_class_constant_long(reflection_ ## class_name ## _ptr, const_name, sizeof(const_name)-1, (zend_long)value); -/* {{{ Smart string functions */ -typedef struct _string { - zend_string *buf; - size_t alloced; -} string; - -static void string_init(string *str) -{ - str->buf= zend_string_alloc(1024, 0); - str->alloced = 1024; - ZSTR_VAL(str->buf)[0] = '\0'; - ZSTR_LEN(str->buf) = 0; -} - -static string *string_printf(string *str, const char *format, ...) -{ - size_t len; - va_list arg; - char *s_tmp; - - va_start(arg, format); - len = zend_vspprintf(&s_tmp, 0, format, arg); - if (len) { - register size_t nlen = (ZSTR_LEN(str->buf) + 1 + len + (1024 - 1)) & ~(1024 - 1); - if (str->alloced < nlen) { - size_t old_len = ZSTR_LEN(str->buf); - str->alloced = nlen; - str->buf = zend_string_extend(str->buf, str->alloced, 0); - ZSTR_LEN(str->buf) = old_len; - } - memcpy(ZSTR_VAL(str->buf) + ZSTR_LEN(str->buf), s_tmp, len + 1); - ZSTR_LEN(str->buf) += len; - } - efree(s_tmp); - va_end(arg); - return str; -} - -static string *string_write(string *str, char *buf, size_t len) -{ - register size_t nlen = (ZSTR_LEN(str->buf) + 1 + len + (1024 - 1)) & ~(1024 - 1); - if (str->alloced < nlen) { - size_t old_len = ZSTR_LEN(str->buf); - str->alloced = nlen; - str->buf = zend_string_extend(str->buf, str->alloced, 0); - ZSTR_LEN(str->buf) = old_len; - } - memcpy(ZSTR_VAL(str->buf) + ZSTR_LEN(str->buf), buf, len); - ZSTR_LEN(str->buf) += len; - ZSTR_VAL(str->buf)[ZSTR_LEN(str->buf)] = '\0'; - return str; -} - -static string *string_append(string *str, string *append) -{ - if (ZSTR_LEN(append->buf) > 0) { - string_write(str, ZSTR_VAL(append->buf), ZSTR_LEN(append->buf)); - } - return str; -} - -static void string_free(string *str) -{ - zend_string_release(str->buf); - str->alloced = 0; - str->buf = NULL; -} -/* }}} */ - /* {{{ Object structure */ /* Struct for properties */ @@ -361,31 +293,31 @@ static zval *reflection_instantiate(zend_class_entry *pce, zval *object) /* {{{ } /* }}} */ -static void _const_string(string *str, char *name, zval *value, char *indent); -static void _function_string(string *str, zend_function *fptr, zend_class_entry *scope, char* indent); -static void _property_string(string *str, zend_property_info *prop, char *prop_name, char* indent); -static void _class_const_string(string *str, char *name, zend_class_constant *c, char* indent); -static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *indent); -static void _extension_string(string *str, zend_module_entry *module, char *indent); -static void _zend_extension_string(string *str, zend_extension *extension, char *indent); +static void _const_string(smart_str *str, char *name, zval *value, char *indent); +static void _function_string(smart_str *str, zend_function *fptr, zend_class_entry *scope, char* indent); +static void _property_string(smart_str *str, zend_property_info *prop, char *prop_name, char* indent); +static void _class_const_string(smart_str *str, char *name, zend_class_constant *c, char* indent); +static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char *indent); +static void _extension_string(smart_str *str, zend_module_entry *module, char *indent); +static void _zend_extension_string(smart_str *str, zend_extension *extension, char *indent); /* {{{ _class_string */ -static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *indent) +static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char *indent) { int count, count_static_props = 0, count_static_funcs = 0, count_shadow_props = 0; - string sub_indent; - string_init(&sub_indent); - string_printf(&sub_indent, "%s ", indent); + smart_str sub_indent = {0}; + smart_str_append_printf(&sub_indent, "%s ", indent); + smart_str_0(&sub_indent); /* TBD: Repair indenting of doc comment (or is this to be done in the parser?) */ if (ce->type == ZEND_USER_CLASS && ce->info.user.doc_comment) { - string_printf(str, "%s%s", indent, ZSTR_VAL(ce->info.user.doc_comment)); - string_write(str, "\n", 1); + smart_str_append_printf(str, "%s%s", indent, ZSTR_VAL(ce->info.user.doc_comment)); + smart_str_appendc(str, '\n'); } if (obj && Z_TYPE_P(obj) == IS_OBJECT) { - string_printf(str, "%sObject of class [ ", indent); + smart_str_append_printf(str, "%sObject of class [ ", indent); } else { char *kind = "Class"; if (ce->ce_flags & ZEND_ACC_INTERFACE) { @@ -393,67 +325,67 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in } else if (ce->ce_flags & ZEND_ACC_TRAIT) { kind = "Trait"; } - string_printf(str, "%s%s [ ", indent, kind); + smart_str_append_printf(str, "%s%s [ ", indent, kind); } - string_printf(str, (ce->type == ZEND_USER_CLASS) ? "<user" : "<internal"); + smart_str_append_printf(str, (ce->type == ZEND_USER_CLASS) ? "<user" : "<internal"); if (ce->type == ZEND_INTERNAL_CLASS && ce->info.internal.module) { - string_printf(str, ":%s", ce->info.internal.module->name); + smart_str_append_printf(str, ":%s", ce->info.internal.module->name); } - string_printf(str, "> "); + smart_str_append_printf(str, "> "); if (ce->get_iterator != NULL) { - string_printf(str, "<iterateable> "); + smart_str_append_printf(str, "<iterateable> "); } if (ce->ce_flags & ZEND_ACC_INTERFACE) { - string_printf(str, "interface "); + smart_str_append_printf(str, "interface "); } else if (ce->ce_flags & ZEND_ACC_TRAIT) { - string_printf(str, "trait "); + smart_str_append_printf(str, "trait "); } else { if (ce->ce_flags & (ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) { - string_printf(str, "abstract "); + smart_str_append_printf(str, "abstract "); } if (ce->ce_flags & ZEND_ACC_FINAL) { - string_printf(str, "final "); + smart_str_append_printf(str, "final "); } - string_printf(str, "class "); + smart_str_append_printf(str, "class "); } - string_printf(str, "%s", ZSTR_VAL(ce->name)); + smart_str_append_printf(str, "%s", ZSTR_VAL(ce->name)); if (ce->parent) { - string_printf(str, " extends %s", ZSTR_VAL(ce->parent->name)); + smart_str_append_printf(str, " extends %s", ZSTR_VAL(ce->parent->name)); } if (ce->num_interfaces) { uint32_t i; if (ce->ce_flags & ZEND_ACC_INTERFACE) { - string_printf(str, " extends %s", ZSTR_VAL(ce->interfaces[0]->name)); + smart_str_append_printf(str, " extends %s", ZSTR_VAL(ce->interfaces[0]->name)); } else { - string_printf(str, " implements %s", ZSTR_VAL(ce->interfaces[0]->name)); + smart_str_append_printf(str, " implements %s", ZSTR_VAL(ce->interfaces[0]->name)); } for (i = 1; i < ce->num_interfaces; ++i) { - string_printf(str, ", %s", ZSTR_VAL(ce->interfaces[i]->name)); + smart_str_append_printf(str, ", %s", ZSTR_VAL(ce->interfaces[i]->name)); } } - string_printf(str, " ] {\n"); + smart_str_append_printf(str, " ] {\n"); /* The information where a class is declared is only available for user classes */ if (ce->type == ZEND_USER_CLASS) { - string_printf(str, "%s @@ %s %d-%d\n", indent, ZSTR_VAL(ce->info.user.filename), + smart_str_append_printf(str, "%s @@ %s %d-%d\n", indent, ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start, ce->info.user.line_end); } /* Constants */ - string_printf(str, "\n"); + smart_str_append_printf(str, "\n"); count = zend_hash_num_elements(&ce->constants_table); - string_printf(str, "%s - Constants [%d] {\n", indent, count); + smart_str_append_printf(str, "%s - Constants [%d] {\n", indent, count); if (count > 0) { zend_string *key; zend_class_constant *c; ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->constants_table, key, c) { - _class_const_string(str, ZSTR_VAL(key), c, ZSTR_VAL(sub_indent.buf)); + _class_const_string(str, ZSTR_VAL(key), c, ZSTR_VAL(sub_indent.s)); } ZEND_HASH_FOREACH_END(); } - string_printf(str, "%s }\n", indent); + smart_str_append_printf(str, "%s }\n", indent); /* Static properties */ /* counting static properties */ @@ -471,17 +403,17 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in } /* static properties */ - string_printf(str, "\n%s - Static properties [%d] {\n", indent, count_static_props); + smart_str_append_printf(str, "\n%s - Static properties [%d] {\n", indent, count_static_props); if (count_static_props > 0) { zend_property_info *prop; ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) { if ((prop->flags & ZEND_ACC_STATIC) && !(prop->flags & ZEND_ACC_SHADOW)) { - _property_string(str, prop, NULL, ZSTR_VAL(sub_indent.buf)); + _property_string(str, prop, NULL, ZSTR_VAL(sub_indent.s)); } } ZEND_HASH_FOREACH_END(); } - string_printf(str, "%s }\n", indent); + smart_str_append_printf(str, "%s }\n", indent); /* Static methods */ /* counting static methods */ @@ -499,7 +431,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in } /* static methods */ - string_printf(str, "\n%s - Static methods [%d] {", indent, count_static_funcs); + smart_str_append_printf(str, "\n%s - Static methods [%d] {", indent, count_static_funcs); if (count_static_funcs > 0) { zend_function *mptr; @@ -507,52 +439,50 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in if (mptr->common.fn_flags & ZEND_ACC_STATIC && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { - string_printf(str, "\n"); - _function_string(str, mptr, ce, ZSTR_VAL(sub_indent.buf)); + smart_str_append_printf(str, "\n"); + _function_string(str, mptr, ce, ZSTR_VAL(sub_indent.s)); } } ZEND_HASH_FOREACH_END(); } else { - string_printf(str, "\n"); + smart_str_append_printf(str, "\n"); } - string_printf(str, "%s }\n", indent); + smart_str_append_printf(str, "%s }\n", indent); /* Default/Implicit properties */ count = zend_hash_num_elements(&ce->properties_info) - count_static_props - count_shadow_props; - string_printf(str, "\n%s - Properties [%d] {\n", indent, count); + smart_str_append_printf(str, "\n%s - Properties [%d] {\n", indent, count); if (count > 0) { zend_property_info *prop; ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) { if (!(prop->flags & (ZEND_ACC_STATIC|ZEND_ACC_SHADOW))) { - _property_string(str, prop, NULL, ZSTR_VAL(sub_indent.buf)); + _property_string(str, prop, NULL, ZSTR_VAL(sub_indent.s)); } } ZEND_HASH_FOREACH_END(); } - string_printf(str, "%s }\n", indent); + smart_str_append_printf(str, "%s }\n", indent); if (obj && Z_TYPE_P(obj) == IS_OBJECT && Z_OBJ_HT_P(obj)->get_properties) { - string dyn; HashTable *properties = Z_OBJ_HT_P(obj)->get_properties(obj); zend_string *prop_name; + smart_str prop_str = {0}; - string_init(&dyn); count = 0; - if (properties && zend_hash_num_elements(properties)) { ZEND_HASH_FOREACH_STR_KEY(properties, prop_name) { if (prop_name && ZSTR_LEN(prop_name) && ZSTR_VAL(prop_name)[0]) { /* skip all private and protected properties */ if (!zend_hash_exists(&ce->properties_info, prop_name)) { count++; - _property_string(&dyn, NULL, ZSTR_VAL(prop_name), ZSTR_VAL(sub_indent.buf)); + _property_string(&prop_str, NULL, ZSTR_VAL(prop_name), ZSTR_VAL(sub_indent.s)); } } } ZEND_HASH_FOREACH_END(); } - string_printf(str, "\n%s - Dynamic properties [%d] {\n", indent, count); - string_append(str, &dyn); - string_printf(str, "%s }\n", indent); - string_free(&dyn); + smart_str_append_printf(str, "\n%s - Dynamic properties [%d] {\n", indent, count); + smart_str_append_smart_str(str, &prop_str); + smart_str_append_printf(str, "%s }\n", indent); + smart_str_free(&prop_str); } /* Non static methods */ @@ -560,11 +490,9 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in if (count > 0) { zend_function *mptr; zend_string *key; - string dyn; + smart_str method_str = {0}; count = 0; - string_init(&dyn); - ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->function_table, key, mptr) { if ((mptr->common.fn_flags & ZEND_ACC_STATIC) == 0 && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) @@ -587,40 +515,40 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in } else { closure = NULL; } - string_printf(&dyn, "\n"); - _function_string(&dyn, mptr, ce, ZSTR_VAL(sub_indent.buf)); + smart_str_appendc(&method_str, '\n'); + _function_string(&method_str, mptr, ce, ZSTR_VAL(sub_indent.s)); count++; _free_function(closure); } } } ZEND_HASH_FOREACH_END(); - string_printf(str, "\n%s - Methods [%d] {", indent, count); + smart_str_append_printf(str, "\n%s - Methods [%d] {", indent, count); + smart_str_append_smart_str(str, &method_str); if (!count) { - string_printf(str, "\n"); + smart_str_append_printf(str, "\n"); } - string_append(str, &dyn); - string_free(&dyn); + smart_str_free(&method_str); } else { - string_printf(str, "\n%s - Methods [0] {\n", indent); + smart_str_append_printf(str, "\n%s - Methods [0] {\n", indent); } - string_printf(str, "%s }\n", indent); + smart_str_append_printf(str, "%s }\n", indent); - string_printf(str, "%s}\n", indent); - string_free(&sub_indent); + smart_str_append_printf(str, "%s}\n", indent); + smart_str_free(&sub_indent); } /* }}} */ /* {{{ _const_string */ -static void _const_string(string *str, char *name, zval *value, char *indent) +static void _const_string(smart_str *str, char *name, zval *value, char *indent) { char *type = zend_zval_type_name(value); if (Z_TYPE_P(value) == IS_ARRAY) { - string_printf(str, "%s Constant [ %s %s ] { Array }\n", + smart_str_append_printf(str, "%s Constant [ %s %s ] { Array }\n", indent, type, name); } else { zend_string *value_str = zval_get_string(value); - string_printf(str, "%s Constant [ %s %s ] { %s }\n", + smart_str_append_printf(str, "%s Constant [ %s %s ] { %s }\n", indent, type, name, ZSTR_VAL(value_str)); zend_string_release(value_str); } @@ -628,7 +556,7 @@ static void _const_string(string *str, char *name, zval *value, char *indent) /* }}} */ /* {{{ _class_const_string */ -static void _class_const_string(string *str, char *name, zend_class_constant *c, char *indent) +static void _class_const_string(smart_str *str, char *name, zend_class_constant *c, char *indent) { char *visibility = zend_visibility_string(Z_ACCESS_FLAGS(c->value)); char *type; @@ -637,12 +565,12 @@ static void _class_const_string(string *str, char *name, zend_class_constant *c, type = zend_zval_type_name(&c->value); if (Z_TYPE(c->value) == IS_ARRAY) { - string_printf(str, "%sConstant [ %s %s %s ] { Array }\n", + smart_str_append_printf(str, "%sConstant [ %s %s %s ] { Array }\n", indent, visibility, type, name); } else { zend_string *value_str = zval_get_string(&c->value); - string_printf(str, "%sConstant [ %s %s %s ] { %s }\n", + smart_str_append_printf(str, "%sConstant [ %s %s %s ] { %s }\n", indent, visibility, type, name, ZSTR_VAL(value_str)); zend_string_release(value_str); @@ -670,81 +598,81 @@ static zend_op* _get_recv_op(zend_op_array *op_array, uint32_t offset) /* }}} */ /* {{{ _parameter_string */ -static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg_info *arg_info, uint32_t offset, zend_bool required, char* indent) +static void _parameter_string(smart_str *str, zend_function *fptr, struct _zend_arg_info *arg_info, uint32_t offset, zend_bool required, char* indent) { - string_printf(str, "Parameter #%d [ ", offset); + smart_str_append_printf(str, "Parameter #%d [ ", offset); if (!required) { - string_printf(str, "<optional> "); + smart_str_append_printf(str, "<optional> "); } else { - string_printf(str, "<required> "); + smart_str_append_printf(str, "<required> "); } if (arg_info->class_name) { - string_printf(str, "%s ", + smart_str_append_printf(str, "%s ", (fptr->type == ZEND_INTERNAL_FUNCTION && !(fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) ? ((zend_internal_arg_info*)arg_info)->class_name : ZSTR_VAL(arg_info->class_name)); if (arg_info->allow_null) { - string_printf(str, "or NULL "); + smart_str_append_printf(str, "or NULL "); } } else if (arg_info->type_hint) { - string_printf(str, "%s ", zend_get_type_by_const(arg_info->type_hint)); + smart_str_append_printf(str, "%s ", zend_get_type_by_const(arg_info->type_hint)); if (arg_info->allow_null) { - string_printf(str, "or NULL "); + smart_str_append_printf(str, "or NULL "); } } if (arg_info->pass_by_reference) { - string_write(str, "&", sizeof("&")-1); + smart_str_appendc(str, '&'); } if (arg_info->is_variadic) { - string_write(str, "...", sizeof("...")-1); + smart_str_appends(str, "..."); } if (arg_info->name) { - string_printf(str, "$%s", + smart_str_append_printf(str, "$%s", (fptr->type == ZEND_INTERNAL_FUNCTION && !(fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) ? ((zend_internal_arg_info*)arg_info)->name : ZSTR_VAL(arg_info->name)); } else { - string_printf(str, "$param%d", offset); + smart_str_append_printf(str, "$param%d", offset); } if (fptr->type == ZEND_USER_FUNCTION && !required) { zend_op *precv = _get_recv_op((zend_op_array*)fptr, offset); if (precv && precv->opcode == ZEND_RECV_INIT && precv->op2_type != IS_UNUSED) { zval zv; - string_write(str, " = ", sizeof(" = ")-1); + smart_str_appends(str, " = "); ZVAL_DUP(&zv, RT_CONSTANT(&fptr->op_array, precv->op2)); zval_update_constant_ex(&zv, fptr->common.scope); if (Z_TYPE(zv) == IS_TRUE) { - string_write(str, "true", sizeof("true")-1); + smart_str_appends(str, "true"); } else if (Z_TYPE(zv) == IS_FALSE) { - string_write(str, "false", sizeof("false")-1); + smart_str_appends(str, "false"); } else if (Z_TYPE(zv) == IS_NULL) { - string_write(str, "NULL", sizeof("NULL")-1); + smart_str_appends(str, "NULL"); } else if (Z_TYPE(zv) == IS_STRING) { - string_write(str, "'", sizeof("'")-1); - string_write(str, Z_STRVAL(zv), MIN(Z_STRLEN(zv), 15)); + smart_str_appendc(str, '\''); + smart_str_appendl(str, Z_STRVAL(zv), MIN(Z_STRLEN(zv), 15)); if (Z_STRLEN(zv) > 15) { - string_write(str, "...", sizeof("...")-1); + smart_str_appends(str, "..."); } - string_write(str, "'", sizeof("'")-1); + smart_str_appendc(str, '\''); } else if (Z_TYPE(zv) == IS_ARRAY) { - string_write(str, "Array", sizeof("Array")-1); + smart_str_appends(str, "Array"); } else { zend_string *zv_str = zval_get_string(&zv); - string_write(str, ZSTR_VAL(zv_str), ZSTR_LEN(zv_str)); + smart_str_append(str, zv_str); zend_string_release(zv_str); } zval_ptr_dtor(&zv); } } - string_write(str, " ]", sizeof(" ]")-1); + smart_str_appends(str, " ]"); } /* }}} */ /* {{{ _function_parameter_string */ -static void _function_parameter_string(string *str, zend_function *fptr, char* indent) +static void _function_parameter_string(smart_str *str, zend_function *fptr, char* indent) { struct _zend_arg_info *arg_info = fptr->common.arg_info; uint32_t i, num_args, num_required = fptr->common.required_num_args; @@ -757,20 +685,20 @@ static void _function_parameter_string(string *str, zend_function *fptr, char* i if (fptr->common.fn_flags & ZEND_ACC_VARIADIC) { num_args++; } - string_printf(str, "\n"); - string_printf(str, "%s- Parameters [%d] {\n", indent, num_args); + smart_str_appendc(str, '\n'); + smart_str_append_printf(str, "%s- Parameters [%d] {\n", indent, num_args); for (i = 0; i < num_args; i++) { - string_printf(str, "%s ", indent); + smart_str_append_printf(str, "%s ", indent); _parameter_string(str, fptr, arg_info, i, i < num_required, indent); - string_write(str, "\n", sizeof("\n")-1); + smart_str_appendc(str, '\n'); arg_info++; } - string_printf(str, "%s}\n", indent); + smart_str_append_printf(str, "%s}\n", indent); } /* }}} */ /* {{{ _function_closure_string */ -static void _function_closure_string(string *str, zend_function *fptr, char* indent) +static void _function_closure_string(smart_str *str, zend_function *fptr, char* indent) { uint32_t i, count; zend_string *key; @@ -787,20 +715,20 @@ static void _function_closure_string(string *str, zend_function *fptr, char* ind return; } - string_printf(str, "\n"); - string_printf(str, "%s- Bound Variables [%d] {\n", indent, zend_hash_num_elements(static_variables)); + smart_str_append_printf(str, "\n"); + smart_str_append_printf(str, "%s- Bound Variables [%d] {\n", indent, zend_hash_num_elements(static_variables)); i = 0; ZEND_HASH_FOREACH_STR_KEY(static_variables, key) { - string_printf(str, "%s Variable #%d [ $%s ]\n", indent, i++, ZSTR_VAL(key)); + smart_str_append_printf(str, "%s Variable #%d [ $%s ]\n", indent, i++, ZSTR_VAL(key)); } ZEND_HASH_FOREACH_END(); - string_printf(str, "%s}\n", indent); + smart_str_append_printf(str, "%s}\n", indent); } /* }}} */ /* {{{ _function_string */ -static void _function_string(string *str, zend_function *fptr, zend_class_entry *scope, char* indent) +static void _function_string(smart_str *str, zend_function *fptr, zend_class_entry *scope, char* indent) { - string param_indent; + smart_str param_indent = {0}; zend_function *overwrites; zend_string *lc_name; size_t lc_name_len; @@ -810,190 +738,190 @@ static void _function_string(string *str, zend_function *fptr, zend_class_entry * swallowed, leading to an unaligned comment. */ if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) { - string_printf(str, "%s%s\n", indent, ZSTR_VAL(fptr->op_array.doc_comment)); + smart_str_append_printf(str, "%s%s\n", indent, ZSTR_VAL(fptr->op_array.doc_comment)); } - string_write(str, indent, strlen(indent)); - string_printf(str, fptr->common.fn_flags & ZEND_ACC_CLOSURE ? "Closure [ " : (fptr->common.scope ? "Method [ " : "Function [ ")); - string_printf(str, (fptr->type == ZEND_USER_FUNCTION) ? "<user" : "<internal"); + smart_str_appendl(str, indent, strlen(indent)); + smart_str_append_printf(str, fptr->common.fn_flags & ZEND_ACC_CLOSURE ? "Closure [ " : (fptr->common.scope ? "Method [ " : "Function [ ")); + smart_str_append_printf(str, (fptr->type == ZEND_USER_FUNCTION) ? "<user" : "<internal"); if (fptr->common.fn_flags & ZEND_ACC_DEPRECATED) { - string_printf(str, ", deprecated"); + smart_str_appends(str, ", deprecated"); } if (fptr->type == ZEND_INTERNAL_FUNCTION && ((zend_internal_function*)fptr)->module) { - string_printf(str, ":%s", ((zend_internal_function*)fptr)->module->name); + smart_str_append_printf(str, ":%s", ((zend_internal_function*)fptr)->module->name); } if (scope && fptr->common.scope) { if (fptr->common.scope != scope) { - string_printf(str, ", inherits %s", ZSTR_VAL(fptr->common.scope->name)); + smart_str_append_printf(str, ", inherits %s", ZSTR_VAL(fptr->common.scope->name)); } else if (fptr->common.scope->parent) { lc_name_len = ZSTR_LEN(fptr->common.function_name); lc_name = zend_string_alloc(lc_name_len, 0); zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(fptr->common.function_name), lc_name_len); if ((overwrites = zend_hash_find_ptr(&fptr->common.scope->parent->function_table, lc_name)) != NULL) { if (fptr->common.scope != overwrites->common.scope) { - string_printf(str, ", overwrites %s", ZSTR_VAL(overwrites->common.scope->name)); + smart_str_append_printf(str, ", overwrites %s", ZSTR_VAL(overwrites->common.scope->name)); } } efree(lc_name); } } if (fptr->common.prototype && fptr->common.prototype->common.scope) { - string_printf(str, ", prototype %s", ZSTR_VAL(fptr->common.prototype->common.scope->name)); + smart_str_append_printf(str, ", prototype %s", ZSTR_VAL(fptr->common.prototype->common.scope->name)); } if (fptr->common.fn_flags & ZEND_ACC_CTOR) { - string_printf(str, ", ctor"); + smart_str_appends(str, ", ctor"); } if (fptr->common.fn_flags & ZEND_ACC_DTOR) { - string_printf(str, ", dtor"); + smart_str_appends(str, ", dtor"); } - string_printf(str, "> "); + smart_str_appends(str, "> "); if (fptr->common.fn_flags & ZEND_ACC_ABSTRACT) { - string_printf(str, "abstract "); + smart_str_appends(str, "abstract "); } if (fptr->common.fn_flags & ZEND_ACC_FINAL) { - string_printf(str, "final "); + smart_str_appends(str, "final "); } if (fptr->common.fn_flags & ZEND_ACC_STATIC) { - string_printf(str, "static "); + smart_str_appends(str, "static "); } if (fptr->common.scope) { /* These are mutually exclusive */ switch (fptr->common.fn_flags & ZEND_ACC_PPP_MASK) { case ZEND_ACC_PUBLIC: - string_printf(str, "public "); + smart_str_appends(str, "public "); break; case ZEND_ACC_PRIVATE: - string_printf(str, "private "); + smart_str_appends(str, "private "); break; case ZEND_ACC_PROTECTED: - string_printf(str, "protected "); + smart_str_appends(str, "protected "); break; default: - string_printf(str, "<visibility error> "); + smart_str_appends(str, "<visibility error> "); break; } - string_printf(str, "method "); + smart_str_appends(str, "method "); } else { - string_printf(str, "function "); + smart_str_appends(str, "function "); } if (fptr->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE) { - string_printf(str, "&"); + smart_str_appendc(str, '&'); } - string_printf(str, "%s ] {\n", ZSTR_VAL(fptr->common.function_name)); + smart_str_append_printf(str, "%s ] {\n", ZSTR_VAL(fptr->common.function_name)); /* The information where a function is declared is only available for user classes */ if (fptr->type == ZEND_USER_FUNCTION) { - string_printf(str, "%s @@ %s %d - %d\n", indent, + smart_str_append_printf(str, "%s @@ %s %d - %d\n", indent, ZSTR_VAL(fptr->op_array.filename), fptr->op_array.line_start, fptr->op_array.line_end); } - string_init(¶m_indent); - string_printf(¶m_indent, "%s ", indent); + smart_str_append_printf(¶m_indent, "%s ", indent); + smart_str_0(¶m_indent); if (fptr->common.fn_flags & ZEND_ACC_CLOSURE) { - _function_closure_string(str, fptr, ZSTR_VAL(param_indent.buf)); + _function_closure_string(str, fptr, ZSTR_VAL(param_indent.s)); } - _function_parameter_string(str, fptr, ZSTR_VAL(param_indent.buf)); - string_free(¶m_indent); + _function_parameter_string(str, fptr, ZSTR_VAL(param_indent.s)); + smart_str_free(¶m_indent); if (fptr->op_array.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) { - string_printf(str, " %s- Return [ ", indent); + smart_str_append_printf(str, " %s- Return [ ", indent); if (fptr->common.arg_info[-1].class_name) { - string_printf(str, "%s ", + smart_str_append_printf(str, "%s ", (fptr->type == ZEND_INTERNAL_FUNCTION && !(fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) ? ((zend_internal_arg_info*)(fptr->common.arg_info - 1))->class_name : ZSTR_VAL(fptr->common.arg_info[-1].class_name)); if (fptr->common.arg_info[-1].allow_null) { - string_printf(str, "or NULL "); + smart_str_appends(str, "or NULL "); } } else if (fptr->common.arg_info[-1].type_hint) { - string_printf(str, "%s ", zend_get_type_by_const(fptr->common.arg_info[-1].type_hint)); + smart_str_append_printf(str, "%s ", zend_get_type_by_const(fptr->common.arg_info[-1].type_hint)); if (fptr->common.arg_info[-1].allow_null) { - string_printf(str, "or NULL "); + smart_str_appends(str, "or NULL "); } } - string_printf(str, "]\n"); + smart_str_appends(str, "]\n"); } - string_printf(str, "%s}\n", indent); + smart_str_append_printf(str, "%s}\n", indent); } /* }}} */ /* {{{ _property_string */ -static void _property_string(string *str, zend_property_info *prop, char *prop_name, char* indent) +static void _property_string(smart_str *str, zend_property_info *prop, char *prop_name, char* indent) { const char *class_name; - string_printf(str, "%sProperty [ ", indent); + smart_str_append_printf(str, "%sProperty [ ", indent); if (!prop) { - string_printf(str, "<dynamic> public $%s", prop_name); + smart_str_append_printf(str, "<dynamic> public $%s", prop_name); } else { if (!(prop->flags & ZEND_ACC_STATIC)) { if (prop->flags & ZEND_ACC_IMPLICIT_PUBLIC) { - string_write(str, "<implicit> ", sizeof("<implicit> ") - 1); + smart_str_appends(str, "<implicit> "); } else { - string_write(str, "<default> ", sizeof("<default> ") - 1); + smart_str_appends(str, "<default> "); } } /* These are mutually exclusive */ switch (prop->flags & ZEND_ACC_PPP_MASK) { case ZEND_ACC_PUBLIC: - string_printf(str, "public "); + smart_str_appends(str, "public "); break; case ZEND_ACC_PRIVATE: - string_printf(str, "private "); + smart_str_appends(str, "private "); break; case ZEND_ACC_PROTECTED: - string_printf(str, "protected "); + smart_str_appends(str, "protected "); break; } if(prop->flags & ZEND_ACC_STATIC) { - string_printf(str, "static "); + smart_str_appends(str, "static "); } zend_unmangle_property_name(prop->name, &class_name, (const char**)&prop_name); - string_printf(str, "$%s", prop_name); + smart_str_append_printf(str, "$%s", prop_name); } - string_printf(str, " ]\n"); + smart_str_appends(str, " ]\n"); } /* }}} */ static int _extension_ini_string(zval *el, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { zend_ini_entry *ini_entry = (zend_ini_entry*)Z_PTR_P(el); - string *str = va_arg(args, string *); + smart_str *str = va_arg(args, smart_str *); char *indent = va_arg(args, char *); int number = va_arg(args, int); char *comma = ""; if (number == ini_entry->module_number) { - string_printf(str, " %sEntry [ %s <", indent, ZSTR_VAL(ini_entry->name)); + smart_str_append_printf(str, " %sEntry [ %s <", indent, ZSTR_VAL(ini_entry->name)); if (ini_entry->modifiable == ZEND_INI_ALL) { - string_printf(str, "ALL"); + smart_str_appends(str, "ALL"); } else { if (ini_entry->modifiable & ZEND_INI_USER) { - string_printf(str, "USER"); + smart_str_appends(str, "USER"); comma = ","; } if (ini_entry->modifiable & ZEND_INI_PERDIR) { - string_printf(str, "%sPERDIR", comma); + smart_str_append_printf(str, "%sPERDIR", comma); comma = ","; } if (ini_entry->modifiable & ZEND_INI_SYSTEM) { - string_printf(str, "%sSYSTEM", comma); + smart_str_append_printf(str, "%sSYSTEM", comma); } } - string_printf(str, "> ]\n"); - string_printf(str, " %s Current = '%s'\n", indent, ini_entry->value ? ZSTR_VAL(ini_entry->value) : ""); + smart_str_appends(str, "> ]\n"); + smart_str_append_printf(str, " %s Current = '%s'\n", indent, ini_entry->value ? ZSTR_VAL(ini_entry->value) : ""); if (ini_entry->modified) { - string_printf(str, " %s Default = '%s'\n", indent, ini_entry->orig_value ? ZSTR_VAL(ini_entry->orig_value) : ""); + smart_str_append_printf(str, " %s Default = '%s'\n", indent, ini_entry->orig_value ? ZSTR_VAL(ini_entry->orig_value) : ""); } - string_printf(str, " %s}\n", indent); + smart_str_append_printf(str, " %s}\n", indent); } return ZEND_HASH_APPLY_KEEP; } @@ -1002,7 +930,7 @@ static int _extension_ini_string(zval *el, int num_args, va_list args, zend_hash static int _extension_class_string(zval *el, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { zend_class_entry *ce = (zend_class_entry*)Z_PTR_P(el); - string *str = va_arg(args, string *); + smart_str *str = va_arg(args, smart_str *); char *indent = va_arg(args, char *); struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*); int *num_classes = va_arg(args, int*); @@ -1010,7 +938,7 @@ static int _extension_class_string(zval *el, int num_args, va_list args, zend_ha if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module && !strcasecmp(ce->info.internal.module->name, module->name)) { /* dump class if it is not an alias */ if (!zend_binary_strcasecmp(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), ZSTR_VAL(hash_key->key), ZSTR_LEN(hash_key->key))) { - string_printf(str, "\n"); + smart_str_append_printf(str, "\n"); _class_string(str, ce, NULL, indent); (*num_classes)++; } @@ -1022,7 +950,7 @@ static int _extension_class_string(zval *el, int num_args, va_list args, zend_ha static int _extension_const_string(zval *el, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { zend_constant *constant = (zend_constant*)Z_PTR_P(el); - string *str = va_arg(args, string *); + smart_str *str = va_arg(args, smart_str *); char *indent = va_arg(args, char *); struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*); int *num_classes = va_arg(args, int*); @@ -1035,78 +963,76 @@ static int _extension_const_string(zval *el, int num_args, va_list args, zend_ha } /* }}} */ -static void _extension_string(string *str, zend_module_entry *module, char *indent) /* {{{ */ +static void _extension_string(smart_str *str, zend_module_entry *module, char *indent) /* {{{ */ { - string_printf(str, "%sExtension [ ", indent); + smart_str_append_printf(str, "%sExtension [ ", indent); if (module->type == MODULE_PERSISTENT) { - string_printf(str, "<persistent>"); + smart_str_appends(str, "<persistent>"); } if (module->type == MODULE_TEMPORARY) { - string_printf(str, "<temporary>" ); + smart_str_appends(str, "<temporary>" ); } - string_printf(str, " extension #%d %s version %s ] {\n", + smart_str_append_printf(str, " extension #%d %s version %s ] {\n", module->module_number, module->name, (module->version == NO_VERSION_YET) ? "<no_version>" : module->version); if (module->deps) { const zend_module_dep* dep = module->deps; - string_printf(str, "\n - Dependencies {\n"); + smart_str_appends(str, "\n - Dependencies {\n"); while(dep->name) { - string_printf(str, "%s Dependency [ %s (", indent, dep->name); + smart_str_append_printf(str, "%s Dependency [ %s (", indent, dep->name); switch(dep->type) { case MODULE_DEP_REQUIRED: - string_write(str, "Required", sizeof("Required") - 1); + smart_str_appends(str, "Required"); break; case MODULE_DEP_CONFLICTS: - string_write(str, "Conflicts", sizeof("Conflicts") - 1); + smart_str_appends(str, "Conflicts"); break; case MODULE_DEP_OPTIONAL: - string_write(str, "Optional", sizeof("Optional") - 1); + smart_str_appends(str, "Optional"); break; default: - string_write(str, "Error", sizeof("Error") - 1); /* shouldn't happen */ + smart_str_appends(str, "Error"); /* shouldn't happen */ break; } if (dep->rel) { - string_printf(str, " %s", dep->rel); + smart_str_append_printf(str, " %s", dep->rel); } if (dep->version) { - string_printf(str, " %s", dep->version); + smart_str_append_printf(str, " %s", dep->version); } - string_write(str, ") ]\n", sizeof(") ]\n") - 1); + smart_str_appends(str, ") ]\n"); dep++; } - string_printf(str, "%s }\n", indent); + smart_str_append_printf(str, "%s }\n", indent); } { - string str_ini; - string_init(&str_ini); + smart_str str_ini = {0}; zend_hash_apply_with_arguments(EG(ini_directives), (apply_func_args_t) _extension_ini_string, 3, &str_ini, indent, module->module_number); - if (ZSTR_LEN(str_ini.buf) > 0) { - string_printf(str, "\n - INI {\n"); - string_append(str, &str_ini); - string_printf(str, "%s }\n", indent); + if (smart_str_get_len(&str_ini) > 0) { + smart_str_append_printf(str, "\n - INI {\n"); + smart_str_append_smart_str(str, &str_ini); + smart_str_append_printf(str, "%s }\n", indent); } - string_free(&str_ini); + smart_str_free(&str_ini); } { - string str_constants; + smart_str str_constants = {0}; int num_constants = 0; - string_init(&str_constants); zend_hash_apply_with_arguments(EG(zend_constants), (apply_func_args_t) _extension_const_string, 4, &str_constants, indent, module, &num_constants); if (num_constants) { - string_printf(str, "\n - Constants [%d] {\n", num_constants); - string_append(str, &str_constants); - string_printf(str, "%s }\n", indent); + smart_str_append_printf(str, "\n - Constants [%d] {\n", num_constants); + smart_str_append_smart_str(str, &str_constants); + smart_str_append_printf(str, "%s }\n", indent); } - string_free(&str_constants); + smart_str_free(&str_constants); } { @@ -1117,57 +1043,55 @@ static void _extension_string(string *str, zend_module_entry *module, char *inde if (fptr->common.type==ZEND_INTERNAL_FUNCTION && fptr->internal_function.module == module) { if (first) { - string_printf(str, "\n - Functions {\n"); + smart_str_append_printf(str, "\n - Functions {\n"); first = 0; } _function_string(str, fptr, NULL, " "); } } ZEND_HASH_FOREACH_END(); if (!first) { - string_printf(str, "%s }\n", indent); + smart_str_append_printf(str, "%s }\n", indent); } } { - string str_classes; - string sub_indent; + smart_str str_classes = {0}; + smart_str sub_indent = {0}; int num_classes = 0; - string_init(&sub_indent); - string_printf(&sub_indent, "%s ", indent); - string_init(&str_classes); - zend_hash_apply_with_arguments(EG(class_table), (apply_func_args_t) _extension_class_string, 4, &str_classes, ZSTR_VAL(sub_indent.buf), module, &num_classes); + smart_str_append_printf(&sub_indent, "%s ", indent); + zend_hash_apply_with_arguments(EG(class_table), (apply_func_args_t) _extension_class_string, 4, &str_classes, ZSTR_VAL(sub_indent.s), module, &num_classes); if (num_classes) { - string_printf(str, "\n - Classes [%d] {", num_classes); - string_append(str, &str_classes); - string_printf(str, "%s }\n", indent); + smart_str_append_printf(str, "\n - Classes [%d] {", num_classes); + smart_str_append_smart_str(str, &str_classes); + smart_str_append_printf(str, "%s }\n", indent); } - string_free(&str_classes); - string_free(&sub_indent); + smart_str_free(&str_classes); + smart_str_free(&sub_indent); } - string_printf(str, "%s}\n", indent); + smart_str_append_printf(str, "%s}\n", indent); } /* }}} */ -static void _zend_extension_string(string *str, zend_extension *extension, char *indent) /* {{{ */ +static void _zend_extension_string(smart_str *str, zend_extension *extension, char *indent) /* {{{ */ { - string_printf(str, "%sZend Extension [ %s ", indent, extension->name); + smart_str_append_printf(str, "%sZend Extension [ %s ", indent, extension->name); if (extension->version) { - string_printf(str, "%s ", extension->version); + smart_str_append_printf(str, "%s ", extension->version); } if (extension->copyright) { - string_printf(str, "%s ", extension->copyright); + smart_str_append_printf(str, "%s ", extension->copyright); } if (extension->author) { - string_printf(str, "by %s ", extension->author); + smart_str_append_printf(str, "by %s ", extension->author); } if (extension->URL) { - string_printf(str, "<%s> ", extension->URL); + smart_str_append_printf(str, "<%s> ", extension->URL); } - string_printf(str, "]\n"); + smart_str_appends(str, "]\n"); } /* }}} */ @@ -1689,15 +1613,14 @@ ZEND_METHOD(reflection_function, __toString) { reflection_object *intern; zend_function *fptr; - string str; + smart_str str = {0}; if (zend_parse_parameters_none() == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(fptr); - string_init(&str); _function_string(&str, fptr, intern->ce, ""); - RETURN_NEW_STR(str.buf); + RETURN_STR(smart_str_extract(&str)); } /* }}} */ @@ -2558,15 +2481,14 @@ ZEND_METHOD(reflection_parameter, __toString) { reflection_object *intern; parameter_reference *param; - string str; + smart_str str = {0}; if (zend_parse_parameters_none() == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(param); - string_init(&str); _parameter_string(&str, param->fptr, param->arg_info, param->offset, param->required, ""); - RETURN_NEW_STR(str.buf); + RETURN_STR(smart_str_extract(&str)); } /* }}} */ @@ -3160,15 +3082,14 @@ ZEND_METHOD(reflection_method, __toString) { reflection_object *intern; zend_function *mptr; - string str; + smart_str str = {0}; if (zend_parse_parameters_none() == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(mptr); - string_init(&str); _function_string(&str, mptr, intern->ce, ""); - RETURN_NEW_STR(str.buf); + RETURN_STR(smart_str_extract(&str)); } /* }}} */ @@ -3699,18 +3620,17 @@ ZEND_METHOD(reflection_class_constant, __toString) { reflection_object *intern; zend_class_constant *ref; - string str; + smart_str str = {0}; zval name; if (zend_parse_parameters_none() == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ref); - string_init(&str); _default_get_entry(getThis(), "name", sizeof("name")-1, &name); _class_const_string(&str, Z_STRVAL(name), ref, ""); zval_ptr_dtor(&name); - RETURN_NEW_STR(str.buf); + RETURN_STR(smart_str_extract(&str)); } /* }}} */ @@ -4050,15 +3970,14 @@ ZEND_METHOD(reflection_class, __toString) { reflection_object *intern; zend_class_entry *ce; - string str; + smart_str str = {0}; if (zend_parse_parameters_none() == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); - string_init(&str); _class_string(&str, ce, &intern->obj, ""); - RETURN_NEW_STR(str.buf); + RETURN_STR(smart_str_extract(&str)); } /* }}} */ @@ -5483,15 +5402,14 @@ ZEND_METHOD(reflection_property, __toString) { reflection_object *intern; property_reference *ref; - string str; + smart_str str = {0}; if (zend_parse_parameters_none() == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ref); - string_init(&str); _property_string(&str, &ref->prop, NULL, ""); - RETURN_NEW_STR(str.buf); + RETURN_STR(smart_str_extract(&str)); } /* }}} */ @@ -5819,15 +5737,14 @@ ZEND_METHOD(reflection_extension, __toString) { reflection_object *intern; zend_module_entry *module; - string str; + smart_str str = {0}; if (zend_parse_parameters_none() == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(module); - string_init(&str); _extension_string(&str, module, ""); - RETURN_NEW_STR(str.buf); + RETURN_STR(smart_str_extract(&str)); } /* }}} */ @@ -6182,15 +6099,14 @@ ZEND_METHOD(reflection_zend_extension, __toString) { reflection_object *intern; zend_extension *extension; - string str; + smart_str str = {0}; if (zend_parse_parameters_none() == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(extension); - string_init(&str); _zend_extension_string(&str, extension, ""); - RETURN_NEW_STR(str.buf); + RETURN_STR(smart_str_extract(&str)); } /* }}} */ diff --git a/ext/session/tests/bug60860-win32.phpt b/ext/session/tests/bug60860-win32.phpt deleted file mode 100644 index a3e32a9988..0000000000 --- a/ext/session/tests/bug60860-win32.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -Bug #60860 (session.save_handler=user without defined function core dumps) ---SKIPIF-- -<?php -include('skipif.inc'); -if (substr(PHP_OS, 0, 3) != 'WIN') { - die('skip only for Windows'); -} -?> ---INI-- -session.save_handler=user -display_errors=off ---FILE-- -<?php - -session_start(); -echo "ok\n"; - -?> ---EXPECTF-- -ok -PHP Recoverable fatal error: PHP Startup: Cannot set 'user' save handler by ini_set() or session_module_name() in Unknown on line 0 - diff --git a/ext/session/tests/bug60860.phpt b/ext/session/tests/bug60860.phpt index a9c7507b31..38a3796b68 100644 --- a/ext/session/tests/bug60860.phpt +++ b/ext/session/tests/bug60860.phpt @@ -3,9 +3,6 @@ Bug #60860 (session.save_handler=user without defined function core dumps) --SKIPIF-- <?php include('skipif.inc'); -if (substr(PHP_OS, 0, 3) == 'WIN') { - die('skip not for Windows'); -} ?> --INI-- session.save_handler=user diff --git a/ext/session/tests/bug66481-win32.phpt b/ext/session/tests/bug66481-win32.phpt deleted file mode 100644 index 1c597b5604..0000000000 --- a/ext/session/tests/bug66481-win32.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Bug #66481: Calls to session_name() segfault when session.name is null, Windows. ---INI-- -session.name= ---SKIPIF-- -<?php include('skipif.inc'); ?> -<?php if(substr(PHP_OS, 0, 3) != "WIN") die("skip Windows only"); ?> ---FILE-- -<?php -ob_start(); - -var_dump(session_name("foo")); -var_dump(session_name("bar")); -?> ---EXPECTF-- -Warning: PHP Startup: session.name cannot be a numeric or empty '' in Unknown on line 0 -string(9) "PHPSESSID" -string(3) "foo" -PHP Warning: PHP Startup: session.name cannot be a numeric or empty '' in Unknown on line 0 diff --git a/ext/session/tests/bug66481.phpt b/ext/session/tests/bug66481.phpt index 280c0b2420..c75cb88d1c 100644 --- a/ext/session/tests/bug66481.phpt +++ b/ext/session/tests/bug66481.phpt @@ -4,7 +4,6 @@ Bug #66481: Calls to session_name() segfault when session.name is null. session.name= --SKIPIF-- <?php include('skipif.inc'); ?> -<?php if(substr(PHP_OS, 0, 3) == "WIN") die("skip Not for Windows"); ?> --FILE-- <?php ob_start(); diff --git a/ext/session/tests/rfc1867_invalid_settings-win.phpt b/ext/session/tests/rfc1867_invalid_settings-win.phpt deleted file mode 100644 index ed854e8898..0000000000 --- a/ext/session/tests/rfc1867_invalid_settings-win.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -session rfc1867 invalid settings ---INI-- -session.upload_progress.freq=-1 -error_log= ---SKIPIF-- -<?php -include('skipif.inc'); -if(substr(PHP_OS, 0, 3) != "WIN") - die("skip windows only test"); -?> ---FILE-- -<?php -var_dump(ini_get("session.upload_progress.freq")); -?> ---EXPECTF-- -Warning: PHP Startup: session.upload_progress.freq must be greater than or equal to zero in %s -string(2) "1%" -PHP Warning: PHP Startup: session.upload_progress.freq must be greater than or equal to zero in %s diff --git a/ext/session/tests/rfc1867_invalid_settings.phpt b/ext/session/tests/rfc1867_invalid_settings.phpt index 640c4d2436..1a989e979b 100644 --- a/ext/session/tests/rfc1867_invalid_settings.phpt +++ b/ext/session/tests/rfc1867_invalid_settings.phpt @@ -6,8 +6,6 @@ error_log= --SKIPIF-- <?php include('skipif.inc'); -if(substr(PHP_OS, 0, 3) == "WIN") - die("skip Not for Windows"); ?> --FILE-- <?php diff --git a/ext/session/tests/rfc1867_invalid_settings_2-win.phpt b/ext/session/tests/rfc1867_invalid_settings_2-win.phpt deleted file mode 100644 index f8e6b6d208..0000000000 --- a/ext/session/tests/rfc1867_invalid_settings_2-win.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -session rfc1867 invalid settings 2 ---INI-- -session.upload_progress.freq=200% -error_log= ---SKIPIF-- -<?php -include('skipif.inc'); -if(substr(PHP_OS, 0, 3) != "WIN") - die("skip windows only test"); -?> ---FILE-- -<?php -var_dump(ini_get("session.upload_progress.freq")); -?> ---EXPECTF-- -Warning: PHP Startup: session.upload_progress.freq cannot be over 100% in %s -string(2) "1%" -PHP Warning: PHP Startup: session.upload_progress.freq cannot be over 100% in %s diff --git a/ext/session/tests/rfc1867_invalid_settings_2.phpt b/ext/session/tests/rfc1867_invalid_settings_2.phpt index c2a0c6ac4e..9246e1dbbc 100644 --- a/ext/session/tests/rfc1867_invalid_settings_2.phpt +++ b/ext/session/tests/rfc1867_invalid_settings_2.phpt @@ -6,8 +6,6 @@ error_log= --SKIPIF-- <?php include('skipif.inc'); -if(substr(PHP_OS, 0, 3) == "WIN") - die("skip Not for Windows"); ?> --FILE-- <?php diff --git a/ext/session/tests/session_set_save_handler_class_014-win32.phpt b/ext/session/tests/session_set_save_handler_class_014-win32.phpt deleted file mode 100644 index f26a9fa098..0000000000 --- a/ext/session/tests/session_set_save_handler_class_014-win32.phpt +++ /dev/null @@ -1,36 +0,0 @@ ---TEST-- -Test session_set_save_handler() : calling default handler when save_handler=user ---INI-- -session.save_handler=user -session.name=PHPSESSID -display_errors=off ---SKIPIF-- -<?php -include('skipif.inc'); -if (substr(PHP_OS, 0, 3) != 'WIN') { - die('skip only for Windows'); -} -?> ---FILE-- -<?php - -ob_start(); - -/* - * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true]) - * Description : Sets user-level session storage functions - * Source code : ext/session/session.c - */ - -echo "*** Testing session_set_save_handler() : calling default handler when save_handler=user ***\n"; - -$oldHandler = ini_get('session.save_handler'); -$handler = new SessionHandler; -session_set_save_handler($handler); - -session_start(); - ---EXPECTF-- -*** Testing session_set_save_handler() : calling default handler when save_handler=user *** -PHP Recoverable fatal error: PHP Startup: Cannot set 'user' save handler by ini_set() or session_module_name() in Unknown on line 0 - diff --git a/ext/session/tests/session_set_save_handler_class_014.phpt b/ext/session/tests/session_set_save_handler_class_014.phpt index 1b06cd0b64..ba689cef02 100644 --- a/ext/session/tests/session_set_save_handler_class_014.phpt +++ b/ext/session/tests/session_set_save_handler_class_014.phpt @@ -7,9 +7,6 @@ display_errors=off --SKIPIF-- <?php include('skipif.inc'); -if (substr(PHP_OS, 0, 3) == 'WIN') { - die('skip not for Windows'); -} ?> --FILE-- <?php diff --git a/ext/soap/tests/bugs/bug31422-win.phpt b/ext/soap/tests/bugs/bug31422-win.phpt deleted file mode 100644 index ba8df0726c..0000000000 --- a/ext/soap/tests/bugs/bug31422-win.phpt +++ /dev/null @@ -1,47 +0,0 @@ ---TEST-- -Bug #31422 (No Error-Logging on SoapServer-Side) ---SKIPIF-- -<?php -if (substr(PHP_OS, 0, 3) != 'WIN') { - die('skip not valid for non windows'); -} -require_once('skipif.inc'); -?> ---INI-- -log_errors=1 ---FILE-- -<?php -function Add($x,$y) { - fopen(); - user_error("Hello", E_USER_ERROR); - return $x+$y; -} - -$server = new SoapServer(null,array('uri'=>"http://testuri.org")); -$server->addfunction("Add"); - -$HTTP_RAW_POST_DATA = <<<EOF -<?xml version="1.0" encoding="ISO-8859-1"?> -<SOAP-ENV:Envelope - SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" - xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" - xmlns:xsd="http://www.w3.org/2001/XMLSchema" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:si="http://soapinterop.org/xsd"> - <SOAP-ENV:Body> - <ns1:Add xmlns:ns1="http://testuri.org"> - <x xsi:type="xsd:int">22</x> - <y xsi:type="xsd:int">33</y> - </ns1:Add> - </SOAP-ENV:Body> -</SOAP-ENV:Envelope> -EOF; - -$server->handle($HTTP_RAW_POST_DATA); -echo "ok\n"; -?> ---EXPECTF-- -<?xml version="1.0" encoding="UTF-8"?> -<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>Hello</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope> -PHP Warning: fopen() expects at least 2 parameters, 0 given in %sbug31422-win.php on line %d -PHP Fatal error: Hello in %sbug31422-win.php on line %d diff --git a/ext/soap/tests/bugs/bug31422.phpt b/ext/soap/tests/bugs/bug31422.phpt index c8ddcfe092..4889b10d8e 100644 --- a/ext/soap/tests/bugs/bug31422.phpt +++ b/ext/soap/tests/bugs/bug31422.phpt @@ -2,9 +2,6 @@ Bug #31422 (No Error-Logging on SoapServer-Side) --SKIPIF-- <?php -if (substr(PHP_OS, 0, 3) == 'WIN') { - die('skip not valid for windows'); -} require_once('skipif.inc'); ?> --INI-- diff --git a/ext/standard/php_smart_string.h b/ext/standard/php_smart_string.h index b8db164076..fac844ae7a 100644 --- a/ext/standard/php_smart_string.h +++ b/ext/standard/php_smart_string.h @@ -17,133 +17,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ +/* Header moved to Zend. This file is retained for BC. */ +#include "zend_smart_string.h" -#ifndef PHP_SMART_STRING_H -#define PHP_SMART_STRING_H - -#include "php_smart_string_public.h" - -#include <stdlib.h> -#ifndef SMART_STR_USE_REALLOC -#include <zend.h> -#endif - -#define smart_string_0(x) do { \ - if ((x)->c) { \ - (x)->c[(x)->len] = '\0'; \ - } \ -} while (0) - -#ifndef SMART_STRING_PREALLOC -#define SMART_STRING_PREALLOC 128 -#endif - -#ifndef SMART_STRING_START_SIZE -#define SMART_STRING_START_SIZE 78 -#endif - -#ifdef SMART_STRING_USE_REALLOC -#define SMART_STRING_REALLOC(a,b,c) realloc((a),(b)) -#else -#define SMART_STRING_REALLOC(a,b,c) perealloc((a),(b),(c)) -#endif - -#define SMART_STRING_DO_REALLOC(d, what) \ - (d)->c = SMART_STRING_REALLOC((d)->c, (d)->a + 1, (what)) - -#define smart_string_alloc4(d, n, what, newlen) do { \ - if (!(d)->c) { \ - (d)->len = 0; \ - newlen = (n); \ - (d)->a = newlen < SMART_STRING_START_SIZE \ - ? SMART_STRING_START_SIZE \ - : newlen + SMART_STRING_PREALLOC; \ - SMART_STRING_DO_REALLOC(d, what); \ - } else { \ - if(UNEXPECTED((size_t)n > SIZE_MAX - (d)->len)) { \ - zend_error(E_ERROR, "String size overflow"); \ - } \ - newlen = (d)->len + (n); \ - if (newlen >= (d)->a) { \ - (d)->a = newlen + SMART_STRING_PREALLOC; \ - SMART_STRING_DO_REALLOC(d, what); \ - } \ - } \ -} while (0) - -#define smart_string_alloc(d, n, what) \ - smart_string_alloc4((d), (n), (what), newlen) - -/* wrapper */ - -#define smart_string_appends_ex(dest, src, what) \ - smart_string_appendl_ex((dest), (src), strlen(src), (what)) -#define smart_string_appends(dest, src) \ - smart_string_appendl((dest), (src), strlen(src)) - -#define smart_string_appendc(dest, c) \ - smart_string_appendc_ex((dest), (c), 0) -#define smart_string_free(s) \ - smart_string_free_ex((s), 0) -#define smart_string_appendl(dest, src, len) \ - smart_string_appendl_ex((dest), (src), (len), 0) -#define smart_string_append(dest, src) \ - smart_string_append_ex((dest), (src), 0) -#define smart_string_append_long(dest, val) \ - smart_string_append_long_ex((dest), (val), 0) -#define smart_string_append_unsigned(dest, val) \ - smart_string_append_unsigned_ex((dest), (val), 0) - -#define smart_string_appendc_ex(dest, ch, what) do { \ - size_t __nl; \ - smart_string_alloc4((dest), 1, (what), __nl); \ - (dest)->len = __nl; \ - ((unsigned char *) (dest)->c)[(dest)->len - 1] = (ch); \ -} while (0) - -#define smart_string_free_ex(s, what) do { \ - smart_string *__s = (smart_string *) (s); \ - if (__s->c) { \ - pefree(__s->c, what); \ - __s->c = NULL; \ - } \ - __s->a = __s->len = 0; \ -} while (0) - -#define smart_string_appendl_ex(dest, src, nlen, what) do { \ - size_t __nl; \ - smart_string *__dest = (smart_string *) (dest); \ - \ - smart_string_alloc4(__dest, (nlen), (what), __nl); \ - memcpy(__dest->c + __dest->len, (src), (nlen)); \ - __dest->len = __nl; \ -} while (0) - -#define smart_string_append_generic_ex(dest, num, type, vartype, func) do { \ - char __b[32]; \ - char *__t = zend_print##func##_to_buf(__b + sizeof(__b) - 1, (num)); \ - smart_string_appendl_ex((dest), __t, __b + sizeof(__b) - 1 - __t, (type)); \ -} while (0) - -#define smart_string_append_unsigned_ex(dest, num, type) \ - smart_string_append_generic_ex((dest), (num), (type), zend_ulong, _ulong) - -#define smart_string_append_long_ex(dest, num, type) \ - smart_string_append_generic_ex((dest), (num), (type), zend_ulong, _long) - -#define smart_string_append_ex(dest, src, what) \ - smart_string_appendl_ex((dest), ((smart_string *)(src))->c, \ - ((smart_string *)(src))->len, (what)); - - -#define smart_string_setl(dest, src, nlen) do { \ - (dest)->len = (nlen); \ - (dest)->a = (nlen) + 1; \ - (dest)->c = (char *) (src); \ -} while (0) - -#define smart_string_sets(dest, src) \ - smart_string_setl((dest), (src), strlen(src)); - -#endif diff --git a/ext/standard/php_smart_string_public.h b/ext/standard/php_smart_string_public.h index dabc359676..2696d4eb0d 100644 --- a/ext/standard/php_smart_string_public.h +++ b/ext/standard/php_smart_string_public.h @@ -17,17 +17,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ +/* Header moved to Zend. This file is retained for BC. */ +#include "zend_smart_string_public.h" -#ifndef PHP_SMART_STRING_PUBLIC_H -#define PHP_SMART_STRING_PUBLIC_H - -#include <sys/types.h> - -typedef struct { - char *c; - size_t len; - size_t a; -} smart_string; - -#endif diff --git a/ext/standard/tests/serialize/bug73154.phpt b/ext/standard/tests/serialize/bug73154.phpt new file mode 100644 index 0000000000..8d0f188bf7 --- /dev/null +++ b/ext/standard/tests/serialize/bug73154.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #73154: serialize object with __sleep function crash +--FILE-- +<?php +class a { + public $a; + public function __sleep() { + $this->a=null; + return array(); + } +} +$s = 'a:1:{i:0;O:1:"a":1:{s:1:"a";R:2;}}'; +var_dump(serialize(unserialize($s))); +?> +--EXPECT-- +string(22) "a:1:{i:0;O:1:"a":0:{}}" diff --git a/ext/standard/var.c b/ext/standard/var.c index ef5e4272ef..7143634489 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -862,9 +862,6 @@ again: return; case IS_OBJECT: { - zval retval; - zval fname; - int res; zend_class_entry *ce = Z_OBJCE_P(struc); if (ce->serialize != NULL) { @@ -893,32 +890,39 @@ again: } if (ce != PHP_IC_ENTRY && zend_hash_str_exists(&ce->function_table, "__sleep", sizeof("__sleep")-1)) { + zval fname, tmp, retval; + int res; + + ZVAL_COPY(&tmp, struc); ZVAL_STRINGL(&fname, "__sleep", sizeof("__sleep") - 1); BG(serialize_lock)++; - res = call_user_function_ex(CG(function_table), struc, &fname, &retval, 0, 0, 1, NULL); + res = call_user_function_ex(CG(function_table), &tmp, &fname, &retval, 0, 0, 1, NULL); BG(serialize_lock)--; zval_dtor(&fname); if (EG(exception)) { zval_ptr_dtor(&retval); + zval_ptr_dtor(&tmp); return; } if (res == SUCCESS) { if (Z_TYPE(retval) != IS_UNDEF) { if (HASH_OF(&retval)) { - php_var_serialize_class(buf, struc, &retval, var_hash); + php_var_serialize_class(buf, &tmp, &retval, var_hash); } else { php_error_docref(NULL, E_NOTICE, "__sleep should return an array only containing the names of instance-variables to serialize"); /* we should still add element even if it's not OK, * since we already wrote the length of the array before */ smart_str_appendl(buf,"N;", 2); } - zval_ptr_dtor(&retval); } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&tmp); return; } zval_ptr_dtor(&retval); + zval_ptr_dtor(&tmp); } /* fall-through */ diff --git a/main/main.c b/main/main.c index 193d88bc44..afa4313570 100644 --- a/main/main.c +++ b/main/main.c @@ -1159,11 +1159,9 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi")) && PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR ) { -#ifdef PHP_WIN32 fprintf(stderr, "%s: %s in %s on line %u\n", error_type_str, buffer, error_filename, error_lineno); +#ifdef PHP_WIN32 fflush(stderr); -#else - fprintf(stderr, "%s: %s in %s on line %u\n", error_type_str, buffer, error_filename, error_lineno); #endif } else { php_printf("%s\n%s: %s in %s on line %d\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); @@ -2116,8 +2114,8 @@ 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; - zuf.vstrpprintf_function = vstrpprintf; + zuf.printf_to_smart_string_function = php_printf_to_smart_string; + zuf.printf_to_smart_str_function = php_printf_to_smart_str; zuf.getenv_function = sapi_getenv; zuf.resolve_path_function = php_resolve_path_for_zend; zend_startup(&zuf, NULL); diff --git a/main/rfc1867.c b/main/rfc1867.c index 9cdaeccb79..97df0c4fce 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -33,7 +33,7 @@ #include "php_variables.h" #include "rfc1867.h" #include "ext/standard/php_string.h" -#include "ext/standard/php_smart_string.h" +#include "zend_smart_string.h" #if defined(PHP_WIN32) && !defined(HAVE_ATOLL) # define atoll(s) _atoi64(s) diff --git a/main/spprintf.c b/main/spprintf.c index 73a5ff52e3..0e0784663c 100644 --- a/main/spprintf.c +++ b/main/spprintf.c @@ -117,7 +117,7 @@ #define EXPONENT_LENGTH 10 #include "zend_smart_str.h" -#include "ext/standard/php_smart_string.h" +#include "zend_smart_string.h" /* {{{ macros */ @@ -138,7 +138,6 @@ } while (0); #define PAD_CHAR(xbuf, ch, count, is_char) do { \ - size_t newlen; \ if ((is_char)) { \ smart_string_alloc(((smart_string *)(xbuf)), (count), 0); \ memset(((smart_string *)(xbuf))->c + ((smart_string *)(xbuf))->len, (ch), (count)); \ @@ -828,76 +827,15 @@ skip_output: } /* }}} */ -/* - * This is the general purpose conversion function. - */ -PHPAPI size_t vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) /* {{{ */ +PHPAPI void php_printf_to_smart_string(smart_string *buf, const char *format, va_list ap) /* {{{ */ { - smart_string buf = {0}; - - /* since there are places where (v)spprintf called without checking for null, - a bit of defensive coding here */ - if(!pbuf) { - return 0; - } - xbuf_format_converter(&buf, 1, format, ap); - - if (max_len && buf.len > max_len) { - buf.len = max_len; - } - - smart_string_0(&buf); - - if (buf.c) { - *pbuf = buf.c; - return buf.len; - } else { - *pbuf = estrndup("", 0); - return 0; - } + xbuf_format_converter(buf, 1, format, ap); } /* }}} */ -PHPAPI size_t spprintf(char **pbuf, size_t max_len, const char *format, ...) /* {{{ */ +PHPAPI void php_printf_to_smart_str(smart_str *buf, const char *format, va_list ap) /* {{{ */ { - size_t cc; - va_list ap; - - va_start(ap, format); - cc = vspprintf(pbuf, max_len, format, ap); - va_end(ap); - return (cc); -} -/* }}} */ - -PHPAPI zend_string *vstrpprintf(size_t max_len, const char *format, va_list ap) /* {{{ */ -{ - smart_str buf = {0}; - - xbuf_format_converter(&buf, 0, format, ap); - - if (!buf.s) { - return ZSTR_EMPTY_ALLOC(); - } - - if (max_len && ZSTR_LEN(buf.s) > max_len) { - ZSTR_LEN(buf.s) = max_len; - } - - smart_str_0(&buf); - return buf.s; -} -/* }}} */ - -PHPAPI zend_string *strpprintf(size_t max_len, const char *format, ...) /* {{{ */ -{ - va_list ap; - zend_string *str; - - va_start(ap, format); - str = vstrpprintf(max_len, format, ap); - va_end(ap); - return str; + xbuf_format_converter(buf, 0, format, ap); } /* }}} */ diff --git a/main/spprintf.h b/main/spprintf.h index 82d2e2378c..d69bffa05b 100644 --- a/main/spprintf.h +++ b/main/spprintf.h @@ -16,36 +16,23 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - -/* - -The pbuf parameter of all spprintf version receives a pointer to the allocated -buffer. This buffer must be freed manually after usage using efree() function. -The buffer will always be terminated by a zero character. When pbuf is NULL -the function can be used to calculate the required size of the buffer but for -that purpose snprintf is faster. When both pbuf and the return value are 0 -than you are out of memory. - -There is also snprintf: See difference explained in snprintf.h - -*/ - #ifndef SPPRINTF_H #define SPPRINTF_H #include "snprintf.h" +#include "zend_smart_str_public.h" +#include "zend_smart_string_public.h" BEGIN_EXTERN_C() -PHPAPI size_t spprintf( char **pbuf, size_t max_len, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); - -PHPAPI size_t vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 3, 0); - -PHPAPI zend_string *vstrpprintf(size_t max_len, const char *format, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 2, 0); - -PHPAPI zend_string *strpprintf(size_t max_len, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3); +PHPAPI void php_printf_to_smart_string(smart_string *buf, const char *format, va_list ap); +PHPAPI void php_printf_to_smart_str(smart_str *buf, const char *format, va_list ap); END_EXTERN_C() +#define spprintf zend_spprintf +#define strpprintf zend_strpprintf +#define vspprintf zend_vspprintf +#define vstrpprintf zend_vstrpprintf + #endif /* SNPRINTF_H */ /* diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index b5fa6ea989..0c34afaac4 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -384,6 +384,9 @@ static void sapi_cli_register_variables(zval *track_vars_array) /* {{{ */ static void sapi_cli_log_message(char *message, int syslog_type_int) /* {{{ */ { fprintf(stderr, "%s\n", message); +#ifdef PHP_WIN32 + fflush(stderr); +#endif } /* }}} */ |