[Python-Dev] Feature request: better support for "wrapper" objects

Jack Jansen jack@oratrix.nl
Wed, 09 Jan 2002 12:55:12 +0100


> > All the Mac toolbox objects (Windows, Dialogs, Controls, Menus and a
> > zillion more), All the Windows HANDLEs, all the MFC objects (although
> > they might be a bit more difficult), the objects in the X11 and Motif
> > modules, the pyexpat parser object, *dbm objects, dlmodule objects,
> > mpz objects, zlib objects, SGI cl and al objects....
> 
> Could you please try once more, being serious this time? AFAICT, I was
> asking for examples of types that are parsed by means of O& currently,
> and do so just to get a void** from the python object.

Shall we try to keep this civil, please? I *am* being serious, and I'm getting 
slightly upset that with this subject (again) you appear to start shooting 
away without trying very hard to understand the issue I'm raising.

> Looking at pyexpat.c, I find a few uses of O&, none related to the
> pyexpat parser object. In zlibmodule.c, I find not a single mentioning
> of O&, likewise in dlmodule.c, clmodule.c, almodule.c, dbmmodule.c,
> and now I'm losing interest into verifying more of your examples.

Ok, let me rephrase my list then. The first five items in my list, which you 
carefully ignored, are examples of objects that now already make heavy use of 
O&. The rest are examples of other objects that wrap a C pointer, and which 
could potentially also be opened up to use in struct or calldll.

And to give a complete example of how useful this would be consider the 
following. I'll give a mac-centric example, because I don't know enough about 
calldll on windows (and I don't think there's a unix version yet).

Assume you're using Python to extend Photoshop. Assume Photoshop has an API to 
allow the plugin to get at the screen. Let's assume that there's a C call
extern GrafPtr ps_GetDrawableSurface(void);
to get at the datastructure you need to draw to.
These GrafPtr's are (in Mac/Modules/qd/_Quickdraw.c) wrapped in 
Carbon.Qd.GrafPortType objects in Python.

In the current situation, if you would want to wrap this ps_GetDrawableSurface 
function you would need to write a C wrapper (which means you would need a C 
compiler, etc etc) because you would need to convert the return value with 
("O&", GrafObj_new). If we had something like ("O@", typeobject) calldll could 
be extended so you could do something like
psapilib = calldll.getlibrary(....)
ps_GetDrawableSurface = calldll.newcall(psapilib.ps_GetDrawableSurface,
	Carbon.Qd.GrafPortType)

(newcall() arguments are funcpointer, return value type, arg1 type, ...)

You cannot do this currently, because there is no way to get from the type 
object (which is the only thing you have available in Python) to the functions 
you need to pass to O&.

--
- Jack Jansen        <Jack.Jansen@oratrix.com>        http://www.cwi.nl/~jack -
- If I can't dance I don't want to be part of your revolution -- Emma Goldman -