Commit 615b9803bb0 for php.net
commit 615b9803bb0d47894b38b2848e895da47443b67f
Author: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Date: Thu May 29 20:14:57 2025 +0200
Get rid of redundant SOAP globals (#18702)
The copy doesn't make sense, remove it.
diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c
index c4fa7702cf4..e3bd3029388 100644
--- a/ext/soap/php_encoding.c
+++ b/ext/soap/php_encoding.c
@@ -3456,7 +3456,7 @@ xmlNsPtr encode_add_ns(xmlNodePtr node, const char* ns)
if (xmlns == NULL) {
xmlChar* prefix;
- if ((prefix = zend_hash_str_find_ptr(&SOAP_GLOBAL(defEncNs), (char*)ns, strlen(ns))) != NULL) {
+ if ((prefix = zend_hash_str_find_ptr(&php_soap_defEncNs, (char*)ns, strlen(ns))) != NULL) {
xmlns = xmlNewNs(node->doc->children, BAD_CAST(ns), prefix);
} else {
smart_str prefix = {0};
@@ -3531,7 +3531,7 @@ encodePtr get_conversion(int encode)
{
encodePtr enc;
- if ((enc = zend_hash_index_find_ptr(&SOAP_GLOBAL(defEncIndex), encode)) == NULL) {
+ if ((enc = zend_hash_index_find_ptr(&php_soap_defEncIndex, encode)) == NULL) {
soap_error0(E_ERROR, "Encoding: Cannot find encoding");
return NULL;
} else {
diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c
index 5826c82c644..9a9df794827 100644
--- a/ext/soap/php_sdl.c
+++ b/ext/soap/php_sdl.c
@@ -177,7 +177,7 @@ encodePtr get_encoder_ex(sdlPtr sdl, const char *nscat, size_t len)
{
encodePtr enc;
- if ((enc = zend_hash_str_find_ptr(&SOAP_GLOBAL(defEnc), nscat, len)) != NULL) {
+ if ((enc = zend_hash_str_find_ptr(&php_soap_defEnc, nscat, len)) != NULL) {
return enc;
} else if (sdl && sdl->encoders && (enc = zend_hash_str_find_ptr(sdl->encoders, nscat, len)) != NULL) {
return enc;
diff --git a/ext/soap/php_soap.h b/ext/soap/php_soap.h
index a78734aa7f1..89dbf4408be 100644
--- a/ext/soap/php_soap.h
+++ b/ext/soap/php_soap.h
@@ -151,9 +151,6 @@ struct _soapService {
ZEND_BEGIN_MODULE_GLOBALS(soap)
- HashTable defEncNs; /* mapping of default namespaces to prefixes */
- HashTable defEnc;
- HashTable defEncIndex;
HashTable *typemap;
int cur_uniq_ns;
int soap_version;
@@ -195,6 +192,8 @@ extern zend_class_entry* soap_var_class_entry;
extern zend_class_entry* soap_url_class_entry;
extern zend_class_entry* soap_sdl_class_entry;
+extern HashTable php_soap_defEncNs, php_soap_defEnc, php_soap_defEncIndex;
+
void add_soap_fault(zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail);
#define soap_error0(severity, format) \
diff --git a/ext/soap/soap.c b/ext/soap/soap.c
index 09043886b9c..094730b88f4 100644
--- a/ext/soap/soap.c
+++ b/ext/soap/soap.c
@@ -390,16 +390,18 @@ STD_PHP_INI_ENTRY("soap.wsdl_cache_limit", "5", PHP_INI_ALL, OnUpdateLong,
cache_limit, zend_soap_globals, soap_globals)
PHP_INI_END()
-static HashTable defEnc, defEncIndex, defEncNs;
+/* Real globals shared for the entire processes across threads, only written during init. */
+HashTable php_soap_defEncNs; /* mapping of default namespaces to prefixes */
+HashTable php_soap_defEnc, php_soap_defEncIndex;
static void php_soap_prepare_globals(void)
{
int i;
encode* enc;
- zend_hash_init(&defEnc, 0, NULL, NULL, 1);
- zend_hash_init(&defEncIndex, 0, NULL, NULL, 1);
- zend_hash_init(&defEncNs, 0, NULL, NULL, 1);
+ zend_hash_init(&php_soap_defEnc, 0, NULL, NULL, 1);
+ zend_hash_init(&php_soap_defEncIndex, 0, NULL, NULL, 1);
+ zend_hash_init(&php_soap_defEncNs, 0, NULL, NULL, 1);
i = 0;
do {
@@ -412,25 +414,25 @@ static void php_soap_prepare_globals(void)
size_t clark_notation_len = spprintf(&clark_notation, 0, "{%s}%s", enc->details.ns, enc->details.type_str);
enc->details.clark_notation = zend_string_init(clark_notation, clark_notation_len, true);
size_t ns_type_len = spprintf(&ns_type, 0, "%s:%s", enc->details.ns, enc->details.type_str);
- zend_hash_str_add_ptr(&defEnc, ns_type, ns_type_len, (void*)enc);
+ zend_hash_str_add_ptr(&php_soap_defEnc, ns_type, ns_type_len, (void*)enc);
efree(clark_notation);
efree(ns_type);
} else {
- zend_hash_str_add_ptr(&defEnc, defaultEncoding[i].details.type_str, strlen(defaultEncoding[i].details.type_str), (void*)enc);
+ zend_hash_str_add_ptr(&php_soap_defEnc, defaultEncoding[i].details.type_str, strlen(defaultEncoding[i].details.type_str), (void*)enc);
}
}
/* Index everything by number */
- zend_hash_index_add_ptr(&defEncIndex, defaultEncoding[i].details.type, (void*)enc);
+ zend_hash_index_add_ptr(&php_soap_defEncIndex, defaultEncoding[i].details.type, (void*)enc);
i++;
} while (defaultEncoding[i].details.type != END_KNOWN_TYPES);
/* hash by namespace */
- zend_hash_str_add_ptr(&defEncNs, XSD_1999_NAMESPACE, sizeof(XSD_1999_NAMESPACE)-1, XSD_NS_PREFIX);
- zend_hash_str_add_ptr(&defEncNs, XSD_NAMESPACE, sizeof(XSD_NAMESPACE)-1, XSD_NS_PREFIX);
- zend_hash_str_add_ptr(&defEncNs, XSI_NAMESPACE, sizeof(XSI_NAMESPACE)-1, XSI_NS_PREFIX);
- zend_hash_str_add_ptr(&defEncNs, XML_NAMESPACE, sizeof(XML_NAMESPACE)-1, XML_NS_PREFIX);
- zend_hash_str_add_ptr(&defEncNs, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)-1, SOAP_1_1_ENC_NS_PREFIX);
- zend_hash_str_add_ptr(&defEncNs, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)-1, SOAP_1_2_ENC_NS_PREFIX);
+ zend_hash_str_add_ptr(&php_soap_defEncNs, XSD_1999_NAMESPACE, sizeof(XSD_1999_NAMESPACE)-1, XSD_NS_PREFIX);
+ zend_hash_str_add_ptr(&php_soap_defEncNs, XSD_NAMESPACE, sizeof(XSD_NAMESPACE)-1, XSD_NS_PREFIX);
+ zend_hash_str_add_ptr(&php_soap_defEncNs, XSI_NAMESPACE, sizeof(XSI_NAMESPACE)-1, XSI_NS_PREFIX);
+ zend_hash_str_add_ptr(&php_soap_defEncNs, XML_NAMESPACE, sizeof(XML_NAMESPACE)-1, XML_NS_PREFIX);
+ zend_hash_str_add_ptr(&php_soap_defEncNs, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)-1, SOAP_1_1_ENC_NS_PREFIX);
+ zend_hash_str_add_ptr(&php_soap_defEncNs, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)-1, SOAP_1_2_ENC_NS_PREFIX);
}
static void php_soap_init_globals(zend_soap_globals *soap_globals)
@@ -438,9 +440,6 @@ static void php_soap_init_globals(zend_soap_globals *soap_globals)
#if defined(COMPILE_DL_SOAP) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
- soap_globals->defEnc = defEnc;
- soap_globals->defEncIndex = defEncIndex;
- soap_globals->defEncNs = defEncNs;
soap_globals->typemap = NULL;
soap_globals->use_soap_error_handler = 0;
soap_globals->error_code = NULL;
@@ -461,9 +460,9 @@ PHP_MSHUTDOWN_FUNCTION(soap)
i++;
} while (defaultEncoding[i].details.type != END_KNOWN_TYPES);
zend_error_cb = old_error_handler;
- zend_hash_destroy(&SOAP_GLOBAL(defEnc));
- zend_hash_destroy(&SOAP_GLOBAL(defEncIndex));
- zend_hash_destroy(&SOAP_GLOBAL(defEncNs));
+ zend_hash_destroy(&php_soap_defEnc);
+ zend_hash_destroy(&php_soap_defEncIndex);
+ zend_hash_destroy(&php_soap_defEncNs);
if (SOAP_GLOBAL(mem_cache)) {
zend_hash_destroy(SOAP_GLOBAL(mem_cache));
free(SOAP_GLOBAL(mem_cache));
@@ -765,7 +764,7 @@ PHP_METHOD(SoapVar, __construct)
if (type_is_null) {
ZVAL_LONG(Z_VAR_ENC_TYPE_P(this_ptr), UNKNOWN_TYPE);
} else {
- if (zend_hash_index_exists(&SOAP_GLOBAL(defEncIndex), type)) {
+ if (zend_hash_index_exists(&php_soap_defEncIndex, type)) {
ZVAL_LONG(Z_VAR_ENC_TYPE_P(this_ptr), type);
} else {
zend_argument_value_error(2, "is not a valid encoding");