mirror of
https://github.com/php/php-src.git
synced 2025-08-16 22:18:50 +02:00
Add smart_str_append for appending zend_strings
Also replaces usages in Zend/ and ext/standard
This commit is contained in:
parent
2a7de9fdbb
commit
a770d29df7
14 changed files with 41 additions and 48 deletions
|
@ -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, "): ");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue