GNOME Bugzilla – Bug 653588
Keycodes cannot be looked up
Last modified: 2012-04-22 14:39:40 UTC
I'm seeing some bogus keycodes when using introspection. Please compare: ~~~~~~~~~~~~~~ >>> from gi.repository import Gdk >>> keymap = Gdk.Keymap.get_default() >>> keyval = Gdk.keyval_from_name('KP_Divide') >>> success, entries = keymap.get_entries_for_keyval(keyval) >>> for entry in entries: ... print (entry.keycode, entry.group, entry.level) ... (25415312L, 0, 1919906921) ~~~~~~~~~~~~~~ $ python >>> import gtk >>> keymap = gtk.gdk.keymap_get_default() >>> keyval = gtk.gdk.keyval_from_name('KP_Divide') >>> entries = keymap.get_entries_for_keyval(keyval) >>> entries ((106, 0, 0),) In #introspection, jdahlin suggested to compare the results of Gtk+ 2 using gi. I did try this, but it seems that certain needed methods are not introspectable as defined by Gdk-2.0.gir, namely gdk_keymap_get_default() and get_for_display(). FWIW, the keyvals returned are the same for pygtk, introspection with Gtk+ 3, and introspection with Gtk+ 2. $ uname -a Linux gumby.localdomain 2.6.38.6-26.rc1.fc15.x86_64 #1 SMP Mon May 9 20:45:15 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
I can confirm this an issue with how PyGObject handles arrays of structs (we free the array without copying the struct). I have fixed this in the invoke-rewrite branch and will look to producing a backport to stable tomorrow.
John, I just tested the fix. Orca (introspection migration in progress) used to hang the desktop due to MemoryError. Now Orca with introspection actually works. :-) Thank you so, so much for the extremely quick solution!
The fix John committed to the invoke-rewrite branch leaks the allocated struct memory.
It shouldn't leak. It is only created on transfer full so the python wrapper should free it when it is garbage collected. The array itself is freed which destroys the original structs.
*** Bug 654821 has been marked as a duplicate of this bug. ***
With current pygobject 3.2 and Gtk 3.4, I get with pygtk: ((106, 0, 0), (106, 0, 1), (106, 0, 2), (106, 0, 3)) and with Gdk-3.0 GI: (106L, 0, 0) (106L, 0, 1) (106L, 0, 2) (106L, 0, 3) which seems correct. The invoke-rewrite branch has landed ages ago, so this report can be closed now. Thanks!