From 07d7e03ea117bcac8e3d3fe69e0b720d947966d0 Mon Sep 17 00:00:00 2001 From: montag451 Date: Sat, 30 Mar 2013 20:33:43 +0100 Subject: [PATCH] Previous commit broke compilation on Python < 2.6, it's now fixed --- pytun.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pytun.c b/pytun.c index 533a5f2..e4f0f01 100644 --- a/pytun.c +++ b/pytun.c @@ -592,7 +592,11 @@ static PyObject* pytun_tuntap_read(PyObject* self, PyObject* args) } /* Allocate a new string */ +#if PY_MAJOR_VERSION >= 3 buf = PyBytes_FromStringAndSize(NULL, rdlen); +#else + buf = PyString_FromStringAndSize(NULL, rdlen); +#endif if (buf == NULL) { return NULL; @@ -600,7 +604,11 @@ static PyObject* pytun_tuntap_read(PyObject* self, PyObject* args) /* Read data */ Py_BEGIN_ALLOW_THREADS +#if PY_MAJOR_VERSION >= 3 outlen = read(tuntap->fd, PyBytes_AS_STRING(buf), rdlen); +#else + outlen = read(tuntap->fd, PyString_AS_STRING(buf), rdlen); +#endif Py_END_ALLOW_THREADS if (outlen < 0) { @@ -613,7 +621,11 @@ static PyObject* pytun_tuntap_read(PyObject* self, PyObject* args) { /* We did not read as many bytes as we anticipated, resize the string if possible and be successful. */ +#if PY_MAJOR_VERSION >= 3 if (_PyBytes_Resize(&buf, outlen) < 0) +#else + if (_PyString_Resize(&buf, outlen) < 0) +#endif { return NULL; }