- (non-)ZTS fixes
authorMichael Wallner <mike@php.net>
Wed, 13 Sep 2006 22:09:07 +0000 (22:09 +0000)
committerMichael Wallner <mike@php.net>
Wed, 13 Sep 2006 22:09:07 +0000 (22:09 +0000)
http.c
http_request_datashare_api.c
http_requestdatashare_object.c
php_http.h
php_http_request_datashare_api.h

diff --git a/http.c b/http.c
index 5a0b05897ca2783cc008ec056a543a4eae74b620..88125ae8e2aada3a21b6a1da0fab48bf2481abe0 100644 (file)
--- a/http.c
+++ b/http.c
@@ -335,6 +335,9 @@ PHP_RINIT_FUNCTION(http)
        if (    (SUCCESS != PHP_RINIT_CALL(http_request_method))
 #ifdef HTTP_HAVE_ZLIB  
                ||      (SUCCESS != PHP_RINIT_CALL(http_encoding))
+#endif
+#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
+               ||      (SUCCESS != PHP_RINIT_CALL(http_request_datashare))
 #endif
        ) {
                return FAILURE;
@@ -353,7 +356,10 @@ PHP_RSHUTDOWN_FUNCTION(http)
 #ifdef HTTP_HAVE_ZLIB
                ||      (SUCCESS != PHP_RSHUTDOWN_CALL(http_encoding))
 #endif
-       ) {
+#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
+               ||      (SUCCESS != PHP_RSHUTDOWN_CALL(http_request_datashare))
+#endif
+          ) {
                status = FAILURE;
        }
        
index efcdb848e657fd346b637a41560480ae4bddcbe5..870e103382f58c39c67f9f515d4d1de1697aaf6a 100644 (file)
 static HashTable http_request_datashare_options;
 static http_request_datashare http_request_datashare_global;
 static int http_request_datashare_compare_handles(void *h1, void *h2);
+static void http_request_datashare_destroy_handles(void *el);
+#ifdef ZTS
 static void http_request_datashare_lock_func(CURL *handle, curl_lock_data data, curl_lock_access locktype, void *userptr);
 static void http_request_datashare_unlock_func(CURL *handle, curl_lock_data data, void *userptr);
+#endif
 
 http_request_datashare *_http_request_datashare_global_get(void)
 {
@@ -63,9 +66,22 @@ PHP_MSHUTDOWN_FUNCTION(http_request_datashare)
        return SUCCESS;
 }
 
+PHP_RINIT_FUNCTION(http_request_datashare)
+{
+       zend_llist_init(&HTTP_G->request.datashare.handles, sizeof(zval *), http_request_datashare_destroy_handles, 0);
+       
+       return SUCCESS;
+}
+
+PHP_RSHUTDOWN_FUNCTION(http_request_datashare)
+{
+       zend_llist_destroy(&HTTP_G->request.datashare.handles);
+       
+       return SUCCESS;
+}
+
 PHP_HTTP_API http_request_datashare *_http_request_datashare_init_ex(http_request_datashare *share, zend_bool persistent TSRMLS_DC)
 {
-       int i;
        zend_bool free_share;
        
        if ((free_share = !share)) {
@@ -81,7 +97,13 @@ PHP_HTTP_API http_request_datashare *_http_request_datashare_init_ex(http_reques
                return NULL;
        }
        
-       if ((share->persistent = persistent)) {
+       if (!(share->persistent = persistent)) {
+               share->handles = emalloc(sizeof(zend_llist));
+               zend_llist_init(share->handles, sizeof(zval *), ZVAL_PTR_DTOR, 0);
+#ifdef ZTS
+       } else {
+               int i;
+               
                share->locks = pecalloc(CURL_LOCK_DATA_LAST, sizeof(http_request_datashare_lock), 1);
                for (i = 0; i < CURL_LOCK_DATA_LAST; ++i) {
                        share->locks[i].mx = tsrm_mutex_alloc();
@@ -89,10 +111,9 @@ PHP_HTTP_API http_request_datashare *_http_request_datashare_init_ex(http_reques
                curl_share_setopt(share->ch, CURLSHOPT_LOCKFUNC, http_request_datashare_lock_func);
                curl_share_setopt(share->ch, CURLSHOPT_UNLOCKFUNC, http_request_datashare_unlock_func);
                curl_share_setopt(share->ch, CURLSHOPT_USERDATA, share);
+#endif
        }
        
-       zend_llist_init(&share->handles, sizeof(zval *), ZVAL_PTR_DTOR, persistent);
-       
        return share;
 }
 
@@ -116,7 +137,7 @@ PHP_HTTP_API STATUS _http_request_datashare_attach(http_request_datashare *share
        
        obj->share = share;
        ZVAL_ADDREF(request);
-       zend_llist_add_element(&share->handles, (void *) &request);
+       zend_llist_add_element(HTTP_RSHARE_HANDLES(share), (void *) &request);
        
        return SUCCESS;
 }
@@ -134,7 +155,7 @@ PHP_HTTP_API STATUS _http_request_datashare_detach(http_request_datashare *share
                http_error_ex(HE_WARNING, HTTP_E_REQUEST, "Could not detach HttpRequest object(#%d) from the HttpRequestDataShare: %s", Z_OBJ_HANDLE_P(request), curl_share_strerror(rc));
        } else {
                obj->share = NULL;
-               zend_llist_del_element(&share->handles, request, http_request_datashare_compare_handles);
+               zend_llist_del_element(HTTP_RSHARE_HANDLES(share), request, http_request_datashare_compare_handles);
                return SUCCESS;
        }
        return FAILURE;
@@ -144,23 +165,28 @@ PHP_HTTP_API void _http_request_datashare_detach_all(http_request_datashare *sha
 {
        zval **r;
        
-       while ((r = zend_llist_get_first(&share->handles))) {
+       while ((r = zend_llist_get_first(HTTP_RSHARE_HANDLES(share)))) {
                http_request_datashare_detach(share, *r);
        }
 }
 
 PHP_HTTP_API void _http_request_datashare_dtor(http_request_datashare *share TSRMLS_DC)
 {
-       int i;
-       
-       zend_llist_destroy(&share->handles);
+       if (!share->persistent) {
+               zend_llist_destroy(share->handles);
+               efree(share->handles);
+       }
        curl_share_cleanup(share->ch);
+#ifdef ZTS
        if (share->persistent) {
+               int i;
+       
                for (i = 0; i < CURL_LOCK_DATA_LAST; ++i) {
                        tsrm_mutex_free(share->locks[i].mx);
                }
                pefree(share->locks, 1);
        }
+#endif
 }
 
 PHP_HTTP_API void _http_request_datashare_free(http_request_datashare **share TSRMLS_DC)
@@ -189,6 +215,17 @@ static int http_request_datashare_compare_handles(void *h1, void *h2)
        return (Z_OBJ_HANDLE_PP((zval **) h1) == Z_OBJ_HANDLE_P((zval *) h2));
 }
 
+static void http_request_datashare_destroy_handles(void *el)
+{
+       zval **r = (zval **) el;
+       TSRMLS_FETCH();
+       getObjectEx(http_request_object, obj, *r);
+       
+       curl_easy_setopt(obj->request->ch, CURLOPT_SHARE, NULL);
+       zval_ptr_dtor(r);
+}
+
+#ifdef ZTS
 static void http_request_datashare_lock_func(CURL *handle, curl_lock_data data, curl_lock_access locktype, void *userptr)
 {
        http_request_datashare *share = (http_request_datashare *) userptr;
@@ -206,6 +243,7 @@ static void http_request_datashare_unlock_func(CURL *handle, curl_lock_data data
                tsrm_mutex_unlock(share->locks[data].mx);
        }
 }
+#endif
 
 #endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */
 
index 451aefe7ddceb6687ceaa5423366387b99f99ed4..af8e9d49426f0ee0d80b18c8dbb273f748510936 100644 (file)
@@ -193,7 +193,7 @@ PHP_METHOD(HttpRequestDataShare, count)
        
        NO_ARGS;
        
-       RETURN_LONG(zend_llist_count(&obj->share->handles));
+       RETURN_LONG(zend_llist_count(HTTP_RSHARE_HANDLES(obj->share)));
 }
 /* }}} */
 
index e614f2236947b99f95b7082a417660732ef24526..4bd31d74c03829dec7033abc49f8264a5c0b3b5d 100644 (file)
@@ -123,8 +123,9 @@ ZEND_BEGIN_MODULE_GLOBALS(http)
                                void *entries;
                        } custom;
                } methods;
-#ifdef ZEND_ENGINE_2
+#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
                struct _http_globals_request_datashare {
+                       zend_llist handles;
                        zend_bool cookie;
                        zend_bool dns;
                        zend_bool ssl;
index 831712f6df8e6c4ed33192212f78ca668bb36d0d..08b30edc9161ff225f722a651c069a3779ac14c5 100644 (file)
 #define PHP_HTTP_REQUEST_DATASHARE_API_H
 #ifdef HTTP_HAVE_CURL
 
+#ifdef ZTS
 typedef struct _http_request_datashare_lock_t {
        CURL *ch;
        MUTEX_T mx;
 } http_request_datashare_lock;
+#endif
 
 typedef struct _http_request_datashare_t {
        CURLSH *ch;
-       zend_llist handles;
        zend_bool persistent;
+       zend_llist *handles;
+#ifdef ZTS
        http_request_datashare_lock *locks;
+#endif
 } http_request_datashare;
 
+#define HTTP_RSHARE_HANDLES(s) ((s)->persistent ? &HTTP_G->request.datashare.handles : (s)->handles)
+
 #define http_request_datashare_global_get _http_request_datashare_global_get
 extern http_request_datashare *_http_request_datashare_global_get(void);
 
 extern PHP_MINIT_FUNCTION(http_request_datashare);
 extern PHP_MSHUTDOWN_FUNCTION(http_request_datashare);
+extern PHP_RINIT_FUNCTION(http_request_datashare);
+extern PHP_RSHUTDOWN_FUNCTION(http_request_datashare);
 
 #define http_request_datashare_new() _http_request_datashare_init_ex(NULL, 0 TSRMLS_CC)
 #define http_request_datashare_init(s) _http_request_datashare_init_ex((s), 0 TSRMLS_CC)
@@ -52,7 +60,7 @@ PHP_HTTP_API void _http_request_datashare_detach_all(http_request_datashare *sha
 PHP_HTTP_API void _http_request_datashare_dtor(http_request_datashare *share TSRMLS_DC);
 
 #define http_request_datashare_free(s) _http_request_datashare_free((s) TSRMLS_CC)
-PHP_HTTP_API void _http_request_datashaere_free(http_request_datashare **share TSRMLS_DC);
+PHP_HTTP_API void _http_request_datashare_free(http_request_datashare **share TSRMLS_DC);
 
 #define http_request_datashare_set(s, o, l, e) _http_request_datashare_set((s), (o), (l), (e) TSRMLS_CC)
 PHP_HTTP_API STATUS _http_request_datashare_set(http_request_datashare *share, const char *option, size_t option_len, zend_bool enable TSRMLS_DC);