[Pyrex] Platform dependent external declarations?

Eric Huss e-huss at netmeridian.com
Wed Feb 28 21:23:59 UTC 2007


On Mon, 26 Feb 2007, Stefan Behnel wrote:

>
>
> Francesc Altet wrote:
> > El dl 26 de 02 del 2007 a les 18:31 +0100, en/na Stefan Behnel va
> > escriure:
> >> Francesc Altet wrote:
> >>> I'm having difficulties when using external C types whose sign depends
> >>> on the platform.  I'm using a library that defines 'hsize_t' as being
> >>> 'unsigned long long' in Unix and 'signed long long' in Win32 (Win32
> >>> doesn't support such an 'unsigned long long' type. My current approach
> >>> is to declare it as 'signed long long', but that generates warnings when
> >>> compiling the code on Unix (although the code works well):
> >>
> >> You should consider doing this in a C-header file that you cimport where you
> >> need it.
> >
> > Mmm. Perhaps I've explained this badly: it is the C-library that I try
> > to link with Pyrex who is declaring this differently for Unix and Win
> > platforms (so, there is already a C-header who does that). My problem is
> > how to get the external declaration correctly in Pyrex for both
> > platforms.
>
> ctypedef it as "external from yourheader.h" in a .pxd and rely on the
> C-compiler to do the right thing? Just define it as "long long" here or
> whatever you prefer. Pyrex does not care.

This is not true.  For example:

cdef extern from "sys/types.h":
    ctypedef unsigned int time_t

def foo(time_t x):
    print x

will generate different code from:

cdef extern from "sys/types.h":
    ctypedef int time_t

def foo(time_t x):
    print x

The only ways that I know of to properly handle typing for different
platforms is to have an autoconf-like thing that generates pyx or pxd
files with the correct definitions, or to use the conditional compilation
feature Sam Rushing made (linked on the main Pyrex page).

-Eric



More information about the Pyrex mailing list