[Bf-python] tp_getset conversion update

Ken Hughes khughes at pacific.edu
Sun Sep 18 02:18:08 CEST 2005


Stephen Swaney wrote:
> On Sat, Sep 17, 2005 at 03:27:18PM -0700, Ken Hughes wrote:
> 
>>OK, so I'm guess the compiler would also check that Lamp_setName() was 
>>declared as:
>>
>>int Lamp_setName( PyObject *self, PyObject *args)
>>
>>as well, an inside Lamp_setName() we have to cast *self back into 
>>whatever it really points at (which is what about half the methods do 
>>anyway).
> 
> 
> No, we can leave those methods alone.  The methods get cast as
> either (PyCFunction) or (setter) or (getter) when they are put into the
> appropriate tables.  All our BPy types are derived from PyObject.
> 

This made me think what the declaration for setter and getter were. 
They've given in /usr/include/python2.3/descrobject.h:

typedef PyObject *(*getter)(PyObject *, void *);
typedef int (*setter)(PyObject *, PyObject *, void *);

So could we just declare EXPP_setterWrapper() this way:

PyObject *EXPP_setterWrapper ( PyObject * self, PyObject * args,
     setter func);

and call it like this:

static PyObject *Lamp_oldsetName( BPy_Lamp * self, PyObject * args )
{
    return EXPP_setterWrapper ( (void *)self, args,
         (setter)Lamp_setName );
}

Ken



More information about the Bf-python mailing list