Fix crash when creating a 'gpu.types.Buffer'

Buffer creation may crash when passed a PyBuffer with no `shape` defined.
(Which is common for strucs).
This commit is contained in:
Germano Cavalcante 2022-04-11 16:50:52 -03:00
parent c4f7f59c65
commit 07cacb6d14
1 changed files with 9 additions and 2 deletions

View File

@ -394,9 +394,16 @@ static PyObject *pygpu_buffer__tp_new(PyTypeObject *UNUSED(type), PyObject *args
return NULL;
}
if (pygpu_buffer_dimensions_tot_len_compare(shape, shape_len, pybuffer.shape, pybuffer.ndim)) {
Py_ssize_t *pybuffer_shape = pybuffer.shape;
Py_ssize_t pybuffer_ndim = pybuffer.ndim;
if (!pybuffer_shape) {
pybuffer_shape = &pybuffer.len;
pybuffer_ndim = 1;
}
if (pygpu_buffer_dimensions_tot_len_compare(shape, shape_len, pybuffer_shape, pybuffer_ndim)) {
buffer = pygpu_buffer_make_from_data(
init, pygpu_dataformat.value_found, pybuffer.ndim, shape, pybuffer.buf);
init, pygpu_dataformat.value_found, shape_len, shape, pybuffer.buf);
}
PyBuffer_Release(&pybuffer);