utils.pyx (_getfd): Hack around Pyrex exception-handling bugs.
[mLib-python] / utils.pyx
index a8a4406..8d4ffad 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):