1 From 05433632fb1ccdabc1d29d78f32bc35de0a8638b Mon Sep 17 00:00:00 2001
2 From: kjetilja <kjetilja>
3 Date: Mon, 29 Sep 2008 10:56:57 +0000
4 Subject: [PATCH 1/5] No longer keep copies of string options since this is managed by libcurl
6 Signed-off-by: Kamil Dudka <kdudka@redhat.com>
8 ChangeLog | 12 +++++++++-
9 src/pycurl.c | 60 +--------------------------------------------------------
10 2 files changed, 12 insertions(+), 60 deletions(-)
12 diff --git a/ChangeLog b/ChangeLog
13 index 0fb7f8c..618654d 100644
17 -Version 7.19.0 [requires libcurl-7.19.0 or better]
18 +Version 7.19.1 [requires libcurl-7.19.0 or better]
21 - * Added CURLFILE, ADDRESS_SCOPE and ISSUERCERT options,
22 + * No longer keep string options copies in the
23 + Curl Python objects, since string options are
24 + now managed by libcurl.
30 + * Added CURLFILE, ADDRESS_SCOPE and ISSUERCERT options,
31 as well as the APPCONNECT_TIME info.
33 * Added PRIMARY_IP info (patch by
34 diff --git a/src/pycurl.c b/src/pycurl.c
35 index a17a23b..6de1514 100644
39 -/* $Id: pycurl.c,v 1.147 2008/09/09 17:40:34 kjetilja Exp $ */
40 +/* $Id: pycurl.c,v 1.148 2008/09/29 10:56:57 kjetilja Exp $ */
42 /* PycURL -- cURL Python module
44 @@ -97,12 +97,6 @@ static void pycurl_ssl_cleanup(void);
45 /* Calculate the number of OBJECTPOINT options we need to store */
46 #define OPTIONS_SIZE ((int)CURLOPT_LASTENTRY % 10000)
47 #define MOPTIONS_SIZE ((int)CURLMOPT_LASTENTRY % 10000)
48 -static int OPT_INDEX(int o)
50 - assert(o >= CURLOPTTYPE_OBJECTPOINT);
51 - assert(o < CURLOPTTYPE_OBJECTPOINT + OPTIONS_SIZE);
52 - return o - CURLOPTTYPE_OBJECTPOINT;
56 static PyObject *ErrorObject = NULL;
57 @@ -161,7 +155,6 @@ typedef struct {
58 PyObject *writedata_fp;
59 PyObject *writeheader_fp;
61 - void *options[OPTIONS_SIZE]; /* for OBJECTPOINT options */
62 char error[CURL_ERROR_SIZE+1];
65 @@ -741,7 +734,6 @@ util_curl_new(void)
66 self->writeheader_fp = NULL;
68 /* Zero string pointer memory buffer used by setopt */
69 - memset(self->options, 0, sizeof(self->options));
70 memset(self->error, 0, sizeof(self->error));
73 @@ -804,7 +796,6 @@ do_curl_new(PyObject *dummy)
77 - self->options[ OPT_INDEX(CURLOPT_USERAGENT) ] = s; s = NULL;
79 /* Success - return new object */
81 @@ -872,7 +863,6 @@ static void
82 util_curl_close(CurlObject *self)
87 /* Zero handle and thread-state to disallow any operations to be run
89 @@ -916,16 +906,6 @@ util_curl_close(CurlObject *self)
90 SFREE(self->postquote);
91 SFREE(self->prequote);
94 - /* Last, free the options. This must be done after the curl handle
95 - * is closed since libcurl assumes that some options are valid when
96 - * invoking curl_easy_cleanup(). */
97 - for (i = 0; i < OPTIONS_SIZE; i++) {
98 - if (self->options[i] != NULL) {
99 - free(self->options[i]);
100 - self->options[i] = NULL;
106 @@ -1424,8 +1404,6 @@ verbose_error:
108 do_curl_reset(CurlObject *self)
112 curl_easy_reset(self->handle);
114 /* Decref callbacks and file handles */
115 @@ -1443,15 +1421,6 @@ do_curl_reset(CurlObject *self)
116 SFREE(self->postquote);
117 SFREE(self->prequote);
120 - /* Last, free the options */
121 - for (i = 0; i < OPTIONS_SIZE; i++) {
122 - if (self->options[i] != NULL) {
123 - free(self->options[i]);
124 - self->options[i] = NULL;
131 @@ -1461,7 +1430,6 @@ static PyObject *
132 util_curl_unsetopt(CurlObject *self, int option)
135 - int opt_index = -1;
137 #define SETOPT2(o,x) \
138 if ((res = curl_easy_setopt(self->handle, (o), (x))) != CURLE_OK) goto error
139 @@ -1502,7 +1470,6 @@ util_curl_unsetopt(CurlObject *self, int option)
140 case CURLOPT_SSL_CIPHER_LIST:
141 case CURLOPT_USERPWD:
143 - opt_index = OPT_INDEX(option);
146 /* info: we explicitly list unsupported options here */
147 @@ -1512,11 +1479,6 @@ util_curl_unsetopt(CurlObject *self, int option)
151 - if (opt_index >= 0 && self->options[opt_index] != NULL) {
152 - free(self->options[opt_index]);
153 - self->options[opt_index] = NULL;
159 @@ -1587,8 +1549,6 @@ do_curl_setopt(CurlObject *self, PyObject *args)
160 if (PyString_Check(obj)) {
166 /* Check that the option specified a string as well as the input */
168 @@ -1651,28 +1611,12 @@ do_curl_setopt(CurlObject *self, PyObject *args)
170 /* Allocate memory to hold the string */
175 - buf = (char *) malloc(len);
176 - if (buf) memcpy(buf, str, len);
179 - return PyErr_NoMemory();
181 - res = curl_easy_setopt(self->handle, (CURLoption)option, buf);
182 + res = curl_easy_setopt(self->handle, (CURLoption)option, str);
183 /* Check for errors */
184 if (res != CURLE_OK) {
188 - /* Save allocated option buffer */
189 - opt_index = OPT_INDEX(option);
190 - if (self->options[opt_index] != NULL) {
191 - free(self->options[opt_index]);
192 - self->options[opt_index] = NULL;
194 - self->options[opt_index] = buf;