]> granicus.if.org Git - php/commitdiff
Add smart_str_append for appending zend_strings
authorNikita Popov <nikic@php.net>
Sun, 21 Sep 2014 18:47:07 +0000 (20:47 +0200)
committerNikita Popov <nikic@php.net>
Sun, 21 Sep 2014 18:58:31 +0000 (20:58 +0200)
Also replaces usages in Zend/ and ext/standard

14 files changed:
Zend/zend_exceptions.c
Zend/zend_inheritance.c
Zend/zend_smart_str.h
ext/curl/php_curl.h
ext/intl/intl_error.h
ext/intl/transliterator/transliterator.h
ext/standard/file.c
ext/standard/filters.c
ext/standard/http.c
ext/standard/http_fopen_wrapper.c
ext/standard/string.c
ext/standard/url_scanner_ex.c
ext/standard/url_scanner_ex.re
ext/standard/var.c

index 8d3145ca2379d79eb4c8e953ca2da748b2e4a756..999b6d790e083e6571c3c943e36f93a40e851083 100644 (file)
@@ -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, "): ");
index 71f5ffa61ffa7c987aa740878183f76d74241c49..5cc970ee92cda27861a63f0718c62921ef111359 100644 (file)
@@ -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, "<expression>");
                                                } 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);
                                                }
                                        }
index 501283df31684c5c37d42cb664c8f9627bf5c0a5..2724ac7323ec4285ea95f24fb14a4b0a62492591 100644 (file)
@@ -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);
        }
 }
 
index 665682c23a77d4b502ae3636684937392e8b2047..ad44ae7b96fe71bd9ec8febff67180a4c7f0b859 100644 (file)
@@ -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
index 7e8f0cf5e4615cd484ddd0ae737feb0fe1d52817..b800d10dbf1e067f5c0280f78326f9c17dabb7da 100644 (file)
@@ -21,7 +21,7 @@
 
 #include <unicode/utypes.h>
 #include <unicode/parseerr.h>
-#include <zend_smart_str_public.h>
+#include <zend_smart_str.h>
 
 #define INTL_ERROR_CODE(e) (e).code
 
index 041c6df41b9176c40f6b029c90ba145a3ec3879e..081a730cbc5cd022f9110dfd829413540517dd50 100644 (file)
@@ -21,7 +21,7 @@
 #include <unicode/utypes.h>
 #include <unicode/utrans.h>
 
-#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 );
index 506105b7ae0546412c5220249f1da144d65ec9b8..446da20fb3aa3653db5641d4764cc6228eef5a90 100644 (file)
@@ -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) {
index bef239920bc0388498200c72d835f326fcc4a097..f0f49950bbfae7cbcd96aed8e092c324cdcbd53d 100644 (file)
@@ -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);
index 45ff3890aa78da17daea200e424fb17762221d16..9174163b7dadd4a1aa5397154c62a124ad5974e6 100644 (file)
@@ -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(&copyzval);
                                                zend_string_free(ekey);
                                        }
index d69592699566414bbea1d2ce1395b8cd451de889..27c6cf62487e4a8ea579abef33ca8a31bb438e73 100644 (file)
@@ -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();
index b49192b1b7493d43a6d4c1bc475f58e058706abd..dcd6f09a9c9bf154a02b271d188edc04da8e68fc 100644 (file)
@@ -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);
index b42b212ac69d7e4bd6c90b3d120fccfb90107a64..3d7aa985b8d9798136e86d8e50ccefc908b49517 100644 (file)
@@ -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);
index ce49b2ede9c78a1144a38d627b2fdf870f735961..2e74b1fb30b82d39b2036c0a81e21a5bac694656 100644 (file)
@@ -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);
index 88a8f9ebe0371cb5211db05c341f7b28007e4577..f9d897a4ec5d3a8aef49b9955f172597a8bdd390 100644 (file)
@@ -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);