]> granicus.if.org Git - python/commitdiff
Patch by Ping (SF bug 415879, Exception.__init__() causes segfault):
authorGuido van Rossum <guido@python.org>
Fri, 13 Apr 2001 15:42:40 +0000 (15:42 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 13 Apr 2001 15:42:40 +0000 (15:42 +0000)
   Calling an unbound method on a C extension class without providing
   an instance can yield a segfault.  Try "Exception.__init__()" or
   "ValueError.__init__()".

   This is a simple fix. The error-reporting bits in call_method
   mistakenly treat the misleadingly-named variable "func" as a
   function, when in fact it is a method.

   If we let get_func_name take care of the work, all is fine.

Python/ceval.c

index 10b5c5d32cc12dcdc3cff92dcdbfb9f09213bbbd..a1b3bc2865652ccc33d665e77ea2d8e84da9e323 100644 (file)
@@ -2883,12 +2883,11 @@ call_method(PyObject *func, PyObject *arg, PyObject *kw)
                                return NULL;
                }
                if (!ok) {
-                       PyObject* fn = ((PyFunctionObject*) func)->func_name;
+                       char* fn = get_func_name(func);
                        PyErr_Format(PyExc_TypeError,
                                     "unbound method %s%smust be "
                                     "called with instance as first argument",
-                                    fn ? PyString_AsString(fn) : "",
-                                    fn ? "() " : "");
+                                    fn ? fn : "", fn ? "() " : "");
                        return NULL;
                }
                Py_INCREF(arg);