-
Notifications
You must be signed in to change notification settings - Fork 7.8k
RFC: Add the RoundingMode enum #14833
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
Conversation
cff3949
to
a8d1e94
Compare
a8d1e94
to
7b54dc6
Compare
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.
At least the BCMath changes and the logic to convert the enum back to a mode seem right.
ext/bcmath/bcmath.c
Outdated
zend_argument_value_error(3, "must be a valid rounding mode (PHP_ROUND_*)"); | ||
/* This is currently unreachable, but might become reachable when new modes are added. */ | ||
zend_argument_value_error(3, " is a rounding mode that is not supported"); |
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 don't see how this can happen now? As the value should always be a correct mode from the enum object, turning this into an assertion seems more logical.
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.
Cannot happen now (as the comment indicates), but can happen if additional cases are added to the RoundingMode
enum in the future that cannot (easily) be supported with BCMath or where the implementation forgets to adjust BCMath.
This error message is thus intended to fail safely rather than crashing or returning bogus values.
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 would rather have this be an assertion and have a test in BC Math that cycles through all the cases of the enum to be sure we don't miss any new ones introduced.
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've added an additional test based on round_RoundingMode.phpt
that goes through all the enum cases, but I've preserved the error message instead of replacing it by an assert. The RoundingMode enum is owned by ext/standard, not ext/bcmath, so to me defensive programming makes sense there.
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
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.
Great
This one will make sure that bcround() is not forgotten when adding rounding modes.
Hello there, I bisected to find why
Apparently, since this PR we have issue in Nix to build the Build log + failing tests
It looks like it cannot find the The issue has been discovered thanks to Find the last successful build at: https://github.com/loophp/php-src-nix/actions/runs/9925576082 |
@petk is this related to some recent build script changes? |
I'm not sure I understand... This PR? |
Bisected to this commit: 5905857 |
Ah, sorry, I didn't see the comment above. I'll check. |
@Girgias, @drupol, @TimWolla, I think this should be the issue (there is missing PHPAPI). Is this it? --- a/ext/standard/php_math_round_mode.h
+++ b/ext/standard/php_math_round_mode.h
@@ -52,4 +52,4 @@
extern PHPAPI zend_class_entry *rounding_mode_ce;
-int php_math_round_mode_from_enum(zend_object *mode);
+PHPAPI int php_math_round_mode_from_enum(zend_object *mode); Issue can be also reproduced like this:
|
Let me patch and retry. |
Yes, that fixed the issue immediately. I created the PR. Let me know if it's OK. |
RFC: https://wiki.php.net/rfc/correctly_name_the_rounding_mode_and_make_it_an_enum