[pypy-commit] pypy py3k_add_terminal_size: get_terminal_size lib-python tests pass on windows after translation.

marky1991 pypy.commits at gmail.com
Thu Aug 25 03:36:11 EDT 2016


Author: Mark Young <marky1991 at gmail.com>
Branch: py3k_add_terminal_size
Changeset: r86523:8d4194d34b83
Date: 2016-08-24 13:37 -0400
http://bitbucket.org/pypy/pypy/changeset/8d4194d34b83/

Log:	get_terminal_size lib-python tests pass on windows after
	translation.

diff --git a/pypy/module/posix/app_posix.py b/pypy/module/posix/app_posix.py
--- a/pypy/module/posix/app_posix.py
+++ b/pypy/module/posix/app_posix.py
@@ -94,7 +94,7 @@
 
 class terminal_size(metaclass=structseqtype):
 
-    name = osname + ".terminal_size"
+    name = "os.terminal_size"
 
     columns  = structseqfield(0, "width of the terminal window in characters")
     lines = structseqfield(1, "height of the terminal window in characters")
diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -11,7 +11,7 @@
 from rpython.rlib import rposix, rposix_stat
 from rpython.rlib import objectmodel, rurandom
 from rpython.rlib.objectmodel import specialize
-from rpython.rlib.rarithmetic import r_longlong, intmask, r_uint
+from rpython.rlib.rarithmetic import r_longlong, intmask, r_uint, r_int
 from rpython.rlib.unroll import unrolling_iterable
 from rpython.rtyper.lltypesystem import lltype
 from rpython.tool.sourcetools import func_with_new_name
@@ -2169,15 +2169,16 @@
         handle = rwin32.GetStdHandle(handle_id)
 
         if handle == rwin32.NULL_HANDLE:
-            raise oefmt(OSError, "handle cannot be retrieved")
+            raise oefmt(space.w_OSError, "handle cannot be retrieved")
         elif handle == rwin32.INVALID_HANDLE_VALUE:
             raise rwin32.lastSavedWindowsError()
-        with lltype.scoped_alloc(CONSOLE_SCREEN_BUFFER_INFO) as buffer_info: 
-            success = GetConsoleScreenBufferInfo(handle, buffer_info)
+        with lltype.scoped_alloc(rwin32.CONSOLE_SCREEN_BUFFER_INFO) as buffer_info: 
+            success = rwin32.GetConsoleScreenBufferInfo(handle, buffer_info)
             if not success:
                 raise rwin32.lastSavedWindowsError()
-            columns = buffer_info.srWindow.Right - buffer_info.srWindow.Left + 1
-            lines = buffer_info.srWindow.Bottom - buffer_info.srWindow.Top + 1
+            # TODO: Is the typing here right?
+            w_columns = space.wrap(r_int(buffer_info.c_srWindow.c_Right) - r_int(buffer_info.c_srWindow.c_Left) + 1)
+            w_lines = space.wrap(r_int(buffer_info.c_srWindow.c_Bottom) - r_int(buffer_info.c_srWindow.c_Top) + 1)
     else:
         # Assuming that all supported platforms will have ioctl at least
         with lltype.scoped_alloc(rposix.WINSIZE) as winsize: 
@@ -2186,10 +2187,11 @@
                 raise exception_from_saved_errno(space, space.w_OSError)
 
             # TODO: Wrap this into a python_lvel int (somehow)
-            columns = space.wrap(winsize.c_ws_col)
-            lines = space.wrap(winsize.c_ws_row)
+            # TODO: is this right?
+            w_columns = space.wrap(r_uint(winsize.c_ws_col))
+            w_lines = space.wrap(r_uint(winsize.c_ws_row))
 
-    w_tuple = space.newtuple([columns, lines])
+    w_tuple = space.newtuple([w_columns, w_lines])
     w_terminal_size = space.getattr(space.getbuiltinmodule(os.name),
                                     space.wrap('terminal_size'))
 
diff --git a/rpython/rlib/rwin32.py b/rpython/rlib/rwin32.py
--- a/rpython/rlib/rwin32.py
+++ b/rpython/rlib/rwin32.py
@@ -73,7 +73,7 @@
         CONSOLE_SCREEN_BUFFER_INFO = Struct("CONSOLE_SCREEN_BUFFER_INFO",
                                             [("dwSize", COORD),
                                              ("dwCursorPosition", COORD),
-                                             ("wAttributes", WORD),
+                                             ("wAttributes", WORD.ctype_hint),
                                              ("srWindow", SMALL_RECT),
                                              ("dwMaximumWindowSize", COORD)])
 
@@ -470,6 +470,6 @@
 
     def GetStdHandle(handle_id):
         return _GetStdHandle(handle_id)
-
-    _GetConsoleScreenBufferInfo = winexternal(
-        "GetConsoleScreenBufferInfo", [HANDLE, csbi], BOOL)
+    CONSOLE_SCREEN_BUFFER_INFO_P = lltype.Ptr(CONSOLE_SCREEN_BUFFER_INFO)
+    GetConsoleScreenBufferInfo = winexternal(
+        "GetConsoleScreenBufferInfo", [HANDLE, CONSOLE_SCREEN_BUFFER_INFO_P], BOOL)


More information about the pypy-commit mailing list