]>
Commit | Line | Data |
---|---|---|
883c26f3 MT |
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 | |
5 | ||
6 | Signed-off-by: Kamil Dudka <kdudka@redhat.com> | |
7 | --- | |
8 | ChangeLog | 12 +++++++++- | |
9 | src/pycurl.c | 60 +-------------------------------------------------------- | |
10 | 2 files changed, 12 insertions(+), 60 deletions(-) | |
11 | ||
12 | diff --git a/ChangeLog b/ChangeLog | |
13 | index 0fb7f8c..618654d 100644 | |
14 | --- a/ChangeLog | |
15 | +++ b/ChangeLog | |
16 | @@ -1,7 +1,15 @@ | |
17 | -Version 7.19.0 [requires libcurl-7.19.0 or better] | |
18 | +Version 7.19.1 [requires libcurl-7.19.0 or better] | |
19 | -------------- | |
20 | ||
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. | |
25 | + | |
26 | + | |
27 | +Version 7.19.0 | |
28 | +-------------- | |
29 | + | |
30 | + * Added CURLFILE, ADDRESS_SCOPE and ISSUERCERT options, | |
31 | as well as the APPCONNECT_TIME info. | |
32 | ||
33 | * Added PRIMARY_IP info (patch by | |
34 | diff --git a/src/pycurl.c b/src/pycurl.c | |
35 | index a17a23b..6de1514 100644 | |
36 | --- a/src/pycurl.c | |
37 | +++ b/src/pycurl.c | |
38 | @@ -1,4 +1,4 @@ | |
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 $ */ | |
41 | ||
42 | /* PycURL -- cURL Python module | |
43 | * | |
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) | |
49 | -{ | |
50 | - assert(o >= CURLOPTTYPE_OBJECTPOINT); | |
51 | - assert(o < CURLOPTTYPE_OBJECTPOINT + OPTIONS_SIZE); | |
52 | - return o - CURLOPTTYPE_OBJECTPOINT; | |
53 | -} | |
54 | ||
55 | /* Type objects */ | |
56 | static PyObject *ErrorObject = NULL; | |
57 | @@ -161,7 +155,6 @@ typedef struct { | |
58 | PyObject *writedata_fp; | |
59 | PyObject *writeheader_fp; | |
60 | /* misc */ | |
61 | - void *options[OPTIONS_SIZE]; /* for OBJECTPOINT options */ | |
62 | char error[CURL_ERROR_SIZE+1]; | |
63 | } CurlObject; | |
64 | ||
65 | @@ -741,7 +734,6 @@ util_curl_new(void) | |
66 | self->writeheader_fp = NULL; | |
67 | ||
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)); | |
71 | ||
72 | return self; | |
73 | @@ -804,7 +796,6 @@ do_curl_new(PyObject *dummy) | |
74 | free(s); | |
75 | goto error; | |
76 | } | |
77 | - self->options[ OPT_INDEX(CURLOPT_USERAGENT) ] = s; s = NULL; | |
78 | ||
79 | /* Success - return new object */ | |
80 | return self; | |
81 | @@ -872,7 +863,6 @@ static void | |
82 | util_curl_close(CurlObject *self) | |
83 | { | |
84 | CURL *handle; | |
85 | - int i; | |
86 | ||
87 | /* Zero handle and thread-state to disallow any operations to be run | |
88 | * from now on */ | |
89 | @@ -916,16 +906,6 @@ util_curl_close(CurlObject *self) | |
90 | SFREE(self->postquote); | |
91 | SFREE(self->prequote); | |
92 | #undef SFREE | |
93 | - | |
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; | |
101 | - } | |
102 | - } | |
103 | } | |
104 | ||
105 | ||
106 | @@ -1424,8 +1404,6 @@ verbose_error: | |
107 | static PyObject* | |
108 | do_curl_reset(CurlObject *self) | |
109 | { | |
110 | - unsigned int i; | |
111 | - | |
112 | curl_easy_reset(self->handle); | |
113 | ||
114 | /* Decref callbacks and file handles */ | |
115 | @@ -1443,15 +1421,6 @@ do_curl_reset(CurlObject *self) | |
116 | SFREE(self->postquote); | |
117 | SFREE(self->prequote); | |
118 | #undef SFREE | |
119 | - | |
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; | |
125 | - } | |
126 | - } | |
127 | - | |
128 | return Py_None; | |
129 | } | |
130 | ||
131 | @@ -1461,7 +1430,6 @@ static PyObject * | |
132 | util_curl_unsetopt(CurlObject *self, int option) | |
133 | { | |
134 | int res; | |
135 | - int opt_index = -1; | |
136 | ||
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: | |
142 | SETOPT((char *) 0); | |
143 | - opt_index = OPT_INDEX(option); | |
144 | break; | |
145 | ||
146 | /* info: we explicitly list unsupported options here */ | |
147 | @@ -1512,11 +1479,6 @@ util_curl_unsetopt(CurlObject *self, int option) | |
148 | return NULL; | |
149 | } | |
150 | ||
151 | - if (opt_index >= 0 && self->options[opt_index] != NULL) { | |
152 | - free(self->options[opt_index]); | |
153 | - self->options[opt_index] = NULL; | |
154 | - } | |
155 | - | |
156 | Py_INCREF(Py_None); | |
157 | return Py_None; | |
158 | ||
159 | @@ -1587,8 +1549,6 @@ do_curl_setopt(CurlObject *self, PyObject *args) | |
160 | if (PyString_Check(obj)) { | |
161 | char *str = NULL; | |
162 | Py_ssize_t len = -1; | |
163 | - char *buf; | |
164 | - int opt_index; | |
165 | ||
166 | /* Check that the option specified a string as well as the input */ | |
167 | switch (option) { | |
168 | @@ -1651,28 +1611,12 @@ do_curl_setopt(CurlObject *self, PyObject *args) | |
169 | } | |
170 | /* Allocate memory to hold the string */ | |
171 | assert(str != NULL); | |
172 | - if (len <= 0) | |
173 | - buf = strdup(str); | |
174 | - else { | |
175 | - buf = (char *) malloc(len); | |
176 | - if (buf) memcpy(buf, str, len); | |
177 | - } | |
178 | - if (buf == NULL) | |
179 | - return PyErr_NoMemory(); | |
180 | /* Call setopt */ | |
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) { | |
185 | - free(buf); | |
186 | CURLERROR_RETVAL(); | |
187 | } | |
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; | |
193 | - } | |
194 | - self->options[opt_index] = buf; | |
195 | Py_INCREF(Py_None); | |
196 | return Py_None; | |
197 | } | |
198 | -- | |
199 | 1.7.1 | |
200 |