Skip to content

Commit

Permalink
Fix matplotlib#4154: Return a writable buffer from conv_color
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Feb 25, 2015
1 parent f529297 commit 6707bec
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 68 deletions.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 12 additions & 4 deletions src/_image_wrapper.cpp
Expand Up @@ -165,14 +165,22 @@ static PyObject *PyImage_color_conv(PyImage *self, PyObject *args, PyObject *kwd
return NULL;
}

PyObject *result = PyBytes_FromStringAndSize(NULL, self->x->rowsOut * self->x->colsOut * 4);
if (result == NULL) {
Py_ssize_t size = self->x->rowsOut * self->x->colsOut * 4;
agg::int8u *buff = (agg::int8u *)malloc(size);
if (buff == NULL) {
PyErr_SetString(PyExc_MemoryError, "Out of memory");
return NULL;
}

CALL_CPP_CLEANUP("color_conv",
(self->x->color_conv(format, (agg::int8u *)PyBytes_AsString(result))),
Py_DECREF(result));
(self->x->color_conv(format, buff)),
free(buff));

PyObject *result = PyByteArray_FromStringAndSize((const char *)buff, size);
if (result == NULL) {
free(buff);
return NULL;
}

return Py_BuildValue("nnN", self->x->rowsOut, self->x->colsOut, result);
}
Expand Down

0 comments on commit 6707bec

Please sign in to comment.