[SciPy-dev] Easier now for extension writers to reuse type names

David M. Cooke cookedm at physics.mcmaster.ca
Sat Oct 29 20:13:41 EDT 2005


Alright, one thing that was bothering me was if you use  
arrayobject.h, and you're writing an extension that wraps some  
library, you may have a conflict with typedefs (Bool, intp, longlong,  
etc.). arrayobject.h is not such a good neighbour there.

So, I've fixed up arrayobject.h and ufuncobject.h so that if the
preprocessor symbol PY_ARRAY_TYPES_PREFIX is defined before they're  
imported, the typedefs in those header files define types prefixed  
with whatever the value of PY_ARRAY_TYPES_PREFIX is.

Example:

#define PY_ARRAY_TYPES_PREFIX PA_
#include "scipy/arrayobject.h"

/* maybe this is in a header file for a library being wrapped */
typedef int Bool;

This will work fine, as the typedef in arrayobject.h is instead

typedef unsigned char PA_Bool;

and all the PyArray API functions will be declared using PA_Bool  
instead within the module.

This isn't a problem with calling the API, as the types are the same  
(just different names).

This is analogous to PY_ARRAY_UNIQUE_SYMBOL used to store the API in  
a unique array.

cheers!

-- 
|>|\/|<
/------------------------------------------------------------------\
|David M. Cooke              http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca




More information about the SciPy-Dev mailing list