allow to return -1 from write callback (#857875)
... and remove the patch for curl-config --static-libs no longer needed
This commit is contained in:
parent
594f991701
commit
77fac8b0fa
@ -1,34 +0,0 @@
|
|||||||
From 0796c0530648ae0e741a20a78d1fcf315783c178 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Kamil Dudka <kdudka@redhat.com>
|
|
||||||
Date: Mon, 25 Feb 2013 19:48:22 +0100
|
|
||||||
Subject: [PATCH 1/2] setup.py: do not use curl-config --static-libs
|
|
||||||
|
|
||||||
---
|
|
||||||
setup.py | 5 ++---
|
|
||||||
1 files changed, 2 insertions(+), 3 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/setup.py b/setup.py
|
|
||||||
index 76b9d58..86a2951 100644
|
|
||||||
--- a/setup.py
|
|
||||||
+++ b/setup.py
|
|
||||||
@@ -101,15 +101,14 @@ else:
|
|
||||||
# support one or the other of these curl-config options, so gracefully
|
|
||||||
# tolerate failure of either, but not both.
|
|
||||||
optbuf = ""
|
|
||||||
- for option in ["--libs", "--static-libs"]:
|
|
||||||
+ for option in ["--libs"]:
|
|
||||||
p = subprocess.Popen("'%s' %s" % (CURL_CONFIG, option), shell=True,
|
|
||||||
stdout=subprocess.PIPE)
|
|
||||||
(stdout, stderr) = p.communicate()
|
|
||||||
if p.wait() == 0:
|
|
||||||
optbuf += stdout
|
|
||||||
if optbuf == "":
|
|
||||||
- raise Exception, ("Neither of curl-config --libs or --static-libs" +
|
|
||||||
- "produced output")
|
|
||||||
+ raise Exception, ("curl-config --libs did not produce output")
|
|
||||||
libs = split_quoted(optbuf)
|
|
||||||
|
|
||||||
for e in libs:
|
|
||||||
--
|
|
||||||
1.7.1
|
|
||||||
|
|
||||||
@ -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@redhat.com>
|
From: Kamil Dudka <kdudka@redhat.com>
|
||||||
Date: Mon, 25 Feb 2013 19:50:18 +0100
|
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 +++++
|
tests/test_internals.py | 5 +++++
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
From c84c2a02a34031a951edeb5d3f81676d05e2765f Mon Sep 17 00:00:00 2001
|
||||||
|
From: Kamil Dudka <kdudka@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
|
||||||
|
|
||||||
45
0103-pycurl.c-allow-to-return-1-from-write-callback.patch
Normal file
45
0103-pycurl.c-allow-to-return-1-from-write-callback.patch
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
From ca4705dab05371c40f398b97277024332ed44651 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Kamil Dudka <kdudka@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
|
||||||
|
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
From d8e4390da96d19a322a6fd3512ccac0200f15ddb Mon Sep 17 00:00:00 2001
|
||||||
|
From: Kamil Dudka <kdudka@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
|
||||||
|
|
||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Name: python-pycurl
|
Name: python-pycurl
|
||||||
Version: 7.19.0
|
Version: 7.19.0
|
||||||
Release: 14%{?dist}
|
Release: 15%{?dist}
|
||||||
Summary: A Python interface to libcurl
|
Summary: A Python interface to libcurl
|
||||||
|
|
||||||
Group: Development/Languages
|
Group: Development/Languages
|
||||||
@ -18,8 +18,10 @@ Patch4: 0004-Test-for-reset-fixes-refcount-bug.patch
|
|||||||
Patch5: 0005-Updating-ChangeLog-with-relevant-changes.patch
|
Patch5: 0005-Updating-ChangeLog-with-relevant-changes.patch
|
||||||
|
|
||||||
# downstream patches
|
# downstream patches
|
||||||
Patch101: 0101-setup.py-do-not-use-curl-config-static-libs.patch
|
Patch101: 0101-test_internals.py-add-a-test-for-ref-counting-of-res.patch
|
||||||
Patch102: 0102-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
|
Requires: keyutils-libs
|
||||||
BuildRequires: python-devel
|
BuildRequires: python-devel
|
||||||
@ -53,6 +55,8 @@ of features.
|
|||||||
%patch5 -p1
|
%patch5 -p1
|
||||||
%patch101 -p1
|
%patch101 -p1
|
||||||
%patch102 -p1
|
%patch102 -p1
|
||||||
|
%patch103 -p1
|
||||||
|
%patch104 -p1
|
||||||
chmod a-x examples/*
|
chmod a-x examples/*
|
||||||
|
|
||||||
%build
|
%build
|
||||||
@ -60,7 +64,7 @@ CFLAGS="$RPM_OPT_FLAGS -DHAVE_CURL_OPENSSL" %{__python} setup.py build
|
|||||||
|
|
||||||
%check
|
%check
|
||||||
export PYTHONPATH=$PWD/build/lib*
|
export PYTHONPATH=$PWD/build/lib*
|
||||||
%{__python} tests/test_internals.py -q
|
make test PYTHON=%{__python}
|
||||||
|
|
||||||
%install
|
%install
|
||||||
%{__python} setup.py install -O1 --skip-build --root %{buildroot}
|
%{__python} setup.py install -O1 --skip-build --root %{buildroot}
|
||||||
@ -71,6 +75,10 @@ rm -rf %{buildroot}%{_datadir}/doc/pycurl
|
|||||||
%{python_sitearch}/*
|
%{python_sitearch}/*
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Wed Mar 06 2013 Kamil Dudka <kdudka@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@redhat.com> - 7.19.0-14
|
* Mon Feb 25 2013 Kamil Dudka <kdudka@redhat.com> - 7.19.0-14
|
||||||
- apply bug-fixes committed to upstream CVS since 7.19.0 (fixes #896025)
|
- apply bug-fixes committed to upstream CVS since 7.19.0 (fixes #896025)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user