From: Stefan Behnel Date: Thu, 30 Dec 2010 18:17:02 +0000 (+0100) Subject: fix strict aliasing issues for type importing code in __Pyx_GetVtable() X-Git-Tag: 0.14.1rc0~29 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=4ebbe013570592c39f4444aad1952baa0c675041;p=cython.git fix strict aliasing issues for type importing code in __Pyx_GetVtable() --- diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 65bec830..24ab14c0 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -2051,12 +2051,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.error_goto_if_null(type.typeptr_cname, pos)) self.use_type_import_utility_code(env) if type.vtabptr_cname: - code.putln( - "if (__Pyx_GetVtable(%s->tp_dict, &%s) < 0) %s" % ( - type.typeptr_cname, - type.vtabptr_cname, - code.error_goto(pos))) env.use_utility_code(Nodes.get_vtable_utility_code) + code.putln("%s = (struct %s*)__Pyx_GetVtable(%s->tp_dict); %s" % ( + type.vtabptr_cname, + type.vtabstruct_cname, + type.typeptr_cname, + code.error_goto_if_null(type.vtabptr_cname, pos))) env.types_imported[type] = 1 py3_type_name_map = {'str' : 'bytes', 'unicode' : 'str'} diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 92c051ac..32ad3efc 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -6244,25 +6244,26 @@ bad: get_vtable_utility_code = UtilityCode( proto = """ -static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/ +static void* __Pyx_GetVtable(PyObject *dict); /*proto*/ """, impl = r""" -static int __Pyx_GetVtable(PyObject *dict, void *vtabptr) { +static void* __Pyx_GetVtable(PyObject *dict) { + void* ptr; PyObject *ob = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__"); if (!ob) goto bad; #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) - *(void **)vtabptr = PyCapsule_GetPointer(ob, 0); + ptr = PyCapsule_GetPointer(ob, 0); #else - *(void **)vtabptr = PyCObject_AsVoidPtr(ob); + ptr = PyCObject_AsVoidPtr(ob); #endif - if (!*(void **)vtabptr) - goto bad; + if (!ptr && !PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type"); Py_DECREF(ob); - return 0; + return ptr; bad: Py_XDECREF(ob); - return -1; + return NULL; } """)