]> granicus.if.org Git - php/commitdiff
Add the Z_PARAM_ARRAY_HT_OR_NULL and Z_PARAM_OBJ macros
authorMáté Kocsis <kocsismate@woohoolabs.com>
Fri, 4 Sep 2020 12:15:17 +0000 (14:15 +0200)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Fri, 4 Sep 2020 12:31:27 +0000 (14:31 +0200)
Zend/zend_API.h

index 72cd3856aeae6892705832881580c50b9475708c..264b67764572ef3095f222eba72bae27a3f2539e 100644 (file)
@@ -1527,6 +1527,9 @@ ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *
 #define Z_PARAM_ARRAY_HT(dest) \
        Z_PARAM_ARRAY_HT_EX(dest, 0, 0)
 
+#define Z_PARAM_ARRAY_HT_OR_NULL(dest) \
+       Z_PARAM_ARRAY_HT_EX(dest, 1, 0)
+
 /* old "H" */
 #define Z_PARAM_ARRAY_OR_OBJECT_HT_EX2(dest, check_null, deref, separate) \
                Z_PARAM_PROLOGUE(deref, separate); \
@@ -1593,6 +1596,24 @@ ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *
 #define Z_PARAM_OBJECT_OR_NULL(dest) \
        Z_PARAM_OBJECT_EX(dest, 1, 0)
 
+/* The same as Z_PARAM_OBJECT_EX2 except that dest is a zend_object rather than a zval */
+#define Z_PARAM_OBJ_EX2(dest, check_null, deref, separate) \
+               Z_PARAM_PROLOGUE(deref, separate); \
+               if (UNEXPECTED(!zend_parse_arg_obj(_arg, &dest, NULL, check_null))) { \
+                       _expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
+                       _error_code = ZPP_ERROR_WRONG_ARG; \
+                       break; \
+               }
+
+#define Z_PARAM_OBJ_EX(dest, check_null, separate) \
+       Z_PARAM_OBJ_EX2(dest, check_null, separate, separate)
+
+#define Z_PARAM_OBJ(dest) \
+       Z_PARAM_OBJ_EX(dest, 0, 0)
+
+#define Z_PARAM_OBJ_OR_NULL(dest) \
+       Z_PARAM_OBJ_EX(dest, 1, 0)
+
 /* old "O" */
 #define Z_PARAM_OBJECT_OF_CLASS_EX2(dest, _ce, check_null, deref, separate) \
                Z_PARAM_PROLOGUE(deref, separate); \
@@ -1983,6 +2004,19 @@ static zend_always_inline bool zend_parse_arg_object(zval *arg, zval **dest, zen
        return 1;
 }
 
+static zend_always_inline bool zend_parse_arg_obj(zval *arg, zend_object **dest, zend_class_entry *ce, bool check_null)
+{
+       if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) &&
+           (!ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce) != 0))) {
+               *dest = Z_OBJ_P(arg);
+       } else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
+               *dest = NULL;
+       } else {
+               return 0;
+       }
+       return 1;
+}
+
 static zend_always_inline bool zend_parse_arg_resource(zval *arg, zval **dest, bool check_null)
 {
        if (EXPECTED(Z_TYPE_P(arg) == IS_RESOURCE)) {