fixed pointless initialization of persistent handles lists on cleanup
authorMichael Wallner <mike@php.net>
Thu, 28 Apr 2016 07:27:44 +0000 (09:27 +0200)
committerMichael Wallner <mike@php.net>
Thu, 28 Apr 2016 07:28:38 +0000 (09:28 +0200)
package.xml
src/php_raphf_api.c
tests/http001.phpt
tests/http002.phpt
tests/http003.phpt
tests/http004.phpt

index e86d88731eb60ef2e66c563a7ed98fe2fdfe7ea9..d4cf12adeb599100053e5129367fec94c98ce649 100644 (file)
@@ -19,7 +19,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <email>mike@php.net</email>
   <active>yes</active>
  </lead>
   <email>mike@php.net</email>
   <active>yes</active>
  </lead>
- <date>2016-01-19</date>
+ <date>2016-04-28</date>
  <version>
   <release>2.0.1dev</release>
   <api>2.0.0</api>
  <version>
   <release>2.0.1dev</release>
   <api>2.0.0</api>
@@ -30,7 +30,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
  </stability>
  <license>BSD, revised</license>
  <notes><![CDATA[
  </stability>
  <license>BSD, revised</license>
  <notes><![CDATA[
-*
+* Fixed pointless initialization of persistent handles lists on cleanup
 ]]></notes>
  <contents>
   <dir name="/">
 ]]></notes>
  <contents>
   <dir name="/">
index f867af6d7a13137f17fad2d40d69a542ceb94e10..b256e4714d3b08739e120e33c3441b1097f31825 100644 (file)
@@ -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(
 }
 
 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);
 {
        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;
        }
 
                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;
 
                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) {
        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);
                        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;
 
        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);
        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) {
 
        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;
                }
                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;
 
 {
        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
        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) {
 
                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,
                                if (list) {
                                        zend_hash_apply_with_argument(&list->free,
                                                        php_persistent_handle_apply_cleanup_ex,
index e79f5b429756f5d9a34c2104d13ba681eb0314df..8c578aefedf25111abaea585a3389cd137aa0cec 100644 (file)
@@ -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)))));
 
 $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);
 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) {
 array(2) {
   ["http\Client\Curl"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP"]=>
     array(2) {
       ["used"]=>
       int(1)
     array(2) {
       ["used"]=>
       int(1)
@@ -54,7 +54,7 @@ array(2) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP:php.net:80"]=>
     array(2) {
       ["used"]=>
       int(3)
     array(2) {
       ["used"]=>
       int(3)
@@ -66,7 +66,7 @@ array(2) {
 array(2) {
   ["http\Client\Curl"]=>
   array(1) {
 array(2) {
   ["http\Client\Curl"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP"]=>
     array(2) {
       ["used"]=>
       int(0)
     array(2) {
       ["used"]=>
       int(0)
@@ -76,7 +76,7 @@ array(2) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP:php.net:80"]=>
     array(2) {
       ["used"]=>
       int(0)
     array(2) {
       ["used"]=>
       int(0)
index 505adc575e54b1283db610179f85d07b734fe89e..e9a59667f1385a3038db1af71395e29264b79643 100644 (file)
@@ -13,7 +13,7 @@ if (!class_exists("http\\Client", false)) {
 <?php
 echo "Test\n";
 
 <?php
 echo "Test\n";
 
-$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);
 do {
        $c->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");
-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)))));
 
 $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) {
 array(2) {
   ["http\Client\Curl"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP"]=>
     array(2) {
       ["used"]=>
       int(0)
     array(2) {
       ["used"]=>
       int(0)
@@ -47,7 +47,7 @@ array(2) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP:php.net:80"]=>
     array(2) {
       ["used"]=>
       int(0)
     array(2) {
       ["used"]=>
       int(0)
@@ -62,7 +62,7 @@ array(2) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP:php.net:80"]=>
     array(2) {
       ["used"]=>
       int(0)
     array(2) {
       ["used"]=>
       int(0)
index 50dbb1c4a52fb5f84511c02ad0f1f6199ba2e274..671b8d4ce9bd11f5bc8ca557f12688a142fcb0a6 100644 (file)
@@ -13,7 +13,7 @@ if (!class_exists("http\\Client", false)) {
 <?php
 echo "Test\n";
 
 <?php
 echo "Test\n";
 
-$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);
 do {
        $c->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)))));
 
 $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)))));
 
 $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) {
 array(2) {
   ["http\Client\Curl"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP"]=>
     array(2) {
       ["used"]=>
       int(0)
     array(2) {
       ["used"]=>
       int(0)
@@ -45,7 +46,7 @@ array(2) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP:php.net:80"]=>
     array(2) {
       ["used"]=>
       int(0)
     array(2) {
       ["used"]=>
       int(0)
@@ -57,7 +58,7 @@ array(2) {
 array(2) {
   ["http\Client\Curl"]=>
   array(1) {
 array(2) {
   ["http\Client\Curl"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP"]=>
     array(2) {
       ["used"]=>
       int(0)
     array(2) {
       ["used"]=>
       int(0)
@@ -67,7 +68,7 @@ array(2) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP:php.net:80"]=>
     array(2) {
       ["used"]=>
       int(0)
     array(2) {
       ["used"]=>
       int(0)
index 7077cbdb533c578a742c58ab24293a808756a05c..0e677f29aaf567ee528dd0f8befe29c727b5da75 100644 (file)
@@ -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)))));
 
 $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"));
 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) {
 array(2) {
   ["http\Client\Curl"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP"]=>
     array(2) {
       ["used"]=>
       int(2)
     array(2) {
       ["used"]=>
       int(2)
@@ -61,7 +61,7 @@ array(2) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP:php.net:80"]=>
     array(2) {
       ["used"]=>
       int(6)
     array(2) {
       ["used"]=>
       int(6)
@@ -73,7 +73,7 @@ array(2) {
 array(2) {
   ["http\Client\Curl"]=>
   array(1) {
 array(2) {
   ["http\Client\Curl"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP"]=>
     array(2) {
       ["used"]=>
       int(1)
     array(2) {
       ["used"]=>
       int(1)
@@ -83,7 +83,7 @@ array(2) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP:php.net:80"]=>
     array(2) {
       ["used"]=>
       int(3)
     array(2) {
       ["used"]=>
       int(3)
@@ -95,7 +95,7 @@ array(2) {
 array(2) {
   ["http\Client\Curl"]=>
   array(1) {
 array(2) {
   ["http\Client\Curl"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP"]=>
     array(2) {
       ["used"]=>
       int(1)
     array(2) {
       ["used"]=>
       int(1)
@@ -105,7 +105,7 @@ array(2) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
   }
   ["http\Client\Curl\Request"]=>
   array(1) {
-    ["php.net:80"]=>
+    ["PHP:php.net:80"]=>
     array(2) {
       ["used"]=>
       int(3)
     array(2) {
       ["used"]=>
       int(3)