Skip to content

Commit be6bded

Browse files
committed
Remove BC breaks from previous implementation
1 parent 36f3060 commit be6bded

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

ext/gmp/gmp.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,22 @@ static zend_result shift_operator_helper(gmp_binary_ui_op_t op, zval *return_val
339339

340340
if (UNEXPECTED(Z_TYPE_P(op2) != IS_LONG)) {
341341
if (UNEXPECTED(!IS_GMP(op2))) {
342-
goto typeof_op_failure;
342+
// For PHP 8.3 and up use zend_try_get_long()
343+
switch (Z_TYPE_P(op2)) {
344+
case IS_DOUBLE:
345+
shift = zval_get_long(op2);
346+
if (UNEXPECTED(EG(exception))) {
347+
return FAILURE;
348+
}
349+
break;
350+
case IS_STRING:
351+
if (is_numeric_str_function(Z_STR_P(op2), &shift, NULL) != IS_LONG) {
352+
goto valueof_op_failure;
353+
}
354+
break;
355+
default:
356+
goto typeof_op_failure;
357+
}
343358
} else {
344359
// TODO We shouldn't cast the GMP object to int here
345360
shift = zval_get_long(op2);
@@ -399,6 +414,9 @@ typeof_op_failure: ;
399414
}
400415
zend_type_error("Unsupported operand types: %s %s %s", zend_zval_type_name(op1), op_sigil, zend_zval_type_name(op2));
401416
return FAILURE;
417+
valueof_op_failure:
418+
zend_value_error("Number is not an integer string");
419+
return FAILURE;
402420
}
403421

404422
#define DO_BINARY_UI_OP_EX(op, uop, check_b_zero) \

ext/gmp/tests/overloading_with_float_string.phpt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,9 @@ ValueError: Number is not an integer string
7676
ValueError: Number is not an integer string
7777
ValueError: Number is not an integer string
7878
ValueError: Number is not an integer string
79-
object(GMP)#3 (1) {
80-
["num"]=>
81-
string(4) "1764"
82-
}
8379
ValueError: Number is not an integer string
8480
ValueError: Number is not an integer string
8581
ValueError: Number is not an integer string
86-
object(GMP)#2 (1) {
87-
["num"]=>
88-
string(3) "168"
89-
}
90-
object(GMP)#2 (1) {
91-
["num"]=>
92-
string(2) "10"
93-
}
82+
ValueError: Number is not an integer string
83+
ValueError: Number is not an integer string
84+
ValueError: Number is not an integer string

ext/gmp/tests/overloading_with_non_numeric_string.phpt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,9 @@ ValueError: Number is not an integer string
7676
ValueError: Number is not an integer string
7777
ValueError: Number is not an integer string
7878
ValueError: Number is not an integer string
79-
object(GMP)#3 (1) {
80-
["num"]=>
81-
string(1) "1"
82-
}
8379
ValueError: Number is not an integer string
8480
ValueError: Number is not an integer string
8581
ValueError: Number is not an integer string
86-
object(GMP)#2 (1) {
87-
["num"]=>
88-
string(2) "42"
89-
}
90-
object(GMP)#2 (1) {
91-
["num"]=>
92-
string(2) "42"
93-
}
82+
ValueError: Number is not an integer string
83+
ValueError: Number is not an integer string
84+
ValueError: Number is not an integer string

0 commit comments

Comments
 (0)