0a2fc21
From 05433632fb1ccdabc1d29d78f32bc35de0a8638b Mon Sep 17 00:00:00 2001
0a2fc21
From: kjetilja <kjetilja>
0a2fc21
Date: Mon, 29 Sep 2008 10:56:57 +0000
0a2fc21
Subject: [PATCH 1/5] No longer keep copies of string options since this is managed by libcurl
0a2fc21
0a2fc21
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
0a2fc21
---
0a2fc21
 ChangeLog    |   12 +++++++++-
0a2fc21
 src/pycurl.c |   60 +--------------------------------------------------------
0a2fc21
 2 files changed, 12 insertions(+), 60 deletions(-)
0a2fc21
0a2fc21
diff --git a/ChangeLog b/ChangeLog
0a2fc21
index 0fb7f8c..618654d 100644
0a2fc21
--- a/ChangeLog
0a2fc21
+++ b/ChangeLog
0a2fc21
@@ -1,7 +1,15 @@
0a2fc21
-Version 7.19.0 [requires libcurl-7.19.0 or better]
0a2fc21
+Version 7.19.1 [requires libcurl-7.19.0 or better]
0a2fc21
 --------------
0a2fc21
 
0a2fc21
-        * Added CURLFILE, ADDRESS_SCOPE and ISSUERCERT options, 
0a2fc21
+        * No longer keep string options copies in the
0a2fc21
+          Curl Python objects, since string options are
0a2fc21
+          now managed by libcurl.
0a2fc21
+
0a2fc21
+
0a2fc21
+Version 7.19.0
0a2fc21
+--------------
0a2fc21
+
0a2fc21
+        * Added CURLFILE, ADDRESS_SCOPE and ISSUERCERT options,
0a2fc21
           as well as the APPCONNECT_TIME info.
0a2fc21
 
0a2fc21
         * Added PRIMARY_IP info (patch by
0a2fc21
diff --git a/src/pycurl.c b/src/pycurl.c
0a2fc21
index a17a23b..6de1514 100644
0a2fc21
--- a/src/pycurl.c
0a2fc21
+++ b/src/pycurl.c
0a2fc21
@@ -1,4 +1,4 @@
0a2fc21
-/* $Id: pycurl.c,v 1.147 2008/09/09 17:40:34 kjetilja Exp $ */
0a2fc21
+/* $Id: pycurl.c,v 1.148 2008/09/29 10:56:57 kjetilja Exp $ */
0a2fc21
 
0a2fc21
 /* PycURL -- cURL Python module
0a2fc21
  *
0a2fc21
@@ -97,12 +97,6 @@ static void pycurl_ssl_cleanup(void);
0a2fc21
 /* Calculate the number of OBJECTPOINT options we need to store */
0a2fc21
 #define OPTIONS_SIZE    ((int)CURLOPT_LASTENTRY % 10000)
0a2fc21
 #define MOPTIONS_SIZE   ((int)CURLMOPT_LASTENTRY % 10000)
0a2fc21
-static int OPT_INDEX(int o)
0a2fc21
-{
0a2fc21
-    assert(o >= CURLOPTTYPE_OBJECTPOINT);
0a2fc21
-    assert(o < CURLOPTTYPE_OBJECTPOINT + OPTIONS_SIZE);
0a2fc21
-    return o - CURLOPTTYPE_OBJECTPOINT;
0a2fc21
-}
0a2fc21
 
0a2fc21
 /* Type objects */
0a2fc21
 static PyObject *ErrorObject = NULL;
0a2fc21
@@ -161,7 +155,6 @@ typedef struct {
0a2fc21
     PyObject *writedata_fp;
0a2fc21
     PyObject *writeheader_fp;
0a2fc21
     /* misc */
0a2fc21
-    void *options[OPTIONS_SIZE];    /* for OBJECTPOINT options */
0a2fc21
     char error[CURL_ERROR_SIZE+1];
0a2fc21
 } CurlObject;
0a2fc21
 
0a2fc21
@@ -741,7 +734,6 @@ util_curl_new(void)
0a2fc21
     self->writeheader_fp = NULL;
0a2fc21
 
0a2fc21
     /* Zero string pointer memory buffer used by setopt */
0a2fc21
-    memset(self->options, 0, sizeof(self->options));
0a2fc21
     memset(self->error, 0, sizeof(self->error));
0a2fc21
 
0a2fc21
     return self;
0a2fc21
@@ -804,7 +796,6 @@ do_curl_new(PyObject *dummy)
0a2fc21
         free(s);
0a2fc21
         goto error;
0a2fc21
     }
0a2fc21
-    self->options[ OPT_INDEX(CURLOPT_USERAGENT) ] = s; s = NULL;
0a2fc21
 
0a2fc21
     /* Success - return new object */
0a2fc21
     return self;
0a2fc21
@@ -872,7 +863,6 @@ static void
0a2fc21
 util_curl_close(CurlObject *self)
0a2fc21
 {
0a2fc21
     CURL *handle;
0a2fc21
-    int i;
0a2fc21
 
0a2fc21
     /* Zero handle and thread-state to disallow any operations to be run
0a2fc21
      * from now on */
0a2fc21
@@ -916,16 +906,6 @@ util_curl_close(CurlObject *self)
0a2fc21
     SFREE(self->postquote);
0a2fc21
     SFREE(self->prequote);
0a2fc21
 #undef SFREE
0a2fc21
-
0a2fc21
-    /* Last, free the options.  This must be done after the curl handle
0a2fc21
-     * is closed since libcurl assumes that some options are valid when
0a2fc21
-     * invoking curl_easy_cleanup(). */
0a2fc21
-    for (i = 0; i < OPTIONS_SIZE; i++) {
0a2fc21
-        if (self->options[i] != NULL) {
0a2fc21
-            free(self->options[i]);
0a2fc21
-            self->options[i] = NULL;
0a2fc21
-        }
0a2fc21
-    }
0a2fc21
 }
0a2fc21
 
0a2fc21
 
0a2fc21
@@ -1424,8 +1404,6 @@ verbose_error:
0a2fc21
 static PyObject*
0a2fc21
 do_curl_reset(CurlObject *self)
0a2fc21
 {
0a2fc21
-    unsigned int i;
0a2fc21
-
0a2fc21
     curl_easy_reset(self->handle);
0a2fc21
 
0a2fc21
     /* Decref callbacks and file handles */
0a2fc21
@@ -1443,15 +1421,6 @@ do_curl_reset(CurlObject *self)
0a2fc21
     SFREE(self->postquote);
0a2fc21
     SFREE(self->prequote);
0a2fc21
 #undef SFREE
0a2fc21
-
0a2fc21
-    /* Last, free the options */
0a2fc21
-    for (i = 0; i < OPTIONS_SIZE; i++) {
0a2fc21
-        if (self->options[i] != NULL) {
0a2fc21
-            free(self->options[i]);
0a2fc21
-            self->options[i] = NULL;
0a2fc21
-        }
0a2fc21
-    }
0a2fc21
-
0a2fc21
     return Py_None;
0a2fc21
 }
0a2fc21
 
0a2fc21
@@ -1461,7 +1430,6 @@ static PyObject *
0a2fc21
 util_curl_unsetopt(CurlObject *self, int option)
0a2fc21
 {
0a2fc21
     int res;
0a2fc21
-    int opt_index = -1;
0a2fc21
 
0a2fc21
 #define SETOPT2(o,x) \
0a2fc21
     if ((res = curl_easy_setopt(self->handle, (o), (x))) != CURLE_OK) goto error
0a2fc21
@@ -1502,7 +1470,6 @@ util_curl_unsetopt(CurlObject *self, int option)
0a2fc21
     case CURLOPT_SSL_CIPHER_LIST:
0a2fc21
     case CURLOPT_USERPWD:
0a2fc21
         SETOPT((char *) 0);
0a2fc21
-        opt_index = OPT_INDEX(option);
0a2fc21
         break;
0a2fc21
 
0a2fc21
     /* info: we explicitly list unsupported options here */
0a2fc21
@@ -1512,11 +1479,6 @@ util_curl_unsetopt(CurlObject *self, int option)
0a2fc21
         return NULL;
0a2fc21
     }
0a2fc21
 
0a2fc21
-    if (opt_index >= 0 && self->options[opt_index] != NULL) {
0a2fc21
-        free(self->options[opt_index]);
0a2fc21
-        self->options[opt_index] = NULL;
0a2fc21
-    }
0a2fc21
-
0a2fc21
     Py_INCREF(Py_None);
0a2fc21
     return Py_None;
0a2fc21
 
0a2fc21
@@ -1587,8 +1549,6 @@ do_curl_setopt(CurlObject *self, PyObject *args)
0a2fc21
     if (PyString_Check(obj)) {
0a2fc21
         char *str = NULL;
0a2fc21
         Py_ssize_t len = -1;
0a2fc21
-        char *buf;
0a2fc21
-        int opt_index;
0a2fc21
 
0a2fc21
         /* Check that the option specified a string as well as the input */
0a2fc21
         switch (option) {
0a2fc21
@@ -1651,28 +1611,12 @@ do_curl_setopt(CurlObject *self, PyObject *args)
0a2fc21
         }
0a2fc21
         /* Allocate memory to hold the string */
0a2fc21
         assert(str != NULL);
0a2fc21
-        if (len <= 0)
0a2fc21
-            buf = strdup(str);
0a2fc21
-        else {
0a2fc21
-            buf = (char *) malloc(len);
0a2fc21
-            if (buf) memcpy(buf, str, len);
0a2fc21
-        }
0a2fc21
-        if (buf == NULL)
0a2fc21
-            return PyErr_NoMemory();
0a2fc21
         /* Call setopt */
0a2fc21
-        res = curl_easy_setopt(self->handle, (CURLoption)option, buf);
0a2fc21
+        res = curl_easy_setopt(self->handle, (CURLoption)option, str);
0a2fc21
         /* Check for errors */
0a2fc21
         if (res != CURLE_OK) {
0a2fc21
-            free(buf);
0a2fc21
             CURLERROR_RETVAL();
0a2fc21
         }
0a2fc21
-        /* Save allocated option buffer */
0a2fc21
-        opt_index = OPT_INDEX(option);
0a2fc21
-        if (self->options[opt_index] != NULL) {
0a2fc21
-            free(self->options[opt_index]);
0a2fc21
-            self->options[opt_index] = NULL;
0a2fc21
-        }
0a2fc21
-        self->options[opt_index] = buf;
0a2fc21
         Py_INCREF(Py_None);
0a2fc21
         return Py_None;
0a2fc21
     }
0a2fc21
-- 
0a2fc21
1.7.1
0a2fc21