Skip to content

Commit 994170e

Browse files
committed
Migrate curl to new parameters API
Plus a handful of char*->zend_string* conversions
1 parent fbec1a7 commit 994170e

File tree

4 files changed

+106
-92
lines changed

4 files changed

+106
-92
lines changed

ext/curl/curl_file.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,24 @@ PHP_CURL_API zend_class_entry *curl_CURLFile_class;
3131

3232
static void curlfile_ctor(INTERNAL_FUNCTION_PARAMETERS)
3333
{
34-
char *fname = NULL, *mime = NULL, *postname = NULL;
35-
size_t fname_len, mime_len, postname_len;
34+
zend_string *fname, *mime = NULL, *postname = NULL;
3635
zval *cf = return_value;
3736

38-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ss", &fname, &fname_len, &mime, &mime_len, &postname, &postname_len) == FAILURE) {
39-
return;
40-
}
37+
ZEND_PARSE_PARAMETERS_START(1,3)
38+
Z_PARAM_STR(fname)
39+
Z_PARAM_OPTIONAL
40+
Z_PARAM_STR(mime)
41+
Z_PARAM_STR(postname)
42+
ZEND_PARSE_PARAMETERS_END();
4143

42-
if (fname) {
43-
zend_update_property_string(curl_CURLFile_class, cf, "name", sizeof("name")-1, fname);
44-
}
44+
zend_update_property_string(curl_CURLFile_class, cf, "name", sizeof("name")-1, ZSTR_VAL(fname));
4545

4646
if (mime) {
47-
zend_update_property_string(curl_CURLFile_class, cf, "mime", sizeof("mime")-1, mime);
47+
zend_update_property_string(curl_CURLFile_class, cf, "mime", sizeof("mime")-1, ZSTR_VAL(mime));
4848
}
4949

5050
if (postname) {
51-
zend_update_property_string(curl_CURLFile_class, cf, "postname", sizeof("postname")-1, postname);
51+
zend_update_property_string(curl_CURLFile_class, cf, "postname", sizeof("postname")-1, ZSTR_VAL(postname));
5252
}
5353
}
5454

@@ -84,13 +84,13 @@ static void curlfile_get_property(char *name, size_t name_len, INTERNAL_FUNCTION
8484

8585
static void curlfile_set_property(char *name, size_t name_len, INTERNAL_FUNCTION_PARAMETERS)
8686
{
87-
char *arg = NULL;
88-
size_t arg_len;
87+
zend_string *arg;
8988

90-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE) {
91-
return;
92-
}
93-
zend_update_property_string(curl_CURLFile_class, getThis(), name, name_len, arg);
89+
ZEND_PARSE_PARAMETERS_START(1,1)
90+
Z_PARAM_STR(arg)
91+
ZEND_PARSE_PARAMETERS_END();
92+
93+
zend_update_property_string(curl_CURLFile_class, getThis(), name, name_len, ZSTR_VAL(arg));
9494
}
9595

9696
/* {{{ proto string CURLFile::getFilename()

ext/curl/interface.c

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,12 +1964,12 @@ PHP_FUNCTION(curl_init)
19641964
{
19651965
php_curl *ch;
19661966
CURL *cp;
1967-
char *url = NULL;
1968-
size_t url_len = 0;
1967+
zend_string *url = NULL;
19691968

1970-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &url, &url_len) == FAILURE) {
1971-
return;
1972-
}
1969+
ZEND_PARSE_PARAMETERS_START(0,1)
1970+
Z_PARAM_OPTIONAL
1971+
Z_PARAM_STR(url)
1972+
ZEND_PARSE_PARAMETERS_END();
19731973

19741974
cp = curl_easy_init();
19751975
if (!cp) {
@@ -1988,7 +1988,7 @@ PHP_FUNCTION(curl_init)
19881988
_php_curl_set_default_options(ch);
19891989

19901990
if (url) {
1991-
if (php_curl_option_url(ch, url, url_len) == FAILURE) {
1991+
if (php_curl_option_url(ch, ZSTR_VAL(url), ZSTR_LEN(url)) == FAILURE) {
19921992
_php_curl_close_ex(ch);
19931993
RETURN_FALSE;
19941994
}
@@ -2080,9 +2080,9 @@ PHP_FUNCTION(curl_copy_handle)
20802080
zval *zid;
20812081
php_curl *ch, *dupch;
20822082

2083-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zid) == FAILURE) {
2084-
return;
2085-
}
2083+
ZEND_PARSE_PARAMETERS_START(1,1)
2084+
Z_PARAM_RESOURCE(zid)
2085+
ZEND_PARSE_PARAMETERS_END();
20862086

20872087
if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
20882088
RETURN_FALSE;
@@ -3311,9 +3311,9 @@ PHP_FUNCTION(curl_errno)
33113311
zval *zid;
33123312
php_curl *ch;
33133313

3314-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zid) == FAILURE) {
3315-
return;
3316-
}
3314+
ZEND_PARSE_PARAMETERS_START(1,1)
3315+
Z_PARAM_RESOURCE(zid)
3316+
ZEND_PARSE_PARAMETERS_END();
33173317

33183318
if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
33193319
RETURN_FALSE;
@@ -3534,24 +3534,25 @@ PHP_FUNCTION(curl_reset)
35343534
URL encodes the given string */
35353535
PHP_FUNCTION(curl_escape)
35363536
{
3537-
char *str = NULL, *res = NULL;
3538-
size_t str_len = 0;
3539-
zval *zid;
3540-
php_curl *ch;
3537+
zend_string *str;
3538+
char *res;
3539+
zval *zid;
3540+
php_curl *ch;
35413541

3542-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &zid, &str, &str_len) == FAILURE) {
3543-
return;
3544-
}
3542+
ZEND_PARSE_PARAMETERS_START(2,2)
3543+
Z_PARAM_RESOURCE(zid)
3544+
Z_PARAM_STR(str)
3545+
ZEND_PARSE_PARAMETERS_END();
35453546

35463547
if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
35473548
RETURN_FALSE;
35483549
}
35493550

3550-
if (ZEND_SIZE_T_INT_OVFL(str_len)) {
3551+
if (ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(str))) {
35513552
RETURN_FALSE;
35523553
}
35533554

3554-
if ((res = curl_easy_escape(ch->cp, str, str_len))) {
3555+
if ((res = curl_easy_escape(ch->cp, ZSTR_VAL(str), ZSTR_LEN(str)))) {
35553556
RETVAL_STRING(res);
35563557
curl_free(res);
35573558
} else {
@@ -3564,25 +3565,26 @@ PHP_FUNCTION(curl_escape)
35643565
URL decodes the given string */
35653566
PHP_FUNCTION(curl_unescape)
35663567
{
3567-
char *str = NULL, *out = NULL;
3568-
size_t str_len = 0;
3569-
int out_len;
3570-
zval *zid;
3571-
php_curl *ch;
3568+
char *out = NULL;
3569+
int out_len;
3570+
zval *zid;
3571+
zend_string *str;
3572+
php_curl *ch;
35723573

3573-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &zid, &str, &str_len) == FAILURE) {
3574-
return;
3575-
}
3574+
ZEND_PARSE_PARAMETERS_START(2,2)
3575+
Z_PARAM_RESOURCE(zid)
3576+
Z_PARAM_STR(str)
3577+
ZEND_PARSE_PARAMETERS_END();
35763578

35773579
if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
35783580
RETURN_FALSE;
35793581
}
35803582

3581-
if (ZEND_SIZE_T_INT_OVFL(str_len)) {
3583+
if (ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(str))) {
35823584
RETURN_FALSE;
35833585
}
35843586

3585-
if ((out = curl_easy_unescape(ch->cp, str, str_len, &out_len))) {
3587+
if ((out = curl_easy_unescape(ch->cp, ZSTR_VAL(str), ZSTR_LEN(str), &out_len))) {
35863588
RETVAL_STRINGL(out, out_len);
35873589
curl_free(out);
35883590
} else {
@@ -3601,9 +3603,10 @@ PHP_FUNCTION(curl_pause)
36013603
zval *zid;
36023604
php_curl *ch;
36033605

3604-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &zid, &bitmask) == FAILURE) {
3605-
return;
3606-
}
3606+
ZEND_PARSE_PARAMETERS_START(2,2)
3607+
Z_PARAM_RESOURCE(zid)
3608+
Z_PARAM_LONG(bitmask)
3609+
ZEND_PARSE_PARAMETERS_END();
36073610

36083611
if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
36093612
RETURN_FALSE;

ext/curl/multi.c

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ PHP_FUNCTION(curl_multi_add_handle)
8282
zval tmp_val;
8383
CURLMcode error = CURLM_OK;
8484

85-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rr", &z_mh, &z_ch) == FAILURE) {
86-
return;
87-
}
85+
ZEND_PARSE_PARAMETERS_START(2,2)
86+
Z_PARAM_RESOURCE(z_mh)
87+
Z_PARAM_RESOURCE(z_ch)
88+
ZEND_PARSE_PARAMETERS_END();
8889

8990
if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
9091
RETURN_FALSE;
@@ -169,9 +170,10 @@ PHP_FUNCTION(curl_multi_remove_handle)
169170
php_curl *ch;
170171
CURLMcode error = CURLM_OK;
171172

172-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rr", &z_mh, &z_ch) == FAILURE) {
173-
return;
174-
}
173+
ZEND_PARSE_PARAMETERS_START(2,2)
174+
Z_PARAM_RESOURCE(z_mh)
175+
Z_PARAM_RESOURCE(z_ch)
176+
ZEND_PARSE_PARAMETERS_END();
175177

176178
if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
177179
RETURN_FALSE;
@@ -214,9 +216,11 @@ PHP_FUNCTION(curl_multi_select)
214216
struct timeval to;
215217
CURLMcode error = CURLM_OK;
216218

217-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|d", &z_mh, &timeout) == FAILURE) {
218-
return;
219-
}
219+
ZEND_PARSE_PARAMETERS_START(1,2)
220+
Z_PARAM_RESOURCE(z_mh)
221+
Z_PARAM_OPTIONAL
222+
Z_PARAM_DOUBLE(timeout)
223+
ZEND_PARSE_PARAMETERS_END();
220224

221225
if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
222226
RETURN_FALSE;
@@ -248,9 +252,10 @@ PHP_FUNCTION(curl_multi_exec)
248252
int still_running;
249253
CURLMcode error = CURLM_OK;
250254

251-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz/", &z_mh, &z_still_running) == FAILURE) {
252-
return;
253-
}
255+
ZEND_PARSE_PARAMETERS_START(2, 2)
256+
Z_PARAM_RESOURCE(z_mh)
257+
Z_PARAM_ZVAL_DEREF_EX(z_still_running, 0, 1)
258+
ZEND_PARSE_PARAMETERS_END();
254259

255260
if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
256261
RETURN_FALSE;
@@ -289,9 +294,9 @@ PHP_FUNCTION(curl_multi_getcontent)
289294
zval *z_ch;
290295
php_curl *ch;
291296

292-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_ch) == FAILURE) {
293-
return;
294-
}
297+
ZEND_PARSE_PARAMETERS_START(1,1)
298+
Z_PARAM_RESOURCE(z_ch)
299+
ZEND_PARSE_PARAMETERS_END();
295300

296301
if ((ch = (php_curl *)zend_fetch_resource(Z_RES_P(z_ch), le_curl_name, le_curl)) == NULL) {
297302
RETURN_FALSE;
@@ -319,9 +324,11 @@ PHP_FUNCTION(curl_multi_info_read)
319324
int queued_msgs;
320325
zval *zmsgs_in_queue = NULL;
321326

322-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|z/", &z_mh, &zmsgs_in_queue) == FAILURE) {
323-
return;
324-
}
327+
ZEND_PARSE_PARAMETERS_START(1, 2)
328+
Z_PARAM_RESOURCE(z_mh)
329+
Z_PARAM_OPTIONAL
330+
Z_PARAM_ZVAL_DEREF_EX(zmsgs_in_queue, 0, 1)
331+
ZEND_PARSE_PARAMETERS_END();
325332

326333
if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
327334
RETURN_FALSE;
@@ -369,9 +376,9 @@ PHP_FUNCTION(curl_multi_close)
369376
zval *z_mh;
370377
php_curlm *mh;
371378

372-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_mh) == FAILURE) {
373-
return;
374-
}
379+
ZEND_PARSE_PARAMETERS_START(1,1)
380+
Z_PARAM_RESOURCE(z_mh)
381+
ZEND_PARSE_PARAMETERS_END();
375382

376383
if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
377384
RETURN_FALSE;
@@ -420,9 +427,9 @@ PHP_FUNCTION(curl_multi_errno)
420427
zval *z_mh;
421428
php_curlm *mh;
422429

423-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_mh) == FAILURE) {
424-
return;
425-
}
430+
ZEND_PARSE_PARAMETERS_START(1,1)
431+
Z_PARAM_RESOURCE(z_mh)
432+
ZEND_PARSE_PARAMETERS_END();
426433

427434
if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
428435
RETURN_FALSE;
@@ -440,9 +447,9 @@ PHP_FUNCTION(curl_multi_strerror)
440447
zend_long code;
441448
const char *str;
442449

443-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &code) == FAILURE) {
444-
return;
445-
}
450+
ZEND_PARSE_PARAMETERS_START(1,1)
451+
Z_PARAM_LONG(code)
452+
ZEND_PARSE_PARAMETERS_END();
446453

447454
str = curl_multi_strerror(code);
448455
if (str) {
@@ -598,9 +605,11 @@ PHP_FUNCTION(curl_multi_setopt)
598605
zend_long options;
599606
php_curlm *mh;
600607

601-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &z_mh, &options, &zvalue) == FAILURE) {
602-
return;
603-
}
608+
ZEND_PARSE_PARAMETERS_START(3,3)
609+
Z_PARAM_RESOURCE(z_mh)
610+
Z_PARAM_LONG(options)
611+
Z_PARAM_ZVAL_DEREF(zvalue)
612+
ZEND_PARSE_PARAMETERS_END();
604613

605614
if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
606615
RETURN_FALSE;

ext/curl/share.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ PHP_FUNCTION(curl_share_close)
5959
zval *z_sh;
6060
php_curlsh *sh;
6161

62-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_sh) == FAILURE) {
63-
return;
64-
}
62+
ZEND_PARSE_PARAMETERS_START(1,1)
63+
Z_PARAM_RESOURCE(z_sh)
64+
ZEND_PARSE_PARAMETERS_END();
6565

6666
if ((sh = (php_curlsh *)zend_fetch_resource(Z_RES_P(z_sh), le_curl_share_handle_name, le_curl_share_handle)) == NULL) {
6767
RETURN_FALSE;
@@ -104,9 +104,11 @@ PHP_FUNCTION(curl_share_setopt)
104104
zend_long options;
105105
php_curlsh *sh;
106106

107-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &zid, &options, &zvalue) == FAILURE) {
108-
return;
109-
}
107+
ZEND_PARSE_PARAMETERS_START(3,3)
108+
Z_PARAM_RESOURCE(zid)
109+
Z_PARAM_LONG(options)
110+
Z_PARAM_ZVAL_DEREF(zvalue)
111+
ZEND_PARSE_PARAMETERS_END();
110112

111113
if ((sh = (php_curlsh *)zend_fetch_resource(Z_RES_P(zid), le_curl_share_handle_name, le_curl_share_handle)) == NULL) {
112114
RETURN_FALSE;
@@ -138,9 +140,9 @@ PHP_FUNCTION(curl_share_errno)
138140
zval *z_sh;
139141
php_curlsh *sh;
140142

141-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_sh) == FAILURE) {
142-
return;
143-
}
143+
ZEND_PARSE_PARAMETERS_START(1,1)
144+
Z_PARAM_RESOURCE(z_sh)
145+
ZEND_PARSE_PARAMETERS_END();
144146

145147
if ((sh = (php_curlsh *)zend_fetch_resource(Z_RES_P(z_sh), le_curl_share_handle_name, le_curl_share_handle)) == NULL) {
146148
RETURN_FALSE;
@@ -159,9 +161,9 @@ PHP_FUNCTION(curl_share_strerror)
159161
zend_long code;
160162
const char *str;
161163

162-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &code) == FAILURE) {
163-
return;
164-
}
164+
ZEND_PARSE_PARAMETERS_START(1,1)
165+
Z_PARAM_LONG(code)
166+
ZEND_PARSE_PARAMETERS_END();
165167

166168
str = curl_share_strerror(code);
167169
if (str) {

0 commit comments

Comments
 (0)