Class method handles in C

Andy Bensky (ab@infoseek.com)
Fri, 4 Mar 1994 10:22:09 +0800

Let's say we have a class called Foo with a method called print_me().
We also have a C function that needs to call the print_me() method for
a number of different instances of Class Foo. Is it necessary to
register a different callback for the print_me() method of each instance
to be manipulated or is there some way of registering Foo.print_me() and
using it over and over again within C. The problem I see is that
call_object() automatically provides the self argument. What I would like is
a way of using call_object() so that I can supply an object to be used as
self.

The problem is even worse when we consider constructors (__init__() method).
There is never an instance to use to register the __init__() method
because the point of the method is to create a new instance. If we do have
an instance then we can register it's __init__() method so that it can be
called from C using call_object(), but that will clearly pass in the wrong
self argument. How does one create a new instance of an object from C? Is
it sufficient to register the Class object and then use call_object() on
that? Is call_object() smart enough to know that if it is given a handle
to a Class object then it automatically calls the constructor?

So far I am quite impressed with the interfaces provided to call C from
Python and vice-versa. The ability to register an unbound method and
explicitly provide a self pointer from C would make it much more useful.

Andy Bensky
InfoSeek Corp.