Guido van Rossum  committed c854b6d

Fix for SF bug 528132 (Armin Rigo): classmethod().__get__() segfault

The proper fix is not quite what was submitted; it's really better to
take the class of the object passed rather than calling PyMethod_New
with NULL pointer args, because that can then cause other core dumps

I also added a testcase for the fix to classmethods() in

I'll apply this to 2.3 too.

  • Participants
  • Parent commits 84f2c77
  • Branches 2.2

Comments (0)

Files changed (2)

File Lib/test/

     vereq(, (D, 1))
     vereq(, (d, 1))
     vereq(, 1), (d, 1))
+    # Test for a specific crash (SF bug 528132)
+    def f(cls, arg): return (cls, arg)
+    ff = classmethod(f)
+    vereq(ff.__get__(0, int)(42), (int, 42))
+    vereq(ff.__get__(0)(42), (int, 42))
 def staticmethods():
     if verbose: print "Testing static methods..."

File Objects/funcobject.c

 				"uninitialized classmethod object");
 		return NULL;
+	if (type == NULL)
+		type = (PyObject *)(obj->ob_type);
  	return PyMethod_New(cm->cm_callable,
 			    type, (PyObject *)(type->ob_type));