Re: Class method handles in C

Guido.van.Rossum@cwi.nl
Fri, 04 Mar 1994 23:36:49 +0100

> I have run some tests which show it to be fairly easy to register an use
> unbound methods from C as long as the firs param in the arglist is an
> instance of the class.

Yes, this works, and should keep working -- though I don't understand
in what situation you need this -- why can't you do something like

call_object(getattr(obj, "methodname"), args)

?

> I still can't figure out, however, how to create a new instance of a class.
> Passing in the unbound __init__ method doesn't work sine there is no class
> instance to pass in as the first argument so call_function() refuses to
> invoke the function it was asked to.
>
> I've located newinstanceobject() in Objects/classobject.c which I believe
> will do what I want, but is this a recommended interface?

Well, this works, but what's better is to use this:

call_object(classobj, args)

> In general, would it be possible to document these C interfaces
> somewhere besides in the code so that if they change in the future
> there will be a single point of reference for what you may and may
> not count on being available from within a C program?

I guess unless I get some volunteer help this will have to wait a
while. For now, most operations announced in Include/*object.h are
reasonably safe. Stuff for which you can find examples of use
anywhere in the Modules directory should especially be fairly safe...

> Again - Kudos to Guido and his associates for making it so easy to locate
> desired functions in the source code and making them really understandable!

Thanks... So it seems you can live without documentation a little
longer :-)

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>