summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2011-04-20 18:40:24 +0000
committerGiampaolo Rodola <g.rodola@gmail.com>2011-04-20 18:40:24 +0000
commit950196b80d85cdb65aef3c8881792faec12e4792 (patch)
tree9d67aad6c6f868907fdea9dde7a48e283d893ed1
parent12abd6b088bfc7d75cab26b114f2b1c06455dd83 (diff)
downloadpysendfile-950196b80d85cdb65aef3c8881792faec12e4792.tar.gz
Linux/Solaris: use 'n' arg for Py_BuildValue which is compatible with ssize_t C type. On py versions < 2.5 cast to long and return long.
-rw-r--r--sendfilemodule.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/sendfilemodule.c b/sendfilemodule.c
index e1bfbc6..6c0bb0b 100644
--- a/sendfilemodule.c
+++ b/sendfilemodule.c
@@ -335,7 +335,11 @@ method_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
goto done;
done:
- return Py_BuildValue("I", sent_h + sent_f + sent_t);
+#if PY_MAJOR_VERSION >= 3 || (PY_MAJOR_VERSION >= 2 && PY_MINOR_VERSION >= 5)
+ return Py_BuildValue("n", sent_h + sent_f + sent_t);
+#else
+ return Py_BuildValue("l", (long)sent_h + (long)sent_f + (long)sent_t);
+#endif
}
/* --- end Linux --- */
@@ -363,8 +367,11 @@ method_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
sent = sendfile(out_fd, in_fd, &offset, nbytes);
if (sent == -1)
return PyErr_SetFromErrno(PyExc_OSError);
- // http://www.barcodeschool.com/2010/04/ssize_t-type-problem/
- return Py_BuildValue("l", sent);
+#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 --- */