Skip to content

Commit

Permalink
Use new param API in standard
Browse files Browse the repository at this point in the history
  • Loading branch information
sgolemon committed Dec 30, 2016
1 parent 625304f commit b71b128
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 55 deletions.
44 changes: 26 additions & 18 deletions ext/standard/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ php_dir_globals dir_globals;
static zend_class_entry *dir_class_entry_ptr;

#define FETCH_DIRP() \
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &id) == FAILURE) { \
return; \
} \
ZEND_PARSE_PARAMETERS_START(0, 1) \
Z_PARAM_OPTIONAL \
Z_PARAM_RESOURCE(id) \
ZEND_PARSE_PARAMETERS_END(); \
if (ZEND_NUM_ARGS() == 0) { \
myself = getThis(); \
if (myself) { \
Expand Down Expand Up @@ -215,9 +216,11 @@ static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETERS, int createobject)
php_stream_context *context = NULL;
php_stream *dirp;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|r", &dirname, &dir_len, &zcontext) == FAILURE) {
RETURN_NULL();
}
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_PATH(dirname, dir_len)
Z_PARAM_OPTIONAL
Z_PARAM_RESOURCE(zcontext)
ZEND_PARSE_PARAMETERS_END();

context = php_stream_context_from_zval(zcontext, 0);

Expand Down Expand Up @@ -291,9 +294,9 @@ PHP_FUNCTION(chroot)
int ret;
size_t str_len;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &str, &str_len) == FAILURE) {
RETURN_FALSE;
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_PATH(str, str_len)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

ret = chroot(str);
if (ret != 0) {
Expand Down Expand Up @@ -323,9 +326,9 @@ PHP_FUNCTION(chdir)
int ret;
size_t str_len;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &str, &str_len) == FAILURE) {
RETURN_FALSE;
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_PATH(str, str_len)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

if (php_check_open_basedir(str)) {
RETURN_FALSE;
Expand Down Expand Up @@ -434,9 +437,11 @@ PHP_FUNCTION(glob)
int ret;
zend_bool basedir_limit = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|l", &pattern, &pattern_len, &flags) == FAILURE) {
return;
}
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_PATH(pattern, pattern_len)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(flags)
ZEND_PARSE_PARAMETERS_END();

if (pattern_len >= MAXPATHLEN) {
php_error_docref(NULL, E_WARNING, "Pattern exceeds the maximum allowed length of %d characters", MAXPATHLEN);
Expand Down Expand Up @@ -557,9 +562,12 @@ PHP_FUNCTION(scandir)
zval *zcontext = NULL;
php_stream_context *context = NULL;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|lr", &dirn, &dirn_len, &flags, &zcontext) == FAILURE) {
return;
}
ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_PATH(dirn, dirn_len)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(flags)
Z_PARAM_RESOURCE(zcontext)
ZEND_PARSE_PARAMETERS_END();

if (dirn_len < 1) {
php_error_docref(NULL, E_WARNING, "Directory name cannot be empty");
Expand Down
57 changes: 38 additions & 19 deletions ext/standard/head.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ PHP_FUNCTION(header)
sapi_header_line ctr = {0};
size_t len;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|bl", &ctr.line,
&len, &rep, &ctr.response_code) == FAILURE)
return;
ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_STRING(ctr.line, len)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(rep)
Z_PARAM_LONG(ctr.response_code)
ZEND_PARSE_PARAMETERS_END();

ctr.line_len = (uint32_t)len;
sapi_header_op(rep ? SAPI_HEADER_REPLACE:SAPI_HEADER_ADD, &ctr);
Expand All @@ -58,9 +61,9 @@ PHP_FUNCTION(header_remove)
sapi_header_line ctr = {0};
size_t len = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &ctr.line,
&len) == FAILURE)
return;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_STRING(ctr.line, len)

This comment has been minimized.

Copy link
@mhagstrand

mhagstrand Dec 30, 2016

Contributor

You need to add Z_PARAM_OPTIONAL above Z_PARAM_STRING(ctr.line, len)

ZEND_PARSE_PARAMETERS_END();

ctr.line_len = (uint32_t)len;
sapi_header_op(ZEND_NUM_ARGS() == 0 ? SAPI_HEADER_DELETE_ALL : SAPI_HEADER_DELETE, &ctr);
Expand Down Expand Up @@ -191,10 +194,16 @@ PHP_FUNCTION(setcookie)
zend_long expires = 0;
zend_bool secure = 0, httponly = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|SlSSbb",
&name, &value, &expires, &path, &domain, &secure, &httponly) == FAILURE) {
return;
}
ZEND_PARSE_PARAMETERS_START(1, 7)
Z_PARAM_STR(name)
Z_PARAM_OPTIONAL
Z_PARAM_STR(value)
Z_PARAM_LONG(expires)
Z_PARAM_STR(path)
Z_PARAM_STR(domain)
Z_PARAM_BOOL(secure)
Z_PARAM_BOOL(httponly)
ZEND_PARSE_PARAMETERS_END();

if (php_setcookie(name, value, expires, path, domain, secure, 1, httponly) == SUCCESS) {
RETVAL_TRUE;
Expand All @@ -212,10 +221,16 @@ PHP_FUNCTION(setrawcookie)
zend_long expires = 0;
zend_bool secure = 0, httponly = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|SlSSbb",
&name, &value, &expires, &path, &domain, &secure, &httponly) == FAILURE) {
return;
}
ZEND_PARSE_PARAMETERS_START(1, 7)
Z_PARAM_STR(name)
Z_PARAM_OPTIONAL
Z_PARAM_STR(value)
Z_PARAM_LONG(expires)
Z_PARAM_STR(path)
Z_PARAM_STR(domain)
Z_PARAM_BOOL(secure)
Z_PARAM_BOOL(httponly)
ZEND_PARSE_PARAMETERS_END();

if (php_setcookie(name, value, expires, path, domain, secure, 0, httponly) == SUCCESS) {
RETVAL_TRUE;
Expand All @@ -234,8 +249,11 @@ PHP_FUNCTION(headers_sent)
const char *file="";
int line=0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z/z/", &arg1, &arg2) == FAILURE)
return;
ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL_DEREF_EX(arg1, 0, 1)
Z_PARAM_ZVAL_DEREF_EX(arg2, 0, 1)
ZEND_PARSE_PARAMETERS_END();

if (SG(headers_sent)) {
line = php_output_get_start_lineno();
Expand Down Expand Up @@ -294,9 +312,10 @@ PHP_FUNCTION(http_response_code)
{
zend_long response_code = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &response_code) == FAILURE) {
return;
}
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(response_code)
ZEND_PARSE_PARAMETERS_END();

if (response_code)
{
Expand Down
10 changes: 7 additions & 3 deletions ext/standard/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,13 @@ PHP_FUNCTION(http_build_query)
smart_str formstr = {0};
zend_long enc_type = PHP_QUERY_RFC1738;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|ssl", &formdata, &prefix, &prefix_len, &arg_sep, &arg_sep_len, &enc_type) != SUCCESS) {
RETURN_FALSE;
}
ZEND_PARSE_PARAMETERS_START(1, 4)
Z_PARAM_ZVAL_DEREF(formdata)
Z_PARAM_OPTIONAL
Z_PARAM_STRING(prefix, prefix_len)
Z_PARAM_STRING(arg_sep, arg_sep_len)
Z_PARAM_LONG(enc_type)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

if (Z_TYPE_P(formdata) != IS_ARRAY && Z_TYPE_P(formdata) != IS_OBJECT) {
php_error_docref(NULL, E_WARNING, "Parameter 1 expected to be Array or Object. Incorrect value given");
Expand Down
7 changes: 4 additions & 3 deletions ext/standard/rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ PHP_FUNCTION(rand)
RETURN_LONG(php_mt_rand() >> 1);
}

if (zend_parse_parameters(argc, "ll", &min, &max) == FAILURE) {
return;
}
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_LONG(min)
Z_PARAM_LONG(max)
ZEND_PARSE_PARAMETERS_END();

if (max < min) {
RETURN_LONG(php_mt_rand_common(max, min));
Expand Down
27 changes: 15 additions & 12 deletions ext/standard/user_filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ PHP_FUNCTION(stream_bucket_make_writeable)
php_stream_bucket_brigade *brigade;
php_stream_bucket *bucket;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zbrigade) == FAILURE) {
RETURN_FALSE;
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_RESOURCE(zbrigade)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

if ((brigade = (php_stream_bucket_brigade*)zend_fetch_resource(
Z_RES_P(zbrigade), PHP_STREAM_BRIGADE_RES_NAME, le_bucket_brigade)) == NULL) {
Expand Down Expand Up @@ -430,9 +430,10 @@ static void php_stream_bucket_attach(int append, INTERNAL_FUNCTION_PARAMETERS)
php_stream_bucket_brigade *brigade;
php_stream_bucket *bucket;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "ro", &zbrigade, &zobject) == FAILURE) {
RETURN_FALSE;
}
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_RESOURCE(zbrigade)
Z_PARAM_OBJECT(zobject)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

if (NULL == (pzbucket = zend_hash_str_find(Z_OBJPROP_P(zobject), "bucket", sizeof("bucket")-1))) {
php_error_docref(NULL, E_WARNING, "Object has no bucket property");
Expand Down Expand Up @@ -500,9 +501,10 @@ PHP_FUNCTION(stream_bucket_new)
size_t buffer_len;
php_stream_bucket *bucket;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs", &zstream, &buffer, &buffer_len) == FAILURE) {
RETURN_FALSE;
}
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_ZVAL_DEREF(zstream)
Z_PARAM_STRING(buffer, buffer_len)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

php_stream_from_zval(stream, zstream);

Expand Down Expand Up @@ -561,9 +563,10 @@ PHP_FUNCTION(stream_filter_register)
zend_string *filtername, *classname;
struct php_user_filter_data *fdat;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &filtername, &classname) == FAILURE) {
RETURN_FALSE;
}
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STR(filtername)
Z_PARAM_STR(classname)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

RETVAL_FALSE;

Expand Down

0 comments on commit b71b128

Please sign in to comment.