Skip to content

Commit a9855a1

Browse files
committed
Fixed BCMATH_PARAM / PARSE macros
1 parent 796dc70 commit a9855a1

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

ext/bcmath/bcmath.c

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,33 +1285,15 @@ static int bcmath_number_compare(zval *op1, zval *op2)
12851285
return zend_std_compare_objects(op1, op2);
12861286
}
12871287

1288-
#define BCMATH_PARSE_PARAMETERS_START(min_num_args, max_num_args) \
1289-
bool bc_num_arg_error = false; \
1290-
ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
1291-
12921288
#define BCMATH_PARAM_NUMBER_OR_STR_OR_LONG(dest_obj, ce, dest_str, dest_long) \
12931289
Z_PARAM_PROLOGUE(0, 0); \
1294-
if (UNEXPECTED(!(zend_parse_arg_obj(_arg, &dest_obj, ce, 0) || \
1295-
zend_parse_arg_str_or_long(_arg, &dest_str, &dest_long, &_dummy, 0, _i)))) { \
1296-
bc_num_arg_error = true;\
1297-
break; \
1298-
}
1299-
1300-
#define BCMATH_PARSE_PARAMETERS_END() \
1301-
ZEND_ASSERT(_i == _max_num_args || _max_num_args == (uint32_t) -1); \
1302-
} while (0); \
1303-
if (UNEXPECTED(bc_num_arg_error)) { \
1304-
if (EG(exception)) { \
1305-
return; \
1306-
} \
1307-
zend_argument_type_error(_i, "must be of type int, string, or %s, %s given", \
1308-
ZSTR_VAL(bcmath_number_ce->name), zend_zval_value_name(_arg)); \
1309-
return; \
1310-
} else if (UNEXPECTED(_error_code != ZPP_ERROR_OK)) { \
1311-
zend_wrong_parameter_error(_error_code, _i, _error, _expected_type, _arg); \
1312-
return; \
1313-
} \
1314-
} while (0)
1290+
if (UNEXPECTED(!(zend_parse_arg_obj(_arg, &(dest_obj), ce, 0) || \
1291+
zend_parse_arg_str_or_long(_arg, &(dest_str), &(dest_long), &_dummy, 0, _i)))) { \
1292+
zend_argument_type_error(_i, "must be of type int, string, or %s, %s given", \
1293+
ZSTR_VAL(bcmath_number_ce->name), zend_zval_value_name(_arg)); \
1294+
_error_code = ZPP_ERROR_FAILURE; \
1295+
break; \
1296+
}
13151297

13161298
static zend_always_inline zend_result bc_num_from_obj_or_str_or_long_with_err(
13171299
bc_num *num, size_t *scale, zend_object *obj, zend_string *str, zend_long lval, uint32_t arg_num)
@@ -1366,11 +1348,11 @@ static void bcmath_number_calc_method(INTERNAL_FUNCTION_PARAMETERS, uint8_t opco
13661348
zend_long scale_lval = 0;
13671349
bool scale_is_null = true;
13681350

1369-
BCMATH_PARSE_PARAMETERS_START(1, 2)
1351+
ZEND_PARSE_PARAMETERS_START(1, 2)
13701352
BCMATH_PARAM_NUMBER_OR_STR_OR_LONG(num_obj, bcmath_number_ce, num_str, num_lval);
13711353
Z_PARAM_OPTIONAL
13721354
Z_PARAM_LONG_OR_NULL(scale_lval, scale_is_null);
1373-
BCMATH_PARSE_PARAMETERS_END();
1355+
ZEND_PARSE_PARAMETERS_END();
13741356

13751357
bc_num num = NULL;
13761358
size_t num_full_scale;
@@ -1472,12 +1454,12 @@ PHP_METHOD(BcMath_Number, powmod)
14721454
zend_long scale_lval = 0;
14731455
bool scale_is_null = true;
14741456

1475-
BCMATH_PARSE_PARAMETERS_START(2, 3)
1457+
ZEND_PARSE_PARAMETERS_START(2, 3)
14761458
BCMATH_PARAM_NUMBER_OR_STR_OR_LONG(exponent_obj, bcmath_number_ce, exponent_str, exponent_lval);
14771459
BCMATH_PARAM_NUMBER_OR_STR_OR_LONG(modulus_obj, bcmath_number_ce, modulus_str, modulus_lval);
14781460
Z_PARAM_OPTIONAL
14791461
Z_PARAM_LONG_OR_NULL(scale_lval, scale_is_null);
1480-
BCMATH_PARSE_PARAMETERS_END();
1462+
ZEND_PARSE_PARAMETERS_END();
14811463

14821464
bc_num exponent_num = NULL;
14831465
bc_num modulus_num = NULL;
@@ -1591,11 +1573,11 @@ PHP_METHOD(BcMath_Number, compare)
15911573
zend_long scale_lval = 0;
15921574
bool scale_is_null = true;
15931575

1594-
BCMATH_PARSE_PARAMETERS_START(1, 2)
1576+
ZEND_PARSE_PARAMETERS_START(1, 2)
15951577
BCMATH_PARAM_NUMBER_OR_STR_OR_LONG(num_obj, bcmath_number_ce, num_str, num_lval);
15961578
Z_PARAM_OPTIONAL
15971579
Z_PARAM_LONG_OR_NULL(scale_lval, scale_is_null);
1598-
BCMATH_PARSE_PARAMETERS_END();
1580+
ZEND_PARSE_PARAMETERS_END();
15991581

16001582
bc_num num = NULL;
16011583
size_t num_full_scale;

0 commit comments

Comments
 (0)