Skip to content

Commit 57001e6

Browse files
committed
soap: store zend_function pointers in soap_functions.ft field
1 parent 9f21aeb commit 57001e6

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

‎ext/soap/soap.c‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,9 @@ PHP_METHOD(SoapServer, __construct)
11001100
service->version = version;
11011101
service->type = SOAP_FUNCTIONS;
11021102
service->soap_functions.functions_all = false;
1103-
service->soap_functions.ft = zend_new_array(0);
1103+
ALLOC_HASHTABLE(service->soap_functions.ft);
1104+
/* This hashtable contains zend_function pointers so doesn't need a destructor */
1105+
zend_hash_init(service->soap_functions.ft, 0, NULL, NULL, false);
11041106

11051107
SOAP_SERVER_BEGIN_CODE();
11061108
if (wsdl) {
@@ -1226,7 +1228,7 @@ PHP_METHOD(SoapServer, setObject)
12261228
PHP_METHOD(SoapServer, getFunctions)
12271229
{
12281230
soapServicePtr service;
1229-
HashTable *ft = NULL;
1231+
const HashTable *ft = NULL;
12301232

12311233
ZEND_PARSE_PARAMETERS_NONE();
12321234

@@ -1240,11 +1242,7 @@ PHP_METHOD(SoapServer, getFunctions)
12401242
} else if (service->soap_functions.functions_all) {
12411243
ft = EG(function_table);
12421244
} else if (service->soap_functions.ft != NULL) {
1243-
zval *name;
1244-
1245-
ZEND_HASH_MAP_FOREACH_VAL(service->soap_functions.ft, name) {
1246-
add_next_index_str(return_value, zend_string_copy(Z_STR_P(name)));
1247-
} ZEND_HASH_FOREACH_END();
1245+
ft = service->soap_functions.ft;
12481246
}
12491247
if (ft != NULL) {
12501248
zend_function *f;
@@ -1263,7 +1261,7 @@ PHP_METHOD(SoapServer, getFunctions)
12631261
PHP_METHOD(SoapServer, addFunction)
12641262
{
12651263
soapServicePtr service;
1266-
zval *function_name, function_copy;
1264+
zval *function_name;
12671265

12681266
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &function_name) == FAILURE) {
12691267
RETURN_THROWS();
@@ -1279,7 +1277,9 @@ PHP_METHOD(SoapServer, addFunction)
12791277

12801278
if (service->soap_functions.ft == NULL) {
12811279
service->soap_functions.functions_all = false;
1282-
service->soap_functions.ft = zend_new_array(zend_hash_num_elements(Z_ARRVAL_P(function_name)));
1280+
ALLOC_HASHTABLE(service->soap_functions.ft);
1281+
/* This hashtable contains zend_function pointers so doesn't need a destructor */
1282+
zend_hash_init(service->soap_functions.ft, zend_hash_num_elements(Z_ARRVAL_P(function_name)), NULL, NULL, false);
12831283
}
12841284

12851285
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(function_name), tmp_function) {
@@ -1292,15 +1292,15 @@ PHP_METHOD(SoapServer, addFunction)
12921292
}
12931293

12941294
key = zend_string_tolower(Z_STR_P(tmp_function));
1295+
f = zend_hash_find_ptr(EG(function_table), key);
12951296

1296-
if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
1297+
if (f == NULL) {
12971298
zend_string_release_ex(key, false);
12981299
zend_type_error("SoapServer::addFunction(): Function \"%s\" not found", Z_STRVAL_P(tmp_function));
12991300
RETURN_THROWS();
13001301
}
13011302

1302-
ZVAL_STR_COPY(&function_copy, f->common.function_name);
1303-
zend_hash_update(service->soap_functions.ft, key, &function_copy);
1303+
zend_hash_update_ptr(service->soap_functions.ft, key, f);
13041304

13051305
zend_string_release_ex(key, 0);
13061306
} ZEND_HASH_FOREACH_END();
@@ -1310,19 +1310,20 @@ PHP_METHOD(SoapServer, addFunction)
13101310
zend_function *f;
13111311

13121312
key = zend_string_tolower(Z_STR_P(function_name));
1313-
1314-
if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
1313+
f = zend_hash_find_ptr(EG(function_table), key);
1314+
if (f == NULL) {
13151315
zend_string_release_ex(key, false);
13161316
zend_argument_type_error(1, "must be a valid function name, function \"%s\" not found", Z_STRVAL_P(function_name));
13171317
RETURN_THROWS();
13181318
}
13191319
if (service->soap_functions.ft == NULL) {
13201320
service->soap_functions.functions_all = false;
1321-
service->soap_functions.ft = zend_new_array(0);
1321+
ALLOC_HASHTABLE(service->soap_functions.ft);
1322+
/* This hashtable contains zend_function pointers so doesn't need a destructor */
1323+
zend_hash_init(service->soap_functions.ft, 0, NULL, NULL, false);
13221324
}
13231325

1324-
ZVAL_STR_COPY(&function_copy, f->common.function_name);
1325-
zend_hash_update(service->soap_functions.ft, key, &function_copy);
1326+
zend_hash_update_ptr(service->soap_functions.ft, key, f);
13261327
zend_string_release_ex(key, 0);
13271328
} else if (Z_TYPE_P(function_name) == IS_LONG) {
13281329
if (Z_LVAL_P(function_name) == SOAP_FUNCTIONS_ALL) {

0 commit comments

Comments
 (0)