[Numpy-svn] r8710 - branches/1.5.x/numpy/core/include/numpy

numpy-svn@scip... numpy-svn@scip...
Sat Sep 11 13:13:18 CDT 2010


Author: ptvirtan
Date: 2010-09-11 13:13:17 -0500 (Sat, 11 Sep 2010)
New Revision: 8710

Modified:
   branches/1.5.x/numpy/core/include/numpy/npy_3kcompat.h
Log:
BUG: (backport r8709) core: fix npy_PyFile_Check implementation on Py3

Modified: branches/1.5.x/numpy/core/include/numpy/npy_3kcompat.h
===================================================================
--- branches/1.5.x/numpy/core/include/numpy/npy_3kcompat.h	2010-09-11 18:11:57 UTC (rev 8709)
+++ branches/1.5.x/numpy/core/include/numpy/npy_3kcompat.h	2010-09-11 18:13:17 UTC (rev 8710)
@@ -227,25 +227,16 @@
     return 0;
 }
 
-static int
+static NPY_INLINE int
 npy_PyFile_Check(PyObject *file)
 {
-    static PyTypeObject *fileio = NULL;
-
-    if (fileio == NULL) {
-        PyObject *mod;
-        mod = PyImport_ImportModule("io");
-        if (mod == NULL) {
-            return 0;
-        }
-        fileio = (PyTypeObject*)PyObject_GetAttrString(mod, "FileIO");
-        Py_DECREF(mod);
+    int fd;
+    fd = PyObject_AsFileDescriptor(file);
+    if (fd == -1) {
+        PyErr_Clear();
+        return 0;
     }
-
-    if (fileio != NULL) {
-        return PyObject_TypeCheck(file, fileio);
-    }
-    return 0;
+    return 1;
 }
 
 #else



More information about the Numpy-svn mailing list