[New-bugs-announce] [issue8959] WINFUNCTYPE wrapped ctypes callbacks not functioning correctly in Python 2.7

Michael Curran report at bugs.python.org
Thu Jun 10 09:05:59 CEST 2010


New submission from Michael Curran <mick at nvaccess.org>:

There seem to be problems with WINFUNCTYPE callbacks causing exceptions, and or getting their return value ignored by the caller, when using Python 2.7 rc1.
Two examples provided.

Example 1:
Providing a WINFUNCTYPE wrapped python function when calling EnumWindows from user32.dll with ctypes, EnumWindows enumerates (calls the python function) for the first 5 windows and then causes a WindowsError, sometimes an access violation (reading, or writing), or even other strange unknown exceptions.
This specific testcase is attached to the bug.
Run this script in  Python 2.7 you should see the WindowsErrors. On Python 2.6 it successfully enumerates through all windows.

Example 2:
Hooking low-level keyboard input in Windows with SetWindowsHookEx from user32.dll, providing a WINFUNCTYPE wrapped python function as the callback, and then typing some keys, causes the callback to be called but the return value is always ignored, which means the hook never blocks keys completely, even if  the value 1 is returned from the callback, to do so.
Again, a testcase is attached to the bug.
Run this script in Python. It will ask you to type some characters and press enter. On Python 2.6 no characters should be echoed to the screen, but you will hear beeps to let you know the keyboard hook is seeing the keys. On Python 2.7, the keys will be echoed to the screen, and you will also hear the beeps (meaning that the hook was seeing the keys, but was unable to actually block them -- its return value was being ignored).
Also in Python 2.7, after the quit message is sent to the hook thread, GetMessageW (in user32.dll) causes a WindowsError exception. This does not happen on Python 2.6.

Perhaps it may be related to this entry in the Python 2.7 What's new:
The underlying libffi library has been updated to version 3.0.9, containing various fixes for different platforms. (Updated by Matthias Klose; issue 8142.)

----------
assignee: theller
components: ctypes
files: test_callbackRetval.py
messages: 107447
nosy: mdcurran, theller
priority: normal
severity: normal
status: open
title: WINFUNCTYPE wrapped ctypes callbacks not functioning correctly in Python 2.7
type: crash
versions: Python 2.7
Added file: http://bugs.python.org/file17604/test_callbackRetval.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8959>
_______________________________________


More information about the New-bugs-announce mailing list