diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index a2f9bc7f01c9..a81d19832cc5 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -125,6 +125,11 @@ PHP 8.7 INTERNALS UPGRADE NOTES . Added php_date_time_duration_create() to create Time\Duration objects without going through the userland API. +- libxml: + . The signature of php_libxml_switch_context() changed from + void php_libxml_switch_context(const zval *context, zval *oldcontext) to + php_stream_context *php_libxml_switch_context(php_stream_context *context) + - MySQLi: . Removed the reverse API. The mysqlnd_reverse_api.h header, the MYSQLND_REVERSE_API struct and the functions zval_to_mysqlnd(), diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index f9ce4c5310e8..57a6efaf6853 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -409,7 +409,7 @@ static PHP_GINIT_FUNCTION(libxml) #if defined(COMPILE_DL_LIBXML) && defined(ZTS) ZEND_TSRMLS_CACHE_UPDATE(); #endif - ZVAL_UNDEF(&libxml_globals->stream_context); + libxml_globals->stream_context = NULL; libxml_globals->error_buffer.s = NULL; libxml_globals->error_list = NULL; libxml_globals->entity_loader_callback = empty_fcall_info_cache; @@ -417,7 +417,11 @@ static PHP_GINIT_FUNCTION(libxml) PHP_LIBXML_API php_stream_context *php_libxml_get_stream_context(void) { - return php_stream_context_from_zval(Z_ISUNDEF(LIBXML(stream_context)) ? NULL : &LIBXML(stream_context), false); + if (LIBXML(stream_context)) { + return LIBXML(stream_context); + } else { + return php_stream_context_get_default(false); + } } /* Channel libxml file io layer through the PHP streams subsystem. @@ -973,14 +977,11 @@ PHP_LIBXML_API void php_libxml_shutdown(void) } } -PHP_LIBXML_API void php_libxml_switch_context(const zval *context, zval *oldcontext) +PHP_LIBXML_API php_stream_context *php_libxml_switch_context(php_stream_context *context) { - if (oldcontext) { - ZVAL_COPY_VALUE(oldcontext, &LIBXML(stream_context)); - } - if (context) { - ZVAL_COPY_VALUE(&LIBXML(stream_context), context); - } + php_stream_context *old_context = LIBXML(stream_context); + LIBXML(stream_context) = context; + return old_context; } static PHP_MINIT_FUNCTION(libxml) @@ -1072,7 +1073,7 @@ static zend_result php_libxml_post_deactivate(void) xmlSetStructuredErrorFunc(NULL, NULL); /* the steam_context resource will be released by resource list destructor */ - ZVAL_UNDEF(&LIBXML(stream_context)); + LIBXML(stream_context) = NULL; smart_str_free(&LIBXML(error_buffer)); if (LIBXML(error_list)) { zend_llist_destroy(LIBXML(error_list)); @@ -1105,11 +1106,14 @@ PHP_FUNCTION(libxml_set_streams_context) Z_PARAM_RESOURCE(arg) ZEND_PARSE_PARAMETERS_END(); - if (php_stream_context_from_zval(arg, true) != NULL) { - if (!Z_ISUNDEF(LIBXML(stream_context))) { - zval_ptr_dtor(&LIBXML(stream_context)); + php_stream_context *context = php_stream_context_from_zval(arg, true); + if (context != NULL) { + if (LIBXML(stream_context)) { + /* Close resource associated to stream context, which will take + * care of freeing the rest of the stream context. */ + zend_list_close(LIBXML(stream_context)->res); } - ZVAL_COPY(&LIBXML(stream_context), arg); + LIBXML(stream_context) = context; } } /* }}} */ diff --git a/ext/libxml/php_libxml.h b/ext/libxml/php_libxml.h index 5896f70803f8..3e0bb3c83a30 100644 --- a/ext/libxml/php_libxml.h +++ b/ext/libxml/php_libxml.h @@ -40,7 +40,7 @@ extern zend_module_entry libxml_module_entry; #define LIBXML_NS_TAG_HOOK 1 ZEND_BEGIN_MODULE_GLOBALS(libxml) - zval stream_context; + php_stream_context *stream_context; smart_str error_buffer; zend_llist *error_list; zend_fcall_info_cache entity_loader_callback; @@ -205,7 +205,7 @@ PHP_LIBXML_API void php_libxml_ctx_warning(void *ctx, const char *msg, ...); PHP_LIBXML_API void php_libxml_pretend_ctx_error_ex(const char *file, int line, int column, const char *msg,...); PHP_LIBXML_API void php_libxml_ctx_error(void *ctx, const char *msg, ...); PHP_LIBXML_API void php_libxml_error_handler_va(php_libxml_error_level error_type, void *ctx, const char *msg, va_list args); -PHP_LIBXML_API void php_libxml_switch_context(const zval *context, zval *oldcontext); +PHP_LIBXML_API php_stream_context *php_libxml_switch_context(php_stream_context *context); PHP_LIBXML_API void php_libxml_issue_error(int level, const char *msg); PHP_LIBXML_API bool php_libxml_disable_entity_loader(bool disable); PHP_LIBXML_API void php_libxml_set_old_ns(xmlDocPtr doc, xmlNsPtr ns); diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 69ab56169c40..13e1024c07cb 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -271,7 +271,6 @@ void sdl_set_uri_credentials(sdlCtx *ctx, char *uri) { char *s; size_t l1, l2; - zval context; zval *header = NULL; /* check if we load xsd from the same server */ @@ -320,18 +319,13 @@ void sdl_set_uri_credentials(sdlCtx *ctx, char *uri) if (l1 == l2 && memcmp(ctx->sdl->source, uri, l1) == 0) { return; } - /* another server. clear authentication credentals */ - php_libxml_switch_context(NULL, &context); - php_libxml_switch_context(&context, NULL); - if (Z_TYPE(context) == IS_UNDEF) { - return; - } - zval *context_ptr = &context; - ctx->context = php_stream_context_from_zval(context_ptr, 1); - - if (!ctx->context) { + /* another server. clear authentication credentials */ + php_stream_context *context = php_libxml_switch_context(NULL); + php_libxml_switch_context(context); + if (context == NULL) { return; } + ctx->context = context; header = php_stream_context_get_option(ctx->context, "http", "header"); if (header == NULL) { @@ -3316,15 +3310,13 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, zend_long cache_wsdl) char* old_error_code = SOAP_GLOBAL(error_code); size_t uri_len = 0; php_stream_context *context=NULL; - zval *tmp, orig_context, new_context; + zval *tmp; smart_str headers = {0}; char* key = NULL; time_t t = time(0); bool has_proxy_authorization = false; bool has_authorization = false; - ZVAL_UNDEF(&orig_context); - ZVAL_UNDEF(&new_context); if (strchr(uri,':') != NULL || IS_ABSOLUTE_PATH(uri, uri_len)) { uri_len = strlen(uri); } else if (VCWD_REALPATH(uri, fn) == NULL) { @@ -3397,9 +3389,6 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, zend_long cache_wsdl) tmp = Z_CLIENT_STREAM_CONTEXT_P(this_ptr); if (Z_TYPE_P(tmp) == IS_RESOURCE) { context = php_stream_context_from_zval(tmp, 0); - /* 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); } tmp = Z_CLIENT_USER_AGENT_P(this_ptr); @@ -3465,9 +3454,9 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, zend_long cache_wsdl) zval_ptr_dtor(&str_headers); } + php_stream_context *orig_context = NULL; if (context) { - ZVAL_RES(&new_context, context->res); - php_libxml_switch_context(&new_context, &orig_context); + orig_context = php_libxml_switch_context(context); } SOAP_GLOBAL(error_code) = "WSDL"; @@ -3480,8 +3469,7 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, zend_long cache_wsdl) SOAP_GLOBAL(error_code) = old_error_code; if (context) { - php_libxml_switch_context(&orig_context, NULL); - zval_ptr_dtor(&new_context); + php_libxml_switch_context(orig_context); } if ((cache_wsdl & WSDL_CACHE_DISK) && key) {