On Sep 22, 2008, at 3:13 PM, Andrew Collette wrote:

> Hi,
>
> I am in the midst of porting a project to Cython, and have run into a
> few issues.  I had been using Pyrex 0.9.8.4 and am trying the latest
> public release of Cython (0.9.8.1.1).  I'm interfacing to the HDF5 C
> library, which has a huge API.  Since I heard Cython (unlike Pyrex)
> supports "cimport *", I wanted consolidate the whole thing into
> "hdf5.pxd" and simply cimport everything into each module I'm  
> building.
> However, this doesn't seem to import typedefs:
>
> # file "ext.pxd":
> cdef extern from "something.h":
>    ctypedef int INT
>
> # file "implementation.pyx":
> from ext cimport *
> def foo():
>     cdef INT q = 1
>     print q
>
> This fails with a syntax error.  If I replace the cimport line with
> "from ext cimport INT" it works fine.  Is this a bug or an intentional
> limitation (or am I using it wrong)?

No, this looks like a bug. http://trac.cython.org/cython_trac/ticket/ 
73 For now, import your ctypedef types explicitly (functions and  
classes should cimport fine).

> The second issue is that Cython.Compiler.Main.compile_multiple doesn't
> work if you use either the "recursive" or "timestamps" options; I  
> get a
> NameError referring to what seems to be a missing global variable
> "context" inside Cython itself:
>
> /usr/lib/python2.5/site-packages/Cython/Compiler/Main.py in
> compile_multiple(sources, options)
>     639             # Compiling multiple sources in one context  
> doesn't
> quite
>     640             # work properly yet.
> --> 641             if not timestamps or
> context.c_file_out_of_date(source):
>     642                 if verbose:
>     643                     sys.stderr.write("Compiling %s\n" %  
> source)
>
> <type 'exceptions.NameError'>: global name 'context' is not defined
>
> I'd like to eventually use this if possible because it lets me run
> Cython from a setup script independent of the actual C build process.
> Will this be fixed in a later version of Cython?

Yes, I certainly hope so. I don't think many people have used this  
yet, so I'm sure it's not robust.

> Finally I noticed that Cython doesn't have the new Pyrex "typecheck"
> builtin.  I've switched back to "isinstance" for now.  Is there/will
> there be a Cython equivalent?

Probably not. One of the goals of Cython is to reduce the need for  
special syntax, trying to stay as close to Python as possible. The  
only problem with isinstance is that the type may lie via its  
__class__ attribute, but if the second argument is an extension class  
then it should to a type test.

http://article.gmane.org/gmane.comp.python.cython.devel/1434

> Other than that everything works!  Thanks in particular for the
> decorator support, which is the main reason I'm switching.

Great. Let us know if you run into anything else.

- Robert


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

Reply via email to