[Numpy-discussion] static void** libnumarray_API

Todd Miller jmiller at stsci.edu
Thu Jul 15 07:36:11 EDT 2004


On Thu, 2004-07-15 at 09:28, Mathieu Gontier wrote:
> Hello, 
> 
> I am developping FEM bendings from a C++ code to Python with Numarray.
> So, I have the following problem.
> 
> In the distribution file 'libnumarray.h', the variable 'libnumarray_API' is 
> defined as a static variable (because of the symbol NO_IMPORT is not 
> defined).
> 
> Then, I understand that all the examples are implemented in a unique file.
> 
> But, in my project, I must edit header files and source files in order to 
> solve other problems (like cycle includes). So, I have two different source 
> files which use numarray :
> 	- the file containing the 'init' function which call the function 
> 'import_libnumarray()' (which initialize 'libnumarray_API')
> 	- a file containing implementations, more precisely an implementation calling 
> numarray functionnalities: with is 'static' state, this 'libnumarray_API' is 
> NULL...
> 
> I tried to compile NumArray with the symbol 'NO_IMPORT' (see libnumarray.h) in 
> order to have an extern variable. But this symbol doesn't allow to import 
> numarray in the python environment.
> 
> So, does someone have a solution allowing to use NumArray API with 
> header/source files ? 

The good news is that the 1.0 headers, at least, work.

I intended to capture this form of multi-compilation-unit module in the
numpy_compat example... but didn't.  I think there's two "tricks"
missing in the example.  In *a* module of the several modules you're
linking together, do the following:

#define NO_IMPORT 1	   /* This prevents the definition of the static
			      version of the API var.  The extern won't
			      conflict with the real definition below. 			   */

#include "libnumarray.h"

void **libnumarray_API;    /* This defines the missing API var for *all*
				your compilation units */

This variable will be assigned the API pointer by the
import_libnumarray() call.

I fixed the numpy_compat example to demonstrate this in CVS but they
have a Numeric flavor.  The same principles apply to libnumarray.  Note
that for numarray-1.0 you must include/import both the Numeric
compatible and native numarray APIs separately if you use both.

Regards,
Todd





More information about the NumPy-Discussion mailing list