After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 653588 - Keycodes cannot be looked up
Keycodes cannot be looked up
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
: 654821 (view as bug list)
Depends on:
Blocks: 626254
 
 
Reported: 2011-06-28 19:52 UTC by Joanmarie Diggs (IRC: joanie)
Modified: 2012-04-22 14:39 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Joanmarie Diggs (IRC: joanie) 2011-06-28 19:52:01 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
Comment 1 johnp 2011-06-28 22:31:23 UTC
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.
Comment 2 Joanmarie Diggs (IRC: joanie) 2011-06-28 23:33:58 UTC
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!
Comment 3 Johan (not receiving bugmail) Dahlin 2011-06-29 13:30:50 UTC
The fix John committed to the invoke-rewrite branch leaks the allocated struct memory.
Comment 4 johnp 2011-06-29 15:46:20 UTC
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.
Comment 5 Sebastian Pölsterl 2011-08-14 09:41:55 UTC
*** Bug 654821 has been marked as a duplicate of this bug. ***
Comment 6 Martin Pitt 2012-04-22 14:39:40 UTC
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!