From 2ccaf8a134e3705268767d1a1850430cebc3c9a1 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 28 Apr 2016 09:27:44 +0200 Subject: [PATCH] fixed pointless initialization of persistent handles lists on cleanup --- package.xml | 4 ++-- src/php_raphf_api.c | 15 ++++++++------- tests/http001.phpt | 10 +++++----- tests/http002.phpt | 10 +++++----- tests/http003.phpt | 13 +++++++------ tests/http004.phpt | 16 ++++++++-------- 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/package.xml b/package.xml index e86d887..d4cf12a 100644 --- a/package.xml +++ b/package.xml @@ -19,7 +19,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> mike@php.net yes - 2016-01-19 + 2016-04-28 2.0.1dev 2.0.0 @@ -30,7 +30,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> BSD, revised diff --git a/src/php_raphf_api.c b/src/php_raphf_api.c index f867af6..b256e47 100644 --- a/src/php_raphf_api.c +++ b/src/php_raphf_api.c @@ -243,7 +243,8 @@ static int php_persistent_handle_list_apply_dtor(zval *p, void *provider) } static inline php_persistent_handle_list_t *php_persistent_handle_list_find( - php_persistent_handle_provider_t *provider, zend_string *ident) + php_persistent_handle_provider_t *provider, zend_string *ident, + zend_bool create) { php_persistent_handle_list_t *list; zval *zlist = zend_symtable_find(&provider->list.free, ident); @@ -255,7 +256,7 @@ static inline php_persistent_handle_list_t *php_persistent_handle_list_find( return list; } - if ((list = php_persistent_handle_list_init(NULL))) { + if (create && (list = php_persistent_handle_list_init(NULL))) { zval p, *rv; zend_string *id; @@ -284,7 +285,7 @@ static int php_persistent_handle_apply_cleanup_all(zval *p, int argc, php_persistent_handle_list_t *list; if (ident && ident->len) { - if ((list = php_persistent_handle_list_find(provider, ident))) { + if ((list = php_persistent_handle_list_find(provider, ident, 0))) { zend_hash_apply_with_argument(&list->free, php_persistent_handle_apply_cleanup_ex, &provider->rf); @@ -394,7 +395,7 @@ void *php_persistent_handle_acquire(php_persistent_handle_factory_t *a, void *in void *handle = NULL; php_persistent_handle_list_t *list; - list = php_persistent_handle_list_find(a->provider, a->ident); + list = php_persistent_handle_list_find(a->provider, a->ident, 1); if (list) { zend_hash_internal_pointer_end(&list->free); key = zend_hash_get_current_key(&list->free, NULL, &index); @@ -427,7 +428,7 @@ void *php_persistent_handle_accrete(php_persistent_handle_factory_t *a, void *ha new_handle = php_resource_factory_handle_copy(&a->provider->rf, handle); if (handle) { - list = php_persistent_handle_list_find(a->provider, a->ident); + list = php_persistent_handle_list_find(a->provider, a->ident, 1); if (list) { ++list->used; } @@ -441,7 +442,7 @@ void php_persistent_handle_release(php_persistent_handle_factory_t *a, void *han { php_persistent_handle_list_t *list; - list = php_persistent_handle_list_find(a->provider, a->ident); + list = php_persistent_handle_list_find(a->provider, a->ident, 1); if (list) { if (a->provider->list.used >= PHP_RAPHF_G->persistent_handle.limit) { #if PHP_RAPHF_DEBUG_PHANDLES @@ -471,7 +472,7 @@ void php_persistent_handle_cleanup(zend_string *name, zend_string *ident) if (zprovider && (provider = Z_PTR_P(zprovider))) { if (ident) { - list = php_persistent_handle_list_find(provider, ident); + list = php_persistent_handle_list_find(provider, ident, 0); if (list) { zend_hash_apply_with_argument(&list->free, php_persistent_handle_apply_cleanup_ex, diff --git a/tests/http001.phpt b/tests/http001.phpt index e79f5b4..8c578ae 100644 --- a/tests/http001.phpt +++ b/tests/http001.phpt @@ -16,7 +16,7 @@ echo "Test\n"; $h = (array) raphf\stat_persistent_handles(); var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h))))); -$c = new http\Client("curl", "php.net:80"); +$c = new http\Client("curl", "PHP"); do { $c->enqueue(new http\Client\Request("GET", "http://php.net")); } while (count($c) < 3); @@ -44,7 +44,7 @@ array(2) { array(2) { ["http\Client\Curl"]=> array(1) { - ["php.net:80"]=> + ["PHP"]=> array(2) { ["used"]=> int(1) @@ -54,7 +54,7 @@ array(2) { } ["http\Client\Curl\Request"]=> array(1) { - ["php.net:80"]=> + ["PHP:php.net:80"]=> array(2) { ["used"]=> int(3) @@ -66,7 +66,7 @@ array(2) { array(2) { ["http\Client\Curl"]=> array(1) { - ["php.net:80"]=> + ["PHP"]=> array(2) { ["used"]=> int(0) @@ -76,7 +76,7 @@ array(2) { } ["http\Client\Curl\Request"]=> array(1) { - ["php.net:80"]=> + ["PHP:php.net:80"]=> array(2) { ["used"]=> int(0) diff --git a/tests/http002.phpt b/tests/http002.phpt index 505adc5..e9a5966 100644 --- a/tests/http002.phpt +++ b/tests/http002.phpt @@ -13,7 +13,7 @@ if (!class_exists("http\\Client", false)) { enqueue(new http\Client\Request("GET", "http://php.net")); } while (count($c) < 3); @@ -25,7 +25,7 @@ var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h)) raphf\clean_persistent_handles("http\\Client\\Curl"); -raphf\clean_persistent_handles("http\\Client\\Curl\\Request", "php.net:80"); +raphf\clean_persistent_handles("http\\Client\\Curl\\Request", "PHP:php.net:80"); $h = (array) raphf\stat_persistent_handles(); var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h))))); @@ -37,7 +37,7 @@ Test array(2) { ["http\Client\Curl"]=> array(1) { - ["php.net:80"]=> + ["PHP"]=> array(2) { ["used"]=> int(0) @@ -47,7 +47,7 @@ array(2) { } ["http\Client\Curl\Request"]=> array(1) { - ["php.net:80"]=> + ["PHP:php.net:80"]=> array(2) { ["used"]=> int(0) @@ -62,7 +62,7 @@ array(2) { } ["http\Client\Curl\Request"]=> array(1) { - ["php.net:80"]=> + ["PHP:php.net:80"]=> array(2) { ["used"]=> int(0) diff --git a/tests/http003.phpt b/tests/http003.phpt index 50dbb1c..671b8d4 100644 --- a/tests/http003.phpt +++ b/tests/http003.phpt @@ -13,7 +13,7 @@ if (!class_exists("http\\Client", false)) { enqueue(new http\Client\Request("GET", "http://php.net")); } while (count($c) < 3); @@ -23,7 +23,8 @@ unset($c); $h = (array) raphf\stat_persistent_handles(); var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h))))); -raphf\clean_persistent_handles(null, "php.net:80"); +raphf\clean_persistent_handles(null, "PHP"); +raphf\clean_persistent_handles(null, "PHP:php.net:80"); $h = (array) raphf\stat_persistent_handles(); var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h))))); @@ -35,7 +36,7 @@ Test array(2) { ["http\Client\Curl"]=> array(1) { - ["php.net:80"]=> + ["PHP"]=> array(2) { ["used"]=> int(0) @@ -45,7 +46,7 @@ array(2) { } ["http\Client\Curl\Request"]=> array(1) { - ["php.net:80"]=> + ["PHP:php.net:80"]=> array(2) { ["used"]=> int(0) @@ -57,7 +58,7 @@ array(2) { array(2) { ["http\Client\Curl"]=> array(1) { - ["php.net:80"]=> + ["PHP"]=> array(2) { ["used"]=> int(0) @@ -67,7 +68,7 @@ array(2) { } ["http\Client\Curl\Request"]=> array(1) { - ["php.net:80"]=> + ["PHP:php.net:80"]=> array(2) { ["used"]=> int(0) diff --git a/tests/http004.phpt b/tests/http004.phpt index 7077cbd..0e677f2 100644 --- a/tests/http004.phpt +++ b/tests/http004.phpt @@ -16,8 +16,8 @@ echo "Test\n"; $h = (array) raphf\stat_persistent_handles(); var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h))))); -$c = new http\Client("curl", "php.net:80"); -$c2 = new http\Client("curl", "php.net:80"); +$c = new http\Client("curl", "PHP"); +$c2 = new http\Client("curl", "PHP"); do { $c->enqueue(new http\Client\Request("GET", "http://php.net")); $c2->enqueue(new http\Client\Request("GET", "http://php.net")); @@ -51,7 +51,7 @@ array(2) { array(2) { ["http\Client\Curl"]=> array(1) { - ["php.net:80"]=> + ["PHP"]=> array(2) { ["used"]=> int(2) @@ -61,7 +61,7 @@ array(2) { } ["http\Client\Curl\Request"]=> array(1) { - ["php.net:80"]=> + ["PHP:php.net:80"]=> array(2) { ["used"]=> int(6) @@ -73,7 +73,7 @@ array(2) { array(2) { ["http\Client\Curl"]=> array(1) { - ["php.net:80"]=> + ["PHP"]=> array(2) { ["used"]=> int(1) @@ -83,7 +83,7 @@ array(2) { } ["http\Client\Curl\Request"]=> array(1) { - ["php.net:80"]=> + ["PHP:php.net:80"]=> array(2) { ["used"]=> int(3) @@ -95,7 +95,7 @@ array(2) { array(2) { ["http\Client\Curl"]=> array(1) { - ["php.net:80"]=> + ["PHP"]=> array(2) { ["used"]=> int(1) @@ -105,7 +105,7 @@ array(2) { } ["http\Client\Curl\Request"]=> array(1) { - ["php.net:80"]=> + ["PHP:php.net:80"]=> array(2) { ["used"]=> int(3) -- 2.30.2