[pypy-svn] r34201 - in pypy/branch/refactor-file/pypy: module/_file rlib

cfbolz at codespeak.net cfbolz at codespeak.net
Sat Nov 4 18:12:58 CET 2006


Author: cfbolz
Date: Sat Nov  4 18:12:56 2006
New Revision: 34201

Modified:
   pypy/branch/refactor-file/pypy/module/_file/interp_file.py
   pypy/branch/refactor-file/pypy/rlib/streamio.py
Log:
(guido, cfbolz): don't use *args to try to not confuse the rtyper (more
specifically the call normalization). thanks samuele.


Modified: pypy/branch/refactor-file/pypy/module/_file/interp_file.py
==============================================================================
--- pypy/branch/refactor-file/pypy/module/_file/interp_file.py	(original)
+++ pypy/branch/refactor-file/pypy/module/_file/interp_file.py	Sat Nov  4 18:12:56 2006
@@ -23,25 +23,11 @@
     return OperationError(space.w_IOError, w_error)
 
 
-EXPOSED_STREAM_METHODS = [
-    ("read", [int]),
-    ("write", [str]),
-    ("tell", []),
-    ("seek", [int, int]),
-    ("readall", []),
-    ("readline", []),
-    ("truncate", [int]),
-    ("flush", []),
-    ("close", []),
-    ("peek", []),
-    ("try_to_find_file_descriptor", []),
-    ]
-
 class W_Stream(Wrappable):
     def __init__(self, space, stream):
         self.stream = stream
 
-for name, argtypes in EXPOSED_STREAM_METHODS:
+for name, argtypes in streamio.STREAM_METHODS:
     numargs = len(argtypes)
     args = ", ".join(["v%s" % i for i in range(numargs)])
     exec py.code.Source("""
@@ -58,7 +44,7 @@
 
 W_Stream.typedef = TypeDef("Stream",
     **dict([(name, interp2app(globals()[name]))
-                for name, _ in EXPOSED_STREAM_METHODS]))
+                for name, _ in streamio.STREAM_METHODS]))
 
 
 def is_mode_ok(space, mode):

Modified: pypy/branch/refactor-file/pypy/rlib/streamio.py
==============================================================================
--- pypy/branch/refactor-file/pypy/rlib/streamio.py	(original)
+++ pypy/branch/refactor-file/pypy/rlib/streamio.py	Sat Nov  4 18:12:56 2006
@@ -340,19 +340,37 @@
 
 # ____________________________________________________________
 
+STREAM_METHODS = [
+    ("read", [int]),
+    ("write", [str]),
+    ("tell", []),
+    ("seek", [int, int]),
+    ("readall", []),
+    ("readline", []),
+    ("truncate", [int]),
+    ("flush", []),
+    ("close", []),
+    ("peek", []),
+    ("try_to_find_file_descriptor", []),
+    ]
 
 def PassThrough(meth_name, flush_buffers):
+    if meth_name in STREAM_METHODS:
+        signature = STREAM_METHODS[meth_name]
+        args = ", ".join(["v%s" % (i, ) for i in range(len(signature))])
+    else:
+        args = "*args"
     if flush_buffers:
-        code = """def %s(self, *args):
+        code = """def %s(self, %s):
                       self.flush_buffers()
-                      return self.base.%s(*args)
+                      return self.base.%s(%s)
 """
     else:
-        code = """def %s(self, *args):
-                      return self.base.%s(*args)
+        code = """def %s(self, %s):
+                      return self.base.%s(%s)
 """
     d = {}
-    exec code % (meth_name, meth_name) in d
+    exec code % (meth_name, args, meth_name, args) in d
     return d[meth_name]
 
 



More information about the Pypy-commit mailing list