Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d9994e0

Browse files
committed
Patch by Ping (SF bug 415879, Exception.__init__() causes segfault):
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.
1 parent d03f8fe commit d9994e0

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

Python/ceval.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,12 +2883,11 @@ call_method(PyObject *func, PyObject *arg, PyObject *kw)
28832883
return NULL;
28842884
}
28852885
if (!ok) {
2886-
PyObject* fn = ((PyFunctionObject*) func)->func_name;
2886+
char* fn = get_func_name(func);
28872887
PyErr_Format(PyExc_TypeError,
28882888
"unbound method %s%smust be "
28892889
"called with instance as first argument",
2890-
fn ? PyString_AsString(fn) : "",
2891-
fn ? "() " : "");
2890+
fn ? fn : "", fn ? "() " : "");
28922891
return NULL;
28932892
}
28942893
Py_INCREF(arg);

0 commit comments

Comments
 (0)