[Numpy-svn] r8709 - trunk/numpy/core/include/numpy

numpy-svn at scipy.org numpy-svn at scipy.org
Sat Sep 11 14:11:57 EDT 2010


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

Modified:
   trunk/numpy/core/include/numpy/npy_3kcompat.h
Log:
BUG: core: fix npy_PyFile_Check implementation on Py3

Modified: trunk/numpy/core/include/numpy/npy_3kcompat.h
===================================================================
--- trunk/numpy/core/include/numpy/npy_3kcompat.h	2010-09-11 17:05:45 UTC (rev 8708)
+++ trunk/numpy/core/include/numpy/npy_3kcompat.h	2010-09-11 18:11:57 UTC (rev 8709)
@@ -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