Skip to content

Commit c4b25e2

Browse files
committed
Make the code match the format string passed to ParseTuple for py3
The "y#" format does not take Py_buffer object. The previous code only worked because of the happy accident that the first member of Py_buffer is a void* to the data.
1 parent fe9e3f2 commit c4b25e2

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

snappymodule.cc

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ static PyObject *SnappyCompressError,
5959
static PyObject *
6060
snappy__compress(PyObject *self, PyObject *args)
6161
{
62-
#if PY_MAJOR_VERSION >= 3
63-
Py_buffer pbuffer;
64-
#endif
6562
const char * input;
6663
int input_size;
6764
size_t compressed_size;
@@ -70,15 +67,12 @@ snappy__compress(PyObject *self, PyObject *args)
7067
snappy_status status;
7168

7269
#if PY_MAJOR_VERSION >= 3
73-
if (!PyArg_ParseTuple(args, "y#", &pbuffer, &input_size))
70+
if (!PyArg_ParseTuple(args, "y#", &input, &input_size))
7471
#else
7572
if (!PyArg_ParseTuple(args, "s#", &input, &input_size))
7673
#endif
7774
return NULL;
7875

79-
#if PY_MAJOR_VERSION >= 3
80-
input = (char*)pbuffer.buf;
81-
#endif
8276
// Ask for the max size of the compressed object.
8377
compressed_size = snappy_max_compressed_length(input_size);
8478

@@ -103,25 +97,18 @@ snappy__compress(PyObject *self, PyObject *args)
10397
static PyObject *
10498
snappy__uncompress(PyObject *self, PyObject *args)
10599
{
106-
#if PY_MAJOR_VERSION >= 3
107-
Py_buffer pbuffer;
108-
#endif
109100
const char * compressed;
110101
int comp_size;
111102
size_t uncomp_size;
112103
PyObject * result;
113104
snappy_status status;
114105

115106
#if PY_MAJOR_VERSION >=3
116-
if (!PyArg_ParseTuple(args, "y#", &pbuffer, &comp_size))
107+
if (!PyArg_ParseTuple(args, "y#", &compressed, &comp_size))
117108
#else
118109
if (!PyArg_ParseTuple(args, "s#", &compressed, &comp_size))
119110
#endif
120111
return NULL;
121-
122-
#if PY_MAJOR_VERSION >= 3
123-
compressed = (char*) pbuffer.buf;
124-
#endif
125112

126113
status = snappy_uncompressed_length(compressed, comp_size, &uncomp_size);
127114
if (status != SNAPPY_OK) {

0 commit comments

Comments
 (0)