-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add support for binary, and octal number prefixes for INI settings #9560
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
This seems to be nearly what strtol() does in the spec:
|
67a564a
to
b172d3b
Compare
Reopenned to trigger CI which didn't want to start because it was targeting the wrong branch |
e2b9149
to
2a4d294
Compare
This drops support for PHP_MIN_VALUE as we now need to manually change the sign of the result. Therefore the lowest possible value without overflow is PHP_MIN_VALUE+1.
3fa80ff
to
e14035f
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.
Looks good to me
if (digits[0] == '0' && !isdigit(digits[1])) { | ||
/* Value is just 0 */ | ||
if ((digits+1) == str_end) { | ||
*errstr = NULL; | ||
return 0; | ||
} | ||
|
||
switch (digits[1]) { | ||
/* Multiplier suffixes */ | ||
case 'g': | ||
case 'G': | ||
case 'm': | ||
case 'M': | ||
case 'k': | ||
case 'K': | ||
goto evaluation; | ||
case 'x': | ||
case 'X': | ||
base = 16; | ||
break; |
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.
Nit: We could simplify like this:
if (digits[0] == '0' && !isdigit(digits[1])) { | |
/* Value is just 0 */ | |
if ((digits+1) == str_end) { | |
*errstr = NULL; | |
return 0; | |
} | |
switch (digits[1]) { | |
/* Multiplier suffixes */ | |
case 'g': | |
case 'G': | |
case 'm': | |
case 'M': | |
case 'k': | |
case 'K': | |
goto evaluation; | |
case 'x': | |
case 'X': | |
base = 16; | |
break; | |
if (digits[0] == '0') { | |
switch (digits[1]) { | |
case 'x': | |
case 'X': | |
base = 16; | |
digits += 2; | |
break; |
This allows to remove the special case for 0
, and the multiplier suffix cases in the switch.
We can then remove the if (UNEXPECTED(digits == str_end)) {
block (we can add a special case for "no digits after base prefix" in the "no valid leading digits" error bellow when base is not 0.)
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 tried doing this and if I try to simplify it then I don't think I can have an error for invalid prefixes
This gives feature parity with INI setting values to use number prefixes in the same way PHP integers can accept them.
Future scope could be to have support for
_
as sepators.However, I'm not exactly sure how to tackle the negative number case. I don't know if it's sensible to move past the negative sign, compute the values as unsigned and then check for overflows before multiplying it by
-1
.