Skip to content
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

Fix GH-11591: AppendIterator fails to iterate with an empty generator #17316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

takaram
Copy link

@takaram takaram commented Jan 1, 2025

Appending an empty generator is virtually a no-op, except that the generator gets consumed and is no longer available.
With this PR, AppendIterator::apend terminates early if its argument is an empty generator.

Comment on lines +108 to +115
static inline void zend_generator_ensure_initialized(zend_generator *generator) /* {{{ */
{
if (UNEXPECTED(Z_TYPE(generator->value) == IS_UNDEF) && EXPECTED(generator->execute_data) && EXPECTED(generator->node.parent == NULL)) {
zend_generator_resume(generator);
generator->flags |= ZEND_GENERATOR_AT_FIRST_YIELD;
}
}
/* }}} */
Copy link
Member

Choose a reason for hiding this comment

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

I don't really like exposing this in a header.

I would rather prefer creating a new API (e.g. zend_generator_is_empty), but considering you are trying to fix a bug in SPL it seems far more likely that SPL is doing something incorrect in the iterator code.

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.

2 participants