[pypy-commit] pypy default: Make getwindowsversion return a sructseq, rather than a tuple. (untested, not ata windows machine)

alex_gaynor noreply at buildbot.pypy.org
Fri Sep 9 18:00:31 CEST 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r47189:101130586a1a
Date: 2011-09-09 09:00 -0700
http://bitbucket.org/pypy/pypy/changeset/101130586a1a/

Log:	Make getwindowsversion return a sructseq, rather than a tuple.
	(untested, not ata windows machine)

diff --git a/pypy/module/sys/test/test_sysmodule.py b/pypy/module/sys/test/test_sysmodule.py
--- a/pypy/module/sys/test/test_sysmodule.py
+++ b/pypy/module/sys/test/test_sysmodule.py
@@ -6,11 +6,11 @@
 import sys
 
 def test_stdin_exists(space):
-    space.sys.get('stdin') 
+    space.sys.get('stdin')
     space.sys.get('__stdin__')
 
 def test_stdout_exists(space):
-    space.sys.get('stdout') 
+    space.sys.get('stdout')
     space.sys.get('__stdout__')
 
 class AppTestAppSysTests:
@@ -25,7 +25,7 @@
         assert 'sys' in modules, ( "An entry for sys "
                                         "is not in sys.modules.")
         sys2 = sys.modules['sys']
-        assert sys is sys2, "import sys is not sys.modules[sys]." 
+        assert sys is sys2, "import sys is not sys.modules[sys]."
     def test_builtin_in_modules(self):
         import sys
         modules = sys.modules
@@ -89,12 +89,12 @@
         else:
             raise AssertionError, "ZeroDivisionError not caught"
 
-    def test_io(self): 
+    def test_io(self):
         import sys
         assert isinstance(sys.__stdout__, file)
         assert isinstance(sys.__stderr__, file)
         assert isinstance(sys.__stdin__, file)
-    
+
         if self.appdirect and not isinstance(sys.stdin, file):
             return
 
@@ -324,7 +324,7 @@
         import sys
         if self.appdirect:
             skip("not worth running appdirect")
-            
+
         encoding = sys.getdefaultencoding()
         try:
             sys.setdefaultencoding("ascii")
@@ -334,11 +334,11 @@
             sys.setdefaultencoding("latin-1")
             assert sys.getdefaultencoding() == 'latin-1'
             assert unicode('\x80') == u'\u0080'
-            
+
         finally:
             sys.setdefaultencoding(encoding)
 
-            
+
     # testing sys.settrace() is done in test_trace.py
     # testing sys.setprofile() is done in test_profile.py
 
@@ -372,6 +372,16 @@
             assert isinstance(v[3], int)
             assert isinstance(v[4], str)
 
+            assert v[0] == v.major
+            assert v[1] == v.minor
+            assert v[2] == v.build
+            assert v[3] == v.platform
+            assert v[4] == v.service_pack
+
+            # This is how platform.py calls it. Make sure tuple still has 5
+            # elements
+            maj, min, buildno, plat, csd = sys.getwindowsversion()
+
     def test_winver(self):
         import sys
         if hasattr(sys, "winver"):
@@ -564,7 +574,7 @@
                 if self.ready: break
                 time.sleep(0.1)
             return sys._current_frames()
-        
+
         frames = f()
         thisframe = frames.pop(thread_id)
         assert thisframe.f_code.co_name == 'f'
diff --git a/pypy/module/sys/vm.py b/pypy/module/sys/vm.py
--- a/pypy/module/sys/vm.py
+++ b/pypy/module/sys/vm.py
@@ -1,11 +1,13 @@
 """
 Implementation of interpreter-level 'sys' routines.
 """
+import sys
+
+from pypy.interpreter import gateway
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.gateway import unwrap_spec, NoneNotWrapped
+from pypy.rlib import jit
 from pypy.rlib.runicode import MAXUNICODE
-from pypy.rlib import jit
-import sys
 
 # ____________________________________________________________
 
@@ -58,7 +60,7 @@
         space.setitem(w_result,
                       space.wrap(thread_ident),
                       space.wrap(f))
-    return w_result                      
+    return w_result
 
 def setrecursionlimit(space, w_new_limit):
     """setrecursionlimit() sets the maximum number of nested calls that
@@ -124,7 +126,7 @@
     """Set the global debug tracing function.  It will be called on each
 function call.  See the debugger chapter in the library manual."""
     space.getexecutioncontext().settrace(w_func)
-    
+
 def setprofile(space, w_func):
     """Set the profiling function.  It will be called on each function call
 and return.  See the profiler chapter in the library manual."""
@@ -145,14 +147,35 @@
 a debugger from a checkpoint, to recursively debug some other code."""
     return space.getexecutioncontext().call_tracing(w_func, w_args)
 
+
+app = gateway.applevel('''
+"NOT_RPYTHON"
+from _structseq import structseqtype, structseqfield
+
+class windows_version_info:
+    __metaclass__ = structseqtype
+
+    name = "sys.getwindowsversion"
+
+    major = structseqfield(0, "Major version number")
+    minor = structseqfield(1, "Minor version number")
+    build = structseqfield(2, "Build number")
+    platform = structseqfield(3, "Operating system platform")
+    service_pack = structseqfield(4, "Latest Service Pack installed on the system")
+''')
+
 def getwindowsversion(space):
     from pypy.rlib import rwin32
     info = rwin32.GetVersionEx()
-    return space.newtuple([space.wrap(info[0]),
-                           space.wrap(info[1]),
-                           space.wrap(info[2]),
-                           space.wrap(info[3]),
-                           space.wrap(info[4])])
+    w_windows_version_info = app.wget(space, "windows_version_info")
+    raw_version = space.newtuple([
+        space.wrap(info[0]),
+        space.wrap(info[1]),
+        space.wrap(info[2]),
+        space.wrap(info[3]),
+        space.wrap(info[4])
+    ])
+    return space.call_function(w_windows_version_info, raw_version)
 
 @jit.dont_look_inside
 def get_dllhandle(space):


More information about the pypy-commit mailing list