# Breakpoint 1, PyUnicodeEncodeError_GetEnd (exc=, end=0xbf9e8f7c) at Objects/exceptions.c:1643 # 1643 PyObject *obj = get_unicode(((PyUnicodeErrorObject *)exc)->object, # (gdb) s # get_unicode (attr=, name=0x82765ea "object") at Objects/exceptions.c:1516 # 1516 if (!attr) { # (gdb) print *attr # $4 = {_ob_next = 0xfefefefe, _ob_prev = 0xfefefefe, ob_refcnt = -16843010, ob_type = 0xfefefefe} # (gdb) c # Continuing. # # Program received signal SIGSEGV, Segmentation fault. # 0x080bc7d9 in get_unicode (attr=, name=0x82765ea "object") at Objects/exceptions.c:1521 # 1521 if (!PyUnicode_Check(attr)) { # # Type confusion. IsInstance check is ineffective because of custom # __getattribute__ method. Contents of string instance is interpreted as # an exception object. import codecs as c errs = [c.ignore_errors, c.replace_errors, c.xmlcharrefreplace_errors, c.backslashreplace_errors] class X(str): def __getattribute__(self, a): return UnicodeEncodeError def f(i): x = X("\xfe"*1024) f_err = errs[i] f_err(x) #argument: 0..3 f(0)