diff options
Diffstat (limited to 'ext/standard/streamsfuncs.c')
-rw-r--r-- | ext/standard/streamsfuncs.c | 82 |
1 files changed, 24 insertions, 58 deletions
diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index e668b973b4..c39a9f3310 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -555,14 +555,10 @@ PHP_FUNCTION(stream_get_transports) } if ((stream_xport_hash = php_stream_xport_get_hash())) { - HashPosition pos; array_init(return_value); - zend_hash_internal_pointer_reset_ex(stream_xport_hash, &pos); - while (zend_hash_get_current_key_ex(stream_xport_hash, - &stream_xport, &num_key, 0, &pos) == HASH_KEY_IS_STRING) { + ZEND_HASH_FOREACH_KEY(stream_xport_hash, num_key, stream_xport) { add_next_index_str(return_value, STR_COPY(stream_xport)); - zend_hash_move_forward_ex(stream_xport_hash, &pos); - } + } ZEND_HASH_FOREACH_END(); } else { RETURN_FALSE; } @@ -583,15 +579,12 @@ PHP_FUNCTION(stream_get_wrappers) } if ((url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash())) { - HashPosition pos; array_init(return_value); - for (zend_hash_internal_pointer_reset_ex(url_stream_wrappers_hash, &pos); - (key_flags = zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &num_key, 0, &pos)) != HASH_KEY_NON_EXISTENT; - zend_hash_move_forward_ex(url_stream_wrappers_hash, &pos)) { - if (key_flags == HASH_KEY_IS_STRING) { - add_next_index_str(return_value, STR_COPY(stream_protocol)); - } - } + ZEND_HASH_FOREACH_KEY(url_stream_wrappers_hash, num_key, stream_protocol) { + if (key_flags == HASH_KEY_IS_STRING) { + add_next_index_str(return_value, STR_COPY(stream_protocol)); + } + } ZEND_HASH_FOREACH_END(); } else { RETURN_FALSE; } @@ -610,10 +603,7 @@ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t return 0; } - for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array)); - (elem = zend_hash_get_current_data(Z_ARRVAL_P(stream_array))) != NULL; - zend_hash_move_forward(Z_ARRVAL_P(stream_array))) { - + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(stream_array), elem) { /* Temporary int fd is needed for the STREAM data type on windows, passing this_fd directly to php_stream_cast() would eventually bring a wrong result on x64. php_stream_cast() casts to int internally, and this will leave the higher bits of a SOCKET variable uninitialized on systems with little endian. */ @@ -639,7 +629,8 @@ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t } cnt++; } - } + } ZEND_HASH_FOREACH_END(); + return cnt ? 1 : 0; } @@ -648,6 +639,8 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC) zval *elem, *dest_elem, new_array; php_stream *stream; int ret = 0; + zend_string *key; + ulong num_ind; if (Z_TYPE_P(stream_array) != IS_ARRAY) { return 0; @@ -655,26 +648,12 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC) 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); - for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array)); - zend_hash_has_more_elements(Z_ARRVAL_P(stream_array)) == SUCCESS; - zend_hash_move_forward(Z_ARRVAL_P(stream_array))) { - - int type; - zend_string *key; - ulong num_ind; + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(stream_array), num_ind, key, elem) { /* Temporary int fd is needed for the STREAM data type on windows, passing this_fd directly to php_stream_cast() would eventually bring a wrong result on x64. php_stream_cast() casts to int internally, and this will leave the higher bits of a SOCKET variable uninitialized on systems with little endian. */ int tmp_fd; - - type = zend_hash_get_current_key(Z_ARRVAL_P(stream_array), - &key, &num_ind, 0); - if (type == HASH_KEY_NON_EXISTENT || - (elem = zend_hash_get_current_data(Z_ARRVAL_P(stream_array))) == NULL) { - continue; /* should not happen */ - } - php_stream_from_zval_no_verify(stream, elem); if (stream == NULL) { continue; @@ -689,9 +668,9 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC) php_socket_t this_fd = (php_socket_t)tmp_fd; if (PHP_SAFE_FD_ISSET(this_fd, fds)) { - if (type == HASH_KEY_IS_LONG) { + if (!key) { dest_elem = zend_hash_index_update(Z_ARRVAL(new_array), num_ind, elem); - } else { /* HASH_KEY_IS_STRING */ + } else { dest_elem = zend_hash_update(Z_ARRVAL(new_array), key, elem); } @@ -702,14 +681,13 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC) continue; } } - } + } ZEND_HASH_FOREACH_END(); /* destroy old array and add new one */ zend_hash_destroy(Z_ARRVAL_P(stream_array)); GC_REMOVE_FROM_BUFFER(Z_ARR_P(stream_array)); efree(Z_ARR_P(stream_array)); - zend_hash_internal_pointer_reset(Z_ARRVAL(new_array)); Z_ARR_P(stream_array) = Z_ARR(new_array); return ret; @@ -727,10 +705,7 @@ static int stream_array_emulate_read_fd_set(zval *stream_array TSRMLS_DC) 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); - for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array)); - (elem = zend_hash_get_current_data(Z_ARRVAL_P(stream_array))) != NULL; - zend_hash_move_forward(Z_ARRVAL_P(stream_array))) { - + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(stream_array), elem) { php_stream_from_zval_no_verify(stream, elem); if (stream == NULL) { continue; @@ -749,14 +724,12 @@ static int stream_array_emulate_read_fd_set(zval *stream_array TSRMLS_DC) ret++; continue; } - } + } ZEND_HASH_FOREACH_END(); if (ret > 0) { /* destroy old array and add new one */ zend_hash_destroy(Z_ARRVAL_P(stream_array)); efree(Z_ARR_P(stream_array)); - - zend_hash_internal_pointer_reset(Z_ARRVAL(new_array)); Z_ARR_P(stream_array) = Z_ARR(new_array); } else { zend_hash_destroy(Z_ARRVAL(new_array)); @@ -911,31 +884,24 @@ static void user_space_stream_notifier_dtor(php_stream_notifier *notifier) static int parse_context_options(php_stream_context *context, zval *options TSRMLS_DC) { - HashPosition pos, opos; zval *wval, *oval; zend_string *wkey, *okey; int ret = SUCCESS; ulong num_key; - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(options), &pos); - while (NULL != (wval = zend_hash_get_current_data_ex(Z_ARRVAL_P(options), &pos))) { - if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_P(options), &wkey, &num_key, 0, &pos) - && Z_TYPE_P(wval) == IS_ARRAY) { - - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(wval), &opos); - while (NULL != (oval = zend_hash_get_current_data_ex(Z_ARRVAL_P(wval), &opos))) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(options), num_key, wkey, wval) { + if (wkey && Z_TYPE_P(wval) == IS_ARRAY) { - if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_P(wval), &okey, &num_key, 0, &opos)) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(wval), num_key, okey, oval) { + if (okey) { php_stream_context_set_option(context, wkey->val, okey->val, oval); } - zend_hash_move_forward_ex(Z_ARRVAL_P(wval), &opos); - } + } ZEND_HASH_FOREACH_END(); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "options should have the form [\"wrappername\"][\"optionname\"] = $value"); } - zend_hash_move_forward_ex(Z_ARRVAL_P(options), &pos); - } + } ZEND_HASH_FOREACH_END(); return ret; } |