[Pyrex] Re: Pyrex versus ctypes

Thomas Heller theller at python.net
Fri Jun 11 13:42:42 CEST 2004


Bob Ippolito <bob at redivi.com> writes:

> On Jun 11, 2004, at 5:32 AM, Thomas Heller wrote:
>
>> Bob Ippolito <bob at redivi.com> writes:
>>
>>> On Jun 10, 2004, at 6:01 PM, David McNab wrote:
>>>
>>>> Can anyone offer some thoughts on the ideal demarcation lines
>>>> between Pyrex and ctypes, and some thoughts on pros and cons, and
>>>> which situations indicate Pyrex over ctypes and vice versa?
>>
>>> It takes more time to wrap a C API with ctypes than with Pyrex because
>>> you can't leverage anything that the C compiler and preprocessor knows
>>> about.
>>
>> Yes, but there's a Tools/Scripts/h2py in Python which converts C header
>> files into python modules.
>
> You still have to do structures, enum, functions by hand.  Everything
> that script does can be done with a few seconds in a text editor that
> supports regular expressions (I know, because I've done it several
> times).  In either case, it doesn't seem to buy you much.

For COM, it works - the readtlb tool creates all of these and more, from
type libraries.  But that won't help you...

>> Maybe h2py could also come handy here?
>
> Hacking bgen to pieces would be a much better bet.. h2py seems like it
> would be pretty useless in practice.
>
> And then, of course, maybe this:
> http://people.cs.uchicago.edu/~varmaa/mini_c/ could be of some use
> (because it is obviously reasonably good at lexing C).  The licensing
> of this software is unclear though.  PLY is LGPL, and it includes some
> modified code from this project (or maybe it's not modified), but does
> not seem to specify its own license.

Ok, I've seen quite some pointers to C parsers, and tried some.  I have
experimented with PLY myself, until I realized that you cannot parse
real world C with a context free grammar (or how is it called).
The best results I got was with simon burton's cdecl.py.

But then I lost interest.  Which doesn't mean that I wouldn't accept a
donation of a C -> ctypes conversion tool.

BTW, and even more off-topic for *this* list: what about some
testing/hacking of ctypes cvs on OSX?

Thomas





More information about the Pyrex mailing list