From c316167fdcbce41e8cc731e8c19cb00f53c1b9cd Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sat, 9 Sep 2017 23:17:47 +0100 Subject: [PATCH] utils.pyx (_getfd): Hack around Pyrex exception-handling bugs. Organization: Straylight/Edgeware From: Mark Wooding It seems that Pyrex has some nasty bugs here. Most obviously, it fails to cancel the exception when handling it. But even then, there's a code-generation bug around returning in an `except' block which leads to a null-pointer dereference. These are Debian #875284 and #875285. --- defs.pxi | 1 + utils.pyx | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/defs.pxi b/defs.pxi index cec2d86..b14b855 100644 --- a/defs.pxi +++ b/defs.pxi @@ -102,6 +102,7 @@ cdef extern from 'Python.h': object PyLong_FromUnsignedLong(unsigned long i) char *PyString_AS_STRING(string) int _PyString_Resize(PyObject **string, int size) except -1 + void PyErr_Clear() void Py_INCREF(PyObject *obj) void Py_DECREF(PyObject *obj) diff --git a/utils.pyx b/utils.pyx index a8a4406..8d4ffad 100644 --- a/utils.pyx +++ b/utils.pyx @@ -40,9 +40,11 @@ cdef object _tobool(int i): cdef int _getfd(object fdobj): try: - return fdobj + fd = int(fdobj) except TypeError: - return fdobj.fileno() + PyErr_Clear() + fd = fdobj.fileno() + return fd cdef object _checkcallable(f, what): if f is not None and not callable(f): -- [mdw]