[Pyrex] Conditional compilation

David M. Cooke cookedm at physics.mcmaster.ca
Tue Apr 5 22:21:25 CEST 2005


On Tue, Apr 05, 2005 at 09:45:08AM +0200, khinsen at cea.fr wrote:
> On 05.04.2005, at 02:06, David M. Cooke wrote:
> 
> >AFAIK, there's no way to do the equivalent of #ifdef. You can try to
> >fake it with header files and compile-time optimization, though. If
> 
> Header files, yes, but relying on compile-time optimization is risky if  
> one cares at all about portability. In many cases, the code to be  
> "switched off" would be incorrect (e.g. using undefined data types)  
> when the condition is not fulfilled. Many if not most compilers would  
> check the code for correctness even if it were ultimately optimized  
> away.
> 
> As for the header file approach, I think this quickly becomes a mess.  
> Take the most common thread-related code in Python:  
> Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS. Without WITH_THREAD,  
> they do nothing - that's easy to emulate using function-style macros in  
> a header file. But with WITH_THREAD, they expand into a pair of braces  
> inside which a temporary variable is defined. This implies restrictions  
> on the syntax of the code in between them, which I can't expect Pyrex  
> to satisfy. In fact it doesn't.

If you're using Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS, then the
stuff between them should be pure C code: how about making that a
function and throwing that into a header file, and including it?

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



More information about the Pyrex mailing list