[Numpy-discussion] Modified header files

Konrad Hinsen hinsen at cnrs-orleans.fr
Wed May 9 12:12:25 EDT 2001


Recently we had a discussion about how to use NumPy arrays from
extension modules with multiple source files, on various platforms.
The modified header files that are attached to this message provide a
(hopefully!) general solution. In fact, I propose to make them part of
the official distribution, unless there are objections.

If used like before, these header files give exactly the same result
as the ones in NumPy 20.0.0. However, they permit to define the name
of the C API pointer array and make it globally visible. Under the
condition that the chosen name is unique, this should not create
problems under any platform, no matter if static or dynamic linking is
used.

To use NumPy features in multiple source file extension modules, you have
to write

   #define PY_ARRAY_UNIQUE_SYMBOL PyArrayXXX
   #include "Numeric/arrayobject.h"

in the main source file (the one that contains the init function) and

   #define PY_ARRAY_UNIQUE_SYMBOL PyArrayXXX
   #define NO_IMPORT_ARRAY
   #include "Numeric/arrayobject.h"

in all the others. The symbol you choose instead of PyArrayXXX should
contain both the name of the imported module (array) and the name of
the importing module (whatever your module is called) in order to be
unique with a reasonably high probability.

The same applies to the Ufunc module, just replace "array" by
"ufunc" in the example. I have also applied the "static" correction
to the Ufunc header file, there is no reason not to do it.

Konrad.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                            | E-Mail: hinsen at cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24
Rue Charles Sadron                       | Fax:  +33-2.38.63.15.17
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais
-------------------------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arrayobject.h
Type: application/octet-stream
Size: 13881 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20010509/998da9db/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ufuncobject.h
Type: application/octet-stream
Size: 6701 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20010509/998da9db/attachment-0001.obj>


More information about the NumPy-Discussion mailing list