[Cython] [cython-users] Cython .pxd introspection: listing defined constants

Stefan Behnel stefan_ml at behnel.de
Tue Feb 22 20:18:21 CET 2011

W. Trevor King, 22.02.2011 18:55:
> I've been working on a more explicit parser that removes the ambiguity
> behind the various visibilities.  This will help me ensure proper
> impolementation of my cdef-ed enums/structs/..., and make it easier to
> update visibility syntax in the future.  Take a look and let me know
> if you think this is a useful direction to take:
> git: http://www.physics.drexel.edu/~wking/code/git/cython.git
> branch: cdef-enums-stucts-and-unions
> gitweb:
>    http://www.physics.drexel.edu/~wking/code/git/gitweb.cgi?p=cython.git;a=log;h=refs/heads/cdef-enums-stucts-and-unions

It doesn't seem like I can leave comments in the gitweb version, so I'll 
comment here.

First thing that caught my eyes: I hope you do not intend to leave the 
logging usage in the parser. This is seriously performance critical code 
that Cython compiles down to pretty fast C code. Note that you can use a 
debugger and Python's profiling/tracing interface to find out what's 
happening, without code impact.

Some of the log statements span more than one line, which makes it trickier 
to strip them out with sed&friends (but backing out the initial changeset 
would likely make it simple enough to remove the rest manually).

Also note that it's best to write runnable tests ("tests/run/"). The tests 
in "tests/compile/" are only compiled and imported. See the hacking guide 
in the wiki. I know you're not there yet with your implementation, I'm just 
mentioning it.

Most important point, however: I think it's a good idea to clean up the 
parsing context the way you did it. The semantic distinction of the three 
new classes you added makes sense to me.

CtxAttribute is the wrong name, though. And the class copy implementation 
gets even more generic than it already was in the Ctx. I'm not a big fan of 
that, especially not in the parser. For one, it prevents changing the 
classes into cdef classes, which had long been on my list for Ctx.

CSource: doesn't sound like quite the right name - it does not describe a C 
source file but information that Cython has about non-Cython things.

I also doubt that Cython allows you to call an attribute "cdef", you'll 
need to change that.


More information about the cython-devel mailing list