Created
December 24, 2012 13:39
-
-
Save adoy/4369286 to your computer and use it in GitHub Desktop.
Improve resource management for curl handle Previous implementation was using its own refcounting (uses field of
the php_curl struct). zend_list_add/remove already implements its own
refcount, so we don't need to use an other one.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 4ed606fb706647466e16a9e4ba8b2bdc8002b219 Mon Sep 17 00:00:00 2001 | |
From: Pierrick Charron <pierrick@webstart.fr> | |
Date: Sat, 22 Dec 2012 17:24:26 -0500 | |
Subject: [PATCH] Improve resource management for curl handle | |
Previous implementation was using its own refcounting (uses field of | |
the php_curl struct). zend_list_add/remove already implements its own | |
refcount, so we don't need to use an other one. | |
--- | |
ext/curl/interface.c | 11 ++--------- | |
ext/curl/multi.c | 13 ++++--------- | |
ext/curl/php_curl.h | 1 - | |
3 files changed, 6 insertions(+), 19 deletions(-) | |
diff --git a/ext/curl/interface.c b/ext/curl/interface.c | |
index 9ac89c5..29ebe66 100644 | |
--- a/ext/curl/interface.c | |
+++ b/ext/curl/interface.c | |
@@ -1542,8 +1542,6 @@ PHP_FUNCTION(curl_init) | |
ch->handlers->read->method = PHP_CURL_DIRECT; | |
ch->handlers->write_header->method = PHP_CURL_IGNORE; | |
- ch->uses = 0; | |
- | |
MAKE_STD_ZVAL(clone); | |
ch->clone = clone; | |
@@ -1607,8 +1605,7 @@ PHP_FUNCTION(curl_copy_handle) | |
TSRMLS_SET_CTX(dupch->thread_ctx); | |
dupch->cp = cp; | |
- dupch->uses = 0; | |
- ch->uses++; | |
+ zend_list_addref(Z_LVAL_P(zid)); | |
if (ch->handlers->write->stream) { | |
Z_ADDREF_P(ch->handlers->write->stream); | |
} | |
@@ -2587,11 +2584,7 @@ PHP_FUNCTION(curl_close) | |
return; | |
} | |
- if (ch->uses) { | |
- ch->uses--; | |
- } else { | |
- zend_list_delete(Z_LVAL_P(zid)); | |
- } | |
+ zend_list_delete(Z_LVAL_P(zid)); | |
} | |
/* }}} */ | |
diff --git a/ext/curl/multi.c b/ext/curl/multi.c | |
index 53e97b8..46bf748 100644 | |
--- a/ext/curl/multi.c | |
+++ b/ext/curl/multi.c | |
@@ -86,7 +86,6 @@ PHP_FUNCTION(curl_multi_add_handle) | |
ZEND_FETCH_RESOURCE(ch, php_curl *, &z_ch, -1, le_curl_name, le_curl); | |
_php_curl_cleanup_handle(ch); | |
- ch->uses++; | |
/* we want to create a copy of this zval that we store in the multihandle structure element "easyh" */ | |
tmp_val = *z_ch; | |
@@ -113,11 +112,7 @@ void _php_curl_multi_cleanup_list(void *data) /* {{{ */ | |
return; | |
} | |
- if (ch->uses) { | |
- ch->uses--; | |
- } else { | |
- zend_list_delete(Z_LVAL_P(z_ch)); | |
- } | |
+ zend_list_delete(Z_LVAL_P(z_ch)); | |
} | |
/* }}} */ | |
@@ -146,12 +141,12 @@ PHP_FUNCTION(curl_multi_remove_handle) | |
ZEND_FETCH_RESOURCE(mh, php_curlm *, &z_mh, -1, le_curl_multi_handle_name, le_curl_multi_handle); | |
ZEND_FETCH_RESOURCE(ch, php_curl *, &z_ch, -1, le_curl_name, le_curl); | |
- --ch->uses; | |
+ | |
+ RETVAL_LONG((long) curl_multi_remove_handle(mh->multi, ch->cp)); | |
zend_llist_del_element( &mh->easyh, &z_ch, | |
(int (*)(void *, void *)) curl_compare_resources ); | |
- | |
- RETURN_LONG((long) curl_multi_remove_handle(mh->multi, ch->cp)); | |
+ | |
} | |
/* }}} */ | |
diff --git a/ext/curl/php_curl.h b/ext/curl/php_curl.h | |
index af6a965..de79b0d 100644 | |
--- a/ext/curl/php_curl.h | |
+++ b/ext/curl/php_curl.h | |
@@ -137,7 +137,6 @@ typedef struct { | |
CURL *cp; | |
php_curl_handlers *handlers; | |
long id; | |
- unsigned int uses; | |
zend_bool in_callback; | |
zval *clone; | |
} php_curl; | |
-- | |
1.7.2.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment