[python-pycurl/f18] reinitialize pycurl-specific defaults in reset() (#896025)

Kamil Dudka kdudka at fedoraproject.org
Tue Feb 26 09:46:05 UTC 2013


commit a8871e55f42a3a26ad8b92fc166ed3b83eb0ebe6
Author: Kamil Dudka <kdudka at redhat.com>
Date:   Tue Feb 26 10:36:22 2013 +0100

    reinitialize pycurl-specific defaults in reset() (#896025)

 ...unt-bug-and-provides-better-organization-.patch |  160 ++++++++++++++++++++
 python-pycurl-fix-do_curl_reset-refcount.patch     |   10 --
 python-pycurl.spec                                 |    7 +-
 3 files changed, 166 insertions(+), 11 deletions(-)
---
diff --git a/0003-Fixes-refcount-bug-and-provides-better-organization-.patch b/0003-Fixes-refcount-bug-and-provides-better-organization-.patch
new file mode 100644
index 0000000..62d14d8
--- /dev/null
+++ b/0003-Fixes-refcount-bug-and-provides-better-organization-.patch
@@ -0,0 +1,160 @@
+From 4a377e2d60fb903e91a370595a6ea22cb7ee0e0e Mon Sep 17 00:00:00 2001
+From: zanee <zanee>
+Date: Wed, 28 Apr 2010 16:02:41 +0000
+Subject: [PATCH] Fixes refcount bug and provides better organization of PyCurl object. Submitted by dbprice1.
+
+https://sourceforge.net/tracker/?func=detail&aid=2893665&group_id=28236&atid=392777
+
+Signed-off-by: Kamil Dudka <kdudka at redhat.com>
+---
+ src/pycurl.c |   87 +++++++++++++++++++++++++++++++++++++--------------------
+ 1 files changed, 56 insertions(+), 31 deletions(-)
+
+diff --git a/src/pycurl.c b/src/pycurl.c
+index 6de1514..32c7ca5 100644
+--- a/src/pycurl.c
++++ b/src/pycurl.c
+@@ -1,4 +1,4 @@
+-/* $Id: pycurl.c,v 1.147 2008/09/09 17:40:34 kjetilja Exp $ */
++/* $Id: pycurl.c,v XXX $ */
+ 
+ /* PycURL -- cURL Python module
+  *
+@@ -747,65 +747,81 @@ util_curl_new(void)
+     return self;
+ }
+ 
+-
+-/* constructor - this is a module-level function returning a new instance */
+-static CurlObject *
+-do_curl_new(PyObject *dummy)
++/* initializer - used to intialize curl easy handles for use with pycurl */
++static int
++util_curl_init(CurlObject *self)
+ {
+-    CurlObject *self = NULL;
+     int res;
+     char *s = NULL;
+ 
+-    UNUSED(dummy);
+-
+-    /* Allocate python curl object */
+-    self = util_curl_new();
+-    if (self == NULL)
+-        return NULL;
+-
+-    /* Initialize curl handle */
+-    self->handle = curl_easy_init();
+-    if (self->handle == NULL)
+-        goto error;
+-
+     /* Set curl error buffer and zero it */
+     res = curl_easy_setopt(self->handle, CURLOPT_ERRORBUFFER, self->error);
+-    if (res != CURLE_OK)
+-        goto error;
++    if (res != CURLE_OK) {
++        return (-1);
++    }
+     memset(self->error, 0, sizeof(self->error));
+ 
+     /* Set backreference */
+     res = curl_easy_setopt(self->handle, CURLOPT_PRIVATE, (char *) self);
+-    if (res != CURLE_OK)
+-        goto error;
++    if (res != CURLE_OK) {
++        return (-1);
++    }
+ 
+     /* Enable NOPROGRESS by default, i.e. no progress output */
+     res = curl_easy_setopt(self->handle, CURLOPT_NOPROGRESS, (long)1);
+-    if (res != CURLE_OK)
+-        goto error;
++    if (res != CURLE_OK) {
++        return (-1);
++    }
+ 
+     /* Disable VERBOSE by default, i.e. no verbose output */
+     res = curl_easy_setopt(self->handle, CURLOPT_VERBOSE, (long)0);
+-    if (res != CURLE_OK)
+-        goto error;
++    if (res != CURLE_OK) {
++        return (-1);
++    }
+ 
+     /* Set FTP_ACCOUNT to NULL by default */
+     res = curl_easy_setopt(self->handle, CURLOPT_FTP_ACCOUNT, NULL);
+-    if (res != CURLE_OK)
+-        goto error;
++    if (res != CURLE_OK) {
++        return (-1);
++    }
+ 
+     /* Set default USERAGENT */
+     s = (char *) malloc(7 + strlen(LIBCURL_VERSION) + 1);
+-    if (s == NULL)
+-        goto error;
++    if (s == NULL) {
++        return (-1);
++    }
+     strcpy(s, "PycURL/"); strcpy(s+7, LIBCURL_VERSION);
+     res = curl_easy_setopt(self->handle, CURLOPT_USERAGENT, (char *) s);
+     if (res != CURLE_OK) {
+         free(s);
+-        goto error;
++        return (-1);
+     }
+     self->options[ OPT_INDEX(CURLOPT_USERAGENT) ] = s; s = NULL;
++    return (0);
++}
++
++/* constructor - this is a module-level function returning a new instance */
++static CurlObject *
++do_curl_new(PyObject *dummy)
++{
++    CurlObject *self = NULL;
++    int res;
++
++    UNUSED(dummy);
+ 
++    /* Allocate python curl object */
++    self = util_curl_new();
++    if (self == NULL)
++        return NULL;
++
++    /* Initialize curl handle */
++    self->handle = curl_easy_init();
++    if (self->handle == NULL)
++        goto error;
++
++    res = util_curl_init(self);
++    if (res < 0)
++            goto error;
+     /* Success - return new object */
+     return self;
+ 
+@@ -1425,6 +1441,7 @@ static PyObject*
+ do_curl_reset(CurlObject *self)
+ {
+     unsigned int i;
++    int res;
+ 
+     curl_easy_reset(self->handle);
+ 
+@@ -1452,6 +1469,14 @@ do_curl_reset(CurlObject *self)
+         }
+     }
+ 
++    res = util_curl_init(self);
++    if (res < 0) {
++        Py_DECREF(self);    /* this also closes self->handle */
++        PyErr_SetString(ErrorObject, "resetting curl failed");
++        return NULL;
++    }
++
++    Py_INCREF(Py_None);
+     return Py_None;
+ }
+ 
+-- 
+1.7.1
+
diff --git a/python-pycurl-fix-do_curl_reset-refcount.patch b/python-pycurl-fix-do_curl_reset-refcount.patch
index 7e20b15..a726e48 100644
--- a/python-pycurl-fix-do_curl_reset-refcount.patch
+++ b/python-pycurl-fix-do_curl_reset-refcount.patch
@@ -1,13 +1,3 @@
---- a/src/pycurl.c	
-+++ a/src/pycurl.c	
-@@ -1452,6 +1452,7 @@ do_curl_reset(CurlObject *self)
-         }
-     }
- 
-+    Py_INCREF(Py_None);
-     return Py_None;
- }
- 
 --- a/tests/test_internals.py	
 +++ a/tests/test_internals.py	
 @@ -245,6 +245,11 @@ if 1 and gc:
diff --git a/python-pycurl.spec b/python-pycurl.spec
index cd2dc6a..79fcfe8 100644
--- a/python-pycurl.spec
+++ b/python-pycurl.spec
@@ -2,7 +2,7 @@
 
 Name:           python-pycurl
 Version:        7.19.0
-Release:        12%{?dist}
+Release:        13%{?dist}
 Summary:        A Python interface to libcurl
 
 Group:          Development/Languages
@@ -11,6 +11,7 @@ URL:            http://pycurl.sourceforge.net/
 Source0:        http://pycurl.sourceforge.net/download/pycurl-%{version}.tar.gz
 Patch0:         %{name}-no-static-libs.patch
 Patch1:         %{name}-fix-do_curl_reset-refcount.patch
+Patch3:         0003-Fixes-refcount-bug-and-provides-better-organization-.patch
 Requires:       keyutils-libs
 
 BuildRequires:  python-devel
@@ -37,6 +38,7 @@ of features.
 
 %prep
 %setup0 -q -n pycurl-%{version}
+%patch3 -p1
 %patch0 -p0
 %patch1 -p1
 chmod a-x examples/*
@@ -57,6 +59,9 @@ rm -rf %{buildroot}%{_datadir}/doc/pycurl
 %{python_sitearch}/*
 
 %changelog
+* Tue Feb 26 2013 Kamil Dudka <kdudka at redhat.com> - 7.19.0-13
+- reinitialize pycurl-specific defaults in reset() (#896025)
+
 * Wed Aug 22 2012 Jan Synáček <jsynacek at redhat.com> - 7.19.0-12
 - Improve spec
 


More information about the scm-commits mailing list