[Python-checkins] r67817 - sandbox/trunk/io-c/io.c

amaury.forgeotdarc python-checkins at python.org
Tue Dec 16 23:41:40 CET 2008


Author: amaury.forgeotdarc
Date: Tue Dec 16 23:41:40 2008
New Revision: 67817

Log:
These objects are directly accessible from C, no need to import another module


Modified:
   sandbox/trunk/io-c/io.c

Modified: sandbox/trunk/io-c/io.c
==============================================================================
--- sandbox/trunk/io-c/io.c	(original)
+++ sandbox/trunk/io-c/io.c	Tue Dec 16 23:41:40 2008
@@ -257,7 +257,6 @@
     int reading = 0, writing = 0, appending = 0, updating = 0;
     int text = 0, binary = 0, universal = 0;
 
-    PyObject *FileIO_class;
     char rawmode[5], *m;
     int line_buffering, isatty;
 
@@ -365,12 +364,8 @@
     }
 
     /* Create the Raw file stream */
-    FileIO_class = PyObject_GetAttrString(io_py_module, "FileIO");
-    if (!FileIO_class)
-        return NULL;
-
-    raw = PyObject_CallFunction(FileIO_class, "Osi", file, rawmode, closefd);
-    Py_DECREF(FileIO_class);
+    raw = PyObject_CallFunction((PyObject *)&PyFileIO_Type,
+				"Osi", file, rawmode, closefd);
     if (raw == NULL)
         return NULL;
 
@@ -436,28 +431,21 @@
 
     /* wraps into a buffered file */
     {
-        char *Buffered_class_name;
         PyObject *Buffered_class;
 
         if (updating)
-            Buffered_class_name = "BufferedRandom";
+	    Buffered_class = (PyObject *)&PyBufferedRandom_Type;
         else if (writing || appending)
-            Buffered_class_name = "BufferedWriter";
+            Buffered_class = (PyObject *)&PyBufferedWriter_Type;
         else if (reading)
-            Buffered_class_name = "BufferedReader";
+            Buffered_class = (PyObject *)&PyBufferedReader_Type;
         else {
             PyErr_Format(PyExc_ValueError,
                          "unknown mode: '%s'", mode);
             goto error;
         }
 
-        Buffered_class = PyObject_GetAttrString(io_py_module,
-                                                Buffered_class_name);
-        if (Buffered_class == NULL)
-            goto error;
-
         buffer = PyObject_CallFunction(Buffered_class, "Oi", raw, buffering);
-        Py_DECREF(Buffered_class);
     }
     Py_CLEAR(raw);
     if (buffer == NULL)


More information about the Python-checkins mailing list