diff options
author | twosee <twose@qq.com> | 2019-04-08 12:58:46 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-08 12:58:46 +0200 |
commit | bdac9ef10d90997f9576564dde693cbef6594142 (patch) | |
tree | 8bf34a6ee4ca18b3314748cc4d5fada2d8d21156 /ext/standard/streamsfuncs.c | |
parent | d7b5954f2818aff6db29a995f407797a7902f38f (diff) | |
download | php-git-bdac9ef10d90997f9576564dde693cbef6594142.tar.gz |
Preserve keys in emulate_read_fd_set()
Keys are already preserved in the non-emulated case.
Diffstat (limited to 'ext/standard/streamsfuncs.c')
-rw-r--r-- | ext/standard/streamsfuncs.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 2654382906..9d725db919 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -710,6 +710,8 @@ static int stream_array_emulate_read_fd_set(zval *stream_array) zval *elem, *dest_elem, new_array; php_stream *stream; int ret = 0; + zend_ulong num_ind; + zend_string *key; if (Z_TYPE_P(stream_array) != IS_ARRAY) { return 0; @@ -717,7 +719,7 @@ static int stream_array_emulate_read_fd_set(zval *stream_array) ZVAL_NEW_ARR(&new_array); zend_hash_init(Z_ARRVAL(new_array), zend_hash_num_elements(Z_ARRVAL_P(stream_array)), NULL, ZVAL_PTR_DTOR, 0); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(stream_array), elem) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(stream_array), num_ind, key, elem) { ZVAL_DEREF(elem); php_stream_from_zval_no_verify(stream, elem); if (stream == NULL) { @@ -730,10 +732,12 @@ static int stream_array_emulate_read_fd_set(zval *stream_array) * This branch of code also allows blocking streams with buffered data to * operate correctly in stream_select. * */ - dest_elem = zend_hash_next_index_insert(Z_ARRVAL(new_array), elem); - if (dest_elem) { - zval_add_ref(dest_elem); + if (!key) { + dest_elem = zend_hash_index_update(Z_ARRVAL(new_array), num_ind, elem); + } else { + dest_elem = zend_hash_update(Z_ARRVAL(new_array), key, elem); } + zval_add_ref(dest_elem); ret++; continue; } |