summaryrefslogtreecommitdiff
path: root/Zend/zend_API.h
diff options
context:
space:
mode:
authorMáté Kocsis <kocsismate@woohoolabs.com>2020-06-30 15:04:54 +0200
committerMáté Kocsis <kocsismate@woohoolabs.com>2020-07-06 12:42:02 +0200
commitb18b2c8fe587321384c9423470cf97d8040b32e2 (patch)
treeef2ffc57c3b54ada2414bca33c5dd07988c5ab9e /Zend/zend_API.h
parenta4b253c40bd2329e66ce12a35b5cabf9c244e652 (diff)
downloadphp-git-b18b2c8fe587321384c9423470cf97d8040b32e2.tar.gz
Add string or object ZPP macros
Closes GH-5788
Diffstat (limited to 'Zend/zend_API.h')
-rw-r--r--Zend/zend_API.h82
1 files changed, 75 insertions, 7 deletions
diff --git a/Zend/zend_API.h b/Zend/zend_API.h
index ae0363f765..578cf629f8 100644
--- a/Zend/zend_API.h
+++ b/Zend/zend_API.h
@@ -1219,6 +1219,8 @@ static zend_always_inline zval *zend_try_array_init(zval *zv)
_(Z_EXPECTED_STRING_OR_LONG_OR_NULL, "of type string|int|null") \
_(Z_EXPECTED_CLASS_NAME_OR_OBJECT, "a valid class name or object") \
_(Z_EXPECTED_CLASS_NAME_OR_OBJECT_OR_NULL, "a valid class name, object, or null") \
+ _(Z_EXPECTED_STRING_OR_OBJECT, "of type object|string") \
+ _(Z_EXPECTED_STRING_OR_OBJECT_OR_NULL, "of type object|string|null") \
#define Z_EXPECTED_TYPE
@@ -1235,18 +1237,22 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(int min_
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(int num, zend_expected_type expected_type, zval *arg);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(int num, const char *name, zval *arg);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_null_error(int num, const char *name, zval *arg);
+ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_error(int num, const char *name, zval *arg);
+ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_or_null_error(int num, const char *name, zval *arg);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(int num, char *error);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_type_error(uint32_t arg_num, const char *format, ...);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num, const char *format, ...);
-#define ZPP_ERROR_OK 0
-#define ZPP_ERROR_FAILURE 1
-#define ZPP_ERROR_WRONG_CALLBACK 2
-#define ZPP_ERROR_WRONG_CLASS 3
-#define ZPP_ERROR_WRONG_CLASS_OR_NULL 4
-#define ZPP_ERROR_WRONG_ARG 5
-#define ZPP_ERROR_WRONG_COUNT 6
+#define ZPP_ERROR_OK 0
+#define ZPP_ERROR_FAILURE 1
+#define ZPP_ERROR_WRONG_CALLBACK 2
+#define ZPP_ERROR_WRONG_CLASS 3
+#define ZPP_ERROR_WRONG_CLASS_OR_NULL 4
+#define ZPP_ERROR_WRONG_ARG 5
+#define ZPP_ERROR_WRONG_COUNT 6
+#define ZPP_ERROR_WRONG_STRING_OR_CLASS 7
+#define ZPP_ERROR_WRONG_STRING_OR_CLASS_OR_NULL 8
#define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \
const int _flags = (flags); \
@@ -1301,6 +1307,10 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
zend_wrong_parameter_class_or_null_error(_i, _error, _arg); \
} else if (_error_code == ZPP_ERROR_WRONG_ARG) { \
zend_wrong_parameter_type_error(_i, _expected_type, _arg); \
+ } else if (_error_code == ZPP_ERROR_WRONG_STRING_OR_CLASS) { \
+ zend_wrong_parameter_string_or_class_error(_i, _error, _arg); \
+ } else if (_error_code == ZPP_ERROR_WRONG_STRING_OR_CLASS_OR_NULL) { \
+ zend_wrong_parameter_string_or_class_or_null_error(_i, _error, _arg); \
} \
} \
failure; \
@@ -1411,6 +1421,40 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
#define Z_PARAM_CLASS_NAME_OR_OBJ_OR_NULL(dest) \
Z_PARAM_CLASS_NAME_OR_OBJ_EX(dest, 1);
+#define Z_PARAM_STR_OR_OBJ_EX(destination_string, destination_object, allow_null) \
+ Z_PARAM_PROLOGUE(0, 0); \
+ if (UNEXPECTED(!zend_parse_arg_str_or_obj(_arg, &destination_string, &destination_object, NULL, allow_null))) { \
+ _expected_type = allow_null ? Z_EXPECTED_STRING_OR_OBJECT_OR_NULL : Z_EXPECTED_STRING_OR_OBJECT; \
+ _error_code = ZPP_ERROR_WRONG_ARG; \
+ break; \
+ }
+
+#define Z_PARAM_STR_OR_OBJ(destination_string, destination_object) \
+ Z_PARAM_STR_OR_OBJ_EX(destination_string, destination_object, 0);
+
+#define Z_PARAM_STR_OR_OBJ_OR_NULL(destination_string, destination_object) \
+ Z_PARAM_STR_OR_OBJ_EX(destination_string, destination_object, 1);
+
+#define Z_PARAM_STR_OR_OBJ_OF_CLASS_EX(destination_string, destination_object, base_ce, allow_null) \
+ Z_PARAM_PROLOGUE(0, 0); \
+ if (UNEXPECTED(!zend_parse_arg_str_or_obj(_arg, &destination_string, &destination_object, base_ce, allow_null))) { \
+ if (base_ce) { \
+ _error = ZSTR_VAL((base_ce)->name); \
+ _error_code = allow_null ? ZPP_ERROR_WRONG_STRING_OR_CLASS_OR_NULL : ZPP_ERROR_WRONG_STRING_OR_CLASS; \
+ break; \
+ } else { \
+ _expected_type = allow_null ? Z_EXPECTED_STRING_OR_OBJECT_OR_NULL : Z_EXPECTED_STRING_OR_OBJECT; \
+ _error_code = ZPP_ERROR_WRONG_ARG; \
+ break; \
+ } \
+ }
+
+#define Z_PARAM_STR_OR_OBJ_OF_CLASS(destination_string, destination_object, base_ce) \
+ Z_PARAM_STR_OR_OBJ_OF_CLASS_EX(destination_string, destination_object, base_ce, 0);
+
+#define Z_PARAM_STR_OR_OBJ_OF_CLASS_OR_NULL(destination_string, destination_object, base_ce) \
+ Z_PARAM_STR_OR_OBJ_OF_CLASS_EX(destination_string, destination_object, base_ce, 1);
+
/* old "d" */
#define Z_PARAM_DOUBLE_EX2(dest, is_null, check_null, deref, separate) \
Z_PARAM_PROLOGUE(deref, separate); \
@@ -1972,6 +2016,30 @@ static zend_always_inline int zend_parse_arg_class_name_or_obj(
return 1;
}
+static zend_always_inline int zend_parse_arg_str_or_obj(
+ zval *arg, zend_string **destination_string, zend_object **destination_object, zend_class_entry *base_ce, int allow_null
+) {
+ if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
+ if (base_ce && UNEXPECTED(!instanceof_function(Z_OBJCE_P(arg), base_ce))) {
+ return 0;
+ }
+
+ *destination_string = NULL;
+ *destination_object = Z_OBJ_P(arg);
+ } else if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
+ *destination_string = Z_STR_P(arg);
+ *destination_object = NULL;
+ } else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
+ *destination_string = NULL;
+ *destination_object = NULL;
+ } else {
+ *destination_object = NULL;
+ return zend_parse_arg_str_slow(arg, destination_string);
+ }
+
+ return 1;
+}
+
END_EXTERN_C()
#endif /* ZEND_API_H */