@@ -141,9 +141,31 @@ def get_win32_screen_buffer_info(self):
141141 """
142142 Return Screen buffer info.
143143 """
144+ # NOTE: We don't call the `GetConsoleScreenBufferInfo` API through
145+ # `self._winapi`. Doing so causes Python to crash on certain 64bit
146+ # Python versions. (Reproduced with 64bit Python 2.7.6, on Windows
147+ # 10). It is not clear why. Possibly, it has to do with passing
148+ # these objects as an argument, or through *args.
149+
150+ # The Python documentation contains the following - possibly related - warning:
151+ # ctypes does not support passing unions or structures with
152+ # bit-fields to functions by value. While this may work on 32-bit
153+ # x86, it's not guaranteed by the library to work in the general
154+ # case. Unions and structures with bit-fields should always be
155+ # passed to functions by pointer.
156+
157+ # Also see:
158+ # - https://github.com/ipython/ipython/issues/10070
159+ # - https://github.com/jonathanslenders/python-prompt-toolkit/issues/406
160+ # - https://github.com/jonathanslenders/python-prompt-toolkit/issues/86
161+
162+ self .flush ()
144163 sbinfo = CONSOLE_SCREEN_BUFFER_INFO ()
145- success = self ._winapi (windll .kernel32 .GetConsoleScreenBufferInfo ,
146- self .hconsole , byref (sbinfo ))
164+ success = windll .kernel32 .GetConsoleScreenBufferInfo (self .hconsole , byref (sbinfo ))
165+
166+ # success = self._winapi(windll.kernel32.GetConsoleScreenBufferInfo,
167+ # self.hconsole, byref(sbinfo))
168+
147169 if success :
148170 return sbinfo
149171 else :
0 commit comments