ZPP: Return tristate from zend_parse_arg_bool_weak()#21739
Open
Girgias wants to merge 4 commits intophp:masterfrom
Open
ZPP: Return tristate from zend_parse_arg_bool_weak()#21739Girgias wants to merge 4 commits intophp:masterfrom
Girgias wants to merge 4 commits intophp:masterfrom
Conversation
AWS x86_64 (c6id.metal)
Laravel 12.11.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)
Symfony 2.8.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)
Wordpress 6.9 main page - 50 iterations, 20 warmups, 20 requests (sec)
bench.php - 50 iterations, 20 warmups, 2 requests (sec)
|
iluuu1994
approved these changes
Apr 13, 2026
Member
iluuu1994
left a comment
There was a problem hiding this comment.
Nice! Looks to be profitable.
Zend/zend_API.h
Outdated
|
|
||
| /* Inlined implementations shared by new and old parameter parsing APIs */ | ||
|
|
||
| typedef enum ZPP_PARSE_BOOL_STATUS { |
Member
There was a problem hiding this comment.
Should just be zpp_parse_bool_status.
Zend/zend_API.h
Outdated
| /* Inlined implementations shared by new and old parameter parsing APIs */ | ||
|
|
||
| typedef enum ZPP_PARSE_BOOL_STATUS { | ||
| ZPP_PARSE_AS_FALSE = 0, |
Member
There was a problem hiding this comment.
IMO, should have a consistent prefix, i.e. ZPP_PARSE_BOOL_STATUS_FALSE.
Zend/zend_API.c
Outdated
Comment on lines
+514
to
+520
| if (EXPECTED(Z_TYPE_P(arg) <= IS_STRING)) { | ||
| if (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) && !zend_null_arg_deprecated("bool", arg_num)) { | ||
| return 0; | ||
| return ZPP_PARSE_ERROR; | ||
| } | ||
| *dest = zend_is_true(arg); | ||
| } else { | ||
| return 0; | ||
| return zend_is_true(arg); | ||
| } | ||
| return 1; | ||
| return ZPP_PARSE_ERROR; |
Member
There was a problem hiding this comment.
Happy path sandwich. Maybe:
if (UNEXPECTED(Z_TYPE_P(arg) > IS_STRING)) {
return ZPP_PARSE_ERROR;
}
if (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) && !zend_null_arg_deprecated("bool", arg_num)) {
return ZPP_PARSE_ERROR;
}
return zend_is_true(arg);
Zend/zend_API.h
Outdated
| *dest = str; | ||
| } else { | ||
| return zend_parse_arg_str_slow(arg, dest, arg_num); | ||
| return 0; |
Member
There was a problem hiding this comment.
Consistent handling with the other cases? I.e. write to and check *dest without a branch? This won't work for zpp_parse_bool_status because of bool coercion, but should work here.
| if (EXPECTED(!strict)) { | ||
| zend_string *str; | ||
| zval tmp; | ||
| zend_string *str; |
90efcd9 to
5c689b4
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up PR on top of #21737.
This idea is based on @ndossche previous PR to reduce codebloat: #18436
This effectively allows us to return the boolean value via the return type rather than using an out pointer.