chiark / gitweb /
utils.pyx (_getfd): Hack around Pyrex exception-handling bugs.
[mLib-python] / utils.pyx
index a8a440667cee471823b682cc86fa6c8912c3d568..8d4ffad73268a376eaca2fa3835ac8367e29d942 100644 (file)
--- 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):