-
Notifications
You must be signed in to change notification settings - Fork 8k
gen_stub: Add return by reference flag #14394
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
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.
LGTM! A test in zend_test may be useful, but I'm also fine with the PR as-is.
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.
I've just seen your edit: in case of doubt, a test is definitely useful.
Also, I've just found this:
https://github.com/php/php-src/blob/c2a9166ef09df59772bf9d4c42414c9daa64e426/Zend/zend_API.h#L126-L125 based on which it looks like the flag should be set via arginfo.
And later, the ZEND_ACC_RETURN_REFERENCE flag is applied here:
Line 2917 in 1c30c5e
| internal_function->fn_flags |= ZEND_ACC_RETURN_REFERENCE; |
(I only found these code paths based on a very quick search, so please take it with a grain of salt ^^)
|
Further evidence I found: https://github.com/kocsismate/php-src/blob/c2a9166ef09df59772bf9d4c42414c9daa64e426/Zend/zend_API.h#L201 The |
660c318 to
8266bb5
Compare
The flag is already set in reality This reverts commit 1d4d884.
8266bb5 to
65e32f2
Compare
|
Turns out the flag is already set, however I have no god-damn clue how one is mean to actually create a reference to some zval* that is usable for userland. Even copying VM APIs seems to not do what I would expect it to do. So if anyone has any idea how to reliably implement this without using an INDIRECT zval I would love to hear the solution. |
|
I'm not quite sure I understand your problem. I would mimic // retval_ptr is basically OP1
if (Z_ISREF_P(retval_ptr)) {
Z_ADDREF_P(retval_ptr);
} else {
ZVAL_MAKE_REF_EX(retval_ptr, 2);
}
ZVAL_REF(return_value, Z_REF_P(retval_ptr)); |
This does not seem to work. |
|
@Girgias This should fix it https://gist.github.com/nielsdos/f519a9c1b019a83871313cd6e6de29f7 |
|
Turns out we already support this and my code was just wrong, because references are weird. |
Looks like this information is never set anywhere for internal functions/methods that return by reference.
EDIT: I'm not exactly sure that's the correct fix even if it looks like it, because I'm still running into some issues for Girgias#19