Blame SOURCES/0001-No-longer-keep-copies-of-string-options-since-this-i.patch

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