]> git.ipfire.org Git - ipfire-3.x.git/blob - python-pycurl/patches/0003-Fixes-refcount-bug-and-provides-better-organization-.patch
make: Update to 4.2.1
[ipfire-3.x.git] / python-pycurl / patches / 0003-Fixes-refcount-bug-and-provides-better-organization-.patch
1 From 4a377e2d60fb903e91a370595a6ea22cb7ee0e0e Mon Sep 17 00:00:00 2001
2 From: zanee <zanee>
3 Date: Wed, 28 Apr 2010 16:02:41 +0000
4 Subject: [PATCH 3/5 v2] Fixes refcount bug and provides better organization of PyCurl object. Submitted by dbprice1.
5
6 https://sourceforge.net/tracker/?func=detail&aid=2893665&group_id=28236&atid=392777
7
8 Signed-off-by: Kamil Dudka <kdudka@redhat.com>
9 ---
10 src/pycurl.c | 88 +++++++++++++++++++++++++++++++++++++--------------------
11 1 files changed, 57 insertions(+), 31 deletions(-)
12
13 diff --git a/src/pycurl.c b/src/pycurl.c
14 index 6de1514..32c7ca5 100644
15 --- a/src/pycurl.c
16 +++ b/src/pycurl.c
17 @@ -1,4 +1,4 @@
18 -/* $Id: pycurl.c,v 1.148 2008/09/29 10:56:57 kjetilja Exp $ */
19 +/* $Id: pycurl.c,v 1.149 2010/04/28 16:02:41 zanee Exp $ */
20
21 /* PycURL -- cURL Python module
22 *
23 @@ -739,64 +739,80 @@ util_curl_new(void)
24 return self;
25 }
26
27 -
28 -/* constructor - this is a module-level function returning a new instance */
29 -static CurlObject *
30 -do_curl_new(PyObject *dummy)
31 +/* initializer - used to intialize curl easy handles for use with pycurl */
32 +static int
33 +util_curl_init(CurlObject *self)
34 {
35 - CurlObject *self = NULL;
36 int res;
37 char *s = NULL;
38
39 - UNUSED(dummy);
40 -
41 - /* Allocate python curl object */
42 - self = util_curl_new();
43 - if (self == NULL)
44 - return NULL;
45 -
46 - /* Initialize curl handle */
47 - self->handle = curl_easy_init();
48 - if (self->handle == NULL)
49 - goto error;
50 -
51 /* Set curl error buffer and zero it */
52 res = curl_easy_setopt(self->handle, CURLOPT_ERRORBUFFER, self->error);
53 - if (res != CURLE_OK)
54 - goto error;
55 + if (res != CURLE_OK) {
56 + return (-1);
57 + }
58 memset(self->error, 0, sizeof(self->error));
59
60 /* Set backreference */
61 res = curl_easy_setopt(self->handle, CURLOPT_PRIVATE, (char *) self);
62 - if (res != CURLE_OK)
63 - goto error;
64 + if (res != CURLE_OK) {
65 + return (-1);
66 + }
67
68 /* Enable NOPROGRESS by default, i.e. no progress output */
69 res = curl_easy_setopt(self->handle, CURLOPT_NOPROGRESS, (long)1);
70 - if (res != CURLE_OK)
71 - goto error;
72 + if (res != CURLE_OK) {
73 + return (-1);
74 + }
75
76 /* Disable VERBOSE by default, i.e. no verbose output */
77 res = curl_easy_setopt(self->handle, CURLOPT_VERBOSE, (long)0);
78 - if (res != CURLE_OK)
79 - goto error;
80 + if (res != CURLE_OK) {
81 + return (-1);
82 + }
83
84 /* Set FTP_ACCOUNT to NULL by default */
85 res = curl_easy_setopt(self->handle, CURLOPT_FTP_ACCOUNT, NULL);
86 - if (res != CURLE_OK)
87 - goto error;
88 + if (res != CURLE_OK) {
89 + return (-1);
90 + }
91
92 /* Set default USERAGENT */
93 s = (char *) malloc(7 + strlen(LIBCURL_VERSION) + 1);
94 - if (s == NULL)
95 - goto error;
96 + if (s == NULL) {
97 + return (-1);
98 + }
99 strcpy(s, "PycURL/"); strcpy(s+7, LIBCURL_VERSION);
100 res = curl_easy_setopt(self->handle, CURLOPT_USERAGENT, (char *) s);
101 if (res != CURLE_OK) {
102 free(s);
103 - goto error;
104 + return (-1);
105 }
106 + return (0);
107 +}
108 +
109 +/* constructor - this is a module-level function returning a new instance */
110 +static CurlObject *
111 +do_curl_new(PyObject *dummy)
112 +{
113 + CurlObject *self = NULL;
114 + int res;
115 +
116 + UNUSED(dummy);
117 +
118 + /* Allocate python curl object */
119 + self = util_curl_new();
120 + if (self == NULL)
121 + return NULL;
122 +
123 + /* Initialize curl handle */
124 + self->handle = curl_easy_init();
125 + if (self->handle == NULL)
126 + goto error;
127
128 + res = util_curl_init(self);
129 + if (res < 0)
130 + goto error;
131 /* Success - return new object */
132 return self;
133
134 @@ -1404,6 +1420,8 @@ verbose_error:
135 static PyObject*
136 do_curl_reset(CurlObject *self)
137 {
138 + int res;
139 +
140 curl_easy_reset(self->handle);
141
142 /* Decref callbacks and file handles */
143 @@ -1421,6 +1439,14 @@ do_curl_reset(CurlObject *self)
144 SFREE(self->postquote);
145 SFREE(self->prequote);
146 #undef SFREE
147 + res = util_curl_init(self);
148 + if (res < 0) {
149 + Py_DECREF(self); /* this also closes self->handle */
150 + PyErr_SetString(ErrorObject, "resetting curl failed");
151 + return NULL;
152 + }
153 +
154 + Py_INCREF(Py_None);
155 return Py_None;
156 }
157
158 --
159 1.7.1
160