Skip to content

Commit daea550

Browse files
committed
Use zend_string
1 parent df0b49e commit daea550

File tree

9 files changed

+27
-31
lines changed

9 files changed

+27
-31
lines changed

ext/mbstring/mb_gpc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ MBSTRING_API SAPI_TREAT_DATA_FUNC(mbstr_treat_data)
100100
case PARSE_POST:
101101
case PARSE_GET:
102102
case PARSE_STRING:
103-
separator = (char *) estrdup(PG(arg_separator).input);
103+
separator = (char *) estrdup(ZSTR_VAL(PG(arg_separator).input));
104104
break;
105105
case PARSE_COOKIE:
106106
separator = ";\0";

ext/mbstring/mbstring.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ PHP_FUNCTION(mb_parse_str)
15371537
encstr = estrndup(encstr, encstr_len);
15381538

15391539
info.data_type = PARSE_STRING;
1540-
info.separator = PG(arg_separator).input;
1540+
info.separator = ZSTR_VAL(PG(arg_separator).input);
15411541
info.report_errors = true;
15421542
info.to_encoding = MBSTRG(current_internal_encoding);
15431543
info.from_encodings = MBSTRG(http_input_list);

ext/standard/http.c

+10-14
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ static void php_url_encode_scalar(zval *scalar, smart_str *form_str,
2727
const char *index_string, size_t index_string_len,
2828
const char *num_prefix, size_t num_prefix_len,
2929
const zend_string *key_prefix,
30-
const char *arg_sep, size_t arg_sep_len)
30+
const zend_string *arg_sep)
3131
{
3232
if (form_str->s) {
33-
smart_str_appendl(form_str, arg_sep, arg_sep_len);
33+
smart_str_append(form_str, arg_sep);
3434
}
3535
/* Simple key=value */
3636
if (key_prefix) {
@@ -87,7 +87,7 @@ static void php_url_encode_scalar(zval *scalar, smart_str *form_str,
8787
PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
8888
const char *num_prefix, size_t num_prefix_len,
8989
const zend_string *key_prefix,
90-
zval *type, const char *arg_sep, size_t arg_sep_len, int enc_type)
90+
zval *type, const zend_string *arg_sep, int enc_type)
9191
{
9292
zend_string *key = NULL;
9393
const char *prop_name;
@@ -103,11 +103,8 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
103103

104104
if (!arg_sep) {
105105
arg_sep = PG(arg_separator.output);
106-
if (!*arg_sep) {
107-
arg_sep = "&";
108-
arg_sep_len = 1;
109-
} else {
110-
arg_sep_len = strlen(arg_sep);
106+
if (ZSTR_LEN(arg_sep) == 0) {
107+
arg_sep = ZSTR_CHAR('&');
111108
}
112109
}
113110

@@ -189,7 +186,7 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
189186
efree(index_int_as_str);
190187
}
191188
GC_TRY_PROTECT_RECURSION(ht);
192-
php_url_encode_hash_ex(HASH_OF(zdata), formstr, NULL, 0, new_prefix, (Z_TYPE_P(zdata) == IS_OBJECT ? zdata : NULL), arg_sep, arg_sep_len, enc_type);
189+
php_url_encode_hash_ex(HASH_OF(zdata), formstr, NULL, 0, new_prefix, (Z_TYPE_P(zdata) == IS_OBJECT ? zdata : NULL), arg_sep, enc_type);
193190
GC_TRY_UNPROTECT_RECURSION(ht);
194191
zend_string_efree(new_prefix);
195192
} else if (Z_TYPE_P(zdata) == IS_NULL || Z_TYPE_P(zdata) == IS_RESOURCE) {
@@ -201,7 +198,7 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
201198
prop_name, prop_len,
202199
num_prefix, num_prefix_len,
203200
key_prefix,
204-
arg_sep, arg_sep_len);
201+
arg_sep);
205202
}
206203
} ZEND_HASH_FOREACH_END();
207204
}
@@ -214,16 +211,15 @@ PHP_FUNCTION(http_build_query)
214211
zval *formdata;
215212
char *prefix = NULL;
216213
size_t prefix_len = 0;
217-
char *arg_sep = NULL;
218-
size_t arg_sep_len = 0;
214+
zend_string *arg_sep = NULL;
219215
smart_str formstr = {0};
220216
zend_long enc_type = PHP_QUERY_RFC1738;
221217

222218
ZEND_PARSE_PARAMETERS_START(1, 4)
223219
Z_PARAM_ARRAY_OR_OBJECT(formdata)
224220
Z_PARAM_OPTIONAL
225221
Z_PARAM_STRING(prefix, prefix_len)
226-
Z_PARAM_STRING_OR_NULL(arg_sep, arg_sep_len)
222+
Z_PARAM_STR(arg_sep)
227223
Z_PARAM_LONG(enc_type)
228224
ZEND_PARSE_PARAMETERS_END();
229225

@@ -232,7 +228,7 @@ PHP_FUNCTION(http_build_query)
232228
RETURN_THROWS();
233229
}
234230

235-
php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, /* key_prefix */ NULL, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL), arg_sep, arg_sep_len, (int)enc_type);
231+
php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, /* key_prefix */ NULL, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL), arg_sep, (int)enc_type);
236232

237233
RETURN_STR(smart_str_extract(&formstr));
238234
}

ext/standard/php_http.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
2525
const char *num_prefix, size_t num_prefix_len,
2626
const zend_string *key_prefix,
27-
zval *type, const char *arg_sep, size_t arg_sep_len, int enc_type);
27+
zval *type, const zend_string *arg_sep, int enc_type);
2828

2929
#endif

ext/standard/url_scanner_ex.re

+7-7
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ alphadash = ([a-zA-Z] | "-");
188188
#define YYLIMIT q
189189
#define YYMARKER r
190190

191-
static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *url_app, const char *separator, int type)
191+
static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *url_app, const zend_string *separator, int type)
192192
{
193193
php_url *url_parts;
194194

@@ -271,7 +271,7 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st
271271
smart_str_appendc(dest, '?');
272272
if (url_parts->query) {
273273
smart_str_appends(dest, ZSTR_VAL(url_parts->query));
274-
smart_str_appends(dest, separator);
274+
smart_str_append(dest, separator);
275275
smart_str_append_smart_str(dest, url_app);
276276
} else {
277277
smart_str_append_smart_str(dest, url_app);
@@ -757,7 +757,7 @@ static inline void php_url_scanner_add_var_impl(const char *name, size_t name_le
757757
}
758758

759759
if (url_state->url_app.s && ZSTR_LEN(url_state->url_app.s) != 0) {
760-
smart_str_appends(&url_state->url_app, PG(arg_separator).output);
760+
smart_str_append(&url_state->url_app, PG(arg_separator).output);
761761
}
762762

763763
if (encode) {
@@ -902,9 +902,9 @@ static inline zend_result php_url_scanner_reset_var_impl(zend_string *name, int
902902
/* Get end of url var */
903903
limit = ZSTR_VAL(url_state->url_app.s) + ZSTR_LEN(url_state->url_app.s);
904904
end = start + ZSTR_LEN(url_app.s);
905-
separator_len = strlen(PG(arg_separator).output);
905+
separator_len = ZSTR_LEN(PG(arg_separator).output);
906906
while (end < limit) {
907-
if (!memcmp(end, PG(arg_separator).output, separator_len)) {
907+
if (!memcmp(end, ZSTR_VAL(PG(arg_separator).output), separator_len)) {
908908
end += separator_len;
909909
sep_removed = 1;
910910
break;
@@ -918,8 +918,8 @@ static inline zend_result php_url_scanner_reset_var_impl(zend_string *name, int
918918
}
919919
/* Check preceding separator */
920920
if (!sep_removed
921-
&& (size_t)(start - PG(arg_separator).output) >= separator_len
922-
&& !memcmp(start - separator_len, PG(arg_separator).output, separator_len)) {
921+
&& (size_t)(start - ZSTR_VAL(PG(arg_separator).output)) >= separator_len
922+
&& !memcmp(start - separator_len, ZSTR_VAL(PG(arg_separator).output), separator_len)) {
923923
start -= separator_len;
924924
}
925925
/* Remove partially */

main/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,8 @@ PHP_INI_BEGIN()
771771

772772
STD_PHP_INI_ENTRY("unserialize_callback_func", NULL, PHP_INI_ALL, OnUpdateString, unserialize_callback_func, php_core_globals, core_globals)
773773
STD_PHP_INI_ENTRY("serialize_precision", "-1", PHP_INI_ALL, OnSetSerializePrecision, serialize_precision, php_core_globals, core_globals)
774-
STD_PHP_INI_ENTRY("arg_separator.output", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator.output, php_core_globals, core_globals)
775-
STD_PHP_INI_ENTRY("arg_separator.input", "&", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, arg_separator.input, php_core_globals, core_globals)
774+
STD_PHP_INI_ENTRY("arg_separator.output", "&", PHP_INI_ALL, OnUpdateStrNotEmpty, arg_separator.output, php_core_globals, core_globals)
775+
STD_PHP_INI_ENTRY("arg_separator.input", "&", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStrNotEmpty, arg_separator.input, php_core_globals, core_globals)
776776

777777
STD_PHP_INI_ENTRY("auto_append_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_append_file, php_core_globals, core_globals)
778778
STD_PHP_INI_ENTRY("auto_prepend_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_prepend_file, php_core_globals, core_globals)

main/php_globals.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ extern ZEND_API struct _php_core_globals core_globals;
4848
struct _php_tick_function_entry;
4949

5050
typedef struct _arg_separators {
51-
char *output;
52-
char *input;
51+
zend_string *output;
52+
zend_string *input;
5353
} arg_separators;
5454

5555
struct _php_core_globals {

main/php_variables.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data)
527527
switch (arg) {
528528
case PARSE_GET:
529529
case PARSE_STRING:
530-
separator = PG(arg_separator).input;
530+
separator = ZSTR_VAL(PG(arg_separator).input);
531531
break;
532532
case PARSE_COOKIE:
533533
separator = ";\0";

sapi/cgi/cgi_main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2420,7 +2420,7 @@ consult the installation file that came with this distribution, or visit \n\
24202420
* test.php v1=test "v2=hello world!"
24212421
*/
24222422
if (!SG(request_info).query_string && argc > php_optind) {
2423-
size_t slen = strlen(PG(arg_separator).input);
2423+
size_t slen = ZSTR_LEN(PG(arg_separator).input);
24242424
len = 0;
24252425
for (i = php_optind; i < argc; i++) {
24262426
if (i < (argc - 1)) {
@@ -2436,7 +2436,7 @@ consult the installation file that came with this distribution, or visit \n\
24362436
for (i = php_optind; i < argc; i++) {
24372437
strlcat(s, argv[i], len);
24382438
if (i < (argc - 1)) {
2439-
strlcat(s, PG(arg_separator).input, len);
2439+
strlcat(s, ZSTR_VAL(PG(arg_separator).input), len);
24402440
}
24412441
}
24422442
SG(request_info).query_string = s;

0 commit comments

Comments
 (0)