[Numpy-discussion] embedded arrays - continued

Thomas Hrabe thrabe@burnham....
Thu Jun 19 16:47:07 CDT 2008


I am still tracking down the memory bug in my C module and I have found a odd inconsistency.

I call import_array in the init function of the module and I want to check in the later code if numpy has been initialised before by checking  the 
value if it is NULL.

I have found out that PyArray_API in the init function is in a different memory location than for my later call. Thus I assume that PyArray_API is not static. Could someone please explain me the code snipplet of the PyArray_API definition in __multiarray_api.h? What do the constants represent? 

#if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)
extern void **PyArray_API;
void **PyArray_API;
static void **PyArray_API=NULL;


-----Ursprüngliche Nachricht-----
Von: numpy-discussion-bounces@scipy.org im Auftrag von Robert Kern
Gesendet: Fr 06.06.2008 15:27
An: Discussion of Numerical Python
Betreff: Re: [Numpy-discussion] embedded arrays
On Fri, Jun 6, 2008 at 17:10, Thomas Hrabe <thrabe@burnham.org> wrote:
> Hi all,
> while writing a extension module in C++ for python & numpy, I find a strange
> error.
> I can send and retrieve numpy arrays to and from my module.
> But python stops if I do the following:
> a = numpy.array([[1.1,2,3],[4,5,6]])
> PM.put(a,'a')   //send a to the module
> b = PM.get('a') //get a identical copy from the module
> print b
> array([[ 1.1,  2. ,  3. ],
>        [ 4. ,  5. ,  6. ]])
> b.__class__
> Out[36]: <type 'numpy.ndarray'>
> perfect, until
> a == b
> the interpreter does not continue from here...
> I can add values to to b, everything, but a == b simply crashes ...?
> Does anybody have a clue for this problem?

Not really. It probably depends on some details with your interfacing.
Since we don't have access to your code, we don't have much to go on.
You might have buggy reference counting or perhaps you gave the numpy
ndarray ownership of the array's memory when it actually shouldn't.
Memory issues can be a bit finicky where everything will work for a
while, then crash.

Try running your program under a C debugger like gdb so we can get a
backtrace. That might give us some more ideas about exactly where
problems are occurring.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
Numpy-discussion mailing list

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 4275 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080619/7a1b41af/attachment-0001.bin 

More information about the Numpy-discussion mailing list