Skip to content

Commit

Permalink
compressiondict: use buffer protocol in __init__ (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
indygreg committed Jun 11, 2017
1 parent a520899 commit f90f206
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions c-ext/compressiondict.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,32 +263,32 @@ PyDoc_STRVAR(ZstdCompressionDict__doc__,

static int ZstdCompressionDict_init(ZstdCompressionDict* self, PyObject* args) {
int result = -1;
const char* source;
Py_ssize_t sourceSize;
Py_buffer source;

self->dictData = NULL;
self->dictSize = 0;

#if PY_MAJOR_VERSION >= 3
if (!PyArg_ParseTuple(args, "y#:ZstdCompressionDict",
if (!PyArg_ParseTuple(args, "y*:ZstdCompressionDict",
#else
if (!PyArg_ParseTuple(args, "s#:ZstdCompressionDict",
if (!PyArg_ParseTuple(args, "s*:ZstdCompressionDict",
#endif
&source, &sourceSize)) {
&source)) {
return -1;
}

self->dictData = PyMem_Malloc(sourceSize);
self->dictData = PyMem_Malloc(source.len);
if (!self->dictData) {
PyErr_NoMemory();
goto finally;
}

memcpy(self->dictData, source, sourceSize);
self->dictSize = sourceSize;
memcpy(self->dictData, source.buf, source.len);
self->dictSize = source.len;
result = 0;

finally:
PyBuffer_Release(&source);
return result;
}

Expand Down

0 comments on commit f90f206

Please sign in to comment.