Skip to content

ext/standard/stream: Use FCC instead of zval for notification callback #19024

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 2 commits into from
Jul 6, 2025

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Jul 3, 2025

Also check that the callable exists while setting the option

Also check that the callable exists while setting the option
@Girgias Girgias marked this pull request as ready for review July 4, 2025 10:12
@Girgias Girgias requested a review from bukka as a code owner July 4, 2025 10:12
@Girgias Girgias requested a review from nielsdos July 4, 2025 10:12
}
for (i = 0; i < 6; i++) {
zend_call_known_fcc(context->notifier->fcc, NULL, 6, zvs, NULL);
for (uint8_t i = 0; i < 6; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

Fun fact: If not unrolled, using an (unsigned) int would be better in the sense that the generated assembly for both x86-64 and arm64 is shorter. For x86 it saves an instruction prefix byte to switch to 8 bit mode, and for arm64 it saves an instruction.
However, the loop is likely unrolled in which case it doesn't matter, but just something to take into account that using a shorter type is not always better.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, why do we even have a loop? Just call the zval_ptr_dtor(_str) on &zvs[2] ?

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 was thinking about that, but can't this be an issue if the notifier callback takes the arguments by-ref and changes them to strings?

Copy link
Member

Choose a reason for hiding this comment

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

No, because the conversion happens on the call frame, not on the original zvals.

Copy link
Member Author

Choose a reason for hiding this comment

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

ACK, will change then

if (context->notifier && Z_TYPE(context->notifier->ptr) != IS_UNDEF && context->notifier->func == user_space_stream_notifier) {
Z_TRY_ADDREF(context->notifier->ptr);
add_assoc_zval_ex(return_value, "notification", sizeof("notification")-1, &context->notifier->ptr);
if (context->notifier && context->notifier->fcc) {
Copy link
Member

Choose a reason for hiding this comment

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

How can you have a notifier without a valid fcc field?

Copy link
Member Author

Choose a reason for hiding this comment

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

That I don't know as I'm not super familiar with the code, so I went the safe route of checking it exists.

Copy link
Member

Choose a reason for hiding this comment

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

How can you have a notifier without a valid fcc field?

Extensions. In fact this change is an actual breaking change. The .ptr could be used to store store arbitrary metadata for the extension-specific .func. Now it can no longer store arbitrary metadata. It should be a void * instead (that is then cast to zend_fcall_info_cache * for user_space_stream_notifier).

There was a reason the if() previously checked for ->func == user_space_stream_notifier instead of asserting that this is the case. Otherwise we would not need func in the first place and could just hardcode it to user_space_stream_notifier.

Copy link
Member

Choose a reason for hiding this comment

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

Fix is in #19158.

@Girgias Girgias merged commit 677a1f8 into php:master Jul 6, 2025
9 checks passed
@Girgias Girgias deleted the stream-use-fcc branch July 6, 2025 00:30
TimWolla added a commit to TimWolla/php-src that referenced this pull request Jul 17, 2025
…nctions

Support for attaching arbitrary metadata for consumption by stream notifier
functions got broken in php#19024 when the previous `zval ptr` got
changed to `zend_fcall_info_cache *fcc`, making the data specific to the
`user_space_stream_notifier`.

Fix this by changing the field to `void *ptr`, avoiding the indirection through
a `zval`, but preserving the ability to store arbitrary data. If necessary to
support different types than `IS_PTR`, extensions can heap-allocate a `zval` to
store within `->ptr` as a minimal change to keep compatibility with PHP 8.4 or
lower.
TimWolla added a commit to TimWolla/php-src that referenced this pull request Jul 17, 2025
…nctions

Support for attaching arbitrary metadata for consumption by stream notifier
functions got broken in php#19024 when the previous `zval ptr` got
changed to `zend_fcall_info_cache *fcc`, making the data specific to the
`user_space_stream_notifier`.

Fix this by changing the field to `void *ptr`, avoiding the indirection through
a `zval`, but preserving the ability to store arbitrary data. If necessary to
support different types than `IS_PTR`, extensions can heap-allocate a `zval` to
store within `->ptr` as a minimal change to keep compatibility with PHP 8.4 or
lower.
TimWolla added a commit to TimWolla/php-src that referenced this pull request Jul 17, 2025
…nctions

Support for attaching arbitrary metadata for consumption by stream notifier
functions got broken in php#19024 when the previous `zval ptr` got
changed to `zend_fcall_info_cache *fcc`, making the data specific to the
`user_space_stream_notifier`.

Fix this by changing the field to `void *ptr`, avoiding the indirection through
a `zval`, but preserving the ability to store arbitrary data. If necessary to
support different types than `IS_PTR`, extensions can heap-allocate a `zval` to
store within `->ptr` as a minimal change to keep compatibility with PHP 8.4 or
lower.
TimWolla added a commit to TimWolla/php-src that referenced this pull request Jul 17, 2025
…nctions

Support for attaching arbitrary metadata for consumption by stream notifier
functions got broken in php#19024 when the previous `zval ptr` got
changed to `zend_fcall_info_cache *fcc`, making the data specific to the
`user_space_stream_notifier`.

Fix this by changing the field to `void *ptr`, avoiding the indirection through
a `zval`, but preserving the ability to store arbitrary data. If necessary to
support different types than `IS_PTR`, extensions can heap-allocate a `zval` to
store within `->ptr` as a minimal change to keep compatibility with PHP 8.4 or
lower.
TimWolla added a commit to TimWolla/php-src that referenced this pull request Jul 17, 2025
…nctions

Support for attaching arbitrary metadata for consumption by stream notifier
functions got broken in php#19024 when the previous `zval ptr` got
changed to `zend_fcall_info_cache *fcc`, making the data specific to the
`user_space_stream_notifier`.

Fix this by changing the field to `void *ptr`, avoiding the indirection through
a `zval`, but preserving the ability to store arbitrary data. If necessary to
support different types than `IS_PTR`, extensions can heap-allocate a `zval` to
store within `->ptr` as a minimal change to keep compatibility with PHP 8.4 or
lower.
TimWolla added a commit to TimWolla/php-src that referenced this pull request Jul 17, 2025
…nctions

Support for attaching arbitrary metadata for consumption by stream notifier
functions got broken in php#19024 when the previous `zval ptr` got
changed to `zend_fcall_info_cache *fcc`, making the data specific to the
`user_space_stream_notifier`.

Fix this by changing the field to `void *ptr`, avoiding the indirection through
a `zval`, but preserving the ability to store arbitrary data. If necessary to
support different types than `IS_PTR`, extensions can heap-allocate a `zval` to
store within `->ptr` as a minimal change to keep compatibility with PHP 8.4 or
lower.
TimWolla added a commit that referenced this pull request Jul 17, 2025
…nctions (#19158)

Support for attaching arbitrary metadata for consumption by stream notifier
functions got broken in #19024 when the previous `zval ptr` got
changed to `zend_fcall_info_cache *fcc`, making the data specific to the
`user_space_stream_notifier`.

Fix this by changing the field to `void *ptr`, avoiding the indirection through
a `zval`, but preserving the ability to store arbitrary data. If necessary to
support different types than `IS_PTR`, extensions can heap-allocate a `zval` to
store within `->ptr` as a minimal change to keep compatibility with PHP 8.4 or
lower.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants