]> granicus.if.org Git - python/commitdiff
Fix for SF bug 528132 (Armin Rigo): classmethod().__get__() segfault
authorGuido van Rossum <guido@python.org>
Mon, 18 Mar 2002 03:09:06 +0000 (03:09 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 18 Mar 2002 03:09:06 +0000 (03:09 +0000)
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
later.

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

I've already applied this to the 2.2 branch.

Lib/test/test_descr.py
Objects/funcobject.c

index 1188e1d560e2b195a21aeb9d2c247edf1b42cfe5..ce28cce4a08abcd12d217e7fe7db2508154a2ab1 100644 (file)
@@ -1208,6 +1208,11 @@ def classmethods():
     vereq(d.goo(1), (D, 1))
     vereq(d.foo(1), (d, 1))
     vereq(D.foo(d, 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..."
index f24cbcf4bf504568710f0cc122179f20976fb1cc..426b8f490a44e3ac50292b539762fac6e473e6a8 100644 (file)
@@ -474,6 +474,8 @@ cm_descr_get(PyObject *self, PyObject *obj, PyObject *type)
                                "uninitialized classmethod object");
                return NULL;
        }
+       if (type == NULL)
+               type = (PyObject *)(obj->ob_type);
        return PyMethod_New(cm->cm_callable,
                            type, (PyObject *)(type->ob_type));
 }