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):
type_test = self.type.type_test_code(
self.arg.py_result(),
self.notnone, exact=self.exact_builtin_type)
code.globalstate.use_utility_code(UtilityCode.load_cached(
"RaiseUnexpectedTypeError", "ObjectHandling.c"))
else:
type_test = self.type.type_test_code(
self.arg.py_result(), self.notnone)
......
......@@ -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_FromStringAndSize __Pyx_Py%s_FromStringAndSize' % c_string_func_name)
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.
PyrexTypes.c_long_type.create_to_py_utility_code(env)
......@@ -1865,6 +1866,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln(
"static int %s(PyObject *o, PyObject *i, PyObject *v) {" % (
scope.mangle_internal("mp_ass_subscript")))
code.putln(
"__Pyx_TypeName o_type_name;")
code.putln(
"if (v) {")
if set_entry:
......@@ -1872,10 +1875,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
else:
self.generate_guarded_basetype_call(
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(
"PyErr_Format(PyExc_NotImplementedError,")
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(
"return -1;")
code.putln(
......@@ -1889,10 +1896,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
else:
self.generate_guarded_basetype_call(
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(
"PyErr_Format(PyExc_NotImplementedError,")
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(
"return -1;")
code.putln(
......@@ -1930,6 +1941,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln(
"static int %s(PyObject *o, Py_ssize_t i, Py_ssize_t j, PyObject *v) {" % (
scope.mangle_internal("sq_ass_slice")))
code.putln(
"__Pyx_TypeName o_type_name;")
code.putln(
"if (v) {")
if set_entry:
......@@ -1939,10 +1952,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
else:
self.generate_guarded_basetype_call(
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(
"PyErr_Format(PyExc_NotImplementedError,")
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(
"return -1;")
code.putln(
......@@ -1956,10 +1973,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
else:
self.generate_guarded_basetype_call(
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(
"PyErr_Format(PyExc_NotImplementedError,")
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(
"return -1;")
code.putln(
......
......@@ -5149,9 +5149,13 @@ class CClassDefNode(ClassDefNode):
code.put_gotref(trial_type, py_object_type)
code.putln("if (((PyTypeObject*) %s)->tp_base != %s) {" % (
trial_type, first_base))
code.putln("PyErr_Format(PyExc_TypeError, \"best base '%s' must be equal to first base '%s'\",")
code.putln(" ((PyTypeObject*) %s)->tp_base->tp_name, %s->tp_name);" % (
trial_type, first_base))
code.putln("__Pyx_TypeName base_name = __Pyx_PyType_GetName(((PyTypeObject*) %s)->tp_base);" % trial_type)
code.putln("__Pyx_TypeName type_name = __Pyx_PyType_GetName(%s);" % 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.funcstate.release_temp(trial_type)
......
......@@ -1442,14 +1442,9 @@ class BuiltinObjectType(PyObjectType):
check += '||((%s) == Py_None)' % arg
if self.name == 'basestring':
name = '(PY_MAJOR_VERSION < 3 ? "basestring" : "str")'
space_for_name = 16
else:
name = '"%s"' % self.name
# avoid wasting too much space but limit number of different format strings
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
return check + ' || __Pyx_RaiseUnexpectedTypeError(%s, %s)' % (name, arg)
def declaration_code(self, entity_code,
for_display = 0, dll_linkage = None, pyrex = 0):
......@@ -3587,6 +3582,7 @@ class CStructOrUnionType(CType):
var_entries=self.scope.var_entries,
funcname=self.from_py_function,
)
env.use_utility_code(UtilityCode.load_cached("RaiseUnexpectedTypeError", "ObjectHandling.c"))
from .UtilityCode import CythonUtilityCode
self._convert_from_py_code = CythonUtilityCode.load(
"FromPyStructUtility" if self.is_struct else "FromPyUnionUtility",
......
......@@ -111,6 +111,7 @@ typedef struct {
#if PY_MAJOR_VERSION < 3
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);
{{for type_ptr, getbuffer, releasebuffer in types}}
......@@ -119,7 +120,11 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
{{endif}}
{{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;
}
......
......@@ -69,8 +69,12 @@ static PyObject* __Pyx_PyExec3(PyObject* o, PyObject* globals, PyObject* locals)
if (!globals || globals == Py_None) {
globals = $moddict_cname;
} else if (unlikely(!PyDict_Check(globals))) {
PyErr_Format(PyExc_TypeError, "exec() arg 2 must be a dict, not %.200s",
Py_TYPE(globals)->tp_name);
__Pyx_TypeName globals_type_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;
}
if (!locals || locals == Py_None) {
......@@ -106,9 +110,11 @@ static PyObject* __Pyx_PyExec3(PyObject* o, PyObject* globals, PyObject* locals)
#else
} else if (unlikely(!PyString_Check(o))) {
#endif
__Pyx_TypeName o_type_name = __Pyx_PyType_GetName(Py_TYPE(o));
PyErr_Format(PyExc_TypeError,
"exec: arg 1 must be string, bytes or code object, got %.200s",
Py_TYPE(o)->tp_name);
"exec: arg 1 must be string, bytes or code object, got " __Pyx_FMT_TYPENAME,
o_type_name);
__Pyx_DECREF_TypeName(o_type_name);
goto bad;
}
#if PY_MAJOR_VERSION >= 3
......@@ -194,11 +200,12 @@ static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
static PyObject* __Pyx_Intern(PyObject* s); /* proto */
//////////////////// Intern ////////////////////
//@requires: ObjectHandling.c::RaiseUnexpectedTypeError
static PyObject* __Pyx_Intern(PyObject* s) {
if (unlikely(!PyString_CheckExact(s))) {
PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(s)->tp_name);
return 0;
__Pyx_RaiseUnexpectedTypeError("str", s);
return NULL;
}
Py_INCREF(s);
#if PY_MAJOR_VERSION >= 3
......@@ -307,8 +314,11 @@ static long __Pyx__PyObject_Ord(PyObject* c) {
#endif
} else {
// 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,
"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;
}
PyErr_Format(PyExc_TypeError,
......
......@@ -6,12 +6,13 @@ cdef extern from *:
PyTypeObject *Py_TYPE(obj)
bint PyMapping_Check(obj)
object PyErr_Format(exc, const char *format, ...)
int __Pyx_RaiseUnexpectedTypeError(const char *expected, object obj) except 0
@cname("{{funcname}}")
cdef {{struct_type}} {{funcname}}(obj) except *:
cdef {{struct_type}} result
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:}}
try:
......@@ -31,13 +32,14 @@ cdef extern from *:
PyTypeObject *Py_TYPE(obj)
bint PyMapping_Check(obj)
object PyErr_Format(exc, const char *format, ...)
int __Pyx_RaiseUnexpectedTypeError(const char *expected, object obj) except 0
@cname("{{funcname}}")
cdef {{struct_type}} {{funcname}}(obj) except *:
cdef {{struct_type}} result
cdef Py_ssize_t length
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
length = len(obj)
......
......@@ -7,9 +7,10 @@ static CYTHON_INLINE PyObject* __Pyx_Generator_Yield_From(__pyx_CoroutineObject
#if CYTHON_USE_TYPE_SLOTS
static void __Pyx_PyIter_CheckErrorAndDecref(PyObject *source) {
__Pyx_TypeName source_type_name = __Pyx_PyType_GetName(Py_TYPE(source));
PyErr_Format(PyExc_TypeError,
"iter() returned non-iterator of type '%.100s'",
Py_TYPE(source)->tp_name);
"iter() returned non-iterator of type '" __Pyx_FMT_TYPENAME "'", source_type_name);
__Pyx_DECREF_TypeName(source_type_name);
Py_DECREF(source);
}
#endif
......@@ -138,13 +139,13 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAwaitableIter(PyObject *o) {
static void __Pyx_Coroutine_AwaitableIterError(PyObject *source) {
#if PY_VERSION_HEX >= 0x030600B3 || defined(_PyErr_FormatFromCause)
_PyErr_FormatFromCause(
PyExc_TypeError,
"'async for' received an invalid object "
"from __anext__: %.100s",
Py_TYPE(source)->tp_name);
__Pyx_TypeName source_type_name = __Pyx_PyType_GetName(Py_TYPE(source));
_PyErr_FormatFromCause(PyExc_TypeError,
"'async for' received an invalid object from __anext__: " __Pyx_FMT_TYPENAME, source_type_name);
__Pyx_DECREF_TypeName(source_type_name);
#elif PY_MAJOR_VERSION >= 3
PyObject *exc, *val, *val2, *tb;
__Pyx_TypeName source_type_name = __Pyx_PyType_GetName(Py_TYPE(source));
assert(PyErr_Occurred());
PyErr_Fetch(&exc, &val, &tb);
PyErr_NormalizeException(&exc, &val, &tb);
......@@ -154,11 +155,9 @@ static void __Pyx_Coroutine_AwaitableIterError(PyObject *source) {
}
Py_DECREF(exc);
assert(!PyErr_Occurred());
PyErr_Format(
PyExc_TypeError,
"'async for' received an invalid object "
"from __anext__: %.100s",
Py_TYPE(source)->tp_name);
PyErr_Format(PyExc_TypeError,
"'async for' received an invalid object from __anext__: " __Pyx_FMT_TYPENAME, source_type_name);
__Pyx_DECREF_TypeName(source_type_name);
PyErr_Fetch(&exc, &val2, &tb);
PyErr_NormalizeException(&exc, &val2, &tb);
......@@ -209,9 +208,10 @@ static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *obj) {
goto bad;
}
if (unlikely(!PyIter_Check(res))) {
__Pyx_TypeName res_type_name = __Pyx_PyType_GetName(Py_TYPE(res));
PyErr_Format(PyExc_TypeError,
"__await__() returned non-iterator of type '%.100s'",
Py_TYPE(res)->tp_name);
"__await__() returned non-iterator of type '" __Pyx_FMT_TYPENAME "'", res_type_name);
__Pyx_DECREF_TypeName(res_type_name);
Py_CLEAR(res);
} else {
int is_coroutine = 0;
......@@ -231,9 +231,12 @@ static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *obj) {
}
return res;
slot_error:
{
__Pyx_TypeName obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
PyErr_Format(PyExc_TypeError,
"object %.100s can't be used in 'await' expression",
Py_TYPE(obj)->tp_name);
"object " __Pyx_FMT_TYPENAME " can't be used in 'await' expression", obj_type_name);
__Pyx_DECREF_TypeName(obj_type_name);
}
bad:
return NULL;
}
......@@ -249,6 +252,7 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_AsyncIterNext(PyObject *o); /*pro
//@requires: ObjectHandling.c::PyObjectCallMethod0
static PyObject *__Pyx_Coroutine_GetAsyncIter_Generic(PyObject *obj) {
__Pyx_TypeName obj_type_name;
#if PY_VERSION_HEX < 0x030500B1
{
PyObject *iter = __Pyx_PyObject_CallMethod0(obj, PYIDENT("__aiter__"));
......@@ -263,8 +267,10 @@ static PyObject *__Pyx_Coroutine_GetAsyncIter_Generic(PyObject *obj) {
if ((0)) (void) __Pyx_PyObject_CallMethod0(obj, PYIDENT("__aiter__"));
#endif
PyErr_Format(PyExc_TypeError, "'async for' requires an object with __aiter__ method, got %.100s",
Py_TYPE(obj)->tp_name);
obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
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;
}
......@@ -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__'
if (PyErr_ExceptionMatches(PyExc_AttributeError))
#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;
}
......
......@@ -38,17 +38,24 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
b = (PyTypeObject*)b0;
if (!__Pyx_PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE))
{
PyErr_Format(PyExc_TypeError, "base class '%.200s' is not a heap type",
b->tp_name);
__Pyx_TypeName b_name = __Pyx_PyType_GetName(b);
PyErr_Format(PyExc_TypeError,
"base class '" __Pyx_FMT_TYPENAME "' is not a heap type", b_name);
__Pyx_DECREF_TypeName(b_name);
return -1;
}
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,
"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 "
"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;
}
}
......@@ -309,8 +316,13 @@ static int __Pyx_setup_reduce(PyObject* type_obj) {
goto __PYX_GOOD;
__PYX_BAD:
if (!PyErr_Occurred())
PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", __Pyx_PyType_Name(type_obj));
if (!PyErr_Occurred()) {
__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;
__PYX_GOOD:
#if !CYTHON_USE_PYTYPE_LOOKUP
......
......@@ -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)
{
__Pyx_TypeName type_name;
__Pyx_TypeName obj_type_name;
if (unlikely(!type)) {
PyErr_SetString(PyExc_SystemError, "Missing type object");
return 0;
......@@ -23,9 +25,13 @@ static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *nam
else {
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,
"Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
name, type->tp_name, Py_TYPE(obj)->tp_name);
"Argument '%.200s' has incorrect type (expected " __Pyx_FMT_TYPENAME
", got " __Pyx_FMT_TYPENAME ")", name, type_name, obj_type_name);
__Pyx_DECREF_TypeName(type_name);
__Pyx_DECREF_TypeName(obj_type_name);
return 0;
}
......@@ -111,7 +117,10 @@ static void __Pyx_RaiseMappingExpectedError(PyObject* arg); /*proto*/
//////////////////// RaiseMappingExpected ////////////////////
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*/
static int __Pyx_MergeVtables(PyTypeObject *type) {
int i;
void** base_vtables;
__Pyx_TypeName tp_base_name;
__Pyx_TypeName base_name;
void* unknown = (void*)-1;
PyObject* bases = type->tp_bases;
int base_depth = 0;
......@@ -798,10 +800,12 @@ static int __Pyx_MergeVtables(PyTypeObject *type) {
free(base_vtables);
return 0;
bad:
PyErr_Format(
PyExc_TypeError,
"multiple bases have vtable conflict: '%s' and '%s'",
type->tp_base->tp_name, ((PyTypeObject*)PyTuple_GET_ITEM(bases, i))->tp_name);
tp_base_name = __Pyx_PyType_GetName(type->tp_base);
base_name = __Pyx_PyType_GetName((PyTypeObject*)PyTuple_GET_ITEM(bases, i));
PyErr_Format(PyExc_TypeError,
"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);
return -1;
}
......
......@@ -704,14 +704,8 @@ static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict,
/* Type slots */
#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))
#else
#define __Pyx_PyType_Name(tp) (((PyTypeObject *)tp)->tp_name)
#define __Pyx_PyType_GetFlags(tp) (((PyTypeObject *)tp)->tp_flags)
#endif
......@@ -901,7 +895,6 @@ static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict,
} __Pyx_PyAsyncMethodsStruct;
#endif
/////////////// SmallCodeConfig.proto ///////////////
#ifndef CYTHON_SMALL_CODE
......
This diff is collapsed.
......@@ -609,9 +609,11 @@ static double __Pyx__PyObject_AsDouble(PyObject* obj) {
if (likely(nb) && likely(nb->nb_float)) {
float_value = nb->nb_float(obj);
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,
"__float__ returned non-float (type %.200s)",
Py_TYPE(float_value)->tp_name);
"__float__ returned non-float (type " __Pyx_FMT_TYPENAME ")",
float_value_type_name);
__Pyx_DECREF_TypeName(float_value_type_name);
Py_DECREF(float_value);
goto bad;
}
......
......@@ -314,23 +314,27 @@ static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
}
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 (PyLong_Check(result)) {
// CPython issue #17576: warn if 'result' not of exact type int.
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
"__int__ returned non-int (type %.200s). "
"The ability to return an instance of a strict subclass of int "
"is deprecated, and may be removed in a future version of Python.",
__Pyx_PyType_Name(Py_TYPE(result)))) {
"__int__ returned non-int (type " __Pyx_FMT_TYPENAME "). "
"The ability to return an instance of a strict subclass of int is deprecated, "
"and may be removed in a future version of Python.",
result_type_name)) {
__Pyx_DECREF_TypeName(result_type_name);
Py_DECREF(result);
return NULL;
}
__Pyx_DECREF_TypeName(result_type_name);
return result;
}
#endif
PyErr_Format(PyExc_TypeError,
"__%.4s__ returned non-%.4s (type %.200s)",
type_name, type_name, __Pyx_PyType_Name(Py_TYPE(result)));
"__%.4s__ returned non-%.4s (type " __Pyx_FMT_TYPENAME ")",
type_name, type_name, result_type_name);
__Pyx_DECREF_TypeName(result_type_name);
Py_DECREF(result);
return NULL;
}
......@@ -492,7 +496,10 @@ static {{struct_type_decl}} {{funcname}}(PyObject * o) {
{{struct_type_decl}} result;
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;
}
......
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