[Pyrex] Re: Pyrex versus ctypes

Bob Ippolito bob at redivi.com
Fri Jun 11 13:20:00 CEST 2004


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.

> And, on the other hand, to create a Windows messagebox, for example,
> it doesn't take more than to write
>    ctypes.windll.user32.MessageBoxA(0, "Hello World", "ctypes", 0)

Which is pretty horrifying if you ask me.. guessing at what the types 
should be and just sending them to the function.  I mean, it works, but 
it seems more like an accident.  Which one was better again.. implicit 
or explicit?  You'll have to remind me :)

I admit that we do this in PyObjC to an extent, but we only assume that 
arguments and return value are "id" (which means that it assumes 
objects in and out), which is a pretty reasonable guess because that's 
what Objective C does too, if you don't specify types for your 
selector.

>> It's a shame that Pyrex can't preprocess .h files and expose their
>> contents into the wrapper module's namespace. There's still a
>> brittleness wrt struct definitions.
>
> 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.

-bob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2357 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20040611/780abae6/smime.bin


More information about the Pyrex mailing list