[python-pycurl] allow to return -1 from write callback (#857875)

Kamil Dudka kdudka at fedoraproject.org
Wed Mar 6 14:20:28 UTC 2013


commit 77fac8b0fa9424dbfb81ac74cf4f37d3e628cc34
Author: Kamil Dudka <kdudka at redhat.com>
Date:   Wed Mar 6 15:02:01 2013 +0100

    allow to return -1 from write callback (#857875)
    
    ... and remove the patch for curl-config --static-libs no longer needed

 ...tup.py-do-not-use-curl-config-static-libs.patch |   34 -----------
 ...als.py-add-a-test-for-ref-counting-of-res.patch |    4 +-
 ...iminate-duplicated-code-in-util_write_cal.patch |   34 +++++++++++
 ...l.c-allow-to-return-1-from-write-callback.patch |   45 +++++++++++++++
 ...abort.py-test-returning-1-from-write-call.patch |   59 ++++++++++++++++++++
 python-pycurl.spec                                 |   16 ++++-
 6 files changed, 152 insertions(+), 40 deletions(-)
---
diff --git a/0102-test_internals.py-add-a-test-for-ref-counting-of-res.patch b/0101-test_internals.py-add-a-test-for-ref-counting-of-res.patch
similarity index 84%
rename from 0102-test_internals.py-add-a-test-for-ref-counting-of-res.patch
rename to 0101-test_internals.py-add-a-test-for-ref-counting-of-res.patch
index 7d3d534..5e889ca 100644
--- a/0102-test_internals.py-add-a-test-for-ref-counting-of-res.patch
+++ b/0101-test_internals.py-add-a-test-for-ref-counting-of-res.patch
@@ -1,7 +1,7 @@
-From 0bd83ea6c820db26f98936e6e017d39fb214cbd0 Mon Sep 17 00:00:00 2001
+From 593cf090dacc230cd28aee1993d86b2b83b414f9 Mon Sep 17 00:00:00 2001
 From: Kamil Dudka <kdudka at redhat.com>
 Date: Mon, 25 Feb 2013 19:50:18 +0100
-Subject: [PATCH 2/2] test_internals.py: add a test for ref-counting of reset()
+Subject: [PATCH 1/4] test_internals.py: add a test for ref-counting of reset()
 
 ---
  tests/test_internals.py |    5 +++++
diff --git a/0102-pycurl.c-eliminate-duplicated-code-in-util_write_cal.patch b/0102-pycurl.c-eliminate-duplicated-code-in-util_write_cal.patch
new file mode 100644
index 0000000..b707a61
--- /dev/null
+++ b/0102-pycurl.c-eliminate-duplicated-code-in-util_write_cal.patch
@@ -0,0 +1,34 @@
+From c84c2a02a34031a951edeb5d3f81676d05e2765f Mon Sep 17 00:00:00 2001
+From: Kamil Dudka <kdudka at redhat.com>
+Date: Tue, 26 Feb 2013 14:49:47 +0100
+Subject: [PATCH 2/4] pycurl.c: eliminate duplicated code in util_write_callback()
+
+Suggested by Zdenek Pavlas <https://bugzilla.redhat.com/857875#c8>.
+---
+ src/pycurl.c |   10 +---------
+ 1 files changed, 1 insertions(+), 9 deletions(-)
+
+diff --git a/src/pycurl.c b/src/pycurl.c
+index 74f5248..f197145 100644
+--- a/src/pycurl.c
++++ b/src/pycurl.c
+@@ -1080,15 +1080,7 @@ util_write_callback(int flags, char *ptr, size_t size, size_t nmemb, void *strea
+     if (result == Py_None) {
+         ret = total_size;           /* None means success */
+     }
+-    else if (PyInt_Check(result)) {
+-        long obj_size = PyInt_AsLong(result);
+-        if (obj_size < 0 || obj_size > total_size) {
+-            PyErr_Format(ErrorObject, "invalid return value for write callback %ld %ld", (long)obj_size, (long)total_size);
+-            goto verbose_error;
+-        }
+-        ret = (size_t) obj_size;    /* success */
+-    }
+-    else if (PyLong_Check(result)) {
++    else if (PyInt_Check(result) || PyLong_Check(result)) {
+         long obj_size = PyLong_AsLong(result);
+         if (obj_size < 0 || obj_size > total_size) {
+             PyErr_Format(ErrorObject, "invalid return value for write callback %ld %ld", (long)obj_size, (long)total_size);
+-- 
+1.7.1
+
diff --git a/0103-pycurl.c-allow-to-return-1-from-write-callback.patch b/0103-pycurl.c-allow-to-return-1-from-write-callback.patch
new file mode 100644
index 0000000..d3d7a3e
--- /dev/null
+++ b/0103-pycurl.c-allow-to-return-1-from-write-callback.patch
@@ -0,0 +1,45 @@
+From ca4705dab05371c40f398b97277024332ed44651 Mon Sep 17 00:00:00 2001
+From: Kamil Dudka <kdudka at redhat.com>
+Date: Tue, 26 Feb 2013 16:58:55 +0100
+Subject: [PATCH 3/4] pycurl.c: allow to return -1 from write callback
+
+... to abort the transfer and WRITEFUNC_PAUSE to pause the transfer
+
+Reported By: Zdenek Pavlas
+Bug: https://bugzilla.redhat.com/857875
+---
+ src/pycurl.c |   11 +++++------
+ 1 files changed, 5 insertions(+), 6 deletions(-)
+
+diff --git a/src/pycurl.c b/src/pycurl.c
+index f197145..b59eeb8 100644
+--- a/src/pycurl.c
++++ b/src/pycurl.c
+@@ -1081,12 +1081,8 @@ util_write_callback(int flags, char *ptr, size_t size, size_t nmemb, void *strea
+         ret = total_size;           /* None means success */
+     }
+     else if (PyInt_Check(result) || PyLong_Check(result)) {
+-        long obj_size = PyLong_AsLong(result);
+-        if (obj_size < 0 || obj_size > total_size) {
+-            PyErr_Format(ErrorObject, "invalid return value for write callback %ld %ld", (long)obj_size, (long)total_size);
+-            goto verbose_error;
+-        }
+-        ret = (size_t) obj_size;    /* success */
++        /* if the cast to long fails, PyLong_AsLong() returns -1L */
++        ret = (size_t) PyLong_AsLong(result);
+     }
+     else {
+         PyErr_SetString(ErrorObject, "write callback must return int or None");
+@@ -3423,6 +3419,9 @@ initpycurl(void)
+     /* Abort curl_read_callback(). */
+     insint_c(d, "READFUNC_ABORT", CURL_READFUNC_ABORT);
+ 
++    /* Pause curl_write_callback(). */
++    insint_c(d, "WRITEFUNC_PAUSE", CURL_WRITEFUNC_PAUSE);
++
+     /* constants for ioctl callback return values */
+     insint_c(d, "IOE_OK", CURLIOE_OK);
+     insint_c(d, "IOE_UNKNOWNCMD", CURLIOE_UNKNOWNCMD);
+-- 
+1.7.1
+
diff --git a/0104-test_write_abort.py-test-returning-1-from-write-call.patch b/0104-test_write_abort.py-test-returning-1-from-write-call.patch
new file mode 100644
index 0000000..b6d4168
--- /dev/null
+++ b/0104-test_write_abort.py-test-returning-1-from-write-call.patch
@@ -0,0 +1,59 @@
+From d8e4390da96d19a322a6fd3512ccac0200f15ddb Mon Sep 17 00:00:00 2001
+From: Kamil Dudka <kdudka at redhat.com>
+Date: Wed, 6 Mar 2013 14:38:01 +0100
+Subject: [PATCH 4/4] test_write_abort.py: test returning -1 from write callback
+
+---
+ Makefile                  |    1 +
+ tests/test_write_abort.py |   27 +++++++++++++++++++++++++++
+ 2 files changed, 28 insertions(+), 0 deletions(-)
+ create mode 100755 tests/test_write_abort.py
+
+diff --git a/Makefile b/Makefile
+index 9b2369d..10b95a7 100644
+--- a/Makefile
++++ b/Makefile
+@@ -16,6 +16,7 @@ build-7.10.8:
+ 
+ test: build
+ 	$(PYTHON) tests/test_internals.py -q
++	$(PYTHON) tests/test_write_abort.py -q
+ 
+ # (needs GNU binutils)
+ strip: build
+diff --git a/tests/test_write_abort.py b/tests/test_write_abort.py
+new file mode 100755
+index 0000000..28e7d1f
+--- /dev/null
++++ b/tests/test_write_abort.py
+@@ -0,0 +1,27 @@
++#!/usr/bin/python
++import os.path
++import pycurl
++import sys
++
++pycurl.global_init(pycurl.GLOBAL_DEFAULT)
++
++def write_cb(_):
++    # this should cause pycurl.WRITEFUNCTION (without any range errors)
++    return -1
++
++# download the script itself through the file:// protocol into write_cb
++c = pycurl.Curl()
++c.setopt(pycurl.URL, 'file://' + os.path.abspath(sys.argv[0]))
++c.setopt(pycurl.WRITEFUNCTION, write_cb)
++try:
++    c.perform()
++except pycurl.error, (err, msg):
++    # we expect pycurl.E_WRITE_ERROR as the response
++    assert pycurl.E_WRITE_ERROR == err
++
++# no additional errors should be reported
++assert not hasattr(sys, 'last_value')
++
++c.close()
++
++pycurl.global_cleanup()
+-- 
+1.7.1
+
diff --git a/python-pycurl.spec b/python-pycurl.spec
index c79ece1..60ee8da 100644
--- a/python-pycurl.spec
+++ b/python-pycurl.spec
@@ -2,7 +2,7 @@
 
 Name:           python-pycurl
 Version:        7.19.0
-Release:        14%{?dist}
+Release:        15%{?dist}
 Summary:        A Python interface to libcurl
 
 Group:          Development/Languages
@@ -18,8 +18,10 @@ Patch4:         0004-Test-for-reset-fixes-refcount-bug.patch
 Patch5:         0005-Updating-ChangeLog-with-relevant-changes.patch
 
 # downstream patches
-Patch101:       0101-setup.py-do-not-use-curl-config-static-libs.patch
-Patch102:       0102-test_internals.py-add-a-test-for-ref-counting-of-res.patch
+Patch101:       0101-test_internals.py-add-a-test-for-ref-counting-of-res.patch
+Patch102:       0102-pycurl.c-eliminate-duplicated-code-in-util_write_cal.patch
+Patch103:       0103-pycurl.c-allow-to-return-1-from-write-callback.patch
+Patch104:       0104-test_write_abort.py-test-returning-1-from-write-call.patch
 
 Requires:       keyutils-libs
 BuildRequires:  python-devel
@@ -53,6 +55,8 @@ of features.
 %patch5 -p1
 %patch101 -p1
 %patch102 -p1
+%patch103 -p1
+%patch104 -p1
 chmod a-x examples/*
 
 %build
@@ -60,7 +64,7 @@ CFLAGS="$RPM_OPT_FLAGS -DHAVE_CURL_OPENSSL" %{__python} setup.py build
 
 %check
 export PYTHONPATH=$PWD/build/lib*
-%{__python} tests/test_internals.py -q
+make test PYTHON=%{__python}
 
 %install
 %{__python} setup.py install -O1 --skip-build --root %{buildroot}
@@ -71,6 +75,10 @@ rm -rf %{buildroot}%{_datadir}/doc/pycurl
 %{python_sitearch}/*
 
 %changelog
+* Wed Mar 06 2013 Kamil Dudka <kdudka at redhat.com> - 7.19.0-15
+- allow to return -1 from the write callback (#857875) 
+- remove the patch for curl-config --static-libs no longer needed
+
 * Mon Feb 25 2013 Kamil Dudka <kdudka at redhat.com> - 7.19.0-14
 - apply bug-fixes committed to upstream CVS since 7.19.0 (fixes #896025)
 


More information about the scm-commits mailing list