summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Slenders <jonathan@slenders.be>2016-12-29 22:23:25 +0100
committerJonathan Slenders <jonathan@slenders.be>2016-12-29 22:23:25 +0100
commitd5d9e296cdd3e2b1e8126f6307a7c09d0bdcdd3a (patch)
treee2d5f8d7d7365c6b75051fd2f2c797329ba45657
parentdfed263e958eda4f5bd642507f4b16bf64ffefc3 (diff)
Fixed the NoConsoleScreenBuffer error that appeared on some 64bit Python versions.
-rw-r--r--prompt_toolkit/terminal/win32_output.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/prompt_toolkit/terminal/win32_output.py b/prompt_toolkit/terminal/win32_output.py
index cf057d39..7021df44 100644
--- a/prompt_toolkit/terminal/win32_output.py
+++ b/prompt_toolkit/terminal/win32_output.py
@@ -141,9 +141,31 @@ class Win32Output(Output):
"""
Return Screen buffer info.
"""
+ # NOTE: We don't call the `GetConsoleScreenBufferInfo` API through
+ # `self._winapi`. Doing so causes Python to crash on certain 64bit
+ # Python versions. (Reproduced with 64bit Python 2.7.6, on Windows
+ # 10). It is not clear why. Possibly, it has to do with passing
+ # these objects as an argument, or through *args.
+
+ # The Python documentation contains the following - possibly related - warning:
+ # ctypes does not support passing unions or structures with
+ # bit-fields to functions by value. While this may work on 32-bit
+ # x86, it's not guaranteed by the library to work in the general
+ # case. Unions and structures with bit-fields should always be
+ # passed to functions by pointer.
+
+ # Also see:
+ # - https://github.com/ipython/ipython/issues/10070
+ # - https://github.com/jonathanslenders/python-prompt-toolkit/issues/406
+ # - https://github.com/jonathanslenders/python-prompt-toolkit/issues/86
+
+ self.flush()
sbinfo = CONSOLE_SCREEN_BUFFER_INFO()
- success = self._winapi(windll.kernel32.GetConsoleScreenBufferInfo,
- self.hconsole, byref(sbinfo))
+ success = windll.kernel32.GetConsoleScreenBufferInfo(self.hconsole, byref(sbinfo))
+
+ # success = self._winapi(windll.kernel32.GetConsoleScreenBufferInfo,
+ # self.hconsole, byref(sbinfo))
+
if success:
return sbinfo
else: