-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ext/gmp: Fix some issues regarding operator overloading #16015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0d853a2
ext/gmp: Add behavioural tests for operator overloading
Girgias e1a8d54
ext/gmp: Fix segfault when null is encountered on an overloaded operator
Girgias a4bc271
Revert "ext/gmp: Fix segfault when null is encountered on an overload…
Girgias c3f81b4
ext/gmp: Fix segfault when null is encountered on an overloaded operator
Girgias b8655f3
ext/gmp: Throw TypeError for unusable types for <<, >>, and ** ops
Girgias 4141ba0
Address review comments
Girgias 3efb1eb
Add test for numeric int
Girgias 0f2ec43
Add float string behaviour
Girgias bc24f27
Add non-numeric string test
Girgias 36f3060
Add float tests
Girgias be6bded
Remove BC breaks from previous implementation
Girgias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--TEST-- | ||
GMP comparison operator overloading supports null | ||
--EXTENSIONS-- | ||
gmp | ||
--FILE-- | ||
<?php | ||
|
||
$num = gmp_init(42); | ||
|
||
try { | ||
var_dump($num < null); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num > null); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num <= null); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num >= null); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num == null); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num <=> null); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
bool(false) | ||
bool(true) | ||
bool(false) | ||
bool(true) | ||
bool(false) | ||
int(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--TEST-- | ||
GMP operator overloading does not support [] | ||
--EXTENSIONS-- | ||
gmp | ||
--FILE-- | ||
<?php | ||
|
||
$num = gmp_init(42); | ||
|
||
try { | ||
var_dump($num + []); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num - []); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num * []); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num / []); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num % []); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num ** []); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num | []); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
try { | ||
var_dump($num & []); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
try { | ||
var_dump($num ^ []); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
try { | ||
var_dump($num << []); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
try { | ||
var_dump($num >> []); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
TypeError: Number must be of type GMP|string|int, array given | ||
TypeError: Number must be of type GMP|string|int, array given | ||
TypeError: Number must be of type GMP|string|int, array given | ||
TypeError: Number must be of type GMP|string|int, array given | ||
TypeError: Number must be of type GMP|string|int, array given | ||
TypeError: Unsupported operand types: GMP ** array | ||
TypeError: Number must be of type GMP|string|int, array given | ||
TypeError: Number must be of type GMP|string|int, array given | ||
TypeError: Number must be of type GMP|string|int, array given | ||
TypeError: Unsupported operand types: GMP << array | ||
TypeError: Unsupported operand types: GMP >> array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
--TEST-- | ||
GMP operator overloading does support float with no fractional | ||
--EXTENSIONS-- | ||
gmp | ||
--FILE-- | ||
<?php | ||
|
||
$num = gmp_init(42); | ||
|
||
try { | ||
var_dump($num + 42.0); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num - 42.0); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num * 42.0); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num / 42.0); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num % 42.0); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num ** 42.0); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
try { | ||
var_dump($num | 42.0); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
try { | ||
var_dump($num & 42.0); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
try { | ||
var_dump($num ^ 42.0); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
try { | ||
var_dump($num << 42.0); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
try { | ||
var_dump($num >> 42.0); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
object(GMP)#2 (1) { | ||
["num"]=> | ||
string(2) "84" | ||
} | ||
object(GMP)#2 (1) { | ||
["num"]=> | ||
string(1) "0" | ||
} | ||
object(GMP)#2 (1) { | ||
["num"]=> | ||
string(4) "1764" | ||
} | ||
object(GMP)#2 (1) { | ||
["num"]=> | ||
string(1) "1" | ||
} | ||
object(GMP)#2 (1) { | ||
["num"]=> | ||
string(1) "0" | ||
} | ||
object(GMP)#2 (1) { | ||
["num"]=> | ||
string(69) "150130937545296572356771972164254457814047970568738777235893533016064" | ||
} | ||
object(GMP)#2 (1) { | ||
["num"]=> | ||
string(2) "42" | ||
} | ||
object(GMP)#2 (1) { | ||
["num"]=> | ||
string(2) "42" | ||
} | ||
object(GMP)#2 (1) { | ||
["num"]=> | ||
string(1) "0" | ||
} | ||
object(GMP)#2 (1) { | ||
["num"]=> | ||
string(15) "184717953466368" | ||
} | ||
object(GMP)#2 (1) { | ||
["num"]=> | ||
string(1) "0" | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing