Skip to content

Commit a01ff38

Browse files
committed
ext/soap: store zend_function pointers in soap_functions.ft field
1 parent 249168b commit a01ff38

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

ext/soap/soap.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,9 @@ PHP_METHOD(SoapServer, __construct)
10091009
service->version = version;
10101010
service->type = SOAP_FUNCTIONS;
10111011
service->soap_functions.functions_all = false;
1012-
service->soap_functions.ft = zend_new_array(0);
1012+
ALLOC_HASHTABLE(service->soap_functions.ft);
1013+
/* This hashtable contains zend_function pointers so doesn't need a destructor */
1014+
zend_hash_init(service->soap_functions.ft, 0, NULL, NULL, false);
10131015

10141016
if (wsdl) {
10151017
service->sdl = get_sdl(ZEND_THIS, ZSTR_VAL(wsdl), cache_wsdl);
@@ -1123,7 +1125,7 @@ PHP_METHOD(SoapServer, setObject)
11231125
PHP_METHOD(SoapServer, getFunctions)
11241126
{
11251127
soapServicePtr service;
1126-
HashTable *ft = NULL;
1128+
const HashTable *ft = NULL;
11271129

11281130
if (zend_parse_parameters_none() == FAILURE) {
11291131
RETURN_THROWS();
@@ -1139,11 +1141,7 @@ PHP_METHOD(SoapServer, getFunctions)
11391141
} else if (service->soap_functions.functions_all) {
11401142
ft = EG(function_table);
11411143
} else if (service->soap_functions.ft != NULL) {
1142-
zval *name;
1143-
1144-
ZEND_HASH_MAP_FOREACH_VAL(service->soap_functions.ft, name) {
1145-
add_next_index_str(return_value, zend_string_copy(Z_STR_P(name)));
1146-
} ZEND_HASH_FOREACH_END();
1144+
ft = service->soap_functions.ft;
11471145
}
11481146
if (ft != NULL) {
11491147
zend_function *f;
@@ -1162,7 +1160,7 @@ PHP_METHOD(SoapServer, getFunctions)
11621160
PHP_METHOD(SoapServer, addFunction)
11631161
{
11641162
soapServicePtr service;
1165-
zval *function_name, function_copy;
1163+
zval *function_name;
11661164

11671165
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &function_name) == FAILURE) {
11681166
RETURN_THROWS();
@@ -1178,7 +1176,9 @@ PHP_METHOD(SoapServer, addFunction)
11781176

11791177
if (service->soap_functions.ft == NULL) {
11801178
service->soap_functions.functions_all = false;
1181-
service->soap_functions.ft = zend_new_array(zend_hash_num_elements(Z_ARRVAL_P(function_name)));
1179+
ALLOC_HASHTABLE(service->soap_functions.ft);
1180+
/* This hashtable contains zend_function pointers so doesn't need a destructor */
1181+
zend_hash_init(service->soap_functions.ft, zend_hash_num_elements(Z_ARRVAL_P(function_name)), NULL, NULL, false);
11821182
}
11831183

11841184
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(function_name), tmp_function) {
@@ -1191,15 +1191,15 @@ PHP_METHOD(SoapServer, addFunction)
11911191
}
11921192

11931193
key = zend_string_tolower(Z_STR_P(tmp_function));
1194+
f = zend_hash_find_ptr(EG(function_table), key);
11941195

1195-
if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
1196+
if (f == NULL) {
11961197
zend_string_release_ex(key, false);
11971198
zend_type_error("SoapServer::addFunction(): Function \"%s\" not found", Z_STRVAL_P(tmp_function));
11981199
RETURN_THROWS();
11991200
}
12001201

1201-
ZVAL_STR_COPY(&function_copy, f->common.function_name);
1202-
zend_hash_update(service->soap_functions.ft, key, &function_copy);
1202+
zend_hash_update_ptr(service->soap_functions.ft, key, f);
12031203

12041204
zend_string_release_ex(key, 0);
12051205
} ZEND_HASH_FOREACH_END();
@@ -1209,19 +1209,20 @@ PHP_METHOD(SoapServer, addFunction)
12091209
zend_function *f;
12101210

12111211
key = zend_string_tolower(Z_STR_P(function_name));
1212-
1213-
if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
1212+
f = zend_hash_find_ptr(EG(function_table), key);
1213+
if (f == NULL) {
12141214
zend_string_release_ex(key, false);
12151215
zend_argument_type_error(1, "must be a valid function name, function \"%s\" not found", Z_STRVAL_P(function_name));
12161216
RETURN_THROWS();
12171217
}
12181218
if (service->soap_functions.ft == NULL) {
12191219
service->soap_functions.functions_all = false;
1220-
service->soap_functions.ft = zend_new_array(0);
1220+
ALLOC_HASHTABLE(service->soap_functions.ft);
1221+
/* This hashtable contains zend_function pointers so doesn't need a destructor */
1222+
zend_hash_init(service->soap_functions.ft, 0, NULL, NULL, false);
12211223
}
12221224

1223-
ZVAL_STR_COPY(&function_copy, f->common.function_name);
1224-
zend_hash_update(service->soap_functions.ft, key, &function_copy);
1225+
zend_hash_update_ptr(service->soap_functions.ft, key, f);
12251226
zend_string_release_ex(key, 0);
12261227
} else if (Z_TYPE_P(function_name) == IS_LONG) {
12271228
if (Z_LVAL_P(function_name) == SOAP_FUNCTIONS_ALL) {

0 commit comments

Comments
 (0)