Help with Extension Class Crash

Giles Brown giles_brown at
Wed Jan 28 14:44:02 CET 2004

Hello folks,
I'm tryin to write an extension class in C (been a while since
I wrote some C :-).  I want the class to be inheritable from Python.
I've put the magic incantations into the type descriptor.  But it
crashes.  I've tracked the crash down to a call to PyObject_GenericGetAttr.

When I sub-class my class the tp_dictoffset comes out as -4 which 

quoting from PyObject_GenericGetAttr:
		if (dictoffset < 0) {
			int tsize;
			size_t size;

			tsize = ((PyVarObject *)obj)->ob_size;
			if (tsize < 0)
				tsize = -tsize;
			size = _PyObject_VAR_SIZE(tp, tsize);

			dictoffset += (long)size;
			assert(dictoffset > 0);
			assert(dictoffset % SIZEOF_VOID_P == 0);
		dictptr = (PyObject **) ((char *)obj + dictoffset);
		dict = *dictptr; <---- crash happens here

The class I'm trying to create is a variable size class.  Everything 
is ok unless I sub-class it.  I'm guess that maybe I haven't set the
sizes up ok so its sending the dictptr off into the blue. Or I've 
missed setting of something, but not sure where to look.

Can anyone help?


More information about the Python-list mailing list