-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ext/gmp: Minor refactorings #15346
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
base: master
Are you sure you want to change the base?
ext/gmp: Minor refactorings #15346
Conversation
ext/gmp/gmp.c
Outdated
bool failed = true; | ||
zend_long shift = zval_try_get_long(op2, &failed); | ||
if (failed) { | ||
//char operator_sigil[2]; |
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.
Left-over comment?
ext/gmp/gmp.c
Outdated
zend_long shift = zval_try_get_long(op2, &failed); | ||
if (failed) { | ||
//char operator_sigil[2]; | ||
char *operator_sigil; |
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.
Should be const
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.
Right, I initially tried to do some stuff with the fixed width char array to be const but my IDE was complaining.
operator_sigil = ">>"; | ||
} | ||
|
||
zend_type_error("Unsupported operand types: GMP %s %s", operator_sigil, zend_zval_value_name(op2)); |
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.
zval_try_get_long
can already throw. This will be chained, but is that desirable?
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.
For reasons that I don't understand it was not actually throwing an exception, might be doing something dumb
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.
Actually I double-checked, and it does not throw an exception (contrary to the non try version)
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.
If you start from an object then the function could fail with an exception. Similarly, passing a double will cause a conversion to a long which can warn and thus can also trigger an exception. So exceptions seem possible to me. I guess it's fine though to chain it with the extra exception you're throwing here. Wdyt ?
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.
I created a test case for this:
<?php
set_error_handler(function () {
throw new Error('whoops');
});
$gmp = new GMP("5");
$gmp << 3.14;
Outputs this for me with this PR:
Fatal error: Uncaught Error: whoops in /run/media/niels/MoreData/php-src/x.php:4
Stack trace:
#0 /run/media/niels/MoreData/php-src/x.php(8): {closure:/run/media/niels/MoreData/php-src/x.php:3}(8192, 'Implicit conver...', '/run/media/niel...', 8)
#1 {main}
Next TypeError: Unsupported operand types: GMP << float in /run/media/niels/MoreData/php-src/x.php:8
Stack trace:
#0 {main}
thrown in /run/media/niels/MoreData/php-src/x.php on line 8
maybe that's fine though.
95de410
to
b9d6463
Compare
I merged the first 3 commits and rebased. |
No description provided.