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 621942 - glib-mkenums can't cope with libraries that have a two-word namespace
glib-mkenums can't cope with libraries that have a two-word namespace
Status: RESOLVED DUPLICATE of bug 661797
Product: glib
Classification: Platform
Component: gobject
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2010-06-17 22:26 UTC by Neil Roberts
Modified: 2017-10-24 10:07 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Neil Roberts 2010-06-17 22:26:07 UTC
Suppose you're making a library called 'recipe kit' which is a tool for accessing a database of recipes. If for some reason you like really long symbol names you might decide to use the two words 'RECIPE_KIT' as the namespace for this project. Then you would define classes like the following:

RecipeKitBook /* Representing a book of recipes */
RepipeKitIngredientsList /* The ingredients part of a recipe */

Then you would define the type number macros for your classes like this:

RECIPE_KIT_TYPE_BOOK
RECIPE_KIT_TYPE_INGREDIENTS_LIST

So in the first case 'RECIPE_KIT' is the namespace and 'BOOK' is the name of the object.

Later when your library gets really advanced and can cook and prepare the recipes all by itself, you might want to define an enum for the GError that that gets thrown when the automatic recipe-cooker goes wrong. You might try to do it like this:

typedef enum {
  RECIPE_KIT_ERROR_MISSING_INGREDIENTS,
  RECIPE_KIT_ERROR_WASHING_UP_NOT_DONE,
  RECIPE_KIT_ERROR_KITCHEN_CAUGHT_FIRE
} RecipeKitError;

Now to match the rest of your library you'd want to the recipe-kit-enum-types.h header to contain a line like this:

#define RECIPE_KIT_TYPE_ERROR (recipe_kit_error_get_type ())

So assuming your recipe-kit-enum-types.h.in file looks like this:

#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type())

that would mean you want @ENUMPREFIX@ to be RECIPE_KIT and @ENUMSHORT@ to be ERROR.

However glib-mkenums doesn't seem to cope with this and instead it can only make @ENUMPREFIX@ from the first word of the whole name of the type so you end up with:

#define RECIPE_TYPE_KIT_ERROR (recipe_kit_error_get_type ())

Perhaps we could add a --namespace option to glib-mkenums that would let you specify which part is the namespace. Then it could use that to work out the short name by removing the prefix rather than the other way around. Alternatively we could add a namespace= option to the hash in the /*< ... >*/ comment.

I know there is already a prefix option in that comment but that seems to only affect how it generates the strings that it uses for the names of the values. It does not affect any of the @WHATEVER@ values. Also there is an underscore_name option but as far as I can tell this only lets you set the whole name and then it will still use the first word of that as the prefix.
Comment 1 Philip Withnall 2017-10-24 10:07:31 UTC
This was fixed in bug #661797, adding the --identifier-prefix and --symbol-prefix options.

*** This bug has been marked as a duplicate of bug 661797 ***