Hi,

Robert Bradshaw wrote:
> On Aug 19, 2008, at 7:53 AM, Stefan Behnel wrote:
> 
>> Andrew Straw wrote:
>>> Hi, looking at the Cython Sphinx documentation, I don't see the  
>>> Python
>>> version as a variable I can use for conditional compilation. This  
>>> would
>>> be handy in the case of newly added features in the Python-C API, for
>>> example. Would this be feasible to add (alongside UNAME_SYSNAME and
>>> friends)?
>> Feasible, yes, but it doesn't make much sense to check the Python  
>> version
>> at Cython compile time. The C code that gets generated by Cython  
>> will run
>> on all Python versions from 2.3 to 3.0, and on all major platforms.  
>> You
>> will loose that if you start generating platform-specific C code  
>> for the
>> system that happens to run Cython on your code.
> 
> If you want to do this I would recommend putting them in an actual .h  
> file (with a cdef extern import block) so that the resulting .c files  
> could be used on multiple Python versions.

No .h file required as the Python version is already in Python's patchlevel.h.
A simple

    cdef extern from *:
        cdef int PY_VERSION_HEX


    ...
    if PY_VERSION_HEX >= 0x02050000:
        handle_py2_5()

will do the trick. Note that I use "if", not "IF" here. The C compiler will do
the right thing.

I also added a Cython/Include/python_version.pxd that you can use.

Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to