From 3aee00fd6981d53a84c05c5afb90bf8033b42da8 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 9 Nov 2026 15:38:04 +0000 Subject: [PATCH] streams: move some stream related globals from std to main This is to try and fix out dependency mess so that main does not depend on ext/standard --- ext/openssl/xp_ssl.c | 9 +++--- ext/sockets/sockets.c | 4 +-- ext/standard/basic_functions.c | 10 ------- ext/standard/file.c | 10 ------- ext/standard/file.h | 7 ----- ext/standard/fsock.c | 2 +- ext/standard/http_fopen_wrapper.c | 4 +-- ext/standard/streamsfuncs.c | 4 +-- main/main.c | 17 +++++++++++ main/network.c | 2 +- main/php_globals.h | 7 +++++ main/streams/filter.c | 17 +++++------ main/streams/stream_errors.c | 40 ++++++++++++------------- main/streams/streams.c | 50 +++++++++++++++---------------- main/streams/transports.c | 3 +- main/streams/userspace.c | 13 ++++---- main/streams/xp_socket.c | 4 +-- sapi/cli/php_cli.c | 2 +- 18 files changed, 98 insertions(+), 107 deletions(-) diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index 0f84a4006565..62b55bdf9ee7 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -20,7 +20,6 @@ #endif #include "php.h" -#include "ext/standard/file.h" #include "ext/uri/php_uri.h" #include "streams/php_streams_int.h" #include "zend_smart_str.h" @@ -3680,9 +3679,9 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val if (value == -1) { if (sslsock->s.timeout.tv_sec == -1) { #ifdef _WIN32 - tv.tv_sec = (long)FG(default_socket_timeout); + tv.tv_sec = (long)PG(default_socket_timeout); #else - tv.tv_sec = (time_t)FG(default_socket_timeout); + tv.tv_sec = (time_t)PG(default_socket_timeout); #endif tv.tv_usec = 0; } else { @@ -4053,9 +4052,9 @@ php_stream *php_openssl_ssl_socket_factory(const char *proto, size_t protolen, sslsock->s.is_blocked = true; /* this timeout is used by standard stream funcs, therefore it should use the default value */ #ifdef _WIN32 - sslsock->s.timeout.tv_sec = (long)FG(default_socket_timeout); + sslsock->s.timeout.tv_sec = (long)PG(default_socket_timeout); #else - sslsock->s.timeout.tv_sec = (time_t)FG(default_socket_timeout); + sslsock->s.timeout.tv_sec = (time_t)PG(default_socket_timeout); #endif sslsock->s.timeout.tv_usec = 0; diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 6776ae4ee2f3..4adc0ed87044 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -24,9 +24,7 @@ #include "php.h" #include "php_network.h" -#include "ext/standard/file.h" #include "ext/standard/info.h" -#include "php_ini.h" #ifdef PHP_WIN32 # include "windows_common.h" # include @@ -2789,7 +2787,7 @@ PHP_FUNCTION(socket_export_stream) stream_data = (php_netstream_data_t *) stream->abstract; stream_data->socket = socket->bsd_socket; stream_data->is_blocked = socket->blocking; - stream_data->timeout.tv_sec = FG(default_socket_timeout); + stream_data->timeout.tv_sec = PG(default_socket_timeout); stream_data->timeout.tv_usec = 0; php_stream_to_zval(stream, &socket->zstream); diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index db302ab724ab..56ad36eccc16 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -418,13 +418,6 @@ PHP_RINIT_FUNCTION(basic) /* {{{ */ /* Setup default context */ FG(default_context) = NULL; - - /* Default to global wrappers only */ - FG(stream_wrappers) = NULL; - - /* Default to global filters only */ - FG(stream_filters) = NULL; - return SUCCESS; } /* }}} */ @@ -457,9 +450,6 @@ PHP_RSHUTDOWN_FUNCTION(basic) /* {{{ */ } } - /* FG(stream_wrappers) and FG(stream_filters) are destroyed - * during php_request_shutdown() */ - PHP_RSHUTDOWN(filestat)(SHUTDOWN_FUNC_ARGS_PASSTHRU); #ifdef HAVE_SYSLOG_H BASIC_RSHUTDOWN_SUBMODULE(syslog); diff --git a/ext/standard/file.c b/ext/standard/file.c index ff68374928c5..feb0ddbf45bd 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -133,19 +133,9 @@ static void file_globals_dtor(php_file_globals *file_globals_p) #endif } -static PHP_INI_MH(OnUpdateAutoDetectLineEndings) -{ - if (zend_ini_parse_bool(new_value)) { - zend_error(E_DEPRECATED, "auto_detect_line_endings is deprecated"); - } - return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage); -} - PHP_INI_BEGIN() STD_PHP_INI_ENTRY("user_agent", NULL, PHP_INI_ALL, OnUpdateStr, user_agent, php_file_globals, file_globals) STD_PHP_INI_ENTRY("from", NULL, PHP_INI_ALL, OnUpdateStr, from_address, php_file_globals, file_globals) - STD_PHP_INI_ENTRY("default_socket_timeout", "60", PHP_INI_ALL, OnUpdateLong, default_socket_timeout, php_file_globals, file_globals) - STD_PHP_INI_BOOLEAN("auto_detect_line_endings", "0", PHP_INI_ALL, OnUpdateAutoDetectLineEndings, auto_detect_line_endings, php_file_globals, file_globals) PHP_INI_END() PHP_MINIT_FUNCTION(file) diff --git a/ext/standard/file.h b/ext/standard/file.h index 9ba5f5b8b93d..08dede7ef9ee 100644 --- a/ext/standard/file.h +++ b/ext/standard/file.h @@ -91,16 +91,9 @@ php_meta_tags_token php_next_meta_token(php_meta_tags_data *); typedef struct { int pclose_ret; size_t def_chunk_size; - bool auto_detect_line_endings; - zend_long default_socket_timeout; zend_string *user_agent; /* for the http wrapper */ zend_string *from_address; /* for the ftp and http wrappers */ - const char *user_stream_current_filename; /* for simple recursion protection */ php_stream_context *default_context; - HashTable *stream_wrappers; /* per-request copy of url_stream_wrappers_hash */ - HashTable *stream_filters; /* per-request copy of stream_filters_hash */ - HashTable *wrapper_logged_errors; /* key: wrapper address; value: linked list of error entries */ - php_stream_error_state stream_error_state; int pclose_wait; #ifdef HAVE_GETHOSTBYNAME_R struct hostent tmp_host_info; diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c index 13485f9d1977..d86f315c9962 100644 --- a/ext/standard/fsock.c +++ b/ext/standard/fsock.c @@ -72,7 +72,7 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) RETVAL_FALSE; if (timeout_is_null) { - timeout = (double)FG(default_socket_timeout); + timeout = (double)PG(default_socket_timeout); } if (persistent) { diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index 21a2be87571f..98c938d26e3f 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -557,9 +557,9 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, #endif } else { #ifndef PHP_WIN32 - timeout.tv_sec = FG(default_socket_timeout); + timeout.tv_sec = PG(default_socket_timeout); #else - timeout.tv_sec = (long)FG(default_socket_timeout); + timeout.tv_sec = (long)PG(default_socket_timeout); #endif timeout.tv_usec = 0; } diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 8bb6064fc6da..e2dc5859d318 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -130,7 +130,7 @@ PHP_FUNCTION(stream_socket_client) RETVAL_FALSE; if (timeout_is_null) { - timeout = (double)FG(default_socket_timeout); + timeout = (double)PG(default_socket_timeout); } else if (!zend_finite(timeout)) { zend_argument_value_error(4, "must be a finite value"); RETURN_THROWS(); @@ -290,7 +290,7 @@ PHP_FUNCTION(stream_socket_accept) ZEND_PARSE_PARAMETERS_END(); if (timeout_is_null) { - timeout = (double)FG(default_socket_timeout); + timeout = (double)PG(default_socket_timeout); } else if (!zend_finite(timeout)) { zend_argument_value_error(2, "must be a finite value"); RETURN_THROWS(); diff --git a/main/main.c b/main/main.c index a8cdff9ff688..1dfd883f7149 100644 --- a/main/main.c +++ b/main/main.c @@ -797,6 +797,15 @@ static PHP_INI_MH(OnChangeMailForceExtra) } /* }}} */ +static PHP_INI_MH(OnUpdateAutoDetectLineEndings) +{ + if (zend_ini_parse_bool(new_value)) { + zend_error(E_DEPRECATED, "auto_detect_line_endings is deprecated"); + } + return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage); +} + + /* defined in browscap.c */ PHP_INI_MH(OnChangeBrowscap); @@ -919,6 +928,8 @@ PHP_INI_BEGIN() STD_PHP_INI_ENTRY("syslog.facility", "LOG_USER", PHP_INI_SYSTEM, OnSetFacility, syslog_facility, php_core_globals, core_globals) STD_PHP_INI_ENTRY("syslog.ident", "php", PHP_INI_SYSTEM, OnUpdateString, syslog_ident, php_core_globals, core_globals) STD_PHP_INI_ENTRY("syslog.filter", "no-ctrl", PHP_INI_ALL, OnSetLogFilter, syslog_filter, php_core_globals, core_globals) + STD_PHP_INI_ENTRY("default_socket_timeout", "60", PHP_INI_ALL, OnUpdateLong, default_socket_timeout, php_core_globals, core_globals) + STD_PHP_INI_BOOLEAN("auto_detect_line_endings", "0", PHP_INI_ALL, OnUpdateAutoDetectLineEndings, auto_detect_line_endings, php_core_globals, core_globals) PHP_INI_END() /* }}} */ @@ -1871,6 +1882,12 @@ zend_result php_request_startup(void) signal(SIGCHLD, sigchld_handler); #endif + /* Default to global wrappers only */ + PG(stream_wrappers) = NULL; + + /* Default to global filters only */ + PG(stream_filters) = NULL; + zend_try { PG(in_error_log) = 0; PG(during_request_startup) = 1; diff --git a/main/network.c b/main/network.c index cdca7efdac72..89c151b45554 100644 --- a/main/network.c +++ b/main/network.c @@ -1292,7 +1292,7 @@ PHPAPI php_stream *_php_stream_sock_open_from_socket(php_socket_t socket, const memset(sock, 0, sizeof(php_netstream_data_t)); sock->is_blocked = true; - sock->timeout.tv_sec = FG(default_socket_timeout); + sock->timeout.tv_sec = PG(default_socket_timeout); sock->timeout.tv_usec = 0; sock->socket = socket; diff --git a/main/php_globals.h b/main/php_globals.h index e3cfe38a63fd..6e14a3089305 100644 --- a/main/php_globals.h +++ b/main/php_globals.h @@ -134,6 +134,7 @@ struct _php_core_globals { bool allow_url_fopen; bool enable_post_data_reading; bool report_zend_debug; + bool auto_detect_line_endings; int last_error_type; uint32_t last_error_lineno; @@ -170,6 +171,12 @@ struct _php_core_globals { char *syslog_ident; zend_long syslog_filter; zend_long error_log_mode; + zend_long default_socket_timeout; + const char *user_stream_current_filename; /* for simple recursion protection */ + HashTable *stream_wrappers; /* per-request copy of url_stream_wrappers_hash */ + HashTable *stream_filters; /* per-request copy of stream_filters_hash */ + HashTable *wrapper_logged_errors; /* key: wrapper address; value: linked list of error entries */ + php_stream_error_state stream_error_state; }; diff --git a/main/streams/filter.c b/main/streams/filter.c index df50ef017cd3..b59f50522816 100644 --- a/main/streams/filter.c +++ b/main/streams/filter.c @@ -14,13 +14,12 @@ #include "php.h" #include "php_network.h" -#include "ext/standard/file.h" /* For FG(stream_filters) */ #include #include #include "php_streams_int.h" -/* Global filter hash, copied to FG(stream_filters) on registration of volatile filter */ +/* Global filter hash, copied to PG(stream_filters) on registration of volatile filter */ static HashTable stream_filters_hash; /* Should only be used during core initialization */ @@ -32,7 +31,7 @@ PHPAPI HashTable *php_get_stream_filters_hash_global(void) /* Normal hash selection/retrieval call */ PHPAPI HashTable *php_get_stream_filters_hash(void) { - return (FG(stream_filters) ? FG(stream_filters) : &stream_filters_hash); + return (PG(stream_filters) ? PG(stream_filters) : &stream_filters_hash); } /* API for registering GLOBAL filters */ @@ -53,13 +52,13 @@ PHPAPI zend_result php_stream_filter_unregister_factory(const char *filterpatter /* API for registering VOLATILE wrappers */ PHPAPI zend_result php_stream_filter_register_factory_volatile(zend_string *filterpattern, const php_stream_filter_factory *factory) { - if (!FG(stream_filters)) { - ALLOC_HASHTABLE(FG(stream_filters)); - zend_hash_init(FG(stream_filters), zend_hash_num_elements(&stream_filters_hash) + 1, NULL, NULL, 0); - zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL); + if (!PG(stream_filters)) { + ALLOC_HASHTABLE(PG(stream_filters)); + zend_hash_init(PG(stream_filters), zend_hash_num_elements(&stream_filters_hash) + 1, NULL, NULL, 0); + zend_hash_copy(PG(stream_filters), &stream_filters_hash, NULL); } - return zend_hash_add_ptr(FG(stream_filters), filterpattern, (void*)factory) ? SUCCESS : FAILURE; + return zend_hash_add_ptr(PG(stream_filters), filterpattern, (void*)factory) ? SUCCESS : FAILURE; } /* Buckets */ @@ -216,7 +215,7 @@ PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket) * charsets (for example) but still be able to provide them all as filters */ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, bool persistent) { - HashTable *filter_hash = (FG(stream_filters) ? FG(stream_filters) : &stream_filters_hash); + HashTable *filter_hash = (PG(stream_filters) ? PG(stream_filters) : &stream_filters_hash); const php_stream_filter_factory *factory = NULL; php_stream_filter *filter = NULL; size_t n; diff --git a/main/streams/stream_errors.c b/main/streams/stream_errors.c index 211cf4df025a..bcdc163ee1ef 100644 --- a/main/streams/stream_errors.c +++ b/main/streams/stream_errors.c @@ -191,7 +191,7 @@ static bool php_stream_has_terminating_error(const php_stream_error_entry *entry static inline php_stream_error_operation *php_stream_get_operation_at_depth(uint32_t depth) { - php_stream_error_state *state = &FG(stream_error_state); + php_stream_error_state *state = &PG(stream_error_state); if (depth < PHP_STREAM_ERROR_OPERATION_POOL_SIZE) { return &state->operation_pool[depth]; @@ -204,7 +204,7 @@ static inline php_stream_error_operation *php_stream_get_operation_at_depth(uint static inline php_stream_error_operation *php_stream_get_parent_operation(void) { - const php_stream_error_state *state = &FG(stream_error_state); + const php_stream_error_state *state = &PG(stream_error_state); if (state->operation_depth <= state->operation_floor) { return NULL; @@ -229,7 +229,7 @@ static void php_stream_error_entry_free(php_stream_error_entry *entry) PHPAPI void php_stream_error_state_cleanup(void) { - php_stream_error_state *state = &FG(stream_error_state); + php_stream_error_state *state = &PG(stream_error_state); state->operation_floor = 0; state->refused_operations = 0; @@ -266,7 +266,7 @@ PHPAPI void php_stream_error_state_cleanup(void) PHPAPI void php_stream_error_get_last(zval *return_value) { - const php_stream_error_state *state = &FG(stream_error_state); + const php_stream_error_state *state = &PG(stream_error_state); if (!state->stored_errors) { ZVAL_EMPTY_ARRAY(return_value); @@ -278,7 +278,7 @@ PHPAPI void php_stream_error_get_last(zval *return_value) PHPAPI void php_stream_error_clear_stored(void) { - php_stream_error_state *state = &FG(stream_error_state); + php_stream_error_state *state = &PG(stream_error_state); php_stream_stored_error *stored = state->stored_errors; while (stored) { @@ -296,7 +296,7 @@ PHPAPI void php_stream_error_clear_stored(void) PHPAPI php_stream_error_operation *php_stream_error_operation_begin(void) { - php_stream_error_state *state = &FG(stream_error_state); + php_stream_error_state *state = &PG(stream_error_state); if (state->operation_depth >= PHP_STREAM_ERROR_MAX_DEPTH) { php_error_docref(NULL, E_WARNING, @@ -338,7 +338,7 @@ PHPAPI php_stream_error_operation *php_stream_error_operation_begin(void) static void php_stream_error_add(zend_enum_StreamErrorCode code, const char *wrapper_name, zend_string *message, const char *docref, int severity, bool terminating) { - php_stream_error_operation *op = FG(stream_error_state).current_operation; + php_stream_error_operation *op = PG(stream_error_state).current_operation; if (!op) { zend_string_release(message); return; @@ -448,7 +448,7 @@ static void php_stream_report_errors(const php_stream_context *context, const ph PHPAPI void php_stream_error_operation_end(const php_stream_context *context) { - php_stream_error_state *state = &FG(stream_error_state); + php_stream_error_state *state = &PG(stream_error_state); php_stream_error_operation *op = state->current_operation; if (state->refused_operations > 0) { @@ -559,7 +559,7 @@ PHPAPI void php_stream_error_operation_end(const php_stream_context *context) PHPAPI void php_stream_error_operation_end_for_stream(const php_stream *stream) { - php_stream_error_state *state = &FG(stream_error_state); + php_stream_error_state *state = &PG(stream_error_state); php_stream_error_operation *op = state->current_operation; if (state->refused_operations > 0) { @@ -586,7 +586,7 @@ PHPAPI void php_stream_error_operation_end_for_stream(const php_stream *stream) PHPAPI void php_stream_error_operation_abort(void) { - php_stream_error_state *state = &FG(stream_error_state); + php_stream_error_state *state = &PG(stream_error_state); php_stream_error_operation *op = state->current_operation; if (state->refused_operations > 0) { @@ -613,7 +613,7 @@ static void php_stream_wrapper_error_internal(const char *wrapper_name, const ph const char *docref, int severity, bool terminating, zend_enum_StreamErrorCode code, zend_string *message) { - bool implicit_operation = (FG(stream_error_state).current_operation == NULL); + bool implicit_operation = (PG(stream_error_state).current_operation == NULL); if (implicit_operation) { php_stream_error_operation_begin(); } @@ -710,19 +710,19 @@ static void php_stream_wrapper_log_store_error(zend_string *message, zend_enum_S entry->severity = severity; entry->terminating = terminating; - if (!FG(wrapper_logged_errors)) { - ALLOC_HASHTABLE(FG(wrapper_logged_errors)); - zend_hash_init(FG(wrapper_logged_errors), 8, NULL, php_stream_error_list_dtor, 0); + if (!PG(wrapper_logged_errors)) { + ALLOC_HASHTABLE(PG(wrapper_logged_errors)); + zend_hash_init(PG(wrapper_logged_errors), 8, NULL, php_stream_error_list_dtor, 0); } zend_llist *list - = zend_hash_str_find_ptr(FG(wrapper_logged_errors), wrapper_name, strlen(wrapper_name)); + = zend_hash_str_find_ptr(PG(wrapper_logged_errors), wrapper_name, strlen(wrapper_name)); if (!list) { zend_llist new_list; zend_llist_init( &new_list, sizeof(php_stream_error_entry *), php_stream_error_entry_dtor_legacy, 0); - list = zend_hash_str_update_mem(FG(wrapper_logged_errors), wrapper_name, + list = zend_hash_str_update_mem(PG(wrapper_logged_errors), wrapper_name, strlen(wrapper_name), &new_list, sizeof(new_list)); } @@ -750,11 +750,11 @@ PHPAPI void php_stream_wrapper_log_error(const php_stream_wrapper *wrapper, static zend_llist *php_stream_get_wrapper_errors_list(const char *wrapper_name) { - if (!FG(wrapper_logged_errors)) { + if (!PG(wrapper_logged_errors)) { return NULL; } return (zend_llist *) zend_hash_str_find_ptr( - FG(wrapper_logged_errors), wrapper_name, strlen(wrapper_name)); + PG(wrapper_logged_errors), wrapper_name, strlen(wrapper_name)); } PHPAPI void php_stream_display_wrapper_name_errors(const char *wrapper_name, @@ -839,8 +839,8 @@ PHPAPI void php_stream_display_wrapper_errors(const php_stream_wrapper *wrapper, PHPAPI void php_stream_tidy_wrapper_name_error_log(const char *wrapper_name) { - if (FG(wrapper_logged_errors)) { - zend_hash_str_del(FG(wrapper_logged_errors), wrapper_name, strlen(wrapper_name)); + if (PG(wrapper_logged_errors)) { + zend_hash_str_del(PG(wrapper_logged_errors), wrapper_name, strlen(wrapper_name)); } } diff --git a/main/streams/streams.c b/main/streams/streams.c index a83e5d6042b2..193270659419 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -34,7 +34,7 @@ #include "php_streams_int.h" /* {{{ resource and registration code */ -/* Global wrapper hash, copied to FG(stream_wrappers) on registration of volatile wrapper */ +/* Global wrapper hash, copied to PG(stream_wrappers) on registration of volatile wrapper */ static HashTable url_stream_wrappers_hash; static int le_stream = -1; /* true global */ static int le_pstream = -1; /* true global */ @@ -57,7 +57,7 @@ PHPAPI int php_file_le_stream_filter(void) PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash(void) { - return (FG(stream_wrappers) ? FG(stream_wrappers) : &url_stream_wrappers_hash); + return (PG(stream_wrappers) ? PG(stream_wrappers) : &url_stream_wrappers_hash); } PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash_global(void) @@ -186,7 +186,7 @@ fprintf(stderr, "stream_alloc: %s:%p persistent=%s\n", ops->label, ret, persiste ret->open_lineno = __zend_orig_lineno ? __zend_orig_lineno : __zend_lineno; #endif - if (FG(auto_detect_line_endings)) { + if (PG(auto_detect_line_endings)) { ret->flags |= PHP_STREAM_FLAG_DETECT_EOL; } @@ -1806,23 +1806,23 @@ static void stream_resource_persistent_dtor(zend_resource *rsrc) void php_shutdown_stream_hashes(void) { - FG(user_stream_current_filename) = NULL; - if (FG(stream_wrappers)) { - zend_hash_destroy(FG(stream_wrappers)); - efree(FG(stream_wrappers)); - FG(stream_wrappers) = NULL; + PG(user_stream_current_filename) = NULL; + if (PG(stream_wrappers)) { + zend_hash_destroy(PG(stream_wrappers)); + efree(PG(stream_wrappers)); + PG(stream_wrappers) = NULL; } - if (FG(stream_filters)) { - zend_hash_destroy(FG(stream_filters)); - efree(FG(stream_filters)); - FG(stream_filters) = NULL; + if (PG(stream_filters)) { + zend_hash_destroy(PG(stream_filters)); + efree(PG(stream_filters)); + PG(stream_filters) = NULL; } - if (FG(wrapper_logged_errors)) { - zend_hash_destroy(FG(wrapper_logged_errors)); - efree(FG(wrapper_logged_errors)); - FG(wrapper_logged_errors) = NULL; + if (PG(wrapper_logged_errors)) { + zend_hash_destroy(PG(wrapper_logged_errors)); + efree(PG(wrapper_logged_errors)); + PG(wrapper_logged_errors) = NULL; } php_stream_error_state_cleanup(); @@ -1896,9 +1896,9 @@ PHPAPI zend_result php_unregister_url_stream_wrapper(const char *protocol) static void clone_wrapper_hash(void) { - ALLOC_HASHTABLE(FG(stream_wrappers)); - zend_hash_init(FG(stream_wrappers), zend_hash_num_elements(&url_stream_wrappers_hash), NULL, NULL, 0); - zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL); + ALLOC_HASHTABLE(PG(stream_wrappers)); + zend_hash_init(PG(stream_wrappers), zend_hash_num_elements(&url_stream_wrappers_hash), NULL, NULL, 0); + zend_hash_copy(PG(stream_wrappers), &url_stream_wrappers_hash, NULL); } /* API for registering VOLATILE wrappers */ @@ -1908,27 +1908,27 @@ PHPAPI zend_result php_register_url_stream_wrapper_volatile(zend_string *protoco return FAILURE; } - if (!FG(stream_wrappers)) { + if (!PG(stream_wrappers)) { clone_wrapper_hash(); } - return zend_hash_add_ptr(FG(stream_wrappers), protocol, wrapper) ? SUCCESS : FAILURE; + return zend_hash_add_ptr(PG(stream_wrappers), protocol, wrapper) ? SUCCESS : FAILURE; } PHPAPI zend_result php_unregister_url_stream_wrapper_volatile(zend_string *protocol) { - if (!FG(stream_wrappers)) { + if (!PG(stream_wrappers)) { clone_wrapper_hash(); } - return zend_hash_del(FG(stream_wrappers), protocol); + return zend_hash_del(PG(stream_wrappers), protocol); } /* }}} */ /* {{{ php_stream_locate_url_wrapper */ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options) { - const HashTable *wrapper_hash = (FG(stream_wrappers) ? FG(stream_wrappers) : &url_stream_wrappers_hash); + const HashTable *wrapper_hash = (PG(stream_wrappers) ? PG(stream_wrappers) : &url_stream_wrappers_hash); php_stream_wrapper *wrapper = NULL; const char *p, *protocol = NULL; size_t n = 0; @@ -2014,7 +2014,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const return NULL; } - if (FG(stream_wrappers)) { + if (PG(stream_wrappers)) { /* The file:// wrapper may have been disabled/overridden */ if (wrapper) { diff --git a/main/streams/transports.c b/main/streams/transports.c index ca0ab7a3d310..a1410aa4a0e4 100644 --- a/main/streams/transports.c +++ b/main/streams/transports.c @@ -14,7 +14,6 @@ #include "php.h" #include "php_streams_int.h" -#include "ext/standard/file.h" /* For FG(default_socket_timeout) */ static HashTable xport_hash; @@ -63,7 +62,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in zend_string *error_text = NULL; struct timeval default_timeout = { 0, 0 }; - default_timeout.tv_sec = FG(default_socket_timeout); + default_timeout.tv_sec = PG(default_socket_timeout); if (timeout == NULL) { timeout = &default_timeout; diff --git a/main/streams/userspace.c b/main/streams/userspace.c index 6f2949a44cca..de25ea22b19f 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -15,7 +15,6 @@ #include "php.h" #include "php_globals.h" -#include "ext/standard/file.h" #include "ext/standard/flock_compat.h" #ifdef HAVE_SYS_FILE_H #include @@ -288,12 +287,12 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char * bool old_in_user_include; /* Try to catch bad usage without preventing flexibility */ - if (FG(user_stream_current_filename) != NULL && strcmp(filename, FG(user_stream_current_filename)) == 0) { + if (PG(user_stream_current_filename) != NULL && strcmp(filename, PG(user_stream_current_filename)) == 0) { php_stream_wrapper_log_warn(wrapper, context, options, RecursionDetected, "infinite recursion prevented"); return NULL; } - FG(user_stream_current_filename) = filename; + PG(user_stream_current_filename) = filename; /* if the user stream was registered as local and we are in include context, we add allow_url_include restrictions to allow_url_fopen ones */ @@ -363,7 +362,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char * zval_ptr_dtor(&args[3]); end: - FG(user_stream_current_filename) = NULL; + PG(user_stream_current_filename) = NULL; PG(in_user_include) = old_in_user_include; if (stream == NULL) { if (us->object) { @@ -393,12 +392,12 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char php_stream *stream = NULL; /* Try to catch bad usage without preventing flexibility */ - if (FG(user_stream_current_filename) != NULL && strcmp(filename, FG(user_stream_current_filename)) == 0) { + if (PG(user_stream_current_filename) != NULL && strcmp(filename, PG(user_stream_current_filename)) == 0) { php_stream_wrapper_log_warn(wrapper, context, options, RecursionDetected, "infinite recursion prevented"); return NULL; } - FG(user_stream_current_filename) = filename; + PG(user_stream_current_filename) = filename; us = emalloc(sizeof(*us)); us->wrapper = uwrap; @@ -444,7 +443,7 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char zval_ptr_dtor(&zretval); end: - FG(user_stream_current_filename) = NULL; + PG(user_stream_current_filename) = NULL; if (stream == NULL) { if (us->object) { OBJ_RELEASE(us->object); diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index 221552056420..57c3f44816a6 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -354,7 +354,7 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void if (value == -1) { if (sock->timeout.tv_sec == -1) { - tv.tv_sec = FG(default_socket_timeout); + tv.tv_sec = PG(default_socket_timeout); tv.tv_usec = 0; } else { tv = sock->timeout; @@ -1168,7 +1168,7 @@ PHPAPI php_stream *php_stream_generic_socket_factory(const char *proto, size_t p memset(sock, 0, sizeof(php_netstream_data_t)); sock->is_blocked = true; - sock->timeout.tv_sec = FG(default_socket_timeout); + sock->timeout.tv_sec = PG(default_socket_timeout); sock->timeout.tv_usec = 0; /* we don't know the socket until we have determined if we are binding or diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index fc62c0dd4b46..80c498354f6a 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -214,7 +214,7 @@ static inline bool sapi_cli_select(php_socket_t fd) { struct timeval tv; - tv.tv_sec = (long)FG(default_socket_timeout); + tv.tv_sec = (long)PG(default_socket_timeout); tv.tv_usec = 0; return php_pollfd_for(fd, POLLOUT, &tv) != -1;