Skip to content

Commit

Permalink
Previous commit broke compilation on Python < 2.6, it's now fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
montag451 committed Mar 30, 2013
1 parent f96124b commit 07d7e03
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pytun.c
Expand Up @@ -592,15 +592,23 @@ 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;
}

/* 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)
{
Expand All @@ -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;
}
Expand Down

0 comments on commit 07d7e03

Please sign in to comment.