Skip to content

Commit bc218c0

Browse files
committed
Use smart_str_extract
1 parent 04217ff commit bc218c0

File tree

15 files changed

+28
-56
lines changed

15 files changed

+28
-56
lines changed

Zend/zend.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ ZEND_API zend_string *zend_vstrpprintf(size_t max_len, const char *format, va_li
272272
ZSTR_LEN(buf.s) = max_len;
273273
}
274274

275-
smart_str_0(&buf);
276-
return smart_str_finalize(&buf);
275+
return smart_str_extract(&buf);
277276
}
278277
/* }}} */
279278

Zend/zend_smart_str.h

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
smart_str_appendl((dest), (src), strlen(src))
2828
#define smart_str_trim_to_len(dest) \
2929
smart_str_trim_to_len_ex((dest), 0)
30-
#define smart_str_finalize(dest) \
31-
smart_str_finalize_ex((dest), 0)
3230
#define smart_str_extend(dest, len) \
3331
smart_str_extend_ex((dest), (len), 0)
3432
#define smart_str_appendc(dest, c) \
@@ -80,29 +78,6 @@ static zend_always_inline size_t smart_str_alloc(smart_str *str, size_t len, boo
8078
return len;
8179
}
8280

83-
static zend_always_inline void smart_str_trim_to_len_ex(smart_str *str, bool persistent)
84-
{
85-
if (str->s && str->a > ZSTR_LEN(str->s)) {
86-
str->s = zend_string_realloc(str->s, ZSTR_LEN(str->s), persistent);
87-
str->a = ZSTR_LEN(str->s);
88-
}
89-
}
90-
91-
static zend_always_inline zend_string* smart_str_finalize_ex(smart_str *str, bool persistent)
92-
{
93-
if (UNEXPECTED(!str->s)) {
94-
return ZSTR_EMPTY_ALLOC();
95-
}
96-
97-
smart_str_trim_to_len_ex(str, persistent);
98-
zend_string *retval = str->s;
99-
100-
str->s = NULL;
101-
str->a = 0;
102-
103-
return retval;
104-
}
105-
10681
static zend_always_inline char* smart_str_extend_ex(smart_str *dest, size_t len, bool persistent) {
10782
size_t new_len = smart_str_alloc(dest, len, persistent);
10883
char *ret = ZSTR_VAL(dest->s) + ZSTR_LEN(dest->s);
@@ -128,10 +103,19 @@ static zend_always_inline size_t smart_str_get_len(smart_str *str) {
128103
return str->s ? ZSTR_LEN(str->s) : 0;
129104
}
130105

106+
static zend_always_inline void smart_str_trim_to_len_ex(smart_str *str, bool persistent)
107+
{
108+
if (str->s && str->a > ZSTR_LEN(str->s)) {
109+
str->s = zend_string_realloc(str->s, ZSTR_LEN(str->s), persistent);
110+
str->a = ZSTR_LEN(str->s);
111+
}
112+
}
113+
131114
static zend_always_inline zend_string *smart_str_extract(smart_str *str) {
132115
if (str->s) {
133116
zend_string *res;
134117
smart_str_0(str);
118+
smart_str_trim_to_len(str);
135119
res = str->s;
136120
str->s = NULL;
137121
return res;

ext/dom/documenttype.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ int dom_documenttype_internal_subset_read(dom_object *obj, zval *retval)
188188
}
189189

190190
if (ret_buf.s) {
191-
smart_str_0(&ret_buf);
192-
ZVAL_STR(retval, smart_str_finalize(&ret_buf));
191+
ZVAL_STR(retval, smart_str_extract(&ret_buf));
193192
return SUCCESS;
194193
}
195194
}

ext/filter/sanitizing_filters.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ static void php_filter_encode_html(zval *value, const unsigned char *chars)
4646
s++;
4747
}
4848

49-
smart_str_0(&str);
5049
zval_ptr_dtor(value);
51-
ZVAL_STR(value, smart_str_finalize(&str));
50+
ZVAL_STR(value, smart_str_extract(&str));
5251
}
5352

5453
static const unsigned char hexchars[] = "0123456789ABCDEF";

ext/iconv/iconv.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,7 @@ PHP_FUNCTION(iconv_substr)
18451845
_php_iconv_show_error(err, GENERIC_SUPERSET_NAME, charset);
18461846

18471847
if (err == PHP_ICONV_ERR_SUCCESS && retval.s != NULL) {
1848-
RETURN_STR(smart_str_finalize(&retval));
1848+
RETURN_STR(smart_str_extract(&retval));
18491849
}
18501850
smart_str_free(&retval);
18511851
RETURN_FALSE;
@@ -2038,7 +2038,7 @@ PHP_FUNCTION(iconv_mime_encode)
20382038
_php_iconv_show_error(err, out_charset, in_charset);
20392039

20402040
if (err == PHP_ICONV_ERR_SUCCESS) {
2041-
RETVAL_STR(smart_str_finalize(&retval));
2041+
RETVAL_STR(smart_str_extract(&retval));
20422042
} else {
20432043
smart_str_free(&retval);
20442044
RETVAL_FALSE;
@@ -2079,7 +2079,7 @@ PHP_FUNCTION(iconv_mime_decode)
20792079
_php_iconv_show_error(err, charset, "???");
20802080

20812081
if (err == PHP_ICONV_ERR_SUCCESS) {
2082-
RETVAL_STR(smart_str_finalize(&retval));
2082+
RETVAL_STR(smart_str_extract(&retval));
20832083
} else {
20842084
smart_str_free(&retval);
20852085
RETVAL_FALSE;

ext/json/json.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ PHP_FUNCTION(json_encode)
212212
}
213213
}
214214

215-
smart_str_0(&buf);
216-
RETURN_STR(smart_str_finalize(&buf));
215+
RETURN_STR(smart_str_extract(&buf));
217216
}
218217
/* }}} */
219218

ext/mbstring/php_mbregex.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
11471147
RETURN_FALSE;
11481148
}
11491149

1150-
smart_str_0(&out_buf);
1151-
RETURN_STR(smart_str_finalize(&out_buf));
1150+
RETURN_STR(smart_str_extract(&out_buf));
11521151
}
11531152
/* }}} */
11541153

ext/session/session.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ PHPAPI zend_result php_session_reset_id(void) /* {{{ */
14641464
smart_str_0(&var);
14651465
if (sid) {
14661466
zval_ptr_dtor_str(sid);
1467-
ZVAL_STR(sid, smart_str_finalize(&var));
1467+
ZVAL_STR(sid, smart_str_extract(&var));
14681468
} else {
14691469
REGISTER_STRINGL_CONSTANT("SID", ZSTR_VAL(var.s), ZSTR_LEN(var.s), 0);
14701470
smart_str_free(&var);
@@ -2362,8 +2362,7 @@ PHP_FUNCTION(session_create_id)
23622362
php_error_docref(NULL, E_WARNING, "Failed to create new ID");
23632363
RETURN_FALSE;
23642364
}
2365-
smart_str_0(&id);
2366-
RETVAL_STR(smart_str_finalize(&id));
2365+
RETVAL_STR(smart_str_extract(&id));
23672366
}
23682367
/* }}} */
23692368

ext/soap/php_sdl.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3261,8 +3261,7 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, zend_long cache_wsdl)
32613261
smart_str_appends(&proxy,Z_STRVAL_P(proxy_host));
32623262
smart_str_appends(&proxy,":");
32633263
smart_str_append_long(&proxy,Z_LVAL_P(proxy_port));
3264-
smart_str_0(&proxy);
3265-
ZVAL_STR(&str_proxy, smart_str_finalize(&proxy));
3264+
ZVAL_STR(&str_proxy, smart_str_extract(&proxy));
32663265

32673266
if (!context) {
32683267
context = php_stream_context_alloc();
@@ -3304,8 +3303,7 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, zend_long cache_wsdl)
33043303
http_context_headers(context, has_authorization, has_proxy_authorization, 0, &headers);
33053304
}
33063305

3307-
smart_str_0(&headers);
3308-
ZVAL_STR(&str_headers, smart_str_finalize(&headers));
3306+
ZVAL_STR(&str_headers, smart_str_extract(&headers));
33093307
php_stream_context_set_option(context, "http", "header", &str_headers);
33103308
zval_ptr_dtor(&str_headers);
33113309
}

ext/spl/spl_array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ PHP_METHOD(ArrayObject, serialize)
15541554
/* done */
15551555
PHP_VAR_SERIALIZE_DESTROY(var_hash);
15561556

1557-
RETURN_STR(smart_str_finalize(&buf));
1557+
RETURN_STR(smart_str_extract(&buf));
15581558
} /* }}} */
15591559

15601560
/* {{{ unserialize the object */

ext/spl/spl_dllist.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,12 +1032,10 @@ PHP_METHOD(SplDoublyLinkedList, serialize)
10321032
current = next;
10331033
}
10341034

1035-
smart_str_0(&buf);
1036-
10371035
/* done */
10381036
PHP_VAR_SERIALIZE_DESTROY(var_hash);
10391037

1040-
RETURN_STR(smart_str_finalize(&buf));
1038+
RETURN_STR(smart_str_extract(&buf));
10411039
} /* }}} */
10421040

10431041
/* {{{ Unserializes storage */

ext/spl/spl_observer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ PHP_METHOD(SplObjectStorage, serialize)
808808
/* done */
809809
PHP_VAR_SERIALIZE_DESTROY(var_hash);
810810

811-
RETURN_STR(smart_str_finalize(&buf));
811+
RETURN_STR(smart_str_extract(&buf));
812812
} /* }}} */
813813

814814
/* {{{ Unserializes storage */

ext/standard/http.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ PHP_FUNCTION(http_build_query)
238238

239239
php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL), arg_sep, (int)enc_type);
240240

241-
smart_str_0(&formstr);
242-
RETURN_STR(smart_str_finalize(&formstr));
241+
RETURN_STR(smart_str_extract(&formstr));
243242
}
244243
/* }}} */

ext/standard/string.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,8 +2891,7 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
28912891

28922892
if (result.s) {
28932893
smart_str_appendl(&result, str + old_pos, slen - old_pos);
2894-
smart_str_0(&result);
2895-
RETVAL_STR(smart_str_finalize(&result));
2894+
RETVAL_STR(smart_str_extract(&result));
28962895
} else {
28972896
smart_str_free(&result);
28982897
RETVAL_STR_COPY(input);

ext/standard/var.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ PHP_FUNCTION(var_export)
645645
smart_str_0 (&buf);
646646

647647
if (return_output) {
648-
RETURN_STR(smart_str_finalize(&buf));
648+
RETURN_STR(smart_str_extract(&buf));
649649
} else {
650650
PHPWRITE(ZSTR_VAL(buf.s), ZSTR_LEN(buf.s));
651651
smart_str_free(&buf);
@@ -1318,7 +1318,7 @@ PHP_FUNCTION(serialize)
13181318
RETURN_THROWS();
13191319
}
13201320

1321-
RETURN_STR(smart_str_finalize(&buf));
1321+
RETURN_STR(smart_str_extract(&buf));
13221322
}
13231323
/* }}} */
13241324

0 commit comments

Comments
 (0)