From 99c022067f53c968d048d3199749471aa4828933 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 7 Jun 2017 20:34:26 +0200 Subject: [PATCH 1/3] Updating to new parameter parsing API --- Zend/zend_builtin_functions.c | 87 +++++++++++++++-------------------- 1 file changed, 37 insertions(+), 50 deletions(-) diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 000348d4754f3..fcff7452d1606 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -481,7 +481,7 @@ ZEND_FUNCTION(func_get_args) q = p; if (EXPECTED(Z_TYPE_INFO_P(q) != IS_UNDEF)) { ZVAL_DEREF(q); - if (Z_OPT_REFCOUNTED_P(q)) { + if (Z_OPT_REFCOUNTED_P(q)) { Z_ADDREF_P(q); } n++; @@ -496,7 +496,7 @@ ZEND_FUNCTION(func_get_args) q = p; if (EXPECTED(Z_TYPE_INFO_P(q) != IS_UNDEF)) { ZVAL_DEREF(q); - if (Z_OPT_REFCOUNTED_P(q)) { + if (Z_OPT_REFCOUNTED_P(q)) { Z_ADDREF_P(q); } n++; @@ -518,9 +518,9 @@ ZEND_FUNCTION(strlen) { zend_string *s; - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_STR(s) - ZEND_PARSE_PARAMETERS_END(); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &s) == FAILURE) { + return; + } RETVAL_LONG(ZSTR_LEN(s)); } @@ -665,10 +665,9 @@ ZEND_FUNCTION(error_reporting) zval *err = NULL; int old_error_reporting; - ZEND_PARSE_PARAMETERS_START(0, 1) - Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(err) - ZEND_PARSE_PARAMETERS_END(); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &err) == FAILURE) { + return; + } old_error_reporting = EG(error_reporting); if (ZEND_NUM_ARGS() != 0) { @@ -779,12 +778,9 @@ ZEND_FUNCTION(define) int case_sensitive = CONST_CS; zend_constant c; - ZEND_PARSE_PARAMETERS_START(2, 3) - Z_PARAM_STR(name) - Z_PARAM_ZVAL(val) - Z_PARAM_OPTIONAL - Z_PARAM_BOOL(non_cs) - ZEND_PARSE_PARAMETERS_END(); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|b", &name, &val, &non_cs) == FAILURE) { + return; + } if (non_cs) { case_sensitive = 0; @@ -860,9 +856,9 @@ ZEND_FUNCTION(defined) { zend_string *name; - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_STR(name) - ZEND_PARSE_PARAMETERS_END(); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { + return; + } if (zend_get_constant_ex(name, zend_get_executed_scope(), ZEND_FETCH_CLASS_SILENT)) { RETURN_TRUE; @@ -963,12 +959,10 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) /* zend_bool allow_string = only_subclass; zend_bool retval; - ZEND_PARSE_PARAMETERS_START(2, 3) - Z_PARAM_ZVAL(obj) - Z_PARAM_STR(class_name) - Z_PARAM_OPTIONAL - Z_PARAM_BOOL(allow_string) - ZEND_PARSE_PARAMETERS_END(); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "zS|b", &obj, &class_name, &allow_string) == FAILURE) { + return; + } + /* * allow_string - is_a default is no, is_subclass_of is yes. * if it's allowed, then the autoloader will be called if the class does not exist. @@ -1110,9 +1104,9 @@ ZEND_FUNCTION(get_object_vars) zend_object *zobj; zend_ulong num_key; - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT(obj) - ZEND_PARSE_PARAMETERS_END(); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &obj) == FAILURE) { + return; + } if (Z_OBJ_HT_P(obj)->get_properties == NULL) { RETURN_FALSE; @@ -1264,11 +1258,10 @@ ZEND_FUNCTION(method_exists) zend_string *lcname; zend_class_entry * ce; - ZEND_PARSE_PARAMETERS_START(2, 2) - Z_PARAM_ZVAL(klass) - Z_PARAM_STR(method_name) - ZEND_PARSE_PARAMETERS_END(); - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "zS", &klass, &method_name) == FAILURE) { + return; + } + if (Z_TYPE_P(klass) == IS_OBJECT) { ce = Z_OBJCE_P(klass); } else if (Z_TYPE_P(klass) == IS_STRING) { @@ -1364,11 +1357,9 @@ ZEND_FUNCTION(class_exists) zend_class_entry *ce; zend_bool autoload = 1; - ZEND_PARSE_PARAMETERS_START(1, 2) - Z_PARAM_STR(class_name) - Z_PARAM_OPTIONAL - Z_PARAM_BOOL(autoload) - ZEND_PARSE_PARAMETERS_END(); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &class_name, &autoload) == FAILURE) { + return; + } if (!autoload) { if (ZSTR_VAL(class_name)[0] == '\\') { @@ -1401,11 +1392,9 @@ ZEND_FUNCTION(interface_exists) zend_class_entry *ce; zend_bool autoload = 1; - ZEND_PARSE_PARAMETERS_START(1, 2) - Z_PARAM_STR(iface_name) - Z_PARAM_OPTIONAL - Z_PARAM_BOOL(autoload) - ZEND_PARSE_PARAMETERS_END(); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &iface_name, &autoload) == FAILURE) { + return; + } if (!autoload) { if (ZSTR_VAL(iface_name)[0] == '\\') { @@ -1437,11 +1426,9 @@ ZEND_FUNCTION(trait_exists) zend_class_entry *ce; zend_bool autoload = 1; - ZEND_PARSE_PARAMETERS_START(1, 2) - Z_PARAM_STR(trait_name) - Z_PARAM_OPTIONAL - Z_PARAM_BOOL(autoload) - ZEND_PARSE_PARAMETERS_END(); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &trait_name, &autoload) == FAILURE) { + return; + } if (!autoload) { if (ZSTR_VAL(trait_name)[0] == '\\') { @@ -1474,9 +1461,9 @@ ZEND_FUNCTION(function_exists) zend_function *func; zend_string *lcname; - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_STR(name) - ZEND_PARSE_PARAMETERS_END(); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { + return; + } if (ZSTR_VAL(name)[0] == '\\') { /* Ignore leading "\" */ From 3f3e5b36df1a38765c2eaeda65880656f0ba7bf4 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 7 Jun 2017 21:46:12 +0200 Subject: [PATCH 2/3] Revert "Updating to new parameter parsing API" This reverts commit 99c022067f53c968d048d3199749471aa4828933. --- Zend/zend_builtin_functions.c | 87 ++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 37 deletions(-) diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index fcff7452d1606..000348d4754f3 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -481,7 +481,7 @@ ZEND_FUNCTION(func_get_args) q = p; if (EXPECTED(Z_TYPE_INFO_P(q) != IS_UNDEF)) { ZVAL_DEREF(q); - if (Z_OPT_REFCOUNTED_P(q)) { + if (Z_OPT_REFCOUNTED_P(q)) { Z_ADDREF_P(q); } n++; @@ -496,7 +496,7 @@ ZEND_FUNCTION(func_get_args) q = p; if (EXPECTED(Z_TYPE_INFO_P(q) != IS_UNDEF)) { ZVAL_DEREF(q); - if (Z_OPT_REFCOUNTED_P(q)) { + if (Z_OPT_REFCOUNTED_P(q)) { Z_ADDREF_P(q); } n++; @@ -518,9 +518,9 @@ ZEND_FUNCTION(strlen) { zend_string *s; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &s) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STR(s) + ZEND_PARSE_PARAMETERS_END(); RETVAL_LONG(ZSTR_LEN(s)); } @@ -665,9 +665,10 @@ ZEND_FUNCTION(error_reporting) zval *err = NULL; int old_error_reporting; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &err) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL(err) + ZEND_PARSE_PARAMETERS_END(); old_error_reporting = EG(error_reporting); if (ZEND_NUM_ARGS() != 0) { @@ -778,9 +779,12 @@ ZEND_FUNCTION(define) int case_sensitive = CONST_CS; zend_constant c; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|b", &name, &val, &non_cs) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_STR(name) + Z_PARAM_ZVAL(val) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(non_cs) + ZEND_PARSE_PARAMETERS_END(); if (non_cs) { case_sensitive = 0; @@ -856,9 +860,9 @@ ZEND_FUNCTION(defined) { zend_string *name; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STR(name) + ZEND_PARSE_PARAMETERS_END(); if (zend_get_constant_ex(name, zend_get_executed_scope(), ZEND_FETCH_CLASS_SILENT)) { RETURN_TRUE; @@ -959,10 +963,12 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) /* zend_bool allow_string = only_subclass; zend_bool retval; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zS|b", &obj, &class_name, &allow_string) == FAILURE) { - return; - } - + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_ZVAL(obj) + Z_PARAM_STR(class_name) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(allow_string) + ZEND_PARSE_PARAMETERS_END(); /* * allow_string - is_a default is no, is_subclass_of is yes. * if it's allowed, then the autoloader will be called if the class does not exist. @@ -1104,9 +1110,9 @@ ZEND_FUNCTION(get_object_vars) zend_object *zobj; zend_ulong num_key; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &obj) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_OBJECT(obj) + ZEND_PARSE_PARAMETERS_END(); if (Z_OBJ_HT_P(obj)->get_properties == NULL) { RETURN_FALSE; @@ -1258,10 +1264,11 @@ ZEND_FUNCTION(method_exists) zend_string *lcname; zend_class_entry * ce; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zS", &klass, &method_name) == FAILURE) { - return; - } - + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(klass) + Z_PARAM_STR(method_name) + ZEND_PARSE_PARAMETERS_END(); + if (Z_TYPE_P(klass) == IS_OBJECT) { ce = Z_OBJCE_P(klass); } else if (Z_TYPE_P(klass) == IS_STRING) { @@ -1357,9 +1364,11 @@ ZEND_FUNCTION(class_exists) zend_class_entry *ce; zend_bool autoload = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &class_name, &autoload) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STR(class_name) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(autoload) + ZEND_PARSE_PARAMETERS_END(); if (!autoload) { if (ZSTR_VAL(class_name)[0] == '\\') { @@ -1392,9 +1401,11 @@ ZEND_FUNCTION(interface_exists) zend_class_entry *ce; zend_bool autoload = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &iface_name, &autoload) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STR(iface_name) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(autoload) + ZEND_PARSE_PARAMETERS_END(); if (!autoload) { if (ZSTR_VAL(iface_name)[0] == '\\') { @@ -1426,9 +1437,11 @@ ZEND_FUNCTION(trait_exists) zend_class_entry *ce; zend_bool autoload = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &trait_name, &autoload) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STR(trait_name) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(autoload) + ZEND_PARSE_PARAMETERS_END(); if (!autoload) { if (ZSTR_VAL(trait_name)[0] == '\\') { @@ -1461,9 +1474,9 @@ ZEND_FUNCTION(function_exists) zend_function *func; zend_string *lcname; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STR(name) + ZEND_PARSE_PARAMETERS_END(); if (ZSTR_VAL(name)[0] == '\\') { /* Ignore leading "\" */ From 4d042ed295f7141009a4721a765b2bf2b4b63ada Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 7 Jun 2017 22:08:18 +0200 Subject: [PATCH 3/3] Updated str functions to new API --- Zend/zend_builtin_functions.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 000348d4754f3..960a1debef170 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -532,9 +532,10 @@ ZEND_FUNCTION(strcmp) { zend_string *s1, *s2; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &s1, &s2) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_STR(s1) + Z_PARAM_STR(s2) + ZEND_PARSE_PARAMETERS_END(); RETURN_LONG(zend_binary_strcmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2))); } @@ -547,9 +548,11 @@ ZEND_FUNCTION(strncmp) zend_string *s1, *s2; zend_long len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSl", &s1, &s2, &len) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_STR(s1) + Z_PARAM_STR(s2) + Z_PARAM_LONG(len) + ZEND_PARSE_PARAMETERS_END(); if (len < 0) { zend_error(E_WARNING, "Length must be greater than or equal to 0"); @@ -566,9 +569,10 @@ ZEND_FUNCTION(strcasecmp) { zend_string *s1, *s2; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &s1, &s2) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_STR(s1) + Z_PARAM_STR(s2) + ZEND_PARSE_PARAMETERS_END(); RETURN_LONG(zend_binary_strcasecmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2))); } @@ -581,9 +585,11 @@ ZEND_FUNCTION(strncasecmp) zend_string *s1, *s2; zend_long len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSl", &s1, &s2, &len) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_STR(s1) + Z_PARAM_STR(s2) + Z_PARAM_LONG(len) + ZEND_PARSE_PARAMETERS_END(); if (len < 0) { zend_error(E_WARNING, "Length must be greater than or equal to 0");