[Pyrex] Platform dependent external declarations?

Francesc Altet faltet at carabos.com
Mon Feb 26 16:19:13 UTC 2007


Hi,

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):

src/hdf5Extension.c:5000: warning: pointer targets in passing argument 3
of ‘H5Sselect_hyperslab’ differ in signedness

My goal, now that Pyrex 0.9.5 is there, is to compile my extensions
without warnings at all. However, I can't see the way to tell Pyrex to
conditionally declare an external C type as 'signed' or 'unsigned'
depending on the platform. I have taken two (naive) approaches here:

"""
if sys.platform == "win32":
  cdef extern from "hdf5.h":
    ctypedef signed long long hsize_t
else:
  cdef extern from "hdf5.h":
    ctypedef unsigned long long hsize_t
"""

which issues a "cdef statement not allowed here" and

"""
cdef extern from "hdf5.h":
  if sys.platform == "win32":
    ctypedef signed long long hsize_t
  else:
    ctypedef unsigned long long hsize_t
"""

which issues a "Syntax error in C variable declaration".

Someone can shed some light here? Thanks!

-- 
Francesc Altet    |  Be careful about using the following code --
Carabos Coop. V.  |  I've only proven that it works, 
www.carabos.com   |  I haven't tested it. -- Donald Knuth




More information about the Pyrex mailing list