Skip to content

Commit feae6eb

Browse files
committed
Zend: refactor fast ZPP to only use zend_expected_type
Removing the usage of zpp_error and allowing 'slow' ZPP to reuse the error logic
1 parent 7bc1cb2 commit feae6eb

5 files changed

Lines changed: 39 additions & 121 deletions

File tree

Zend/zend_API.c

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -359,49 +359,49 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_or_null_error(uint32_t
359359
}
360360
/* }}} */
361361

362-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(zpp_error error_code, uint32_t num, char *name, zend_expected_type expected_type, const zval *arg) /* {{{ */
362+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(uint32_t num, char *name, zend_expected_type expected_type, const zval *arg) /* {{{ */
363363
{
364-
switch (error_code) {
365-
case ZPP_ERROR_WRONG_CALLBACK:
364+
switch (expected_type) {
365+
case Z_EXPECTED_FUNC:
366366
zend_wrong_callback_error(num, name);
367367
break;
368-
case ZPP_ERROR_WRONG_CALLBACK_OR_NULL:
368+
case Z_EXPECTED_FUNC_OR_NULL:
369369
zend_wrong_callback_or_null_error(num, name);
370370
break;
371-
case ZPP_ERROR_WRONG_CLASS_NAME:
371+
case Z_EXPECTED_CLASS_NAME:
372372
zend_wrong_class_name_error(num, name, arg);
373373
break;
374-
case ZPP_ERROR_WRONG_CLASS_NAME_OR_NULL:
374+
case Z_EXPECTED_CLASS_NAME_OR_NULL:
375375
zend_wrong_class_name_or_null_error(num, name, arg);
376376
break;
377-
case ZPP_ERROR_WRONG_CLASS:
377+
case Z_EXPECTED_CLASS:
378378
zend_wrong_parameter_class_error(num, name, arg);
379379
break;
380-
case ZPP_ERROR_WRONG_CLASS_OR_NULL:
380+
case Z_EXPECTED_CLASS_OR_NULL:
381381
zend_wrong_parameter_class_or_null_error(num, name, arg);
382382
break;
383-
case ZPP_ERROR_WRONG_CLASS_OR_STRING:
383+
case Z_EXPECTED_CLASS_OR_STRING:
384384
zend_wrong_parameter_class_or_string_error(num, name, arg);
385385
break;
386-
case ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL:
386+
case Z_EXPECTED_CLASS_OR_STRING_OR_NULL:
387387
zend_wrong_parameter_class_or_string_or_null_error(num, name, arg);
388388
break;
389-
case ZPP_ERROR_WRONG_CLASS_OR_LONG:
389+
case Z_EXPECTED_CLASS_OR_LONG:
390390
zend_wrong_parameter_class_or_long_error(num, name, arg);
391391
break;
392-
case ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL:
392+
case Z_EXPECTED_CLASS_OR_LONG_OR_NULL:
393393
zend_wrong_parameter_class_or_long_or_null_error(num, name, arg);
394394
break;
395-
case ZPP_ERROR_WRONG_ARG:
395+
default:
396396
zend_wrong_parameter_type_error(num, expected_type, arg);
397397
break;
398-
case ZPP_ERROR_UNEXPECTED_EXTRA_NAMED:
398+
case Z_EXPECTED_NO_EXTRA_NAMED:
399399
zend_unexpected_extra_named_error();
400400
break;
401-
case ZPP_ERROR_FAILURE:
401+
case Z_EXPECTED_FAILURE:
402402
ZEND_ASSERT(EG(exception) && "Should have produced an error already");
403403
break;
404-
case ZPP_ERROR_OK:
404+
case Z_EXPECTED_OK:
405405
ZEND_UNREACHABLE();
406406
}
407407
}
@@ -1095,48 +1095,7 @@ static zend_result zend_parse_arg(uint32_t arg_num, zval *arg, va_list *va, cons
10951095
}
10961096

10971097
if (!(flags & ZEND_PARSE_PARAMS_QUIET)) {
1098-
/* More complex error, can only happen for:
1099-
* Objects of a specific class
1100-
* Z_EXPECTED_OBJECT
1101-
* Z_EXPECTED_OBJECT_OR_NULL
1102-
* Class names
1103-
* Z_EXPECTED_OBJECT_OR_CLASS_NAME
1104-
* Z_EXPECTED_OBJECT_OR_CLASS_NAME_OR_NULL
1105-
* Functions
1106-
* Z_EXPECTED_FUNC
1107-
* Z_EXPECTED_FUNC_OR_NULL
1108-
*/
1109-
if (error) {
1110-
switch (expected_type) {
1111-
case Z_EXPECTED_OBJECT:
1112-
/* DO NOT FREE error: it's a pointer to ZSTR_VAL(ce->name) */
1113-
zend_wrong_parameter_class_error(arg_num, error, arg);
1114-
break;
1115-
case Z_EXPECTED_OBJECT_OR_NULL:
1116-
/* DO NOT FREE error: it's a pointer to ZSTR_VAL(ce->name) */
1117-
zend_wrong_parameter_class_or_null_error(arg_num, error, arg);
1118-
break;
1119-
case Z_EXPECTED_FUNC:
1120-
/* error is freed by zend_wrong_callback_error() */
1121-
zend_wrong_callback_error(arg_num, error);
1122-
break;
1123-
case Z_EXPECTED_FUNC_OR_NULL:
1124-
/* error is freed by zend_wrong_callback_or_null_error() */
1125-
zend_wrong_callback_or_null_error(arg_num, error);
1126-
break;
1127-
case Z_EXPECTED_CLASS_NAME:
1128-
/* DO NOT FREE error: it's a pointer to ZSTR_VAL(ce->name) */
1129-
zend_wrong_class_name_error(arg_num, error, arg);
1130-
break;
1131-
case Z_EXPECTED_CLASS_NAME_OR_NULL:
1132-
/* DO NOT FREE error: it's a pointer to ZSTR_VAL(ce->name) */
1133-
zend_wrong_class_name_or_null_error(arg_num, error, arg);
1134-
break;
1135-
default:
1136-
ZEND_UNREACHABLE();
1137-
}
1138-
}
1139-
zend_wrong_parameter_type_error(arg_num, expected_type, arg);
1098+
zend_wrong_parameter_error(arg_num, error, expected_type, arg);
11401099
} else if (error
11411100
/* Only free error if it's a callable expected type, as otherwise it's a pointer to ZSTR_VAL(ce->name) */
11421101
&& (expected_type == Z_EXPECTED_FUNC || expected_type == Z_EXPECTED_FUNC_OR_NULL)) {

0 commit comments

Comments
 (0)