summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2012-01-03 20:06:59 +0000
committerGiampaolo Rodola <g.rodola@gmail.com>2012-01-03 20:06:59 +0000
commita8900bc6d7ea58cf195150a0cb5c161b290f4487 (patch)
tree44aa5e5b83975e79bb31fff797298ac837848f46
parentfcaff6ca53e0741e7d60b062e7a41df90c55432d (diff)
downloadpysendfile-a8900bc6d7ea58cf195150a0cb5c161b290f4487.tar.gz
drop support for python 2.4: we need to use Py_ssize_t type because the current implementation is broken
-rw-r--r--sendfilemodule.c23
-rw-r--r--setup.py3
2 files changed, 10 insertions, 16 deletions
diff --git a/sendfilemodule.c b/sendfilemodule.c
index 7e2b60c..b22c0c5 100644
--- a/sendfilemodule.c
+++ b/sendfilemodule.c
@@ -234,11 +234,11 @@ method_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
{
int out_fd, in_fd;
off_t offset;
- size_t nbytes;
- ssize_t sent = 0;
+ Py_ssize_t nbytes;
+ Py_ssize_t sent;
PyObject *offobj;
- if (!PyArg_ParseTuple(args, "iiOI", &out_fd, &in_fd, &offobj, &nbytes)) {
+ if (!PyArg_ParseTuple(args, "iiOn", &out_fd, &in_fd, &offobj, &nbytes)) {
return NULL;
}
@@ -258,11 +258,7 @@ method_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
if (sent == -1)
return PyErr_SetFromErrno(PyExc_OSError);
-#if PY_MAJOR_VERSION >= 3 || (PY_MAJOR_VERSION >= 2 && PY_MINOR_VERSION >= 5)
return Py_BuildValue("n", sent);
-#else
- return Py_BuildValue("l", (long)sent);
-#endif
}
/* --- end Linux --- */
@@ -276,13 +272,11 @@ method_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
int out_fd;
int in_fd;
off_t offset;
- size_t nbytes;
- ssize_t sent;
+ Py_ssize_t nbytes;
+ Py_ssize_t sent;
PyObject *offobj;
- if (!PyArg_ParseTuple(args,
- "iiOI",
- &out_fd, &in_fd, &offobj, &nbytes)) {
+ if (!PyArg_ParseTuple(args, "iiOn", &out_fd, &in_fd, &offobj, &nbytes)) {
return NULL;
}
if (!_parse_off_t(offobj, &offset))
@@ -290,11 +284,8 @@ method_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
sent = sendfile(out_fd, in_fd, &offset, nbytes);
if (sent == -1)
return PyErr_SetFromErrno(PyExc_OSError);
-#if PY_MAJOR_VERSION >= 3 || (PY_MAJOR_VERSION >= 2 && PY_MINOR_VERSION >= 5)
+
return Py_BuildValue("n", sent);
-#else
- return Py_BuildValue("l", (long)sent);
-#endif
}
#else
/* --- end SUN OS --- */
diff --git a/setup.py b/setup.py
index 431c123..7734d3a 100644
--- a/setup.py
+++ b/setup.py
@@ -7,6 +7,9 @@ try:
except ImportError:
from distutils.core import setup, Extension
+if sys.version_info < (2, 5):
+ sys.exit('python version not supported (< 2.5)')
+
if 'sunos' in sys.platform:
libraries = ["sendfile"]
else: