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 705290 - Use autogenerated enum type ATK_ROLE_TYPE to get the role name
Use autogenerated enum type ATK_ROLE_TYPE to get the role name
Status: RESOLVED FIXED
Product: atk
Classification: Platform
Component: atk
unspecified
Other Linux
: Normal normal
: ---
Assigned To: ATK maintainer(s)
ATK maintainer(s)
: 654174 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2013-08-01 13:56 UTC by Alejandro Piñeiro Iglesias (IRC: infapi00)
Modified: 2013-12-09 17:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
First version of the patch (6.36 KB, patch)
2013-08-01 14:12 UTC, Alejandro Piñeiro Iglesias (IRC: infapi00)
none Details | Review

Description Alejandro Piñeiro Iglesias (IRC: infapi00) 2013-08-01 13:56:04 UTC
Right now adding a new role is tricky, because the name of the role is stored at a static array of strings, and a strings with the offset of each string. Computing each offset can be error prone. Although probably this could be simplified using one two dimensional array, it is still a burden the need to add a role to the enum at the header and then the name at the source file.

While talking about bug 704092 on IRC, it was suggested to use the (already) generated enum type. Mike Gorse mentioned that he is doing something similar for atspi.
Comment 1 Alejandro Piñeiro Iglesias (IRC: infapi00) 2013-08-01 14:12:19 UTC
Created attachment 250624 [details] [review]
First version of the patch

During the trip Vienna-Brno I worked on this. This is the first version of the patch. Problem: right now it changes the role name.

As in the case of atspi, what is being used to get the role name is the value-nick of the enum. This is convenient as the nick is basically the name of the role (ie: for ATK_ROLE_ICON is "icon") and if needed, we can specify the nick on the very same enum at the header. Example:
  ATK_ROLE_ACCEL_LABEL,      /*<nick=accelerator-label>*/

This patch uses that approach.

Problem: that nick has a '-' in the middle, so the name change (if you execute tests/testrole it fails). I tried to use "/*nick=accelerator label*/", but doing that the typelib generation for Atk fails due the ' ':
** (g-ir-compiler:25873): ERROR **: Invalid typelib for module 'Atk': In directory (Context: Role)): The value contains invalid characters: 'accelerator label'
/bin/bash: line 1: 25873 Trace/breakpoint trap   (core dumped) /opt/gnome3/bin/g-ir-compiler --includedir=. Atk-1.0.gir -o Atk-1.0.typelib

One could be tempted to blame g-i-introspection, but there are something else to take into account. If this is solved at the g-i-introspection side, would mean that we would need to specify the nick for each enum value, when in most cases is the same nick but without '-'.

atspi easily solves that because get_role_name returns a new string each time, so it just replacing the '-' with ' '. We can't do that directly here as we return a const gchar*

One option would be create a array with the role names at initialization, replacing the spaces. Having a array with role names would not be really a problem. We already have one, to store the extra roles. We could in fact, use the same array for the official roles name and the extra roles.

Sharing the first version of the patch and my discoveries just in case people want to share their thoughts.
Comment 2 Alejandro Piñeiro Iglesias (IRC: infapi00) 2013-08-12 10:01:41 UTC
Fixed with commit 840e63030289c57660e7c670cc2e9ec54387e47d, that is a updated version of patch on comment 1.

Closing bug.
Comment 3 Alejandro Piñeiro Iglesias (IRC: infapi00) 2013-12-09 17:15:47 UTC
*** Bug 654174 has been marked as a duplicate of this bug. ***