-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[random] split getInt() with no arguments into nextInt() #9057
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
if ($e->getMessage() !== 'Generated value exceeds size of int') { | ||
die($engine::class . ': nextInt: failure: {$e->getMesasge()}'); | ||
throw $e; |
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.
- before this
if
, other similar tests (compatibility_user.phpt) first do aif (\PHP_INT_SIZE >= 8) { throw $e; }
- typo in the
die
:$e->getMesasge()
should be$e->getMessage()
- bug in the
die
: single-quotes should be double-quotes, or (maybe better) replace string interpolation with concatenation - this
throw
is unreachable (after adie
)
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.
My brain was shutting down.
I will fix it. I am ashamed. 😭
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.
fixed: d78c647
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.
In the case of nextInt(), the method is checked for exception messages, since conditional branching by PHP_INT_SIZE would completely prevent the method from being tested
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.
OK for the fixes (of my last 3 points),
but I don't understand your last comment (about my first point) 😕 I saw
php-src/ext/random/tests/03_randomizer/compatibility_user.phpt
Lines 45 to 52 in d78c647
} catch (\RuntimeException $e) { | |
if (\PHP_INT_SIZE >= 8) { | |
throw $e; | |
} | |
if ($e->getMessage() !== 'Generated value exceeds size of int') { | |
throw $e; | |
} | |
} |
} catch (\RuntimeException $e) {
+ if (\PHP_INT_SIZE >= 8) {
+ die($engine::class . ": nextInt: failure: {$e->getMessage()}");
+ }
if ($e->getMessage() !== 'Generated value exceeds size of int') {
die($engine::class . ": nextInt: failure: {$e->getMessage()}");
}
}
? or maybe merge the two if
s into one if ($e->getMessage() !== 'Generated value exceeds size of int' || \PHP_INT_SIZE >= 8)
(in both files)? (just questions BTW, not blocking this PR)
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.
Sorry. I was confused again.
This is completely unnecessary and should be removed. If it is a good thing to modify at the same time as this PR, I will do so now. 😭
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.
Sorry. I was confused again.
No big deal 😄
This is completely unnecessary and should be removed.
Well, I thought that it was at least testing that nextInt() doesn't throw a "Generated value exceeds size of int" exception on 64-bit systems, but you know better 😉
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.
fixed: 7c41dd9
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.
Fine (I guess, given
php-src/ext/random/randomizer.c
Lines 97 to 99 in 7c41dd9
result = randomizer->algo->generate(randomizer->status); | |
if (randomizer->status->last_generated_size > sizeof(zend_long)) { | |
zend_throw_exception(spl_ce_RuntimeException, "Generated value exceeds size of int", 0); |
php-src/ext/random/engine_user.c
Lines 36 to 40 in 7c41dd9
/* Guard for over 64-bit results */ | |
if (size > sizeof(uint64_t)) { | |
size = sizeof(uint64_t); | |
} | |
status->last_generated_size = size; |
sizeof(zend_long)
is equal to sizeof(uint64_t)
on 64-bit systems), but as I said, there were 2 occurrences in that file (compatibility_user.phpt), but you only removed the first one; did you "forget" to also remove the second one (php-src/ext/random/tests/03_randomizer/compatibility_user.phpt
Lines 72 to 74 in 7c41dd9
if (\PHP_INT_SIZE >= 8) { | |
throw $e; | |
} |
Xoshiro256StarStar
(although it apparently wasn't for PcgOneseq128XslRr64
)?
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.
Thank you for your calm and measured point of view. I was totally confused. From what I see, the guard test is unnecessary as it is tested in get_bytes.phpt. I have removed the if completely.
fixed: 5144026
53e82e4
to
d78c647
Compare
7c41dd9
to
5144026
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.
Thank you! I'm very much in favor of splitting the method in two. The patch looks good to me.
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.
The diff looks reasonable to me. Just one remark to clarify that nextInt()
will return positive numbers only, as the most-significant bit is shifted out.
I guess the release managers should decide on this one?
@ramsey, @saundefined, @adoy, any objections? If this gets merged, the RFC should probably be amended, so that the doc team won't put outdated information in the migration guide. |
Will this change the RFC in any way that would have caused any voters to vote "no" had this been part of the original RFC? |
Since the method is only separated, I don't think anyone would be negative about it, or that it would be so negative that it would be rejected if a vote were actually taken. Nevertheless, this is a very exceptional measure and may set a bad precedent. As PHP 8.2 Release Manager, can you hearing the ML if they have any objections to this change? I apologize for the extra hassle this has caused. |
8885bad
to
a92af01
Compare
Specific ML thread (created shortly after this PR): https://externals.io/message/118290
There has already been precedents, e.g. https://externals.io/message/117136, not necessarily "bad" ;) |
It might be useful to get a decision here, so that this can go into Beta 2 (or not).
I agree with zeriyoshi's argument here. The same functionality is still available, just separated into two independent methods with a cleaner method signature for each of them. |
If there are no objections, I'll merge this on Monday. @zeriyoshi, could you please fix the merge conflicts? |
…xtInt() Since argument overloading is not safe for reflection, the method needed to be split appropriately.
Co-authored-by: Tim Düsterhus <[email protected]>
a92af01
to
908cb0b
Compare
The Random Extension 5.x and Random Extension Improvement proposals passed, but with the problem of argument overloading.
#8094
As noted by some, argument overloading is now discouraged and should not be implemented anew.
https://externals.io/message/118163#118269
https://github.com/php/php-src/pull/8094/files#r919693108
cc / @TimWolla @kocsismate
I am sorry for the review you gave us.
I have split the PR and corrected the points you pointed out.