Where is PyMethod_GET_CLASS in Python 3?

Terry Reedy tjreedy at udel.edu
Wed Dec 16 18:10:19 EST 2009


On 12/16/2009 3:37 AM, Infinity77 wrote:
> Hi,
>
> On Dec 15, 9:22 pm, Terry Reedy wrote:
>> On 12/15/2009 11:08 AM, Infinity77 wrote:
>>
>>> Hi All,
>>
>>>       When building C extensions In Python 2.X, there was a magical
>>> PyMethod_GET_CLASS implemented like this:
>>
>>> #define PyMethod_GET_CLASS(meth) \
>>>     (((PyMethodObject *)meth) ->    im_class)
>>
>>> It looks like Python 3 has wiped out the "im_class" attribute.
>>
>> For bound methods, renamed to __class__ to be consistent with other
>> objects. Unbound methods were eliminated as extra cruft.

What I said is true at the Python level. At the C level, check the 
appropriate .c or .h file for the structure definition. Sorry if they 
are not the same.

>
> First of all, thank you for your answer. However, being a complete
> newbie in writing C extension, I couldn't seem to find a way to do
> what I asked in the first place:
>
> Try 1:
>
> # define PyMethod_GET_CLASS(meth) \
>           (((PyMethodObject *)meth) ->  __class__)
>
> error C2039: '__class__' : is not a member of 'PyMethodObject'
>
> Try 2:
>
> PyObject * magicClass = method ->  __class__
>
> error C2039: '__class__' : is not a member of '_object'
>
>
> I know I am doing something stupid, please be patient :-D . Any
> suggestion is more than welcome.
>
> Andrea.





More information about the Python-list mailing list