-
Notifications
You must be signed in to change notification settings - Fork 209
PHPC-348: Check for errors after calling bson_to_zval() #1034
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
@jmikola heads up, I've changed all instances to return early to avoid subsequent operations if we're going to throw an exception anyways. I figured this is most sensible considering we don't want multiple exceptions to be thrown as they would create confusion. As mentioned, there are a few more instances in |
src/MongoDB/Command.c
Outdated
php_phongo_bson_to_zval(bson_get_data(intern->bson), intern->bson->len, &zv); | ||
if (!php_phongo_bson_to_zval(bson_get_data(intern->bson), intern->bson->len, &zv)) { | ||
zval_ptr_dtor(&zv); | ||
return Z_ARRVAL(retval); |
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.
Thoughts on using goto done;
and adding a done:
label above the original return Z_ARRVAL(retval);
line at the end of this function? It'd be closer to what we do in other places with failure/cleanup jumps.
I wouldn't suggest this for cases where we're simply returning (e.g. Javascript::getScope()
), but I think helps avoid duplication when we're returning an expression, which could get out of sync. If so, other get_debug_info
handlers could get the same treatment.
Happy to defer to you on this. You're also allowed to berate me for publicly advocating for a goto
statement :)
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.
That said, use of goto
as a replacement for finally
and failure returns is established in the driver, so I don't mind adding those here as well 👍
https://jira.mongodb.org/browse/PHPC-348
Note: there are three occurrences of
php_phongo_bson_to_zval_ex
inCursor.c
(1, 2, 3) where I wasn't sure if freeing the result was a good idea.When used in the
debug_info
functions, I thought it was best to addnull
values and continue assembling the output, but we may want to return without processing any further properties. I'm not quite sure what the preferred course of action is.