Skip to content

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Oct 7, 2019

https://jira.mongodb.org/browse/PHPC-348

Note: there are three occurrences of php_phongo_bson_to_zval_ex in Cursor.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 add null 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.

@alcaeus alcaeus requested a review from jmikola October 7, 2019 19:17
@alcaeus alcaeus self-assigned this Oct 7, 2019
@alcaeus
Copy link
Member Author

alcaeus commented Oct 25, 2019

@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 MongoDB\BSON\Javascript, but I'll clean those up once this PR and #1036 are merged.

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);
Copy link
Member

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 :)

Copy link
Member Author

Choose a reason for hiding this comment

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

XKCD goto
(Source: XKCD)

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 👍

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