1 From 4a377e2d60fb903e91a370595a6ea22cb7ee0e0e Mon Sep 17 00:00:00 2001
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.
6 https://sourceforge.net/tracker/?func=detail&aid=2893665&group_id=28236&atid=392777
8 Signed-off-by: Kamil Dudka <kdudka@redhat.com>
10 src/pycurl.c | 88 +++++++++++++++++++++++++++++++++++++--------------------
11 1 files changed, 57 insertions(+), 31 deletions(-)
13 diff --git a/src/pycurl.c b/src/pycurl.c
14 index 6de1514..32c7ca5 100644
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 $ */
21 /* PycURL -- cURL Python module
23 @@ -739,64 +739,80 @@ util_curl_new(void)
28 -/* constructor - this is a module-level function returning a new instance */
30 -do_curl_new(PyObject *dummy)
31 +/* initializer - used to intialize curl easy handles for use with pycurl */
33 +util_curl_init(CurlObject *self)
35 - CurlObject *self = NULL;
41 - /* Allocate python curl object */
42 - self = util_curl_new();
46 - /* Initialize curl handle */
47 - self->handle = curl_easy_init();
48 - if (self->handle == NULL)
51 /* Set curl error buffer and zero it */
52 res = curl_easy_setopt(self->handle, CURLOPT_ERRORBUFFER, self->error);
53 - if (res != CURLE_OK)
55 + if (res != CURLE_OK) {
58 memset(self->error, 0, sizeof(self->error));
60 /* Set backreference */
61 res = curl_easy_setopt(self->handle, CURLOPT_PRIVATE, (char *) self);
62 - if (res != CURLE_OK)
64 + if (res != CURLE_OK) {
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)
72 + if (res != CURLE_OK) {
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)
80 + if (res != CURLE_OK) {
84 /* Set FTP_ACCOUNT to NULL by default */
85 res = curl_easy_setopt(self->handle, CURLOPT_FTP_ACCOUNT, NULL);
86 - if (res != CURLE_OK)
88 + if (res != CURLE_OK) {
92 /* Set default USERAGENT */
93 s = (char *) malloc(7 + strlen(LIBCURL_VERSION) + 1);
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) {
109 +/* constructor - this is a module-level function returning a new instance */
111 +do_curl_new(PyObject *dummy)
113 + CurlObject *self = NULL;
118 + /* Allocate python curl object */
119 + self = util_curl_new();
123 + /* Initialize curl handle */
124 + self->handle = curl_easy_init();
125 + if (self->handle == NULL)
128 + res = util_curl_init(self);
131 /* Success - return new object */
134 @@ -1404,6 +1420,8 @@ verbose_error:
136 do_curl_reset(CurlObject *self)
140 curl_easy_reset(self->handle);
142 /* Decref callbacks and file handles */
143 @@ -1421,6 +1439,14 @@ do_curl_reset(CurlObject *self)
144 SFREE(self->postquote);
145 SFREE(self->prequote);
147 + res = util_curl_init(self);
149 + Py_DECREF(self); /* this also closes self->handle */
150 + PyErr_SetString(ErrorObject, "resetting curl failed");
154 + Py_INCREF(Py_None);