Skip to content

Commit

Permalink
Change logic for arguments to block functions to fallback to bytes (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanunderwood committed May 17, 2017
1 parent e016c36 commit 7b01595
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions lz4/block/_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,7 @@ compress (PyObject * Py_UNUSED (self), PyObject * args, PyObject * kwargs)
{
return NULL;
}
if (PyBytes_Check(py_source))
{
source = PyBytes_AsString(py_source);
if (source == NULL)
{
PyErr_SetString (PyExc_ValueError, "Failed to access source bytes object");
return NULL;
}
source_size = PyBytes_GET_SIZE(py_source);
}
else if (PyByteArray_Check(py_source))
if (PyByteArray_Check(py_source))
{
source = PyByteArray_AsString(py_source);
if (source == NULL)
Expand All @@ -145,8 +135,13 @@ compress (PyObject * Py_UNUSED (self), PyObject * args, PyObject * kwargs)
}
else
{
PyErr_SetString (PyExc_ValueError, "Incorrect type for source object");
return NULL;
source = PyBytes_AsString(py_source);
if (source == NULL)
{
PyErr_SetString (PyExc_ValueError, "Failed to access source object");
return NULL;
}
source_size = PyBytes_GET_SIZE(py_source);
}
#else
const char *source;
Expand Down Expand Up @@ -291,17 +286,7 @@ decompress (PyObject * Py_UNUSED (self), PyObject * args, PyObject * kwargs)
{
return NULL;
}
if (PyBytes_Check(py_source))
{
source = PyBytes_AsString(py_source);
if (source == NULL)
{
PyErr_SetString (PyExc_ValueError, "Failed to access source bytes object");
return NULL;
}
source_size = PyBytes_Size(py_source);
}
else if (PyByteArray_Check(py_source))
if (PyByteArray_Check(py_source))
{
source = PyByteArray_AsString(py_source);
if (source == NULL)
Expand All @@ -313,8 +298,13 @@ decompress (PyObject * Py_UNUSED (self), PyObject * args, PyObject * kwargs)
}
else
{
PyErr_SetString (PyExc_ValueError, "Incorrect type for source object");
return NULL;
source = PyBytes_AsString(py_source);
if (source == NULL)
{
PyErr_SetString (PyExc_ValueError, "Failed to access source object");
return NULL;
}
source_size = PyBytes_Size(py_source);
}
#else
const char *source;
Expand Down

0 comments on commit 7b01595

Please sign in to comment.