From cdd9e98b7ef80d6cdd33303689a9982dfd75ebc1 Mon Sep 17 00:00:00 2001 From: Jorgen Stenarson Date: Tue, 5 Jul 2011 21:41:09 +0200 Subject: [PATCH 1/5] Changing console.py to be 64-bit compliant --- pyreadline/console/__init__.py | 2 +- pyreadline/console/console.py | 65 ++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/pyreadline/console/__init__.py b/pyreadline/console/__init__.py index 805fb95..9d821ab 100644 --- a/pyreadline/console/__init__.py +++ b/pyreadline/console/__init__.py @@ -15,7 +15,7 @@ else: success = True except ImportError: pass - + raise if not success: raise ImportError( diff --git a/pyreadline/console/console.py b/pyreadline/console/console.py index 2204003..cb1ca65 100644 --- a/pyreadline/console/console.py +++ b/pyreadline/console/console.py @@ -27,6 +27,7 @@ from pyreadline.console.ansi import AnsiState,AnsiWriter try: from ctypes import * from _ctypes import call_function + from ctypes.wintypes import HWND, LPCSTR, UINT, WORD, DWORD, BOOL#, TCHAR except ImportError: raise ImportError(u"You need ctypes to run this code") @@ -192,14 +193,13 @@ class Console(object): self.hout = self.GetStdHandle(STD_OUTPUT_HANDLE) self.hin = self.GetStdHandle(STD_INPUT_HANDLE) - self.inmode = c_int(0) + self.inmode = DWORD(0) self.GetConsoleMode(self.hin, byref(self.inmode)) self.SetConsoleMode(self.hin, 0xf) info = CONSOLE_SCREEN_BUFFER_INFO() self.GetConsoleScreenBufferInfo(self.hout, byref(info)) self.attr = info.wAttributes self.saveattr = info.wAttributes # remember the initial colors - self.defaultstate = AnsiState() self.defaultstate.winattr = info.wAttributes self.ansiwriter = AnsiWriter(self.defaultstate) @@ -214,6 +214,7 @@ class Console(object): self.pythondll = \ CDLL(u'python%s%s' % (sys.version[0], sys.version[2])) + self.pythondll.PyMem_Malloc.restype = c_size_t self.inputHookPtr = \ c_int.from_address(addressof(self.pythondll.PyOS_InputHook)).value setattr(Console, u'PyMem_Malloc', self.pythondll.PyMem_Malloc) @@ -595,8 +596,66 @@ class Console(object): # add the functions from the dll to the class for func in funcs: setattr(Console, func, getattr(windll.kernel32, func)) + windll.kernel32.SetConsoleTitleW.argtypes = [c_wchar_p] -windll.kernel32.GetConsoleTitleW.argtypes = [c_wchar_p,c_short] +windll.kernel32.GetConsoleTitleW.argtypes = [c_wchar_p, c_short] + +if True: + from ctypes.wintypes import HWND, LPCSTR, UINT, WORD, DWORD, BOOL#, TCHAR + Console.AllocConsole.restype = BOOL + Console.AllocConsole.argtypes = [] #void + Console.CreateConsoleScreenBuffer.restype = HWND + Console.CreateConsoleScreenBuffer.argtypes = [DWORD, DWORD, HWND, DWORD, HWND] #DWORD, DWORD, SECURITY_ATTRIBUTES*, DWORD, LPVOID + Console.FillConsoleOutputAttribute.restype = BOOL + Console.FillConsoleOutputAttribute.argtypes = [HWND, WORD, DWORD, c_int, HWND] #HANDLE, WORD, DWORD, COORD, LPDWORD + Console.FillConsoleOutputCharacterW.restype = BOOL + Console.FillConsoleOutputCharacterW.argtypes = [HWND, c_uint, DWORD, c_int, HWND] #HANDLE, TCHAR, DWORD, COORD, LPDWORD + Console.FreeConsole.restype = BOOL + Console.FreeConsole.argtypes = [] #void + Console.GetConsoleCursorInfo.restype = BOOL + Console.GetConsoleCursorInfo.argtypes = [HWND, HWND] #HWND, PCONSOLE_CURSOR_INFO + Console.GetConsoleMode.restype = BOOL + Console.GetConsoleMode.argtypes = [HWND, HWND] #HWND, LPDWORD + Console.GetConsoleScreenBufferInfo.restype = BOOL + Console.GetConsoleScreenBufferInfo.argtypes = [HWND, HWND] #HWND, PCONSOLE_SCREEN_BUFFER_INFO + Console.GetConsoleTitleW.restype = DWORD + Console.GetConsoleTitleW.argtypes = [c_wchar_p, c_short] #LPTSTR , DWORD + Console.GetProcAddress.restype = HWND + Console.GetProcAddress.argtypes = [HWND, c_char_p] #HMODULE , LPCSTR + Console.GetStdHandle.restype = HWND + Console.GetStdHandle.argtypes = [DWORD] + Console.PeekConsoleInputW.restype = BOOL + Console.PeekConsoleInputW.argtypes = [HWND, HWND, DWORD, HWND] #HANDLE, PINPUT_RECORD, DWORD, LPDWORD + Console.ReadConsoleInputW.restype = BOOL + Console.ReadConsoleInputW.argtypes = [HWND, HWND, DWORD, HWND] #HANDLE, PINPUT_RECORD, DWORD, LPDWORD + Console.ScrollConsoleScreenBufferW.restype = BOOL + Console.ScrollConsoleScreenBufferW.argtypes = [HWND, HWND, HWND, c_int, HWND] #HANDLE, SMALL_RECT*, SMALL_RECT*, COORD, LPDWORD + Console.SetConsoleActiveScreenBuffer.restype = BOOL + Console.SetConsoleActiveScreenBuffer.argtypes = [HWND] #HANDLE + Console.SetConsoleCursorInfo.restype = BOOL + Console.SetConsoleCursorInfo.argtypes = [HWND, HWND] #HANDLE, CONSOLE_CURSOR_INFO* + Console.SetConsoleCursorPosition.restype = BOOL + Console.SetConsoleCursorPosition.argtypes = [HWND, c_int] #HANDLE, COORD + Console.SetConsoleMode.restype = BOOL + Console.SetConsoleMode.argtypes = [HWND, DWORD] #HANDLE, DWORD + Console.SetConsoleScreenBufferSize.restype = BOOL + Console.SetConsoleScreenBufferSize.argtypes = [HWND, c_int] #HANDLE, COORD + Console.SetConsoleTextAttribute.restype = BOOL + Console.SetConsoleTextAttribute.argtypes = [HWND, c_short] #HANDLE, WORD + Console.SetConsoleTitleW.restype = BOOL + Console.SetConsoleTitleW.argtypes = [c_wchar_p] #LPCTSTR + Console.SetConsoleTitleW.restype = BOOL + Console.SetConsoleTitleW.argtypes = [c_wchar_p] #LPCTSTR + Console.SetConsoleWindowInfo.restype = BOOL + Console.SetConsoleWindowInfo.argtypes = [HWND, BOOL, HWND] #HANDLE, BOOL, SMALL_RECT* + Console.WriteConsoleW.restype = BOOL + Console.WriteConsoleW.argtypes = [HWND, HWND, DWORD, HWND, HWND] #HANDLE, VOID*, DWORD, LPDWORD, LPVOID + Console.WriteConsoleOutputCharacterW.restype = BOOL + Console.WriteConsoleOutputCharacterW.argtypes = [HWND, HWND, DWORD, c_int, HWND] #HANDLE, LPCTSTR, DWORD, COORD, LPDWORD + Console.WriteFile.restype = BOOL + Console.WriteFile.argtypes = [HWND, HWND, DWORD, HWND, HWND] #HANDLE, LPCVOID , DWORD, LPDWORD , LPOVERLAPPED + + from event import Event From 62c034eb200c740c65a435048e72cac61b9bf4a2 Mon Sep 17 00:00:00 2001 From: Jorgen Stenarson Date: Tue, 5 Jul 2011 21:57:50 +0200 Subject: [PATCH 2/5] Some more changes for 64-bit --- pyreadline/console/console.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pyreadline/console/console.py b/pyreadline/console/console.py index cb1ca65..f598db9 100644 --- a/pyreadline/console/console.py +++ b/pyreadline/console/console.py @@ -644,8 +644,6 @@ if True: Console.SetConsoleTextAttribute.argtypes = [HWND, c_short] #HANDLE, WORD Console.SetConsoleTitleW.restype = BOOL Console.SetConsoleTitleW.argtypes = [c_wchar_p] #LPCTSTR - Console.SetConsoleTitleW.restype = BOOL - Console.SetConsoleTitleW.argtypes = [c_wchar_p] #LPCTSTR Console.SetConsoleWindowInfo.restype = BOOL Console.SetConsoleWindowInfo.argtypes = [HWND, BOOL, HWND] #HANDLE, BOOL, SMALL_RECT* Console.WriteConsoleW.restype = BOOL @@ -742,6 +740,10 @@ HOOKFUNC23 = CFUNCTYPE(c_char_p, c_void_p, c_void_p, c_char_p) readline_hook = None # the python hook goes here readline_ref = None # reference to the c-callable to keep it alive +cdll.msvcrt.strncpy.restype = c_char_p +cdll.msvcrt.strncpy.argtypes = [c_char_p, c_char_p, c_size_t] +cdll.msvcrt._strdup.restype = c_char_p +cdll.msvcrt._strdup.argtypes = [c_char_p] def hook_wrapper_23(stdin, stdout, prompt): u'''Wrap a Python readline so it behaves like GNU readline.''' @@ -764,7 +766,7 @@ def hook_wrapper_23(stdin, stdout, prompt): # we have to make a copy because the caller expects to free the result n = len(res) p = Console.PyMem_Malloc(n + 1) - cdll.msvcrt.strncpy(p, res, n + 1) + cdll.msvcrt.strncpy(cast(p, c_char_p), res, n + 1) return p def hook_wrapper(prompt): From 6d756675a01b305d753aba447f538f1c1e312bfb Mon Sep 17 00:00:00 2001 From: Jorgen Stenarson Date: Wed, 6 Jul 2011 19:48:11 +0200 Subject: [PATCH 3/5] Some more 64-bit fixes suggested by Cristoph Gohlke --- pyreadline/console/console.py | 127 +++++++++++++++++----------------- 1 file changed, 65 insertions(+), 62 deletions(-) diff --git a/pyreadline/console/console.py b/pyreadline/console/console.py index f598db9..b377de5 100644 --- a/pyreadline/console/console.py +++ b/pyreadline/console/console.py @@ -25,9 +25,11 @@ from pyreadline.keysyms import make_KeyPress, KeyPress from pyreadline.console.ansi import AnsiState,AnsiWriter try: + import ctypes.util from ctypes import * from _ctypes import call_function from ctypes.wintypes import HWND, LPCSTR, UINT, WORD, DWORD, BOOL#, TCHAR + from ctypes.wintypes import HWND, LPCSTR, UINT, WORD, DWORD, BOOL#, TCHAR except ImportError: raise ImportError(u"You need ctypes to run this code") @@ -215,6 +217,7 @@ class Console(object): self.pythondll = \ CDLL(u'python%s%s' % (sys.version[0], sys.version[2])) self.pythondll.PyMem_Malloc.restype = c_size_t + self.pythondll.PyMem_Malloc.argtypes = [c_size_t] self.inputHookPtr = \ c_int.from_address(addressof(self.pythondll.PyOS_InputHook)).value setattr(Console, u'PyMem_Malloc', self.pythondll.PyMem_Malloc) @@ -597,61 +600,65 @@ class Console(object): for func in funcs: setattr(Console, func, getattr(windll.kernel32, func)) -windll.kernel32.SetConsoleTitleW.argtypes = [c_wchar_p] -windll.kernel32.GetConsoleTitleW.argtypes = [c_wchar_p, c_short] -if True: - from ctypes.wintypes import HWND, LPCSTR, UINT, WORD, DWORD, BOOL#, TCHAR - Console.AllocConsole.restype = BOOL - Console.AllocConsole.argtypes = [] #void - Console.CreateConsoleScreenBuffer.restype = HWND - Console.CreateConsoleScreenBuffer.argtypes = [DWORD, DWORD, HWND, DWORD, HWND] #DWORD, DWORD, SECURITY_ATTRIBUTES*, DWORD, LPVOID - Console.FillConsoleOutputAttribute.restype = BOOL - Console.FillConsoleOutputAttribute.argtypes = [HWND, WORD, DWORD, c_int, HWND] #HANDLE, WORD, DWORD, COORD, LPDWORD - Console.FillConsoleOutputCharacterW.restype = BOOL - Console.FillConsoleOutputCharacterW.argtypes = [HWND, c_uint, DWORD, c_int, HWND] #HANDLE, TCHAR, DWORD, COORD, LPDWORD - Console.FreeConsole.restype = BOOL - Console.FreeConsole.argtypes = [] #void - Console.GetConsoleCursorInfo.restype = BOOL - Console.GetConsoleCursorInfo.argtypes = [HWND, HWND] #HWND, PCONSOLE_CURSOR_INFO - Console.GetConsoleMode.restype = BOOL - Console.GetConsoleMode.argtypes = [HWND, HWND] #HWND, LPDWORD - Console.GetConsoleScreenBufferInfo.restype = BOOL - Console.GetConsoleScreenBufferInfo.argtypes = [HWND, HWND] #HWND, PCONSOLE_SCREEN_BUFFER_INFO - Console.GetConsoleTitleW.restype = DWORD - Console.GetConsoleTitleW.argtypes = [c_wchar_p, c_short] #LPTSTR , DWORD - Console.GetProcAddress.restype = HWND - Console.GetProcAddress.argtypes = [HWND, c_char_p] #HMODULE , LPCSTR - Console.GetStdHandle.restype = HWND - Console.GetStdHandle.argtypes = [DWORD] - Console.PeekConsoleInputW.restype = BOOL - Console.PeekConsoleInputW.argtypes = [HWND, HWND, DWORD, HWND] #HANDLE, PINPUT_RECORD, DWORD, LPDWORD - Console.ReadConsoleInputW.restype = BOOL - Console.ReadConsoleInputW.argtypes = [HWND, HWND, DWORD, HWND] #HANDLE, PINPUT_RECORD, DWORD, LPDWORD - Console.ScrollConsoleScreenBufferW.restype = BOOL - Console.ScrollConsoleScreenBufferW.argtypes = [HWND, HWND, HWND, c_int, HWND] #HANDLE, SMALL_RECT*, SMALL_RECT*, COORD, LPDWORD - Console.SetConsoleActiveScreenBuffer.restype = BOOL - Console.SetConsoleActiveScreenBuffer.argtypes = [HWND] #HANDLE - Console.SetConsoleCursorInfo.restype = BOOL - Console.SetConsoleCursorInfo.argtypes = [HWND, HWND] #HANDLE, CONSOLE_CURSOR_INFO* - Console.SetConsoleCursorPosition.restype = BOOL - Console.SetConsoleCursorPosition.argtypes = [HWND, c_int] #HANDLE, COORD - Console.SetConsoleMode.restype = BOOL - Console.SetConsoleMode.argtypes = [HWND, DWORD] #HANDLE, DWORD - Console.SetConsoleScreenBufferSize.restype = BOOL - Console.SetConsoleScreenBufferSize.argtypes = [HWND, c_int] #HANDLE, COORD - Console.SetConsoleTextAttribute.restype = BOOL - Console.SetConsoleTextAttribute.argtypes = [HWND, c_short] #HANDLE, WORD - Console.SetConsoleTitleW.restype = BOOL - Console.SetConsoleTitleW.argtypes = [c_wchar_p] #LPCTSTR - Console.SetConsoleWindowInfo.restype = BOOL - Console.SetConsoleWindowInfo.argtypes = [HWND, BOOL, HWND] #HANDLE, BOOL, SMALL_RECT* - Console.WriteConsoleW.restype = BOOL - Console.WriteConsoleW.argtypes = [HWND, HWND, DWORD, HWND, HWND] #HANDLE, VOID*, DWORD, LPDWORD, LPVOID - Console.WriteConsoleOutputCharacterW.restype = BOOL - Console.WriteConsoleOutputCharacterW.argtypes = [HWND, HWND, DWORD, c_int, HWND] #HANDLE, LPCTSTR, DWORD, COORD, LPDWORD - Console.WriteFile.restype = BOOL - Console.WriteFile.argtypes = [HWND, HWND, DWORD, HWND, HWND] #HANDLE, LPCVOID , DWORD, LPDWORD , LPOVERLAPPED +msvcrt = cdll.LoadLibrary(ctypes.util.find_msvcrt()) +_strncpy = msvcrt.strncpy +_strncpy.restype = c_char_p +_strncpy.argtypes = [c_char_p, c_char_p, c_size_t] +_strdup = msvcrt._strdup +_strdup.restype = c_char_p +_strdup.argtypes = [c_char_p] + +Console.AllocConsole.restype = BOOL +Console.AllocConsole.argtypes = [] #void +Console.CreateConsoleScreenBuffer.restype = HWND +Console.CreateConsoleScreenBuffer.argtypes = [DWORD, DWORD, HWND, DWORD, HWND] #DWORD, DWORD, SECURITY_ATTRIBUTES*, DWORD, LPVOID +Console.FillConsoleOutputAttribute.restype = BOOL +Console.FillConsoleOutputAttribute.argtypes = [HWND, WORD, DWORD, c_int, HWND] #HANDLE, WORD, DWORD, COORD, LPDWORD +Console.FillConsoleOutputCharacterW.restype = BOOL +Console.FillConsoleOutputCharacterW.argtypes = [HWND, c_uint, DWORD, c_int, HWND] #HANDLE, TCHAR, DWORD, COORD, LPDWORD +Console.FreeConsole.restype = BOOL +Console.FreeConsole.argtypes = [] #void +Console.GetConsoleCursorInfo.restype = BOOL +Console.GetConsoleCursorInfo.argtypes = [HWND, HWND] #HWND, PCONSOLE_CURSOR_INFO +Console.GetConsoleMode.restype = BOOL +Console.GetConsoleMode.argtypes = [HWND, HWND] #HWND, LPDWORD +Console.GetConsoleScreenBufferInfo.restype = BOOL +Console.GetConsoleScreenBufferInfo.argtypes = [HWND, HWND] #HWND, PCONSOLE_SCREEN_BUFFER_INFO +Console.GetConsoleTitleW.restype = DWORD +Console.GetConsoleTitleW.argtypes = [c_wchar_p, c_short] #LPTSTR , DWORD +Console.GetProcAddress.restype = HWND +Console.GetProcAddress.argtypes = [HWND, c_char_p] #HMODULE , LPCSTR +Console.GetStdHandle.restype = HWND +Console.GetStdHandle.argtypes = [DWORD] +Console.PeekConsoleInputW.restype = BOOL +Console.PeekConsoleInputW.argtypes = [HWND, HWND, DWORD, HWND] #HANDLE, PINPUT_RECORD, DWORD, LPDWORD +Console.ReadConsoleInputW.restype = BOOL +Console.ReadConsoleInputW.argtypes = [HWND, HWND, DWORD, HWND] #HANDLE, PINPUT_RECORD, DWORD, LPDWORD +Console.ScrollConsoleScreenBufferW.restype = BOOL +Console.ScrollConsoleScreenBufferW.argtypes = [HWND, HWND, HWND, c_int, HWND] #HANDLE, SMALL_RECT*, SMALL_RECT*, COORD, LPDWORD +Console.SetConsoleActiveScreenBuffer.restype = BOOL +Console.SetConsoleActiveScreenBuffer.argtypes = [HWND] #HANDLE +Console.SetConsoleCursorInfo.restype = BOOL +Console.SetConsoleCursorInfo.argtypes = [HWND, HWND] #HANDLE, CONSOLE_CURSOR_INFO* +Console.SetConsoleCursorPosition.restype = BOOL +Console.SetConsoleCursorPosition.argtypes = [HWND, c_int] #HANDLE, COORD +Console.SetConsoleMode.restype = BOOL +Console.SetConsoleMode.argtypes = [HWND, DWORD] #HANDLE, DWORD +Console.SetConsoleScreenBufferSize.restype = BOOL +Console.SetConsoleScreenBufferSize.argtypes = [HWND, c_int] #HANDLE, COORD +Console.SetConsoleTextAttribute.restype = BOOL +Console.SetConsoleTextAttribute.argtypes = [HWND, c_short] #HANDLE, WORD +Console.SetConsoleTitleW.restype = BOOL +Console.SetConsoleTitleW.argtypes = [c_wchar_p] #LPCTSTR +Console.SetConsoleWindowInfo.restype = BOOL +Console.SetConsoleWindowInfo.argtypes = [HWND, BOOL, HWND] #HANDLE, BOOL, SMALL_RECT* +Console.WriteConsoleW.restype = BOOL +Console.WriteConsoleW.argtypes = [HWND, HWND, DWORD, HWND, HWND] #HANDLE, VOID*, DWORD, LPDWORD, LPVOID +Console.WriteConsoleOutputCharacterW.restype = BOOL +Console.WriteConsoleOutputCharacterW.argtypes = [HWND, HWND, DWORD, c_int, HWND] #HANDLE, LPCTSTR, DWORD, COORD, LPDWORD +Console.WriteFile.restype = BOOL +Console.WriteFile.argtypes = [HWND, HWND, DWORD, HWND, HWND] #HANDLE, LPCVOID , DWORD, LPDWORD , LPOVERLAPPED @@ -740,10 +747,6 @@ HOOKFUNC23 = CFUNCTYPE(c_char_p, c_void_p, c_void_p, c_char_p) readline_hook = None # the python hook goes here readline_ref = None # reference to the c-callable to keep it alive -cdll.msvcrt.strncpy.restype = c_char_p -cdll.msvcrt.strncpy.argtypes = [c_char_p, c_char_p, c_size_t] -cdll.msvcrt._strdup.restype = c_char_p -cdll.msvcrt._strdup.argtypes = [c_char_p] def hook_wrapper_23(stdin, stdout, prompt): u'''Wrap a Python readline so it behaves like GNU readline.''' @@ -766,7 +769,7 @@ def hook_wrapper_23(stdin, stdout, prompt): # we have to make a copy because the caller expects to free the result n = len(res) p = Console.PyMem_Malloc(n + 1) - cdll.msvcrt.strncpy(cast(p, c_char_p), res, n + 1) + _strncpy(cast(p, c_char_p), res, n + 1) return p def hook_wrapper(prompt): @@ -788,7 +791,7 @@ def hook_wrapper(prompt): traceback.print_exc() res = u'\n' # we have to make a copy because the caller expects to free the result - p = cdll.msvcrt._strdup(res) + p = _strdup(res) return p def install_readline(hook): @@ -798,7 +801,7 @@ def install_readline(hook): # save the hook so the wrapper can call it readline_hook = hook # get the address of PyOS_ReadlineFunctionPointer so we can update it - PyOS_RFP = c_int.from_address(Console.GetProcAddress(sys.dllhandle, + PyOS_RFP = c_void_p.from_address(Console.GetProcAddress(sys.dllhandle, "PyOS_ReadlineFunctionPointer")) # save a reference to the generated C-callable so it doesn't go away if sys.version < '2.3': @@ -806,7 +809,7 @@ def install_readline(hook): else: readline_ref = HOOKFUNC23(hook_wrapper_23) # get the address of the function - func_start = c_int.from_address(addressof(readline_ref)).value + func_start = c_void_p.from_address(addressof(readline_ref)).value # write the function address into PyOS_ReadlineFunctionPointer PyOS_RFP.value = func_start From 6ead15b3d65231d300dc67055d2648d5bb76c419 Mon Sep 17 00:00:00 2001 From: Jorgen Stenarson Date: Thu, 7 Jul 2011 21:30:23 +0200 Subject: [PATCH 4/5] Applying 6$-bit patch from Cristoph Gohlke --- pyreadline/console/console.py | 78 ++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/pyreadline/console/console.py b/pyreadline/console/console.py index b377de5..f53802a 100644 --- a/pyreadline/console/console.py +++ b/pyreadline/console/console.py @@ -28,8 +28,7 @@ try: import ctypes.util from ctypes import * from _ctypes import call_function - from ctypes.wintypes import HWND, LPCSTR, UINT, WORD, DWORD, BOOL#, TCHAR - from ctypes.wintypes import HWND, LPCSTR, UINT, WORD, DWORD, BOOL#, TCHAR + from ctypes.wintypes import * except ImportError: raise ImportError(u"You need ctypes to run this code") @@ -219,7 +218,7 @@ class Console(object): self.pythondll.PyMem_Malloc.restype = c_size_t self.pythondll.PyMem_Malloc.argtypes = [c_size_t] self.inputHookPtr = \ - c_int.from_address(addressof(self.pythondll.PyOS_InputHook)).value + c_void_p.from_address(addressof(self.pythondll.PyOS_InputHook)).value setattr(Console, u'PyMem_Malloc', self.pythondll.PyMem_Malloc) def __del__(self): @@ -351,7 +350,7 @@ class Console(object): def write_color(self, text, attr=None): text = ensure_unicode(text) n, res= self.ansiwriter.write_color(text, attr) - junk = c_int(0) + junk = DWORD(0) for attr,chunk in res: log(u"console.attr:%s"%unicode(attr)) log(u"console.chunk:%s"%unicode(chunk)) @@ -367,7 +366,7 @@ class Console(object): log(u'write("%s", %s)' %(text, attr)) if attr is None: attr = self.attr - n = c_int(0) + junk = DWORD(0) self.SetConsoleTextAttribute(self.hout, attr) for short_chunk in split_block(chunk): self.WriteConsoleW(self.hout, ensure_unicode(short_chunk), @@ -379,7 +378,7 @@ class Console(object): if os.environ.has_key(u"EMACS"): def write_color(self, text, attr=None): text = ensure_str(text) - junk = c_int(0) + junk = DWORD(0) self.WriteFile(self.hout, text, len(text), byref(junk), None) return len(text) write_plain = write_color @@ -410,7 +409,7 @@ class Console(object): self.SetConsoleCursorPosition(self.hout, self.fixcoord(0, 0)) w = info.dwSize.X - n = c_int(0) + n = DWORD(0) for y in range(info.dwSize.Y): self.FillConsoleOutputAttribute(self.hout, attr, w, self.fixcoord(0, y), byref(n)) @@ -425,7 +424,7 @@ class Console(object): attr = self.attr pos = self.fixcoord(x, y) - n = c_int(0) + n = DWORD(0) self.WriteConsoleOutputCharacterW(self.hout, text, len(text), pos, byref(n)) self.FillConsoleOutputAttribute(self.hout, attr, n, pos, byref(n)) @@ -441,7 +440,7 @@ class Console(object): def rectangle(self, rect, attr=None, fill=u' '): u'''Fill Rectangle.''' x0, y0, x1, y1 = rect - n = c_int(0) + n = DWORD(0) if attr is None: attr = self.attr for y in range(y0, y1): @@ -493,10 +492,10 @@ class Console(object): def get(self): u'''Get next event from queue.''' - inputHookFunc = c_int.from_address(self.inputHookPtr).value + inputHookFunc = c_void_p.from_address(self.inputHookPtr).value Cevent = INPUT_RECORD() - count = c_int(0) + count = DWORD(0) while 1: if inputHookFunc: call_function(inputHookFunc, ()) @@ -528,7 +527,7 @@ class Console(object): u'''Get next character from queue.''' Cevent = INPUT_RECORD() - count = c_int(0) + count = DWORD(0) while 1: status = self.ReadConsoleInputW(self.hin, byref(Cevent), 1, byref(count)) @@ -544,7 +543,7 @@ class Console(object): def peek(self): u'''Check event queue.''' Cevent = INPUT_RECORD() - count = c_int(0) + count = DWORD(0) status = self.PeekConsoleInputW(self.hin, byref(Cevent), 1, byref(count)) if status and count == 1: @@ -609,56 +608,61 @@ _strdup = msvcrt._strdup _strdup.restype = c_char_p _strdup.argtypes = [c_char_p] +LPVOID = c_void_p +LPCVOID = c_void_p +FARPROC = c_void_p +LPDWORD = POINTER(DWORD) + Console.AllocConsole.restype = BOOL Console.AllocConsole.argtypes = [] #void -Console.CreateConsoleScreenBuffer.restype = HWND -Console.CreateConsoleScreenBuffer.argtypes = [DWORD, DWORD, HWND, DWORD, HWND] #DWORD, DWORD, SECURITY_ATTRIBUTES*, DWORD, LPVOID +Console.CreateConsoleScreenBuffer.restype = HANDLE +Console.CreateConsoleScreenBuffer.argtypes = [DWORD, DWORD, c_void_p, DWORD, LPVOID] #DWORD, DWORD, SECURITY_ATTRIBUTES*, DWORD, LPVOID Console.FillConsoleOutputAttribute.restype = BOOL -Console.FillConsoleOutputAttribute.argtypes = [HWND, WORD, DWORD, c_int, HWND] #HANDLE, WORD, DWORD, COORD, LPDWORD +Console.FillConsoleOutputAttribute.argtypes = [HANDLE, WORD, DWORD, c_int, LPDWORD] #HANDLE, WORD, DWORD, COORD, LPDWORD Console.FillConsoleOutputCharacterW.restype = BOOL -Console.FillConsoleOutputCharacterW.argtypes = [HWND, c_uint, DWORD, c_int, HWND] #HANDLE, TCHAR, DWORD, COORD, LPDWORD +Console.FillConsoleOutputCharacterW.argtypes = [HANDLE, c_ushort, DWORD, c_int, LPDWORD] #HANDLE, TCHAR, DWORD, COORD, LPDWORD Console.FreeConsole.restype = BOOL Console.FreeConsole.argtypes = [] #void Console.GetConsoleCursorInfo.restype = BOOL -Console.GetConsoleCursorInfo.argtypes = [HWND, HWND] #HWND, PCONSOLE_CURSOR_INFO +Console.GetConsoleCursorInfo.argtypes = [HANDLE, c_void_p] #HANDLE, PCONSOLE_CURSOR_INFO Console.GetConsoleMode.restype = BOOL -Console.GetConsoleMode.argtypes = [HWND, HWND] #HWND, LPDWORD +Console.GetConsoleMode.argtypes = [HANDLE, LPDWORD] #HANDLE, LPDWORD Console.GetConsoleScreenBufferInfo.restype = BOOL -Console.GetConsoleScreenBufferInfo.argtypes = [HWND, HWND] #HWND, PCONSOLE_SCREEN_BUFFER_INFO +Console.GetConsoleScreenBufferInfo.argtypes = [HANDLE, c_void_p] #HANDLE, PCONSOLE_SCREEN_BUFFER_INFO Console.GetConsoleTitleW.restype = DWORD -Console.GetConsoleTitleW.argtypes = [c_wchar_p, c_short] #LPTSTR , DWORD -Console.GetProcAddress.restype = HWND -Console.GetProcAddress.argtypes = [HWND, c_char_p] #HMODULE , LPCSTR -Console.GetStdHandle.restype = HWND +Console.GetConsoleTitleW.argtypes = [c_wchar_p, DWORD] #LPTSTR , DWORD +Console.GetProcAddress.restype = FARPROC +Console.GetProcAddress.argtypes = [HMODULE, c_char_p] #HMODULE , LPCSTR +Console.GetStdHandle.restype = HANDLE Console.GetStdHandle.argtypes = [DWORD] Console.PeekConsoleInputW.restype = BOOL -Console.PeekConsoleInputW.argtypes = [HWND, HWND, DWORD, HWND] #HANDLE, PINPUT_RECORD, DWORD, LPDWORD +Console.PeekConsoleInputW.argtypes = [HANDLE, c_void_p, DWORD, LPDWORD] #HANDLE, PINPUT_RECORD, DWORD, LPDWORD Console.ReadConsoleInputW.restype = BOOL -Console.ReadConsoleInputW.argtypes = [HWND, HWND, DWORD, HWND] #HANDLE, PINPUT_RECORD, DWORD, LPDWORD +Console.ReadConsoleInputW.argtypes = [HANDLE, c_void_p, DWORD, LPDWORD] #HANDLE, PINPUT_RECORD, DWORD, LPDWORD Console.ScrollConsoleScreenBufferW.restype = BOOL -Console.ScrollConsoleScreenBufferW.argtypes = [HWND, HWND, HWND, c_int, HWND] #HANDLE, SMALL_RECT*, SMALL_RECT*, COORD, LPDWORD +Console.ScrollConsoleScreenBufferW.argtypes = [HANDLE, c_void_p, c_void_p, c_int, c_void_p] #HANDLE, SMALL_RECT*, SMALL_RECT*, COORD, LPDWORD Console.SetConsoleActiveScreenBuffer.restype = BOOL -Console.SetConsoleActiveScreenBuffer.argtypes = [HWND] #HANDLE +Console.SetConsoleActiveScreenBuffer.argtypes = [HANDLE] #HANDLE Console.SetConsoleCursorInfo.restype = BOOL -Console.SetConsoleCursorInfo.argtypes = [HWND, HWND] #HANDLE, CONSOLE_CURSOR_INFO* +Console.SetConsoleCursorInfo.argtypes = [HANDLE, c_void_p] #HANDLE, CONSOLE_CURSOR_INFO* Console.SetConsoleCursorPosition.restype = BOOL -Console.SetConsoleCursorPosition.argtypes = [HWND, c_int] #HANDLE, COORD +Console.SetConsoleCursorPosition.argtypes = [HANDLE, c_int] #HANDLE, COORD Console.SetConsoleMode.restype = BOOL -Console.SetConsoleMode.argtypes = [HWND, DWORD] #HANDLE, DWORD +Console.SetConsoleMode.argtypes = [HANDLE, DWORD] #HANDLE, DWORD Console.SetConsoleScreenBufferSize.restype = BOOL -Console.SetConsoleScreenBufferSize.argtypes = [HWND, c_int] #HANDLE, COORD +Console.SetConsoleScreenBufferSize.argtypes = [HANDLE, c_int] #HANDLE, COORD Console.SetConsoleTextAttribute.restype = BOOL -Console.SetConsoleTextAttribute.argtypes = [HWND, c_short] #HANDLE, WORD +Console.SetConsoleTextAttribute.argtypes = [HANDLE, WORD] #HANDLE, WORD Console.SetConsoleTitleW.restype = BOOL Console.SetConsoleTitleW.argtypes = [c_wchar_p] #LPCTSTR Console.SetConsoleWindowInfo.restype = BOOL -Console.SetConsoleWindowInfo.argtypes = [HWND, BOOL, HWND] #HANDLE, BOOL, SMALL_RECT* +Console.SetConsoleWindowInfo.argtypes = [HANDLE, BOOL, c_void_p] #HANDLE, BOOL, SMALL_RECT* Console.WriteConsoleW.restype = BOOL -Console.WriteConsoleW.argtypes = [HWND, HWND, DWORD, HWND, HWND] #HANDLE, VOID*, DWORD, LPDWORD, LPVOID +Console.WriteConsoleW.argtypes = [HANDLE, c_void_p, DWORD, LPDWORD, LPVOID] #HANDLE, VOID*, DWORD, LPDWORD, LPVOID Console.WriteConsoleOutputCharacterW.restype = BOOL -Console.WriteConsoleOutputCharacterW.argtypes = [HWND, HWND, DWORD, c_int, HWND] #HANDLE, LPCTSTR, DWORD, COORD, LPDWORD +Console.WriteConsoleOutputCharacterW.argtypes = [HANDLE, c_wchar_p, DWORD, c_int, LPDWORD] #HANDLE, LPCTSTR, DWORD, COORD, LPDWORD Console.WriteFile.restype = BOOL -Console.WriteFile.argtypes = [HWND, HWND, DWORD, HWND, HWND] #HANDLE, LPCVOID , DWORD, LPDWORD , LPOVERLAPPED +Console.WriteFile.argtypes = [HANDLE, LPCVOID, DWORD, LPDWORD, c_void_p] #HANDLE, LPCVOID , DWORD, LPDWORD , LPOVERLAPPED From d5e23948e766a4441dd68bae15703e6223e61e2c Mon Sep 17 00:00:00 2001 From: Jorgen Stenarson Date: Thu, 7 Jul 2011 23:55:20 +0200 Subject: [PATCH 5/5] Fix for loading msvcrt in ctypes on python <2.6. Provided by Cristoph Gohlke --- pyreadline/console/console.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyreadline/console/console.py b/pyreadline/console/console.py index f53802a..213486c 100644 --- a/pyreadline/console/console.py +++ b/pyreadline/console/console.py @@ -599,8 +599,10 @@ class Console(object): for func in funcs: setattr(Console, func, getattr(windll.kernel32, func)) - -msvcrt = cdll.LoadLibrary(ctypes.util.find_msvcrt()) +if sys.version_info[:2] < (2, 6): + msvcrt = cdll.msvcrt +else: + msvcrt = cdll.LoadLibrary(ctypes.util.find_msvcrt()) _strncpy = msvcrt.strncpy _strncpy.restype = c_char_p _strncpy.argtypes = [c_char_p, c_char_p, c_size_t]