Subclassing in C

Iker Arizmendi iker at research.att.com
Tue Sep 14 11:24:42 EDT 2004


I was setting tp_getattr to 0 in my subclass (*), but when
I set it to PyObject_GenericGetAttr Python crashed. What
does PyObject_GenericGetAttr do that would help in
this case?

Regards,
Iker

(*) The class I'm deriving from is defined in another
extension module and it has its own tp_getattr method.


Here's the stack trace (via Valgrind), just in case:

Process terminating with default action of signal 11 (SIGSEGV)
Access not within mapped region at address 0x65C9
at 0x1B97CAC3: PyType_IsSubtype (in /usr/lib/libpython2.3.so.1.0)
by 0x1B96C92D: PyObject_GenericGetAttr (in /usr/lib/libpython2.3.so.1.0)
by 0x1B96C5E8: PyObject_GetAttr (in /usr/lib/libpython2.3.so.1.0)
by 0x1B9A51D2: (within /usr/lib/libpython2.3.so.1.0)
by 0x1B9A65E2: PyEval_EvalCodeEx (in /usr/lib/libpython2.3.so.1.0)
by 0x1B9A31B4: PyEval_EvalCode (in /usr/lib/libpython2.3.so.1.0)
by 0x1B9D4D20: (within /usr/lib/libpython2.3.so.1.0)
by 0x1B9D41EE: PyRun_SimpleFileExFlags (in /usr/lib/libpython2.3.so.1.0)
by 0x1B9D3BEF: PyRun_AnyFileExFlags (in /usr/lib/libpython2.3.so.1.0)
by 0x1B9DC7A3: Py_Main (in /usr/lib/libpython2.3.so.1.0)
by 0x8048640: main (in /usr/bin/python2.3)



Michael Hudson wrote:
> Iker Arizmendi <iker at research.att.com> writes:
> 
> 
>>Hello all,
>>
>>I've defined a class in a C extension module that is
>>(or rather, I would like to be) a subclass of another
>>class. I do this by simply setting the tp_base pointer
>>of my subclass's type object. However, this results
>>in a class that exposes the methods of the base class,
>>but ONLY those. The methods of my subclass are hidden.
>>I'd obviously like to have the methods of the base
>>class AND the new methods of the subclass available.
> 
> 
> Are you setting tp_getattro to PyObject_GenericGetAttr? (just a
> guess).
> 
> Cheers,
> mwh
> 



More information about the Python-list mailing list