On Tue, Jan 26, 2021 at 3:50 AM Friedrich Romstedt <friedrichromst...@gmail.com> wrote: > > Hi, > > This is with Python 3.8.2 64-bit and numpy 1.19.2 on Windows 10. I'd > like to be able to convert some C++ extension type to a numpy array by > using ``numpy.asarray``. The extension type implements the Python > buffer interface to support this. > > The extension type, called "Image" here, holds some chunk of > ``double``, C order, contiguous, 2 dimensions. It "owns" the buffer; > the buffer is not shared with other objects. The following Python > code crashes:: > > image = <... Image production ...> > ar = numpy.asarray(image) > > However, when I say:: > > image = <... Image production ...> > print("---") > ar = numpy.asarray(image) > > the entire program is executing properly with correct data in the > numpy ndarray produced using the buffer interface.
Maybe a dereference bug. Try setting pointers to NULL after freeing, something like this: delete[] view->shape; view->shape = NULL; delete[] view->strides; view->strides = NULL; ... delete[] self->data; self->data = NULL; _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion