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

Sebastian Berg sebastian at sipsolutions.net
Mon Feb 15 10:54:19 EST 2021


On Mon, 2021-02-15 at 10:12 +0100, Friedrich Romstedt wrote:
> Hi,
> 
> Am Do., 4. Feb. 2021 um 09:07 Uhr schrieb Friedrich Romstedt
> <friedrichromstedt at gmail.com>:
> > Am Mo., 1. Feb. 2021 um 09:46 Uhr schrieb Matti Picus <
> > matti.picus at gmail.com>:
> > > Typically, one would create a complete example and then pointing
> > > to the
> > > code (as repo or pastebin, not as an attachment to a mail here).
> > 
> > https://github.com/friedrichromstedt/bughunting-01
> 
> Last week I updated my example code to be more slim.  There now
> exists
> a single-file extension module:
> https://github.com/friedrichromstedt/bughunting-01/blob/master/lib/bughuntingfrmod/bughuntingfrmod.cpp
> .
> The corresponding test program
> https://github.com/friedrichromstedt/bughunting-01/blob/master/test/2021-02-11_0909.py
> crashes "properly" both on Windows 10 (Python 3.8.2, numpy 1.19.2) as
> well as on Arch Linux (Python 3.9.1, numpy 1.20.0), when the
> ``print``
> statement contained in the test file is commented out.
> 
> My hope to be able to fix my error myself by reducing the code to
> reproduce the problem has not been fulfillled.  I feel that the
> abovementioned test code is short enough to ask for help with it
> here.
> Any hint on how I could solve my problem would be appreciated very
> much.

I have tried it out, and can confirm that using debugging tools (namely
valgrind), will allow you track down the issue (valgrind reports it
from within python, running a python without debug symbols may
obfuscate the actual problem; if that is the limiting you, I can post
my valgrind output).
Since you are running a linux system, I am confident that you can run
it in valgrind to find it yourself.  (There may be other ways.)

Just remember to run valgrind with `PYTHONMALLOC=malloc valgrind` and
ignore some errors e.g. when importing NumPy.

Cheers,

Sebastian


> 
> There are some points which were not clarified yet; I am citing them
> below.
> 
> So far,
> Friedrich
> 
> > > - There are tools out there to analyze refcount problems. Python
> > > has
> > > some built-in tools for switching allocation strategies.
> > 
> > Can you give me some pointer about this?
> > 
> > > - numpy.asarray has a number of strategies to convert instances,
> > > which
> > > one is it using?
> > 
> > I've tried to read about this, but couldn't find anything.  What
> > are
> > these different strategies?
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20210215/fd70e35e/attachment.sig>


More information about the NumPy-Discussion mailing list