calling instance methods from C

Andy Bensky (ab@infoseek.com)
Mon, 19 Sep 1994 20:53:30 -0700

I am working in a C module that has pointers to some user defined objects
from python. I need to be able to call methods of these instances
and am not having much uck with call_object(). I've tried using
getattr(object,"method_name") and using call_object on what is returned,
but I can't seem to get it to work. call_object is constantly returning 0.

here is a sample:

c_get_stuff_method(object *my_object)
{
object *arglist;
object *result;

if ( my_object )
{
arglist = mkvalue("(O)", None);
/* xtra note: what ever happened to mktuple()???? */
result = call_object(getattr(my_object,"MethodName"),arglist);
DECREF(arglist);
}
}

This particular case is intended to call a method that takes only the self
argument, like a simple 'get' method. I have also tried making the
arglist a tuple containing just my_object and tried it both ways (using
my_object and None) witout making a tuple first. same results in all cases.

Before anyone asks the obvious, we decided that none of our attribute names
should be exposed outside a class definition, so getting all attributes
must be done with methods in case the underlying implementation changes.

I am tired so I may be overlooking something obvious. Anyone have a clue?

thanks,

Andy Bensky
InfoSeek Corp.