Skip to content

PHPC-635: WriteResult debug handler should return objects #472

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 1 commit into from
Dec 19, 2016

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Nov 28, 2016

@jmikola jmikola changed the title [WIP] PHPC-635: WriteResult debug handler should return objects PHPC-635: WriteResult debug handler should return objects Nov 28, 2016
uint32_t len;
const uint8_t *data = NULL;

bson_iter_document(&iter, &len, &data);
Copy link
Member Author

Choose a reason for hiding this comment

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

BSON_ITER_HOLDS_DOCUMENT() and bson_iter_document() is consistent with what we were already doing in phongo_writeconcernerror_init() for a very similar routine. This replaces the previous bson_append_iter() code path, which is much less common.


bson_iter_document(&iter, &len, &data);

if (!data) {
return false;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

With BSON_ITER_HOLDS_DOCUMENT() guarding this block, bson_iter_document() will always populate the document's data. This removes an odd case where we might have returned false without throwing. If the data is somehow null after this (I can't imagine how), phongo_bson_to_zval() will catch and throw an error when initializing the BSON reader.

return false;
}

ZVAL_ZVAL(return_value, writeconcernerror, 1, 1);
Copy link
Member Author

Choose a reason for hiding this comment

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

I ran into trouble trying to use zval_ptr_dtor() on the input argument so it seemed more straightforward to create my own zval in this function and copy it into the return value on success. For any failure case, we clean up our internally allocated zval and leave the return value initialized to null.

@@ -50,6 +50,108 @@ PHONGO_API zend_class_entry *php_phongo_writeresult_ce;

zend_object_handlers php_phongo_handler_writeresult;

static bool php_phongo_writeresult_get_writeconcernerror(php_phongo_writeresult_t *intern, zval *return_value TSRMLS_DC)
Copy link
Member Author

Choose a reason for hiding this comment

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

Although these two functions return a boolean indicating their success, we don't actually check for it later. The return value is always initialized to something usable (e.g. empty array or null), so we add it to the debug info's hash regardless. If an exception was thrown, it will be caught above the debug handler (technically get_properties).

@jmikola
Copy link
Member Author

jmikola commented Dec 16, 2016

@derickr: We didn't want to stuff this into 1.2.0 at the last minute, but I believe it's worth revisiting for inclusion in a future release. Please review when you get a chance.

Copy link
Contributor

@derickr derickr left a comment

Choose a reason for hiding this comment

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

LGTM

@jmikola jmikola merged commit 2599607 into mongodb:master Dec 19, 2016
jmikola added a commit that referenced this pull request Dec 19, 2016
@jmikola jmikola deleted the phpc-635 branch December 19, 2016 15:57
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