Skip to content

Avoid modifying the return value of readline_completion_function() #6582

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

Closed
wants to merge 1 commit into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Jan 6, 2021

The internal function _readline_command_generator() modifies the
internal array pointer of readline_completion_function()'s return
value. We therefore separate the array, what also avoids failing
assertions regarding the array refcount.

The internal function `_readline_command_generator()` modifies the
internal array pointer of `readline_completion_function()`'s return
value.  We therefore separate the array, what also avoids failing
assertions regarding the array refcount.
@cmb69 cmb69 added the Bug label Jan 6, 2021
@nikic
Copy link
Member

nikic commented Jan 6, 2021

Can we switch it to use ZEND_HASH_FOREACH instead?

@cmb69
Copy link
Member Author

cmb69 commented Jan 7, 2021

The array pointer is advanced only one element for every executed callback:

static char *_readline_command_generator(const char *text, int state)
{
HashTable *myht = Z_ARRVAL(_readline_array);
zval *entry;
if (!state) {
zend_hash_internal_pointer_reset(myht);
}
while ((entry = zend_hash_get_current_data(myht)) != NULL) {
zend_hash_move_forward(myht);
convert_to_string_ex(entry);
if (strncmp (Z_STRVAL_P(entry), text, strlen(text)) == 0) {
return (strdup(Z_STRVAL_P(entry)));
}
}
return NULL;
}

We could store an external HashPosition, and use that API, but I'm not sure whether that would be a real improvement.

Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

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

Right, that makes sense.

It's also not just the array pointer, we also convert elements to string.

@php-pulls php-pulls closed this in 9450893 Jan 7, 2021
@cmb69 cmb69 deleted the cmb/readline-separate branch January 7, 2021 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants