PY_ARRAY_UNIQUE_SYMBOL

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

PY_ARRAY_UNIQUE_SYMBOL

wfspotz-sandia
I am running into a problem with a numpy-compatible extension module  
that I develop, and I believe it has to do with PY_ARRAY_UNIQUE_SYMBOL.

I set PY_ARRAY_UNIQUE_SYMBOL to "PyTrilinos".  On my machine (Mac OS  
X), the module loads and works properly.  Another user, however (on  
Ubuntu), gets the following:

     ImportError: Failure linking new module: /usr/local/lib/python2.4/
site-
     packages/PyTrilinos/_Epetra.so: Symbol not found: _PyTrilinos
     Referenced from: /usr/local/lib/libpytrilinos.dylib
     Expected in: dynamic lookup

On my machine, I see:

     $ nm libpytrilinos.dylib | grep PyTrilinos
          U _PyTrilinos
          ...

and I'm not sure where the symbol actually IS defined.  I don't  
understand enough about how PY_ARRAY_UNIQUE_SYMBOL is actually used to  
hunt this down, especially through another user on a machine I don't  
have access to.

Any ideas on what I should be looking for?

Thanks

** Bill Spotz                                              **
** Sandia National Laboratories  Voice: (505)845-0170      **
** P.O. Box 5800                 Fax:   (505)284-0154      **
** Albuquerque, NM 87185-0370    Email: [hidden email] **






_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: PY_ARRAY_UNIQUE_SYMBOL

Robert Kern-2
On Wed, May 21, 2008 at 3:34 PM, Bill Spotz <[hidden email]> wrote:
> I am running into a problem with a numpy-compatible extension module
> that I develop, and I believe it has to do with PY_ARRAY_UNIQUE_SYMBOL.
>
> I set PY_ARRAY_UNIQUE_SYMBOL to "PyTrilinos".

Why? My understanding is also limited, but it does not appear to me to
be something one should change.

> On my machine (Mac OS
> X), the module loads and works properly.  Another user, however (on
> Ubuntu), gets the following:
>
>     ImportError: Failure linking new module: /usr/local/lib/python2.4/
> site-
>     packages/PyTrilinos/_Epetra.so: Symbol not found: _PyTrilinos
>     Referenced from: /usr/local/lib/libpytrilinos.dylib
>     Expected in: dynamic lookup

??? How did an Ubuntu user get a hold of a .dylib?

> On my machine, I see:
>
>     $ nm libpytrilinos.dylib | grep PyTrilinos
>          U _PyTrilinos
>          ...
>
> and I'm not sure where the symbol actually IS defined.

It gets generated into __multiarray_api.h:

#if defined(PY_ARRAY_UNIQUE_SYMBOL)
#define PyArray_API PY_ARRAY_UNIQUE_SYMBOL
#endif

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


How did this symbol end up in a .dylib rather than a Python extension
module? I think it might be difficult to arrange for a non-extension
dynamic library to call into numpy.

--
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
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: PY_ARRAY_UNIQUE_SYMBOL

wfspotz-sandia
On May 21, 2008, at 5:15 PM, Robert Kern wrote:

> On Wed, May 21, 2008 at 3:34 PM, Bill Spotz <[hidden email]>  
> wrote:
>> I am running into a problem with a numpy-compatible extension module
>> that I develop, and I believe it has to do with  
>> PY_ARRAY_UNIQUE_SYMBOL.
>>
>> I set PY_ARRAY_UNIQUE_SYMBOL to "PyTrilinos".
>
> Why? My understanding is also limited, but it does not appear to me to
> be something one should change.

My understanding is that if your extension module requires more than  
one source file, then this macro needs to be set to something  
reasonably unique to your project.  And that NO_IMPORT_ARRAY needs to  
be set in those files that do not call import_array().

>> On my machine (Mac OS
>> X), the module loads and works properly.  Another user, however (on
>> Ubuntu), gets the following:
>>
>>    ImportError: Failure linking new module: /usr/local/lib/python2.4/
>> site-
>>    packages/PyTrilinos/_Epetra.so: Symbol not found: _PyTrilinos
>>    Referenced from: /usr/local/lib/libpytrilinos.dylib
>>    Expected in: dynamic lookup
>
> ??? How did an Ubuntu user get a hold of a .dylib?

I could have this wrong.  He is asking me questions about Mac OS X and  
Ubuntu simultaneously.  But going back through his emails, I thought I  
had this right.

>> On my machine, I see:
>>
>>    $ nm libpytrilinos.dylib | grep PyTrilinos
>>         U _PyTrilinos
>>         ...
>>
>> and I'm not sure where the symbol actually IS defined.
>
> It gets generated into __multiarray_api.h:
>
> #if defined(PY_ARRAY_UNIQUE_SYMBOL)
> #define PyArray_API PY_ARRAY_UNIQUE_SYMBOL
> #endif
>
> #if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)
> extern void **PyArray_API;
> #else
> #if defined(PY_ARRAY_UNIQUE_SYMBOL)
> void **PyArray_API;
> #else
> static void **PyArray_API=NULL;
> #endif
> #endif
>
>
> How did this symbol end up in a .dylib rather than a Python extension
> module? I think it might be difficult to arrange for a non-extension
> dynamic library to call into numpy.

It is designed so that the extension modules (plural -- there are many  
of them) link to the dylib that has the symbol.  The code in this  
dylib is only ever accessed through those extension modules.

** Bill Spotz                                              **
** Sandia National Laboratories  Voice: (505)845-0170      **
** P.O. Box 5800                 Fax:   (505)284-0154      **
** Albuquerque, NM 87185-0370    Email: [hidden email] **






_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion