[Numpy-discussion] Unreliable crash when converting using numpy.asarray via C buffer interface

Hameer Abbasi hameerabbasi at yahoo.com
Mon Feb 1 03:03:33 EST 2021


Hey Friedrich,

If you can produce an MVCE that would be really helpful, along with your hardware and environment. Without that, it isn’t possible to be of much help.

https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports

Best Regards,
Hameer Abbasi

--
Sent from Canary (https://canarymail.io)

> On Dienstag, Jan. 26, 2021 at 9:49 AM, Friedrich Romstedt <friedrichromstedt at gmail.com (mailto:friedrichromstedt at 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.
>
> The extension type permits reading the pixel values by a method;
> copying them over by a Python loop works fine. I am ``Py_INCREF``-ing
> the producer in the C++ buffer view creation function properly. The
> shapes and strides of the buffer view are ``delete[]``-ed upon
> releasing the buffer; avoiding this does not prevent the crash. I am
> catching ``std::exception`` in the view creation function; no such
> exception occurs. The shapes and strides are allocated by ``new
> Py_ssize_t[2]``, so they will survive the view creation function.
>
> I spent some hours trying to figure out what I am doing wrong. Maybe
> someone has an idea about this? I double-checked each line of code
> related to this problem and couldn't find any mistake. Probabaly I am
> not looking at the right aspect.
>
> Best,
> Friedrich
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20210201/6afdec35/attachment.html>


More information about the NumPy-Discussion mailing list