Skip to content

PHPC-1162: Add reference to currentDocument in debug info #811

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
Apr 18, 2018

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Apr 16, 2018

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

This fixes a segfault while dumping the cursor between iterations with IteratorIterator.

@jmikola jmikola requested review from derickr and kvwalker April 16, 2018 20:42
@@ -509,7 +509,7 @@ static HashTable *php_phongo_cursor_get_debug_info(zval *object, int *is_temp TS
if (!Z_ISUNDEF(intern->visitor_data.zchild)) {
#if PHP_VERSION_ID >= 70000
ADD_ASSOC_ZVAL_EX(&retval, "currentDocument", &intern->visitor_data.zchild);
/*Z_ADDREF(intern->visitor_data.zchild);*/
Z_ADDREF(intern->visitor_data.zchild);
Copy link
Contributor

Choose a reason for hiding this comment

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

Where are you removing this reference again? And why is this different for PHP 7+ and PHP 7- ?

Copy link
Member Author

Choose a reason for hiding this comment

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

If you look at the original commit (78839bd#diff-d11812fede193d119daadf3b31af5049R344), I think this was just over oversight. This change makes PHP 7+ consistent with 5.x (and other zvals in the debug output on all PHP versions) by always adding a reference.

Is it necessary to free the reference in debug info? My understanding is that it's essentially a return value and the root array (or HashTable) will get freed by the caller.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a concern that we're only adding a pointer to the current document here instead of copying the zval and it could change later if the user were to hold a reference to it (not with var_dump() but presumably some other method).

I'll note that php_phongo_cursor_free_current() is going to zval_ptr_dtor() and ZVAL_UNDEF() at each step of iteration.

This fixes a segfault while dumping the cursor between iterations with IteratorIterator.
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 1dfc8df into mongodb:v1.4 Apr 18, 2018
jmikola added a commit that referenced this pull request Apr 18, 2018
@jmikola jmikola deleted the 1.4-phpc-1162 branch April 18, 2018 16:59
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.

3 participants