__dict__ in class inherited from C extension module

Tamas Nepusz ntamas at gmail.com
Tue May 9 03:08:29 CEST 2006

Dear Python experts,

I have a strange problem - or more precisely, I'm not even sure if it's
a problem or not. I'm developing a Python extension module in C which
creates a new type with methods, mapping support and stuff like that :)
Everything's working fine, but if I inherit a new class from this type
in Python, I start getting strange warning messages in valgrind. Just a
simple example:

import mymodule

class InheritedType(mymodule.MyType):
    def a_new_method(self): print "test"


("mymodule" is the C extension module I developed)
The error message I see in valgrind is the following:

==6579== Conditional jump or move depends on uninitialized value(s)
==6579==    at 0x807CFF9: PyObject_GenericGetAttr (object.c:1283)
==6579==    by 0x80B2EA3: PyEval_EvalFrame (ceval.c:1957)

I'm using Python 2.4.3, and by taking a look at the source of object.c
(line 1283), it looks like the tp_dict member of the type object of my
subclass is not initialized. The code snippet from line 1281-1285 looks
like this:

dictptr = (PyObject **) ((char *)obj + dictoffset);
dict = *dictptr;
if (dict != NULL) {
  res = PyDict_GetItem(dict, name);
  if (res != NULL) {

Should I worry about Valgrind's warning or is it just a false alarm? It
does not occur if I try to inherit my class from a built-in class (like
string or module or whatever), only if I use my extension's class, so I
suspect that I'm doing something wrong. Is there anything I should
watch out for when I create inheritable classes in a C extension?

Thanks a lot in advance.

Tamas <ntamas at gmail.com>

More information about the Python-list mailing list