Commit 0bf060f9 authored by Matthias Braun's avatar Matthias Braun Committed by GitHub

Avoid using "tp_name" when CYTHON_COMPILING_IN_LIMITED_API (GH-3693)

parent 61a4f099
...@@ -13111,6 +13111,8 @@ class PyTypeTestNode(CoercionNode): ...@@ -13111,6 +13111,8 @@ class PyTypeTestNode(CoercionNode):
type_test = self.type.type_test_code( type_test = self.type.type_test_code(
self.arg.py_result(), self.arg.py_result(),
self.notnone, exact=self.exact_builtin_type) self.notnone, exact=self.exact_builtin_type)
code.globalstate.use_utility_code(UtilityCode.load_cached(
"RaiseUnexpectedTypeError", "ObjectHandling.c"))
else: else:
type_test = self.type.type_test_code( type_test = self.type.type_test_code(
self.arg.py_result(), self.notnone) self.arg.py_result(), self.notnone)
......
...@@ -781,6 +781,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -781,6 +781,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln('#define __Pyx_PyObject_FromString __Pyx_Py%s_FromString' % c_string_func_name) code.putln('#define __Pyx_PyObject_FromString __Pyx_Py%s_FromString' % c_string_func_name)
code.putln('#define __Pyx_PyObject_FromStringAndSize __Pyx_Py%s_FromStringAndSize' % c_string_func_name) code.putln('#define __Pyx_PyObject_FromStringAndSize __Pyx_Py%s_FromStringAndSize' % c_string_func_name)
code.put(UtilityCode.load_as_string("TypeConversions", "TypeConversion.c")[0]) code.put(UtilityCode.load_as_string("TypeConversions", "TypeConversion.c")[0])
env.use_utility_code(UtilityCode.load_cached("FormatTypeName", "ObjectHandling.c"))
# These utility functions are assumed to exist and used elsewhere. # These utility functions are assumed to exist and used elsewhere.
PyrexTypes.c_long_type.create_to_py_utility_code(env) PyrexTypes.c_long_type.create_to_py_utility_code(env)
...@@ -1865,6 +1866,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1865,6 +1866,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln( code.putln(
"static int %s(PyObject *o, PyObject *i, PyObject *v) {" % ( "static int %s(PyObject *o, PyObject *i, PyObject *v) {" % (
scope.mangle_internal("mp_ass_subscript"))) scope.mangle_internal("mp_ass_subscript")))
code.putln(
"__Pyx_TypeName o_type_name;")
code.putln( code.putln(
"if (v) {") "if (v) {")
if set_entry: if set_entry:
...@@ -1872,10 +1875,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1872,10 +1875,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
else: else:
self.generate_guarded_basetype_call( self.generate_guarded_basetype_call(
base_type, "tp_as_mapping", "mp_ass_subscript", "o, i, v", code) base_type, "tp_as_mapping", "mp_ass_subscript", "o, i, v", code)
code.putln(
"o_type_name = __Pyx_PyType_GetName(Py_TYPE(o));")
code.putln( code.putln(
"PyErr_Format(PyExc_NotImplementedError,") "PyErr_Format(PyExc_NotImplementedError,")
code.putln( code.putln(
' "Subscript assignment not supported by %.200s", Py_TYPE(o)->tp_name);') ' "Subscript assignment not supported by " __Pyx_FMT_TYPENAME, o_type_name);')
code.putln(
"__Pyx_DECREF_TypeName(o_type_name);")
code.putln( code.putln(
"return -1;") "return -1;")
code.putln( code.putln(
...@@ -1889,10 +1896,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1889,10 +1896,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
else: else:
self.generate_guarded_basetype_call( self.generate_guarded_basetype_call(
base_type, "tp_as_mapping", "mp_ass_subscript", "o, i, v", code) base_type, "tp_as_mapping", "mp_ass_subscript", "o, i, v", code)
code.putln(
"o_type_name = __Pyx_PyType_GetName(Py_TYPE(o));")
code.putln( code.putln(
"PyErr_Format(PyExc_NotImplementedError,") "PyErr_Format(PyExc_NotImplementedError,")
code.putln( code.putln(
' "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name);') ' "Subscript deletion not supported by " __Pyx_FMT_TYPENAME, o_type_name);')
code.putln(
"__Pyx_DECREF_TypeName(o_type_name);")
code.putln( code.putln(
"return -1;") "return -1;")
code.putln( code.putln(
...@@ -1930,6 +1941,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1930,6 +1941,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln( code.putln(
"static int %s(PyObject *o, Py_ssize_t i, Py_ssize_t j, PyObject *v) {" % ( "static int %s(PyObject *o, Py_ssize_t i, Py_ssize_t j, PyObject *v) {" % (
scope.mangle_internal("sq_ass_slice"))) scope.mangle_internal("sq_ass_slice")))
code.putln(
"__Pyx_TypeName o_type_name;")
code.putln( code.putln(
"if (v) {") "if (v) {")
if set_entry: if set_entry:
...@@ -1939,10 +1952,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1939,10 +1952,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
else: else:
self.generate_guarded_basetype_call( self.generate_guarded_basetype_call(
base_type, "tp_as_sequence", "sq_ass_slice", "o, i, j, v", code) base_type, "tp_as_sequence", "sq_ass_slice", "o, i, j, v", code)
code.putln(
"o_type_name = __Pyx_PyType_GetName(Py_TYPE(o));")
code.putln( code.putln(
"PyErr_Format(PyExc_NotImplementedError,") "PyErr_Format(PyExc_NotImplementedError,")
code.putln( code.putln(
' "2-element slice assignment not supported by %.200s", Py_TYPE(o)->tp_name);') ' "2-element slice assignment not supported by " __Pyx_FMT_TYPENAME, o_type_name);')
code.putln(
"__Pyx_DECREF_TypeName(o_type_name);")
code.putln( code.putln(
"return -1;") "return -1;")
code.putln( code.putln(
...@@ -1956,10 +1973,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1956,10 +1973,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
else: else:
self.generate_guarded_basetype_call( self.generate_guarded_basetype_call(
base_type, "tp_as_sequence", "sq_ass_slice", "o, i, j, v", code) base_type, "tp_as_sequence", "sq_ass_slice", "o, i, j, v", code)
code.putln(
"o_type_name = __Pyx_PyType_GetName(Py_TYPE(o));")
code.putln( code.putln(
"PyErr_Format(PyExc_NotImplementedError,") "PyErr_Format(PyExc_NotImplementedError,")
code.putln( code.putln(
' "2-element slice deletion not supported by %.200s", Py_TYPE(o)->tp_name);') ' "2-element slice deletion not supported by " __Pyx_FMT_TYPENAME, o_type_name);')
code.putln(
"__Pyx_DECREF_TypeName(o_type_name);")
code.putln( code.putln(
"return -1;") "return -1;")
code.putln( code.putln(
......
...@@ -5149,9 +5149,13 @@ class CClassDefNode(ClassDefNode): ...@@ -5149,9 +5149,13 @@ class CClassDefNode(ClassDefNode):
code.put_gotref(trial_type, py_object_type) code.put_gotref(trial_type, py_object_type)
code.putln("if (((PyTypeObject*) %s)->tp_base != %s) {" % ( code.putln("if (((PyTypeObject*) %s)->tp_base != %s) {" % (
trial_type, first_base)) trial_type, first_base))
code.putln("PyErr_Format(PyExc_TypeError, \"best base '%s' must be equal to first base '%s'\",") code.putln("__Pyx_TypeName base_name = __Pyx_PyType_GetName(((PyTypeObject*) %s)->tp_base);" % trial_type)
code.putln(" ((PyTypeObject*) %s)->tp_base->tp_name, %s->tp_name);" % ( code.putln("__Pyx_TypeName type_name = __Pyx_PyType_GetName(%s);" % first_base)
trial_type, first_base)) code.putln("PyErr_Format(PyExc_TypeError, "
"\"best base '\" __Pyx_FMT_TYPENAME \"' must be equal to first base '\" __Pyx_FMT_TYPENAME \"'\",")
code.putln(" base_name, type_name);")
code.putln("__Pyx_DECREF_TypeName(base_name);")
code.putln("__Pyx_DECREF_TypeName(type_name);")
code.putln(code.error_goto(self.pos)) code.putln(code.error_goto(self.pos))
code.putln("}") code.putln("}")
code.funcstate.release_temp(trial_type) code.funcstate.release_temp(trial_type)
......
...@@ -1442,14 +1442,9 @@ class BuiltinObjectType(PyObjectType): ...@@ -1442,14 +1442,9 @@ class BuiltinObjectType(PyObjectType):
check += '||((%s) == Py_None)' % arg check += '||((%s) == Py_None)' % arg
if self.name == 'basestring': if self.name == 'basestring':
name = '(PY_MAJOR_VERSION < 3 ? "basestring" : "str")' name = '(PY_MAJOR_VERSION < 3 ? "basestring" : "str")'
space_for_name = 16
else: else:
name = '"%s"' % self.name name = '"%s"' % self.name
# avoid wasting too much space but limit number of different format strings return check + ' || __Pyx_RaiseUnexpectedTypeError(%s, %s)' % (name, arg)
space_for_name = (len(self.name) // 16 + 1) * 16
error = '(PyErr_Format(PyExc_TypeError, "Expected %%.%ds, got %%.200s", %s, __Pyx_PyType_Name(Py_TYPE(%s))), 0)' % (
space_for_name, name, arg)
return check + '||' + error
def declaration_code(self, entity_code, def declaration_code(self, entity_code,
for_display = 0, dll_linkage = None, pyrex = 0): for_display = 0, dll_linkage = None, pyrex = 0):
...@@ -3587,6 +3582,7 @@ class CStructOrUnionType(CType): ...@@ -3587,6 +3582,7 @@ class CStructOrUnionType(CType):
var_entries=self.scope.var_entries, var_entries=self.scope.var_entries,
funcname=self.from_py_function, funcname=self.from_py_function,
) )
env.use_utility_code(UtilityCode.load_cached("RaiseUnexpectedTypeError", "ObjectHandling.c"))
from .UtilityCode import CythonUtilityCode from .UtilityCode import CythonUtilityCode
self._convert_from_py_code = CythonUtilityCode.load( self._convert_from_py_code = CythonUtilityCode.load(
"FromPyStructUtility" if self.is_struct else "FromPyUnionUtility", "FromPyStructUtility" if self.is_struct else "FromPyUnionUtility",
......
...@@ -111,6 +111,7 @@ typedef struct { ...@@ -111,6 +111,7 @@ typedef struct {
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
__Pyx_TypeName obj_type_name;
if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags); if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags);
{{for type_ptr, getbuffer, releasebuffer in types}} {{for type_ptr, getbuffer, releasebuffer in types}}
...@@ -119,7 +120,11 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { ...@@ -119,7 +120,11 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
{{endif}} {{endif}}
{{endfor}} {{endfor}}
PyErr_Format(PyExc_TypeError, "'%.200s' does not have the buffer interface", Py_TYPE(obj)->tp_name); obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
PyErr_Format(PyExc_TypeError,
"'" __Pyx_FMT_TYPENAME "' does not have the buffer interface",
obj_type_name);
__Pyx_DECREF_TypeName(obj_type_name);
return -1; return -1;
} }
......
...@@ -69,8 +69,12 @@ static PyObject* __Pyx_PyExec3(PyObject* o, PyObject* globals, PyObject* locals) ...@@ -69,8 +69,12 @@ static PyObject* __Pyx_PyExec3(PyObject* o, PyObject* globals, PyObject* locals)
if (!globals || globals == Py_None) { if (!globals || globals == Py_None) {
globals = $moddict_cname; globals = $moddict_cname;
} else if (unlikely(!PyDict_Check(globals))) { } else if (unlikely(!PyDict_Check(globals))) {
PyErr_Format(PyExc_TypeError, "exec() arg 2 must be a dict, not %.200s", __Pyx_TypeName globals_type_name =
Py_TYPE(globals)->tp_name); __Pyx_PyType_GetName(Py_TYPE(globals));
PyErr_Format(PyExc_TypeError,
"exec() arg 2 must be a dict, not " __Pyx_FMT_TYPENAME,
globals_type_name);
__Pyx_DECREF_TypeName(globals_type_name);
goto bad; goto bad;
} }
if (!locals || locals == Py_None) { if (!locals || locals == Py_None) {
...@@ -106,9 +110,11 @@ static PyObject* __Pyx_PyExec3(PyObject* o, PyObject* globals, PyObject* locals) ...@@ -106,9 +110,11 @@ static PyObject* __Pyx_PyExec3(PyObject* o, PyObject* globals, PyObject* locals)
#else #else
} else if (unlikely(!PyString_Check(o))) { } else if (unlikely(!PyString_Check(o))) {
#endif #endif
__Pyx_TypeName o_type_name = __Pyx_PyType_GetName(Py_TYPE(o));
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"exec: arg 1 must be string, bytes or code object, got %.200s", "exec: arg 1 must be string, bytes or code object, got " __Pyx_FMT_TYPENAME,
Py_TYPE(o)->tp_name); o_type_name);
__Pyx_DECREF_TypeName(o_type_name);
goto bad; goto bad;
} }
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
...@@ -194,11 +200,12 @@ static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) { ...@@ -194,11 +200,12 @@ static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
static PyObject* __Pyx_Intern(PyObject* s); /* proto */ static PyObject* __Pyx_Intern(PyObject* s); /* proto */
//////////////////// Intern //////////////////// //////////////////// Intern ////////////////////
//@requires: ObjectHandling.c::RaiseUnexpectedTypeError
static PyObject* __Pyx_Intern(PyObject* s) { static PyObject* __Pyx_Intern(PyObject* s) {
if (unlikely(!PyString_CheckExact(s))) { if (unlikely(!PyString_CheckExact(s))) {
PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(s)->tp_name); __Pyx_RaiseUnexpectedTypeError("str", s);
return 0; return NULL;
} }
Py_INCREF(s); Py_INCREF(s);
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
...@@ -307,8 +314,11 @@ static long __Pyx__PyObject_Ord(PyObject* c) { ...@@ -307,8 +314,11 @@ static long __Pyx__PyObject_Ord(PyObject* c) {
#endif #endif
} else { } else {
// FIXME: support character buffers - but CPython doesn't support them either // FIXME: support character buffers - but CPython doesn't support them either
__Pyx_TypeName c_type_name = __Pyx_PyType_GetName(Py_TYPE(c));
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"ord() expected string of length 1, but %.200s found", c->ob_type->tp_name); "ord() expected string of length 1, but " __Pyx_FMT_TYPENAME " found",
c_type_name);
__Pyx_DECREF_TypeName(c_type_name);
return (long)(Py_UCS4)-1; return (long)(Py_UCS4)-1;
} }
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
......
...@@ -6,12 +6,13 @@ cdef extern from *: ...@@ -6,12 +6,13 @@ cdef extern from *:
PyTypeObject *Py_TYPE(obj) PyTypeObject *Py_TYPE(obj)
bint PyMapping_Check(obj) bint PyMapping_Check(obj)
object PyErr_Format(exc, const char *format, ...) object PyErr_Format(exc, const char *format, ...)
int __Pyx_RaiseUnexpectedTypeError(const char *expected, object obj) except 0
@cname("{{funcname}}") @cname("{{funcname}}")
cdef {{struct_type}} {{funcname}}(obj) except *: cdef {{struct_type}} {{funcname}}(obj) except *:
cdef {{struct_type}} result cdef {{struct_type}} result
if not PyMapping_Check(obj): if not PyMapping_Check(obj):
PyErr_Format(TypeError, b"Expected %.16s, got %.200s", b"a mapping", Py_TYPE(obj).tp_name) __Pyx_RaiseUnexpectedTypeError(b"a mapping", obj)
{{for member in var_entries:}} {{for member in var_entries:}}
try: try:
...@@ -31,13 +32,14 @@ cdef extern from *: ...@@ -31,13 +32,14 @@ cdef extern from *:
PyTypeObject *Py_TYPE(obj) PyTypeObject *Py_TYPE(obj)
bint PyMapping_Check(obj) bint PyMapping_Check(obj)
object PyErr_Format(exc, const char *format, ...) object PyErr_Format(exc, const char *format, ...)
int __Pyx_RaiseUnexpectedTypeError(const char *expected, object obj) except 0
@cname("{{funcname}}") @cname("{{funcname}}")
cdef {{struct_type}} {{funcname}}(obj) except *: cdef {{struct_type}} {{funcname}}(obj) except *:
cdef {{struct_type}} result cdef {{struct_type}} result
cdef Py_ssize_t length cdef Py_ssize_t length
if not PyMapping_Check(obj): if not PyMapping_Check(obj):
PyErr_Format(TypeError, b"Expected %.16s, got %.200s", b"a mapping", Py_TYPE(obj).tp_name) __Pyx_RaiseUnexpectedTypeError(b"a mapping", obj)
last_found = None last_found = None
length = len(obj) length = len(obj)
......
...@@ -7,9 +7,10 @@ static CYTHON_INLINE PyObject* __Pyx_Generator_Yield_From(__pyx_CoroutineObject ...@@ -7,9 +7,10 @@ static CYTHON_INLINE PyObject* __Pyx_Generator_Yield_From(__pyx_CoroutineObject
#if CYTHON_USE_TYPE_SLOTS #if CYTHON_USE_TYPE_SLOTS
static void __Pyx_PyIter_CheckErrorAndDecref(PyObject *source) { static void __Pyx_PyIter_CheckErrorAndDecref(PyObject *source) {
__Pyx_TypeName source_type_name = __Pyx_PyType_GetName(Py_TYPE(source));
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"iter() returned non-iterator of type '%.100s'", "iter() returned non-iterator of type '" __Pyx_FMT_TYPENAME "'", source_type_name);
Py_TYPE(source)->tp_name); __Pyx_DECREF_TypeName(source_type_name);
Py_DECREF(source); Py_DECREF(source);
} }
#endif #endif
...@@ -138,13 +139,13 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAwaitableIter(PyObject *o) { ...@@ -138,13 +139,13 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAwaitableIter(PyObject *o) {
static void __Pyx_Coroutine_AwaitableIterError(PyObject *source) { static void __Pyx_Coroutine_AwaitableIterError(PyObject *source) {
#if PY_VERSION_HEX >= 0x030600B3 || defined(_PyErr_FormatFromCause) #if PY_VERSION_HEX >= 0x030600B3 || defined(_PyErr_FormatFromCause)
_PyErr_FormatFromCause( __Pyx_TypeName source_type_name = __Pyx_PyType_GetName(Py_TYPE(source));
PyExc_TypeError, _PyErr_FormatFromCause(PyExc_TypeError,
"'async for' received an invalid object " "'async for' received an invalid object from __anext__: " __Pyx_FMT_TYPENAME, source_type_name);
"from __anext__: %.100s", __Pyx_DECREF_TypeName(source_type_name);
Py_TYPE(source)->tp_name);
#elif PY_MAJOR_VERSION >= 3 #elif PY_MAJOR_VERSION >= 3
PyObject *exc, *val, *val2, *tb; PyObject *exc, *val, *val2, *tb;
__Pyx_TypeName source_type_name = __Pyx_PyType_GetName(Py_TYPE(source));
assert(PyErr_Occurred()); assert(PyErr_Occurred());
PyErr_Fetch(&exc, &val, &tb); PyErr_Fetch(&exc, &val, &tb);
PyErr_NormalizeException(&exc, &val, &tb); PyErr_NormalizeException(&exc, &val, &tb);
...@@ -154,11 +155,9 @@ static void __Pyx_Coroutine_AwaitableIterError(PyObject *source) { ...@@ -154,11 +155,9 @@ static void __Pyx_Coroutine_AwaitableIterError(PyObject *source) {
} }
Py_DECREF(exc); Py_DECREF(exc);
assert(!PyErr_Occurred()); assert(!PyErr_Occurred());
PyErr_Format( PyErr_Format(PyExc_TypeError,
PyExc_TypeError, "'async for' received an invalid object from __anext__: " __Pyx_FMT_TYPENAME, source_type_name);
"'async for' received an invalid object " __Pyx_DECREF_TypeName(source_type_name);
"from __anext__: %.100s",
Py_TYPE(source)->tp_name);
PyErr_Fetch(&exc, &val2, &tb); PyErr_Fetch(&exc, &val2, &tb);
PyErr_NormalizeException(&exc, &val2, &tb); PyErr_NormalizeException(&exc, &val2, &tb);
...@@ -209,9 +208,10 @@ static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *obj) { ...@@ -209,9 +208,10 @@ static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *obj) {
goto bad; goto bad;
} }
if (unlikely(!PyIter_Check(res))) { if (unlikely(!PyIter_Check(res))) {
__Pyx_TypeName res_type_name = __Pyx_PyType_GetName(Py_TYPE(res));
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"__await__() returned non-iterator of type '%.100s'", "__await__() returned non-iterator of type '" __Pyx_FMT_TYPENAME "'", res_type_name);
Py_TYPE(res)->tp_name); __Pyx_DECREF_TypeName(res_type_name);
Py_CLEAR(res); Py_CLEAR(res);
} else { } else {
int is_coroutine = 0; int is_coroutine = 0;
...@@ -231,9 +231,12 @@ static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *obj) { ...@@ -231,9 +231,12 @@ static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *obj) {
} }
return res; return res;
slot_error: slot_error:
PyErr_Format(PyExc_TypeError, {
"object %.100s can't be used in 'await' expression", __Pyx_TypeName obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
Py_TYPE(obj)->tp_name); PyErr_Format(PyExc_TypeError,
"object " __Pyx_FMT_TYPENAME " can't be used in 'await' expression", obj_type_name);
__Pyx_DECREF_TypeName(obj_type_name);
}
bad: bad:
return NULL; return NULL;
} }
...@@ -249,6 +252,7 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_AsyncIterNext(PyObject *o); /*pro ...@@ -249,6 +252,7 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_AsyncIterNext(PyObject *o); /*pro
//@requires: ObjectHandling.c::PyObjectCallMethod0 //@requires: ObjectHandling.c::PyObjectCallMethod0
static PyObject *__Pyx_Coroutine_GetAsyncIter_Generic(PyObject *obj) { static PyObject *__Pyx_Coroutine_GetAsyncIter_Generic(PyObject *obj) {
__Pyx_TypeName obj_type_name;
#if PY_VERSION_HEX < 0x030500B1 #if PY_VERSION_HEX < 0x030500B1
{ {
PyObject *iter = __Pyx_PyObject_CallMethod0(obj, PYIDENT("__aiter__")); PyObject *iter = __Pyx_PyObject_CallMethod0(obj, PYIDENT("__aiter__"));
...@@ -263,8 +267,10 @@ static PyObject *__Pyx_Coroutine_GetAsyncIter_Generic(PyObject *obj) { ...@@ -263,8 +267,10 @@ static PyObject *__Pyx_Coroutine_GetAsyncIter_Generic(PyObject *obj) {
if ((0)) (void) __Pyx_PyObject_CallMethod0(obj, PYIDENT("__aiter__")); if ((0)) (void) __Pyx_PyObject_CallMethod0(obj, PYIDENT("__aiter__"));
#endif #endif
PyErr_Format(PyExc_TypeError, "'async for' requires an object with __aiter__ method, got %.100s", obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
Py_TYPE(obj)->tp_name); PyErr_Format(PyExc_TypeError,
"'async for' requires an object with __aiter__ method, got " __Pyx_FMT_TYPENAME, obj_type_name);
__Pyx_DECREF_TypeName(obj_type_name);
return NULL; return NULL;
} }
...@@ -297,8 +303,12 @@ static PyObject *__Pyx__Coroutine_AsyncIterNext(PyObject *obj) { ...@@ -297,8 +303,12 @@ static PyObject *__Pyx__Coroutine_AsyncIterNext(PyObject *obj) {
// FIXME: for the sake of a nicely conforming exception message, assume any AttributeError meant '__anext__' // FIXME: for the sake of a nicely conforming exception message, assume any AttributeError meant '__anext__'
if (PyErr_ExceptionMatches(PyExc_AttributeError)) if (PyErr_ExceptionMatches(PyExc_AttributeError))
#endif #endif
PyErr_Format(PyExc_TypeError, "'async for' requires an object with __anext__ method, got %.100s", {
Py_TYPE(obj)->tp_name); __Pyx_TypeName obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
PyErr_Format(PyExc_TypeError,
"'async for' requires an object with __anext__ method, got " __Pyx_FMT_TYPENAME, obj_type_name);
__Pyx_DECREF_TypeName(obj_type_name);
}
return NULL; return NULL;
} }
......
...@@ -38,17 +38,24 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) { ...@@ -38,17 +38,24 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
b = (PyTypeObject*)b0; b = (PyTypeObject*)b0;
if (!__Pyx_PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE)) if (!__Pyx_PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE))
{ {
PyErr_Format(PyExc_TypeError, "base class '%.200s' is not a heap type", __Pyx_TypeName b_name = __Pyx_PyType_GetName(b);
b->tp_name); PyErr_Format(PyExc_TypeError,
"base class '" __Pyx_FMT_TYPENAME "' is not a heap type", b_name);
__Pyx_DECREF_TypeName(b_name);
return -1; return -1;
} }
if (t->tp_dictoffset == 0 && b->tp_dictoffset) if (t->tp_dictoffset == 0 && b->tp_dictoffset)
{ {
__Pyx_TypeName t_name = __Pyx_PyType_GetName(t);
__Pyx_TypeName b_name = __Pyx_PyType_GetName(b);
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"extension type '%.200s' has no __dict__ slot, but base type '%.200s' has: " "extension type '" __Pyx_FMT_TYPENAME "' has no __dict__ slot, "
"but base type '" __Pyx_FMT_TYPENAME "' has: "
"either add 'cdef dict __dict__' to the extension type " "either add 'cdef dict __dict__' to the extension type "
"or add '__slots__ = [...]' to the base type", "or add '__slots__ = [...]' to the base type",
t->tp_name, b->tp_name); t_name, b_name);
__Pyx_DECREF_TypeName(t_name);
__Pyx_DECREF_TypeName(b_name);
return -1; return -1;
} }
} }
...@@ -309,8 +316,13 @@ static int __Pyx_setup_reduce(PyObject* type_obj) { ...@@ -309,8 +316,13 @@ static int __Pyx_setup_reduce(PyObject* type_obj) {
goto __PYX_GOOD; goto __PYX_GOOD;
__PYX_BAD: __PYX_BAD:
if (!PyErr_Occurred()) if (!PyErr_Occurred()) {
PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", __Pyx_PyType_Name(type_obj)); __Pyx_TypeName type_obj_name =
__Pyx_PyType_GetName((PyTypeObject*)type_obj);
PyErr_Format(PyExc_RuntimeError,
"Unable to initialize pickling for " __Pyx_FMT_TYPENAME, type_obj_name);
__Pyx_DECREF_TypeName(type_obj_name);
}
ret = -1; ret = -1;
__PYX_GOOD: __PYX_GOOD:
#if !CYTHON_USE_PYTYPE_LOOKUP #if !CYTHON_USE_PYTYPE_LOOKUP
......
...@@ -11,6 +11,8 @@ static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *nam ...@@ -11,6 +11,8 @@ static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *nam
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact)
{ {
__Pyx_TypeName type_name;
__Pyx_TypeName obj_type_name;
if (unlikely(!type)) { if (unlikely(!type)) {
PyErr_SetString(PyExc_SystemError, "Missing type object"); PyErr_SetString(PyExc_SystemError, "Missing type object");
return 0; return 0;
...@@ -23,9 +25,13 @@ static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *nam ...@@ -23,9 +25,13 @@ static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *nam
else { else {
if (likely(__Pyx_TypeCheck(obj, type))) return 1; if (likely(__Pyx_TypeCheck(obj, type))) return 1;
} }
type_name = __Pyx_PyType_GetName(type);
obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"Argument '%.200s' has incorrect type (expected %.200s, got %.200s)", "Argument '%.200s' has incorrect type (expected " __Pyx_FMT_TYPENAME
name, type->tp_name, Py_TYPE(obj)->tp_name); ", got " __Pyx_FMT_TYPENAME ")", name, type_name, obj_type_name);
__Pyx_DECREF_TypeName(type_name);
__Pyx_DECREF_TypeName(obj_type_name);
return 0; return 0;
} }
...@@ -111,7 +117,10 @@ static void __Pyx_RaiseMappingExpectedError(PyObject* arg); /*proto*/ ...@@ -111,7 +117,10 @@ static void __Pyx_RaiseMappingExpectedError(PyObject* arg); /*proto*/
//////////////////// RaiseMappingExpected //////////////////// //////////////////// RaiseMappingExpected ////////////////////
static void __Pyx_RaiseMappingExpectedError(PyObject* arg) { static void __Pyx_RaiseMappingExpectedError(PyObject* arg) {
PyErr_Format(PyExc_TypeError, "'%.200s' object is not a mapping", Py_TYPE(arg)->tp_name); __Pyx_TypeName arg_type_name = __Pyx_PyType_GetName(Py_TYPE(arg));
PyErr_Format(PyExc_TypeError,
"'" __Pyx_FMT_TYPENAME "' object is not a mapping", arg_type_name);
__Pyx_DECREF_TypeName(arg_type_name);
} }
......
...@@ -756,6 +756,8 @@ static int __Pyx_MergeVtables(PyTypeObject *type); /*proto*/ ...@@ -756,6 +756,8 @@ static int __Pyx_MergeVtables(PyTypeObject *type); /*proto*/
static int __Pyx_MergeVtables(PyTypeObject *type) { static int __Pyx_MergeVtables(PyTypeObject *type) {
int i; int i;
void** base_vtables; void** base_vtables;
__Pyx_TypeName tp_base_name;
__Pyx_TypeName base_name;
void* unknown = (void*)-1; void* unknown = (void*)-1;
PyObject* bases = type->tp_bases; PyObject* bases = type->tp_bases;
int base_depth = 0; int base_depth = 0;
...@@ -798,10 +800,12 @@ static int __Pyx_MergeVtables(PyTypeObject *type) { ...@@ -798,10 +800,12 @@ static int __Pyx_MergeVtables(PyTypeObject *type) {
free(base_vtables); free(base_vtables);
return 0; return 0;
bad: bad:
PyErr_Format( tp_base_name = __Pyx_PyType_GetName(type->tp_base);
PyExc_TypeError, base_name = __Pyx_PyType_GetName((PyTypeObject*)PyTuple_GET_ITEM(bases, i));
"multiple bases have vtable conflict: '%s' and '%s'", PyErr_Format(PyExc_TypeError,
type->tp_base->tp_name, ((PyTypeObject*)PyTuple_GET_ITEM(bases, i))->tp_name); "multiple bases have vtable conflict: '" __Pyx_FMT_TYPENAME "' and '" __Pyx_FMT_TYPENAME "'", tp_base_name, base_name);
__Pyx_DECREF_TypeName(tp_base_name);
__Pyx_DECREF_TypeName(base_name);
free(base_vtables); free(base_vtables);
return -1; return -1;
} }
......
...@@ -704,14 +704,8 @@ static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict, ...@@ -704,14 +704,8 @@ static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict,
/* Type slots */ /* Type slots */
#if CYTHON_COMPILING_IN_LIMITED_API #if CYTHON_COMPILING_IN_LIMITED_API
#if defined(_PyType_Name)
#define __Pyx_PyType_Name(tp) (_PyType_Name((PyTypeObject *)tp))
#else
#define __Pyx_PyType_Name(tp) (((PyTypeObject *)tp)->tp_name)
#endif
#define __Pyx_PyType_GetFlags(tp) (PyType_GetFlags((PyTypeObject *)tp)) #define __Pyx_PyType_GetFlags(tp) (PyType_GetFlags((PyTypeObject *)tp))
#else #else
#define __Pyx_PyType_Name(tp) (((PyTypeObject *)tp)->tp_name)
#define __Pyx_PyType_GetFlags(tp) (((PyTypeObject *)tp)->tp_flags) #define __Pyx_PyType_GetFlags(tp) (((PyTypeObject *)tp)->tp_flags)
#endif #endif
...@@ -901,7 +895,6 @@ static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict, ...@@ -901,7 +895,6 @@ static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict,
} __Pyx_PyAsyncMethodsStruct; } __Pyx_PyAsyncMethodsStruct;
#endif #endif
/////////////// SmallCodeConfig.proto /////////////// /////////////// SmallCodeConfig.proto ///////////////
#ifndef CYTHON_SMALL_CODE #ifndef CYTHON_SMALL_CODE
......
This diff is collapsed.
...@@ -609,9 +609,11 @@ static double __Pyx__PyObject_AsDouble(PyObject* obj) { ...@@ -609,9 +609,11 @@ static double __Pyx__PyObject_AsDouble(PyObject* obj) {
if (likely(nb) && likely(nb->nb_float)) { if (likely(nb) && likely(nb->nb_float)) {
float_value = nb->nb_float(obj); float_value = nb->nb_float(obj);
if (likely(float_value) && unlikely(!PyFloat_Check(float_value))) { if (likely(float_value) && unlikely(!PyFloat_Check(float_value))) {
__Pyx_TypeName float_value_type_name = __Pyx_PyType_GetName(Py_TYPE(float_value));
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"__float__ returned non-float (type %.200s)", "__float__ returned non-float (type " __Pyx_FMT_TYPENAME ")",
Py_TYPE(float_value)->tp_name); float_value_type_name);
__Pyx_DECREF_TypeName(float_value_type_name);
Py_DECREF(float_value); Py_DECREF(float_value);
goto bad; goto bad;
} }
......
...@@ -314,23 +314,27 @@ static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { ...@@ -314,23 +314,27 @@ static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
} }
static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
__Pyx_TypeName result_type_name = __Pyx_PyType_GetName(Py_TYPE(result));
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
if (PyLong_Check(result)) { if (PyLong_Check(result)) {
// CPython issue #17576: warn if 'result' not of exact type int. // CPython issue #17576: warn if 'result' not of exact type int.
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
"__int__ returned non-int (type %.200s). " "__int__ returned non-int (type " __Pyx_FMT_TYPENAME "). "
"The ability to return an instance of a strict subclass of int " "The ability to return an instance of a strict subclass of int is deprecated, "
"is deprecated, and may be removed in a future version of Python.", "and may be removed in a future version of Python.",
__Pyx_PyType_Name(Py_TYPE(result)))) { result_type_name)) {
__Pyx_DECREF_TypeName(result_type_name);
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;
} }
__Pyx_DECREF_TypeName(result_type_name);
return result; return result;
} }
#endif #endif
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"__%.4s__ returned non-%.4s (type %.200s)", "__%.4s__ returned non-%.4s (type " __Pyx_FMT_TYPENAME ")",
type_name, type_name, __Pyx_PyType_Name(Py_TYPE(result))); type_name, type_name, result_type_name);
__Pyx_DECREF_TypeName(result_type_name);
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;
} }
...@@ -492,7 +496,10 @@ static {{struct_type_decl}} {{funcname}}(PyObject * o) { ...@@ -492,7 +496,10 @@ static {{struct_type_decl}} {{funcname}}(PyObject * o) {
{{struct_type_decl}} result; {{struct_type_decl}} result;
if (!PyTuple_Check(o) || PyTuple_GET_SIZE(o) != {{size}}) { if (!PyTuple_Check(o) || PyTuple_GET_SIZE(o) != {{size}}) {
PyErr_Format(PyExc_TypeError, "Expected %.16s of size %d, got %.200s", "a tuple", {{size}}, Py_TYPE(o)->tp_name); __Pyx_TypeName o_type_name = __Pyx_PyType_GetName(Py_TYPE(o));
PyErr_Format(PyExc_TypeError,
"Expected a tuple of size %d, got " __Pyx_FMT_TYPENAME, {{size}}, o_type_name);
__Pyx_DECREF_TypeName(o_type_name);
goto bad; goto bad;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment