Skip to content

PHPC-2111: Replace zend_parse_parameters calls with macros #1338

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

Merged
merged 4 commits into from
Jul 26, 2022

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Jul 25, 2022

@alcaeus alcaeus requested a review from jmikola July 25, 2022 11:41
@alcaeus alcaeus self-assigned this Jul 25, 2022
Z_PARAM_OPTIONAL
Z_PARAM_STRING_OR_NULL(uri_string, uri_string_len)
Z_PARAM_ARRAY_EX(options, 1, 1)
Z_PARAM_ARRAY_EX(driverOptions, 1, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted that Z_PARAM_ARRAY_EX's second and third arguments correspond to check_null and separate, respectively (see: lxr).

PHONGO_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_ZVAL(mode)
Z_PARAM_OPTIONAL
Z_PARAM_ARRAY_EX(tagSets, 1, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted this applies separate for the parsed zval. I believe the Manager and ReadPreference constructors were the only place where this was necessary.

@@ -145,7 +144,7 @@ static PHP_METHOD(WriteConcern, __construct)

switch (ZEND_NUM_ARGS()) {
case 3:
if (Z_TYPE_P(journal) != IS_NULL) {
if (journal && Z_TYPE_P(journal) != IS_NULL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this change necessary? Did zend_parse_parameters previously always initialize zval *journal or what this a long-standing bug?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the additional check I was presented with a compiler warning about journal potentially being uninitialised. Looking through the sources, we can see that zend_parse_arg_zval_deref will always assign the arg pointer to *dest if check_null is false (as is the case for journal). I'm not entirely sure what arg would be for optional arguments that weren't provided, or why this wasn't an issue before, especially considering that the call stack always ends up in the above zend_parse_arg_zval_deref function. I lack the internals knowledge to figure that one out, hence the simple NULL check.

@alcaeus alcaeus force-pushed the feature/phpc-2111 branch from fd7a261 to 4958e36 Compare July 26, 2022 07:35
@alcaeus alcaeus merged commit e2f9144 into mongodb:master Jul 26, 2022
@alcaeus alcaeus deleted the feature/phpc-2111 branch July 26, 2022 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants