diff --git a/ext/bz2/bz2.c b/ext/bz2/bz2.c index dd1b87d2bf61..fd06cb230a7f 100644 --- a/ext/bz2/bz2.c +++ b/ext/bz2/bz2.c @@ -386,7 +386,7 @@ PHP_FUNCTION(bzopen) php_socket_t fd; size_t stream_mode_len; - php_stream_from_zval(stream, file); + php_stream_from_res(stream, Z_RES_P(file)); stream_mode_len = strlen(stream->mode); char primary_stream_mode; diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c index 4bc76b44ea72..3cc4165c3fba 100644 --- a/ext/fileinfo/fileinfo.c +++ b/ext/fileinfo/fileinfo.c @@ -300,7 +300,7 @@ PHP_FUNCTION(finfo_file) zend_argument_must_not_be_empty_error(hasThis() ? 1 : 2); RETURN_THROWS(); } - php_stream_context *context = php_stream_context_from_zval(zcontext, false); + php_stream_context *context = php_stream_context_from_zval_or_default(zcontext); if (!context) { RETURN_THROWS(); } @@ -402,7 +402,7 @@ PHP_FUNCTION(mime_content_type) break; case IS_RESOURCE: - php_stream_from_zval(stream, path_or_stream); + php_stream_from_res(stream, Z_RES_P(path_or_stream)); break; default: @@ -424,7 +424,7 @@ PHP_FUNCTION(mime_content_type) const char *ret_val; if (path) { - php_stream_context *context = php_stream_context_get_default(false); + php_stream_context *context = php_stream_context_get_default(); ret_val = php_fileinfo_from_path(magic, path, context); } else { /* remember stream position for restoration */ diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 527ef8968d70..3b91c8dbb657 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -4540,7 +4540,7 @@ static gdIOCtx *create_output_context(zval *to_zval, uint32_t arg_num) { ZEND_ASSERT(arg_num > 0); if (Z_TYPE_P(to_zval) == IS_RESOURCE) { - php_stream_from_zval_no_verify(stream, to_zval); + php_stream_from_res_no_verify(stream, Z_RES_P(to_zval)); if (stream == NULL) { return NULL; } diff --git a/ext/hash/hash.c b/ext/hash/hash.c index 20e8d120b5b4..4579db24f064 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -356,7 +356,7 @@ static void php_hash_do_hash( zend_argument_value_error(2, "must not contain any null bytes"); RETURN_THROWS(); } - stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context)); + stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, php_stream_context_get_default()); if (!stream) { /* Stream will report errors opening file */ RETURN_FALSE; @@ -499,7 +499,7 @@ static void php_hash_do_hash_hmac( zend_argument_value_error(2, "must not contain any null bytes"); RETURN_THROWS(); } - stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context)); + stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, php_stream_context_get_default()); if (!stream) { /* Stream will report errors opening file */ RETURN_FALSE; @@ -743,7 +743,7 @@ PHP_FUNCTION(hash_update_file) hash = php_hashcontext_from_object(Z_OBJ_P(zhash)); PHP_HASHCONTEXT_VERIFY(hash); - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); stream = php_stream_open_wrapper_ex(ZSTR_VAL(filename), "rb", REPORT_ERRORS, NULL, context); if (!stream) { diff --git a/ext/pdo/pdo_sql_parser.re b/ext/pdo/pdo_sql_parser.re index d77425531cc4..eae2f8b483ec 100644 --- a/ext/pdo/pdo_sql_parser.re +++ b/ext/pdo/pdo_sql_parser.re @@ -239,7 +239,7 @@ safe: if (param->param_type == PDO_PARAM_LOB && Z_TYPE_P(parameter) == IS_RESOURCE) { php_stream *stm; - php_stream_from_zval_no_verify(stm, parameter); + php_stream_from_res_no_verify(stm, Z_RES_P(parameter)); if (stm) { zend_string *buf; diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index ce4253c82c91..d51063824acf 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -540,7 +540,7 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, enum pdo } else if (Z_TYPE_P(dest) == IS_RESOURCE) { /* Convert LOB stream to string */ php_stream *stream; - php_stream_from_zval_no_verify(stream, dest); + php_stream_from_res_no_verify(stream, Z_RES_P(dest)); zend_string *str = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0); zval_ptr_dtor_nogc(dest); if (str == NULL) { diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c index 1d3edd20d9f8..e5d3c9f95d56 100644 --- a/ext/pdo_firebird/firebird_statement.c +++ b/ext/pdo_firebird/firebird_statement.c @@ -705,7 +705,7 @@ static int pdo_firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param if (Z_TYPE_P(parameter) == IS_RESOURCE) { php_stream *stm = NULL; - php_stream_from_zval_no_verify(stm, parameter); + php_stream_from_res_no_verify(stm, Z_RES_P(parameter)); if (stm) { zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); zval_ptr_dtor(parameter); diff --git a/ext/pdo_mysql/mysql_statement.c b/ext/pdo_mysql/mysql_statement.c index f6b182fcb9ad..4598a9792dc5 100644 --- a/ext/pdo_mysql/mysql_statement.c +++ b/ext/pdo_mysql/mysql_statement.c @@ -444,7 +444,7 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da } if (Z_TYPE_P(parameter) == IS_RESOURCE) { php_stream *stm = NULL; - php_stream_from_zval_no_verify(stm, parameter); + php_stream_from_res_no_verify(stm, Z_RES_P(parameter)); if (stm) { zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); zval_ptr_dtor(parameter); diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index f9d3506a4c88..feb81fe57bf7 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -861,7 +861,7 @@ void pgsqlCopyFromFile_internal(INTERNAL_FUNCTION_PARAMETERS) PDO_CONSTRUCT_CHECK; PDO_DBH_CLEAR_ERR(); - stream = php_stream_open_wrapper_ex(filename, "rb", 0, NULL, FG(default_context)); + stream = php_stream_open_wrapper_ex(filename, "rb", 0, NULL, php_stream_context_get_default()); if (!stream) { pdo_pgsql_error_msg(dbh, PGRES_FATAL_ERROR, "Unable to open the file"); PDO_HANDLE_DBH_ERR(); @@ -966,7 +966,7 @@ void pgsqlCopyToFile_internal(INTERNAL_FUNCTION_PARAMETERS) H = (pdo_pgsql_db_handle *)dbh->driver_data; - stream = php_stream_open_wrapper_ex(filename, "wb", 0, NULL, FG(default_context)); + stream = php_stream_open_wrapper_ex(filename, "wb", 0, NULL, php_stream_context_get_default()); if (!stream) { pdo_pgsql_error_msg(dbh, PGRES_FATAL_ERROR, "Unable to open the file for writing"); PDO_HANDLE_DBH_ERR(); diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c index e2c8a35944c5..43aabecc7b5b 100644 --- a/ext/pdo_pgsql/pgsql_statement.c +++ b/ext/pdo_pgsql/pgsql_statement.c @@ -558,7 +558,7 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data * if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB && Z_TYPE_P(parameter) == IS_RESOURCE) { php_stream *stm; - php_stream_from_zval_no_verify(stm, parameter); + php_stream_from_res_no_verify(stm, Z_RES_P(parameter)); if (stm) { if (php_stream_is(stm, &pdo_pgsql_lob_stream_ops)) { struct pdo_pgsql_lob_self *self = (struct pdo_pgsql_lob_self*)stm->abstract; diff --git a/ext/pdo_sqlite/sqlite_statement.c b/ext/pdo_sqlite/sqlite_statement.c index 0d088c99ce7a..dae86e854b19 100644 --- a/ext/pdo_sqlite/sqlite_statement.c +++ b/ext/pdo_sqlite/sqlite_statement.c @@ -138,7 +138,7 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d } if (Z_TYPE_P(parameter) == IS_RESOURCE) { php_stream *stm = NULL; - php_stream_from_zval_no_verify(stm, parameter); + php_stream_from_res_no_verify(stm, Z_RES_P(parameter)); if (stm) { zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); zval_ptr_dtor(parameter); diff --git a/ext/phar/func_interceptors.c b/ext/phar/func_interceptors.c index e4cf1933b797..f5d0b322259b 100644 --- a/ext/phar/func_interceptors.c +++ b/ext/phar/func_interceptors.c @@ -64,7 +64,7 @@ PHP_FUNCTION(phar_opendir) /* {{{ */ zend_string_release_ex(entry, false); zend_string_release_ex(arch, false); if (zcontext) { - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); } stream = php_stream_opendir(name, REPORT_ERRORS, context); efree(name); @@ -185,7 +185,7 @@ PHP_FUNCTION(phar_file_get_contents) /* {{{ */ php_stream *stream; if (zcontext) { - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); } stream = php_stream_open_wrapper_ex(ZSTR_VAL(name), "rb", 0 | REPORT_ERRORS, NULL, context); @@ -245,7 +245,7 @@ PHP_FUNCTION(phar_readfile) /* {{{ */ } php_stream *stream; - php_stream_context *context = php_stream_context_from_zval(zcontext, 0); + php_stream_context *context = php_stream_context_from_zval_or_default(zcontext); stream = php_stream_open_wrapper_ex(ZSTR_VAL(name), "rb", 0 | REPORT_ERRORS, NULL, context); @@ -292,7 +292,7 @@ PHP_FUNCTION(phar_fopen) /* {{{ */ } php_stream *stream; - php_stream_context *context = php_stream_context_from_zval(zcontext, 0); + php_stream_context *context = php_stream_context_from_zval_or_default(zcontext); stream = php_stream_open_wrapper_ex(ZSTR_VAL(name), mode, 0 | REPORT_ERRORS, NULL, context); diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 9d3bd842cb72..3ffb83104366 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -1407,7 +1407,7 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */ case IS_STRING: break; case IS_RESOURCE: - php_stream_from_zval_no_verify(fp, value); + php_stream_from_res_no_verify(fp, Z_RES_P(value)); if (!fp) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Iterator %pS returned an invalid stream handle", ce->name); @@ -2849,7 +2849,7 @@ PHP_METHOD(Phar, setStub) RETURN_THROWS(); } - if ((php_stream_from_zval_no_verify(stream, zstub)) != NULL) { + if ((php_stream_from_res_no_verify(stream, Z_RES_P(zstub))) != NULL) { if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%pS\" is persistent, unable to copy on write", phar_obj->archive->fname); RETURN_THROWS(); diff --git a/ext/posix/posix.c b/ext/posix/posix.c index f217199118db..799a8813c8d0 100644 --- a/ext/posix/posix.c +++ b/ext/posix/posix.c @@ -436,11 +436,11 @@ PHP_FUNCTION(posix_ctermid) /* }}} */ /* Checks if the provides resource is a stream and if it provides a file descriptor */ -static zend_result php_posix_stream_get_fd(zval *zfp, zend_long *ret) /* {{{ */ +static zend_result php_posix_stream_get_fd(zend_resource *zfp, zend_long *ret) /* {{{ */ { php_stream *stream; - php_stream_from_zval_no_verify(stream, zfp); + php_stream_from_res_no_verify(stream, zfp); if (stream == NULL) { return FAILURE; @@ -481,7 +481,7 @@ PHP_FUNCTION(posix_ttyname) ZEND_PARSE_PARAMETERS_END(); if (Z_TYPE_P(z_fd) == IS_RESOURCE) { - if (php_posix_stream_get_fd(z_fd, &fd) == FAILURE) { + if (php_posix_stream_get_fd(Z_RES_P(z_fd), &fd) == FAILURE) { RETURN_FALSE; } } else { @@ -543,7 +543,7 @@ PHP_FUNCTION(posix_isatty) ZEND_PARSE_PARAMETERS_END(); if (Z_TYPE_P(z_fd) == IS_RESOURCE) { - if (php_posix_stream_get_fd(z_fd, &fd) == FAILURE) { + if (php_posix_stream_get_fd(Z_RES_P(z_fd), &fd) == FAILURE) { RETURN_FALSE; } } else { @@ -1363,7 +1363,7 @@ PHP_FUNCTION(posix_fpathconf) ZEND_PARSE_PARAMETERS_END(); if (Z_TYPE_P(z_fd) == IS_RESOURCE) { - if (php_posix_stream_get_fd(z_fd, &fd) == FAILURE) { + if (php_posix_stream_get_fd(Z_RES_P(z_fd), &fd) == FAILURE) { RETURN_FALSE; } } else { diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index b4b368cfeadd..f28fdc9ec7f0 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -453,7 +453,7 @@ bool make_http_soap_request( tmp = Z_CLIENT_HTTPSOCKET_P(this_ptr); if (Z_TYPE_P(tmp) == IS_RESOURCE) { - php_stream_from_zval_no_verify(stream,tmp); + php_stream_from_res_no_verify(stream, Z_RES_P(tmp)); tmp = Z_CLIENT_USE_PROXY_P(this_ptr); if (Z_TYPE_P(tmp) == IS_LONG) { use_proxy = Z_LVAL_P(tmp); @@ -473,7 +473,7 @@ bool make_http_soap_request( tmp = Z_CLIENT_STREAM_CONTEXT_P(this_ptr); if (Z_TYPE_P(tmp) == IS_RESOURCE) { - context = php_stream_context_from_zval(tmp, 0); + context = php_stream_context_from_zval_or_default(tmp); } if (context && diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 69ab56169c40..79a830e00205 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -3396,7 +3396,7 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, zend_long cache_wsdl) if (instanceof_function(Z_OBJCE_P(this_ptr), soap_class_entry)) { tmp = Z_CLIENT_STREAM_CONTEXT_P(this_ptr); if (Z_TYPE_P(tmp) == IS_RESOURCE) { - context = php_stream_context_from_zval(tmp, 0); + context = php_stream_context_from_zval_or_default(tmp); /* Share a reference with new_context down below. * For new contexts, the reference is only in new_context so that doesn't need extra refcounting. */ GC_ADDREF(context->res); diff --git a/ext/soap/soap.c b/ext/soap/soap.c index df39d5f429dd..d02f91ae82b8 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -1428,7 +1428,7 @@ PHP_METHOD(SoapServer, handle) */ sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8")-1, 1); - php_stream_context *context = php_stream_context_from_zval(NULL, false); + php_stream_context *context = php_stream_context_get_default(); php_stream *stream = php_stream_open_wrapper_ex(service->sdl->source, "rb", REPORT_ERRORS, NULL, context); if (stream) { php_stream_passthru(stream); diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 6776ae4ee2f3..c46fc940689e 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -2667,7 +2667,7 @@ PHP_FUNCTION(socket_import_stream) ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_RESOURCE(zstream) ZEND_PARSE_PARAMETERS_END(); - php_stream_from_zval(stream, zstream); + php_stream_from_res(stream, Z_RES_P(zstream)); if (php_stream_cast(stream, PHP_STREAM_AS_SOCKETD, (void**)&socket, 1) == FAILURE) { /* error supposedly already shown */ diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 85a979829cfa..6596ecab7ce0 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -283,7 +283,7 @@ static void spl_filesystem_dir_open(spl_filesystem_object* intern, zend_string * bool skip_dots = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_SKIPDOTS); intern->type = SPL_FS_DIR; - intern->u.dir.dirp = php_stream_opendir(ZSTR_VAL(path), REPORT_ERRORS, FG(default_context)); + intern->u.dir.dirp = php_stream_opendir(ZSTR_VAL(path), REPORT_ERRORS, php_stream_context_get_default()); if (intern->u.dir.dirp) { /* we prevent potential UAF with conflicting explicit fclose(), relying on the object destructor for this */ @@ -328,7 +328,7 @@ static zend_result spl_filesystem_file_open(spl_filesystem_object *intern, bool return FAILURE; } - intern->u.file.context = php_stream_context_from_zval(intern->u.file.zcontext, 0); + intern->u.file.context = php_stream_context_from_zval_or_default(intern->u.file.zcontext); intern->u.file.stream = php_stream_open_wrapper_ex(ZSTR_VAL(intern->file_name), ZSTR_VAL(intern->u.file.open_mode), (use_include_path ? USE_PATH : 0) | REPORT_ERRORS, NULL, intern->u.file.context); if (!ZSTR_LEN(intern->file_name) || !intern->u.file.stream) { diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 6b9e761e2b48..198c912f5693 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -1655,7 +1655,7 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ php_stream *stream = NULL; zend_string *buffer = NULL; if (Z_TYPE_P(parameter) == IS_RESOURCE) { - php_stream_from_zval_no_verify(stream, parameter); + php_stream_from_res_no_verify(stream, Z_RES_P(parameter)); if (stream == NULL) { php_sqlite3_error(stmt_obj->db_obj, 0, "Unable to read stream for parameter %ld", param->param_number); return FAILURE; diff --git a/ext/standard/dir.c b/ext/standard/dir.c index f313d5f539d1..ce3790d093fd 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -117,7 +117,7 @@ static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETERS, int createobject) Z_PARAM_RESOURCE_OR_NULL(zcontext) ZEND_PARSE_PARAMETERS_END(); - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); dirp = php_stream_opendir(dirname, REPORT_ERRORS, context); @@ -579,7 +579,7 @@ PHP_FUNCTION(scandir) } if (zcontext) { - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); } if (flags == PHP_SCANDIR_SORT_ASCENDING) { diff --git a/ext/standard/file.c b/ext/standard/file.c index ff68374928c5..90d1f98c3151 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -411,7 +411,7 @@ PHP_FUNCTION(file_get_contents) } php_stream_error_operation_begin(); - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); stream = php_stream_open_wrapper_ex(filename, "rb", (use_include_path ? USE_PATH : 0) | REPORT_ERRORS, NULL, context); @@ -467,7 +467,7 @@ PHP_FUNCTION(file_put_contents) ZEND_PARSE_PARAMETERS_END(); if (Z_TYPE_P(data) == IS_RESOURCE) { - php_stream_from_zval(srcstream, data); + php_stream_from_res(srcstream, Z_RES_P(data)); } php_stream_error_operation_begin(); @@ -761,7 +761,7 @@ PHP_FUNCTION(fopen) ZEND_PARSE_PARAMETERS_END(); php_stream_error_operation_begin(); - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); stream = php_stream_open_wrapper_ex(filename, mode, (use_include_path ? USE_PATH : 0) | REPORT_ERRORS, NULL, context); php_stream_error_operation_end(context); @@ -1164,7 +1164,7 @@ PHP_FUNCTION(mkdir) Z_PARAM_RESOURCE_OR_NULL(zcontext) ZEND_PARSE_PARAMETERS_END(); - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); php_stream_error_operation_begin(); RETVAL_BOOL(php_stream_mkdir(dir, (int)mode, (recursive ? PHP_STREAM_MKDIR_RECURSIVE : 0) | REPORT_ERRORS, context)); @@ -1186,7 +1186,7 @@ PHP_FUNCTION(rmdir) Z_PARAM_RESOURCE_OR_NULL(zcontext) ZEND_PARSE_PARAMETERS_END(); - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); php_stream_error_operation_begin(); RETVAL_BOOL(php_stream_rmdir(dir, REPORT_ERRORS, context)); @@ -1212,7 +1212,7 @@ PHP_FUNCTION(readfile) Z_PARAM_RESOURCE_OR_NULL(zcontext) ZEND_PARSE_PARAMETERS_END(); - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); php_stream_error_operation_begin(); stream = php_stream_open_wrapper_ex(filename, "rb", (use_include_path ? USE_PATH : 0) | REPORT_ERRORS, NULL, context); @@ -1290,7 +1290,7 @@ PHP_FUNCTION(rename) ZEND_PARSE_PARAMETERS_END(); php_stream_error_operation_begin(); - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); wrapper = php_stream_locate_url_wrapper(old_name, NULL, 0); @@ -1333,7 +1333,7 @@ PHP_FUNCTION(unlink) ZEND_PARSE_PARAMETERS_END(); php_stream_error_operation_begin(); - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); wrapper = php_stream_locate_url_wrapper(filename, NULL, 0); @@ -1523,7 +1523,7 @@ PHP_FUNCTION(copy) ZEND_PARSE_PARAMETERS_END(); php_stream_error_operation_begin(); - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); if (php_stream_locate_url_wrapper(source, NULL, 0) == &php_plain_files_wrapper && php_check_open_basedir(source)) { php_stream_error_operation_end(context); diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 8bb6064fc6da..1002999f7f0c 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -68,7 +68,7 @@ PHP_FUNCTION(stream_socket_pair) } php_stream_error_operation_begin(); - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); s1 = php_stream_sock_open_from_socket(pair[0], 0); if (s1 == NULL) { @@ -529,7 +529,7 @@ PHP_FUNCTION(stream_copy_to_stream) } php_stream_error_operation_begin(); - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); if (pos > 0 && php_stream_seek(src, pos, SEEK_SET) < 0) { php_stream_error_operation_end(context); @@ -791,7 +791,7 @@ PHP_FUNCTION(stream_select) ZEND_PARSE_PARAMETERS_END(); php_stream_error_operation_begin(); - php_stream_context *context = php_stream_context_from_zval(zcontext, 0); + php_stream_context *context = php_stream_context_from_zval_or_default(zcontext); /* The sets grow as streams are added, past FD_SETSIZE */ php_growable_fd_set rfds, wfds, efds; @@ -1190,10 +1190,7 @@ PHP_FUNCTION(stream_context_get_default) Z_PARAM_ARRAY_HT_OR_NULL(params) ZEND_PARSE_PARAMETERS_END(); - if (FG(default_context) == NULL) { - FG(default_context) = php_stream_context_alloc(); - } - context = FG(default_context); + context = php_stream_context_get_default(); if (params) { if (parse_context_options(context, params) == FAILURE) { @@ -1233,10 +1230,7 @@ PHP_FUNCTION(stream_context_set_default) Z_PARAM_ARRAY_HT(options) ZEND_PARSE_PARAMETERS_END(); - if (FG(default_context) == NULL) { - FG(default_context) = php_stream_context_alloc(); - } - context = FG(default_context); + context = php_stream_context_get_default(); if (php_stream_context_options_has_error_settings(options)) { zend_value_error("Stream error handling options cannot be set on the default context"); @@ -1697,7 +1691,7 @@ PHP_FUNCTION(stream_is_local) ZEND_PARSE_PARAMETERS_END(); if (Z_TYPE_P(zstream) == IS_RESOURCE) { - php_stream_from_zval(stream, zstream); + php_stream_from_res(stream, Z_RES_P(zstream)); wrapper = stream->wrapper; } else { if (!try_convert_to_string(zstream)) { @@ -1705,7 +1699,7 @@ PHP_FUNCTION(stream_is_local) } php_stream_error_operation_begin(); - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); wrapper = php_stream_locate_url_wrapper(Z_STRVAL_P(zstream), NULL, 0); php_stream_error_operation_end(context); } diff --git a/ext/standard/url.c b/ext/standard/url.c index ac303027a722..4ccda45bd433 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -702,7 +702,7 @@ PHP_FUNCTION(get_headers) Z_PARAM_RESOURCE_OR_NULL(zcontext) ZEND_PARSE_PARAMETERS_END(); - context = php_stream_context_from_zval(zcontext, 0); + context = php_stream_context_from_zval_or_default(zcontext); if (!(stream = php_stream_open_wrapper_ex(url, "r", REPORT_ERRORS | STREAM_USE_URL | STREAM_ONLY_GET_HEADERS, NULL, context))) { RETURN_FALSE; diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 75e2e5ae2718..a16b51e579f7 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -621,7 +621,7 @@ PHP_FUNCTION(gzfile) } /* using a stream here is a bit more efficient (resource wise) than php_gzopen_wrapper */ - stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, php_stream_context_from_zval(NULL, false) STREAMS_CC); + stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, php_stream_context_get_default() STREAMS_CC); if (!stream) { /* Error reporting is already done by stream code */ @@ -664,7 +664,7 @@ PHP_FUNCTION(gzopen) flags |= USE_PATH; } - stream = php_stream_gzopen(NULL, filename, mode, flags, NULL, php_stream_context_from_zval(NULL, false) STREAMS_CC); + stream = php_stream_gzopen(NULL, filename, mode, flags, NULL, php_stream_context_get_default() STREAMS_CC); if (!stream) { RETURN_FALSE; @@ -691,7 +691,7 @@ PHP_FUNCTION(readgzfile) flags |= USE_PATH; } - stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, php_stream_context_from_zval(NULL, false) STREAMS_CC); + stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, php_stream_context_get_default() STREAMS_CC); if (!stream) { RETURN_FALSE; diff --git a/main/php_streams.h b/main/php_streams.h index a697dff65254..fc21c3d53252 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -292,7 +292,7 @@ END_EXTERN_C() return; \ } \ } while (0) -#define php_stream_from_res_no_verify(xstr, pzval) (xstr) = (php_stream*)zend_fetch_resource2((res), "stream", php_file_le_stream(), php_file_le_pstream()) +#define php_stream_from_res_no_verify(xstr, res) (xstr) = (php_stream*)zend_fetch_resource2((res), "stream", php_file_le_stream(), php_file_le_pstream()) #define php_stream_from_zval_no_verify(xstr, pzval) (xstr) = (php_stream*)zend_fetch_resource2_ex((pzval), "stream", php_file_le_stream(), php_file_le_pstream()) static zend_always_inline php_stream* php_stream_from_zval_no_verify_no_error(zval *zval) { diff --git a/main/streams/php_stream_context.h b/main/streams/php_stream_context.h index 9373182f7c2e..f8b2691166ff 100644 --- a/main/streams/php_stream_context.h +++ b/main/streams/php_stream_context.h @@ -24,16 +24,22 @@ typedef void (*php_stream_notification_func)(php_stream_context *context, #define PHP_STREAM_NOTIFIER_PROGRESS 1 /* TODO: Remove dependence on ext/standard/file.h for the default context global */ -#define php_stream_context_get_default(without_context) \ - (without_context) ? NULL : FG(default_context) ? FG(default_context) : \ - (FG(default_context) = php_stream_context_alloc()) +#define php_stream_context_get_default() \ + FG(default_context) ? FG(default_context) : (FG(default_context) = php_stream_context_alloc()) + +#define php_stream_context_get_default_ex(without_context) \ + (without_context) ? NULL : php_stream_context_get_default() /* Attempt to fetch context from the zval passed, If no context was passed, use the default context The default context has not yet been created, do it now. */ #define php_stream_context_from_zval(zcontext, nocontext) ( \ (zcontext) ? zend_fetch_resource_ex(zcontext, "Stream-Context", php_le_stream_context()) : \ - php_stream_context_get_default(nocontext)) + php_stream_context_get_default_ex(nocontext)) + +#define php_stream_context_from_zval_or_default(zcontext) ( \ + (zcontext) ? zend_fetch_resource_ex(zcontext, "Stream-Context", php_le_stream_context()) : \ + php_stream_context_get_default()) #define php_stream_context_to_zval(context, zval) { ZVAL_RES(zval, (context)->res); GC_ADDREF((context)->res); } diff --git a/main/streams/stream_errors.c b/main/streams/stream_errors.c index 211cf4df025a..b02a79aa5ca9 100644 --- a/main/streams/stream_errors.c +++ b/main/streams/stream_errors.c @@ -473,7 +473,7 @@ PHPAPI void php_stream_error_operation_end(const php_stream_context *context) } if (context == NULL) { - context = FG(default_context); + context = php_stream_context_get_default(); } php_stream_error_mode error_mode = php_stream_get_error_mode(context);