Skip to content

Commit e50cb32

Browse files
committed
Add the Z_PARAM_ARRAY_HT_OR_NULL and Z_PARAM_OBJ macros
1 parent 7805b97 commit e50cb32

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Zend/zend_API.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,9 @@ ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *
15271527
#define Z_PARAM_ARRAY_HT(dest) \
15281528
Z_PARAM_ARRAY_HT_EX(dest, 0, 0)
15291529

1530+
#define Z_PARAM_ARRAY_HT_OR_NULL(dest) \
1531+
Z_PARAM_ARRAY_HT_EX(dest, 1, 0)
1532+
15301533
/* old "H" */
15311534
#define Z_PARAM_ARRAY_OR_OBJECT_HT_EX2(dest, check_null, deref, separate) \
15321535
Z_PARAM_PROLOGUE(deref, separate); \
@@ -1593,6 +1596,24 @@ ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *
15931596
#define Z_PARAM_OBJECT_OR_NULL(dest) \
15941597
Z_PARAM_OBJECT_EX(dest, 1, 0)
15951598

1599+
/* The same as Z_PARAM_OBJECT_EX2 except that dest is a zend_object rather than a zval */
1600+
#define Z_PARAM_OBJ_EX2(dest, check_null, deref, separate) \
1601+
Z_PARAM_PROLOGUE(deref, separate); \
1602+
if (UNEXPECTED(!zend_parse_arg_obj(_arg, &dest, NULL, check_null))) { \
1603+
_expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
1604+
_error_code = ZPP_ERROR_WRONG_ARG; \
1605+
break; \
1606+
}
1607+
1608+
#define Z_PARAM_OBJ_EX(dest, check_null, separate) \
1609+
Z_PARAM_OBJ_EX2(dest, check_null, separate, separate)
1610+
1611+
#define Z_PARAM_OBJ(dest) \
1612+
Z_PARAM_OBJ_EX(dest, 0, 0)
1613+
1614+
#define Z_PARAM_OBJ_OR_NULL(dest) \
1615+
Z_PARAM_OBJ_EX(dest, 1, 0)
1616+
15961617
/* old "O" */
15971618
#define Z_PARAM_OBJECT_OF_CLASS_EX2(dest, _ce, check_null, deref, separate) \
15981619
Z_PARAM_PROLOGUE(deref, separate); \
@@ -1983,6 +2004,19 @@ static zend_always_inline bool zend_parse_arg_object(zval *arg, zval **dest, zen
19832004
return 1;
19842005
}
19852006

2007+
static zend_always_inline bool zend_parse_arg_obj(zval *arg, zend_object **dest, zend_class_entry *ce, bool check_null)
2008+
{
2009+
if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) &&
2010+
(!ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce) != 0))) {
2011+
*dest = Z_OBJ_P(arg);
2012+
} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2013+
*dest = NULL;
2014+
} else {
2015+
return 0;
2016+
}
2017+
return 1;
2018+
}
2019+
19862020
static zend_always_inline bool zend_parse_arg_resource(zval *arg, zval **dest, bool check_null)
19872021
{
19882022
if (EXPECTED(Z_TYPE_P(arg) == IS_RESOURCE)) {

0 commit comments

Comments
 (0)