Re: [ctypes-users] Since I don't seem to be getting time to do the rest of the work any time soon
by Thomas Heller other posts by this author
Nov 23 2006 12:25PM messages near this date
Re: [ctypes-users] Since I don't seem to be getting time to do the rest of the work any time soon
|
Re: [ctypes-users] Since I don't seem to be getting time to do the rest of the work any time soon
Thomas Heller schrieb:
> Mike C. Fletcher schrieb:
> > I was intending to the work of integrating the code-generation
> > refactoring, testing that all of the various sub-classes were working,
> > but as time grows short I don't seem to be getting to it. Thus, here's
> > the diff for the code generator that I'm using in the OpenGL-ctypes code
> > generator. It is a far more modular design, but is still basically just
> > the same code broken out to allow for subclassing/overriding elements.
> >
> > http://pyopengl.cvs.sourceforge.net/pyopengl/OpenGL-ctypes/src/ctypes_codegenerator_refac
tor.diff?view=markup
>
> Mike,
>
> I like this patch (apart from the fact that it uses a different whitespace coding style
> than I would use myself, but this can easily be fixed).
I have found these bugs so far (patches for patches don't read well, so
I present the code snippets):
1. The TEMPLATE of "class Function(Emitter)" must be this, I had to add
[] around the %(argTypes)s in the last line, otherwise invalid code is
generated for functions taking no arguments:
TEMPLATE = """%(location)s%(name)s = %(libname)s.%(name)s
%(name)s.restype = %(returnType)s
%(argNames)s%(name)s.argtypes = [%(argTypes)s]
"""
^ ^
2. In Generator.__init__(), I had to add parens because '+' binds stronger
than 'or':
self.emitters = (emitters or []) + self.defaultEmitters()
^ ^
3. In Generator.generate(), if no emitter is found 'item' must
be added to 'self.done' to avoid unlimited recursion:
log.warn("""Unable to find emitter for %r instance""", type(item))
# Added this line:
self.done.add(item)
Maybe it would be better to raise an error instead of a warning, because
the generated code will not work anyway in this case.
Thanks,
Thomas
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
ctypes-users mailing list
ctypes-users@[...].net
https://lists.sourceforge.net/lists/listinfo/ctypes-users
Thread:
Mike C. Fletcher
Thomas Heller
Mike C. Fletcher
Thomas Heller
Thomas Heller
Mike C. Fletcher
|