From: Nikita Popov Date: Sun, 21 Sep 2014 18:47:07 +0000 (+0200) Subject: Add smart_str_append for appending zend_strings X-Git-Tag: PRE_NATIVE_TLS_MERGE~158^2~75 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a770d29df74515197c76efdf1a64d9794c27b4af;p=php Add smart_str_append for appending zend_strings Also replaces usages in Zend/ and ext/standard --- diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 8d3145ca23..999b6d790e 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -342,7 +342,7 @@ ZEND_METHOD(error_exception, getSeverity) zend_error(E_WARNING, "Value for %s is no string", key); \ smart_str_appends(str, "[unknown]"); \ } else { \ - smart_str_appendl(str, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); \ + smart_str_append(str, Z_STR_P(tmp)); \ } \ } \ } while (0) @@ -454,14 +454,11 @@ static void _build_trace_args(zval *arg, smart_str *str TSRMLS_DC) /* {{{ */ case IS_ARRAY: smart_str_appends(str, "Array, "); break; - case IS_OBJECT: { - zend_string *class_name = zend_get_object_classname(Z_OBJ_P(arg) TSRMLS_CC); - + case IS_OBJECT: smart_str_appends(str, "Object("); - smart_str_appendl(str, class_name->val, class_name->len); + smart_str_append(str, zend_get_object_classname(Z_OBJ_P(arg) TSRMLS_CC)); smart_str_appends(str, "), "); break; - } } } /* }}} */ @@ -492,7 +489,7 @@ static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num TSRM } else { line = 0; } - smart_str_appendl(str, Z_STRVAL_P(file), Z_STRLEN_P(file)); + smart_str_append(str, Z_STR_P(file)); smart_str_appendc(str, '('); smart_str_append_long(str, line); smart_str_appends(str, "): "); diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index 71f5ffa61f..5cc970ee92 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -334,11 +334,11 @@ static zend_string *zend_get_function_declaration(zend_function *fptr TSRMLS_DC) } if (fptr->common.scope) { - smart_str_appendl(&str, fptr->common.scope->name->val, fptr->common.scope->name->len); + smart_str_append(&str, fptr->common.scope->name); smart_str_appends(&str, "::"); } - smart_str_appendl(&str, fptr->common.function_name->val, fptr->common.function_name->len); + smart_str_append(&str, fptr->common.function_name); smart_str_appendc(&str, '('); if (fptr->common.arg_info) { @@ -409,7 +409,7 @@ static zend_string *zend_get_function_declaration(zend_function *fptr TSRMLS_DC) zval *zv = precv->op2.zv; if (Z_TYPE_P(zv) == IS_CONSTANT) { - smart_str_appendl(&str, Z_STRVAL_P(zv), Z_STRLEN_P(zv)); + smart_str_append(&str, Z_STR_P(zv)); } else if (Z_TYPE_P(zv) == IS_FALSE) { smart_str_appends(&str, "false"); } else if (Z_TYPE_P(zv) == IS_TRUE) { @@ -429,7 +429,7 @@ static zend_string *zend_get_function_declaration(zend_function *fptr TSRMLS_DC) smart_str_appends(&str, ""); } else { zend_string *zv_str = zval_get_string(zv); - smart_str_appendl(&str, zv_str->val, zv_str->len); + smart_str_append(&str, zv_str); zend_string_release(zv_str); } } diff --git a/Zend/zend_smart_str.h b/Zend/zend_smart_str.h index 501283df31..2724ac7323 100644 --- a/Zend/zend_smart_str.h +++ b/Zend/zend_smart_str.h @@ -38,6 +38,8 @@ smart_str_appendc_ex((dest), (c), 0) #define smart_str_appendl(dest, src, len) \ smart_str_appendl_ex((dest), (src), (len), 0) +#define smart_str_append(dest, src) \ + smart_str_append_ex((dest), (src), 0) #define smart_str_append_smart_str(dest, src) \ smart_str_append_smart_str_ex((dest), (src), 0) #define smart_str_sets(dest, src) \ @@ -92,9 +94,13 @@ static zend_always_inline void smart_str_appendl_ex(smart_str *dest, const char dest->s->len = new_len; } +static zend_always_inline void smart_str_append_ex(smart_str *dest, const zend_string *src, zend_bool persistent) { + smart_str_appendl_ex(dest, src->val, src->len, persistent); +} + static zend_always_inline void smart_str_append_smart_str_ex(smart_str *dest, const smart_str *src, zend_bool persistent) { if (src->s && src->s->len) { - smart_str_appendl_ex(dest, src->s->val, src->s->len, persistent); + smart_str_append_ex(dest, src->s, persistent); } } diff --git a/ext/curl/php_curl.h b/ext/curl/php_curl.h index 665682c23a..ad44ae7b96 100644 --- a/ext/curl/php_curl.h +++ b/ext/curl/php_curl.h @@ -23,7 +23,7 @@ #define _PHP_CURL_H #include "php.h" -#include "zend_smart_str_public.h" +#include "zend_smart_str.h" #ifdef COMPILE_DL_CURL #undef HAVE_CURL diff --git a/ext/intl/intl_error.h b/ext/intl/intl_error.h index 7e8f0cf5e4..b800d10dbf 100644 --- a/ext/intl/intl_error.h +++ b/ext/intl/intl_error.h @@ -21,7 +21,7 @@ #include #include -#include +#include #define INTL_ERROR_CODE(e) (e).code diff --git a/ext/intl/transliterator/transliterator.h b/ext/intl/transliterator/transliterator.h index 041c6df41b..081a730cbc 100644 --- a/ext/intl/transliterator/transliterator.h +++ b/ext/intl/transliterator/transliterator.h @@ -21,7 +21,7 @@ #include #include -#include "zend_smart_str_public.h" +#include "zend_smart_str.h" void transliterator_register_constants( INIT_FUNC_ARGS ); smart_str transliterator_parse_error_to_string( UParseError* pe ); diff --git a/ext/standard/file.c b/ext/standard/file.c index 506105b7ae..446da20fb3 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1943,7 +1943,7 @@ PHPAPI size_t php_fputcsv(php_stream *stream, zval *fields, char delimiter, char } smart_str_appendc(&csvline, enclosure); } else { - smart_str_appendl(&csvline, field_str->val, field_str->len); + smart_str_append(&csvline, field_str); } if (++i != count) { diff --git a/ext/standard/filters.c b/ext/standard/filters.c index bef239920b..f0f49950bb 100644 --- a/ext/standard/filters.c +++ b/ext/standard/filters.c @@ -263,7 +263,7 @@ static php_stream_filter *strfilter_strip_tags_create(const char *filtername, zv ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(filterparams), tmp) { convert_to_string_ex(tmp); smart_str_appendc(&tags_ss, '<'); - smart_str_appendl(&tags_ss, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); + smart_str_append(&tags_ss, Z_STR_P(tmp)); smart_str_appendc(&tags_ss, '>'); } ZEND_HASH_FOREACH_END(); smart_str_0(&tags_ss); diff --git a/ext/standard/http.c b/ext/standard/http.c index 45ff3890aa..9174163b7d 100644 --- a/ext/standard/http.c +++ b/ext/standard/http.c @@ -159,18 +159,14 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, } else { ekey = php_url_encode(prop_name, prop_len); } - smart_str_appendl(formstr, ekey->val, ekey->len); + smart_str_append(formstr, ekey); zend_string_free(ekey); } else { - char *ekey; - int ekey_len; /* Numeric key */ if (num_prefix) { smart_str_appendl(formstr, num_prefix, num_prefix_len); } - ekey_len = spprintf(&ekey, 0, "%pd", idx); - smart_str_appendl(formstr, ekey, ekey_len); - efree(ekey); + smart_str_append_long(formstr, idx); } smart_str_appendl(formstr, key_suffix, key_suffix_len); smart_str_appendl(formstr, "=", 1); @@ -182,18 +178,12 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, } else { ekey = php_url_encode(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata)); } - smart_str_appendl(formstr, ekey->val, ekey->len); + smart_str_append(formstr, ekey); zend_string_free(ekey); } break; case IS_LONG: - { - char *ekey; - int ekey_len; - ekey_len = spprintf(&ekey, 0, "%pd", Z_LVAL_P(zdata)); - smart_str_appendl(formstr, ekey, ekey_len); - efree(ekey); - } + smart_str_append_long(formstr, Z_LVAL_P(zdata)); break; case IS_FALSE: smart_str_appendl(formstr, "0", sizeof("0")-1); @@ -221,7 +211,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, } else { ekey = php_url_encode(Z_STRVAL(copyzval), Z_STRLEN(copyzval)); } - smart_str_appendl(formstr, ekey->val, ekey->len); + smart_str_append(formstr, ekey); zval_ptr_dtor(©zval); zend_string_free(ekey); } diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index d695926995..27c6cf6248 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -422,7 +422,7 @@ finish: ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(tmpzval), tmpheader) { if (Z_TYPE_P(tmpheader) == IS_STRING) { - smart_str_appendl(&tmpstr, Z_STRVAL_P(tmpheader), Z_STRLEN_P(tmpheader)); + smart_str_append(&tmpstr, Z_STR_P(tmpheader)); smart_str_appendl(&tmpstr, "\r\n", sizeof("\r\n") - 1); } } ZEND_HASH_FOREACH_END(); diff --git a/ext/standard/string.c b/ext/standard/string.c index b49192b1b7..dcd6f09a9c 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -1150,7 +1150,7 @@ PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value TSRMLS_DC) again: switch (Z_TYPE_P(tmp)) { case IS_STRING: - smart_str_appendl(&implstr, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); + smart_str_append(&implstr, Z_STR_P(tmp)); break; case IS_LONG: @@ -1179,14 +1179,14 @@ again: default: str = zval_get_string(tmp); - smart_str_appendl(&implstr, str->val, str->len); + smart_str_append(&implstr, str); zend_string_release(str); break; } if (++i != numelems) { - smart_str_appendl(&implstr, Z_STRVAL_P(delim), Z_STRLEN_P(delim)); + smart_str_append(&implstr, Z_STR_P(delim)); } } ZEND_HASH_FOREACH_END(); @@ -2907,7 +2907,7 @@ static void php_strtr_array(zval *return_value, char *str, size_t slen, HashTabl entry = zend_hash_str_find(pats, key, len); if (entry != NULL) { zend_string *str = zval_get_string(entry); - smart_str_appendl(&result, str->val, str->len); + smart_str_append(&result, str); pos += len; found = 1; zend_string_release(str); @@ -2932,7 +2932,7 @@ static void php_strtr_array(zval *return_value, char *str, size_t slen, HashTabl entry = zend_hash_str_find(pats, key, len); if (entry != NULL) { zend_string *str = zval_get_string(entry); - smart_str_appendl(&result, str->val, str->len); + smart_str_append(&result, str); pos += len; found = 1; zend_string_release(str); diff --git a/ext/standard/url_scanner_ex.c b/ext/standard/url_scanner_ex.c index b42b212ac6..3d7aa985b8 100644 --- a/ext/standard/url_scanner_ex.c +++ b/ext/standard/url_scanner_ex.c @@ -958,7 +958,7 @@ static char *url_adapt_ext(const char *src, size_t srclen, size_t *newlen, zend_ } smart_str_0(&ctx->result); if (do_flush) { - smart_str_appendl(&ctx->result, ctx->buf.s->val, ctx->buf.s->len); + smart_str_append(&ctx->result, ctx->buf.s); *newlen += ctx->buf.s->len; smart_str_free(&ctx->buf); smart_str_free(&ctx->val); @@ -1007,7 +1007,7 @@ static void php_url_scanner_output_handler(char *output, uint output_len, char * } else if (BG(url_adapt_state_ex).url_app.s->len == 0) { url_adapt_state_ex_t *ctx = &BG(url_adapt_state_ex); if (ctx->buf.s && ctx->buf.s->len) { - smart_str_appendl(&ctx->result, ctx->buf.s->val, ctx->buf.s->len); + smart_str_append(&ctx->result, ctx->buf.s); smart_str_appendl(&ctx->result, output, output_len); *handled_output = estrndup(ctx->result.s->val, ctx->result.s->len); diff --git a/ext/standard/url_scanner_ex.re b/ext/standard/url_scanner_ex.re index ce49b2ede9..2e74b1fb30 100644 --- a/ext/standard/url_scanner_ex.re +++ b/ext/standard/url_scanner_ex.re @@ -410,7 +410,7 @@ static char *url_adapt_ext(const char *src, size_t srclen, size_t *newlen, zend_ } smart_str_0(&ctx->result); if (do_flush) { - smart_str_appendl(&ctx->result, ctx->buf.s->val, ctx->buf.s->len); + smart_str_append(&ctx->result, ctx->buf.s); *newlen += ctx->buf.s->len; smart_str_free(&ctx->buf); smart_str_free(&ctx->val); @@ -459,7 +459,7 @@ static void php_url_scanner_output_handler(char *output, uint output_len, char * } else if (BG(url_adapt_state_ex).url_app.s->len == 0) { url_adapt_state_ex_t *ctx = &BG(url_adapt_state_ex); if (ctx->buf.s && ctx->buf.s->len) { - smart_str_appendl(&ctx->result, ctx->buf.s->val, ctx->buf.s->len); + smart_str_append(&ctx->result, ctx->buf.s); smart_str_appendl(&ctx->result, output, output_len); *handled_output = estrndup(ctx->result.s->val, ctx->result.s->len); diff --git a/ext/standard/var.c b/ext/standard/var.c index 88a8f9ebe0..f9d897a4ec 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -413,7 +413,7 @@ static void php_array_element_export(zval *zv, zend_ulong index, zend_string *ke buffer_append_spaces(buf, level + 1); smart_str_appendc(buf, '\''); - smart_str_appendl(buf, tmp_str->val, tmp_str->len); + smart_str_append(buf, tmp_str); smart_str_appendl(buf, "' => ", 5); zend_string_free(ckey); @@ -438,7 +438,7 @@ static void php_object_element_export(zval *zv, zend_ulong index, zend_string *k pname_esc = php_addcslashes(prop_name, prop_name_len, 0, "'\\", 2 TSRMLS_CC); smart_str_appendc(buf, '\''); - smart_str_appendl(buf, pname_esc->val, pname_esc->len); + smart_str_append(buf, pname_esc); smart_str_appendc(buf, '\''); zend_string_release(pname_esc); } else { @@ -486,7 +486,7 @@ again: ztmp2 = php_str_to_str_ex(ztmp->val, ztmp->len, "\0", 1, "' . \"\\0\" . '", 12, 0, NULL); smart_str_appendc(buf, '\''); - smart_str_appendl(buf, ztmp2->val, ztmp2->len); + smart_str_append(buf, ztmp2); smart_str_appendc(buf, '\''); zend_string_free(ztmp); @@ -535,7 +535,7 @@ again: } class_name = Z_OBJ_HANDLER_P(struc, get_class_name)(Z_OBJ_P(struc), 0 TSRMLS_CC); - smart_str_appendl(buf, class_name->val, class_name->len); + smart_str_append(buf, class_name); smart_str_appendl(buf, "::__set_state(array(\n", 21); zend_string_release(class_name); @@ -675,7 +675,7 @@ static inline zend_bool php_var_serialize_class_name(smart_str *buf, zval *struc smart_str_appendl(buf, "O:", 2); smart_str_append_unsigned(buf, class_name->len); smart_str_appendl(buf, ":\"", 2); - smart_str_appendl(buf, class_name->val, class_name->len); + smart_str_append(buf, class_name); smart_str_appendl(buf, "\":", 2); PHP_CLEANUP_CLASS_ATTRIBUTES(); return incomplete_class; @@ -859,7 +859,7 @@ again: smart_str_appendl(buf, "C:", 2); smart_str_append_unsigned(buf, Z_OBJCE_P(struc)->name->len); smart_str_appendl(buf, ":\"", 2); - smart_str_appendl(buf, Z_OBJCE_P(struc)->name->val, Z_OBJCE_P(struc)->name->len); + smart_str_append(buf, Z_OBJCE_P(struc)->name); smart_str_appendl(buf, "\":", 2); smart_str_append_unsigned(buf, serialized_length);