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 604485 - Rewritten enum.pl script.
Rewritten enum.pl script.
Status: RESOLVED FIXED
Product: glibmm
Classification: Bindings
Component: build
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2009-12-13 22:09 UTC by Krzesimir Nowak
Modified: 2010-03-23 17:18 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Updates enum.pl script. (14.62 KB, patch)
2009-12-13 22:09 UTC, Krzesimir Nowak
none Details | Review
Updates enum.pl script. (16.21 KB, patch)
2009-12-14 01:49 UTC, Krzesimir Nowak
none Details | Review
gtkmm_withnewenumsscript.patch (16.56 KB, patch)
2009-12-17 10:12 UTC, Murray Cumming
none Details | Review
enum.pl script (11.89 KB, text/plain)
2009-12-18 00:38 UTC, Krzesimir Nowak
  Details
Changes splitters in GtkDefs.pm and in Enum.pm (9.39 KB, patch)
2010-01-05 00:28 UTC, Krzesimir Nowak
none Details | Review
Another updated enum script patch. (16.83 KB, patch)
2010-01-05 00:31 UTC, Krzesimir Nowak
none Details | Review
Updated patch with new splitters. (8.73 KB, patch)
2010-01-05 17:31 UTC, Krzesimir Nowak
none Details | Review
Reworked another updated enum script patch. (17.03 KB, patch)
2010-01-05 22:39 UTC, Krzesimir Nowak
none Details | Review
Comparison scripts. (9.43 KB, application/x-compressed-tar)
2010-02-11 15:39 UTC, Krzesimir Nowak
  Details

Description Krzesimir Nowak 2009-12-13 22:09:45 UTC
Created attachment 149655 [details] [review]
Updates enum.pl script.

I have rewritten an enum.pl script, so it copes with most flags. More on it is on gtkmm-list [1]. I filed a bug since mailing lists does not support nicely attachments to mails (attachment is created as a separate mail?)[2]

I'm attaching a patch here.

[1] http://mail.gnome.org/archives/gtkmm-list/2009-December/msg00046.html
[2] http://mail.gnome.org/archives/gtkmm-list/2009-December/msg00047.html
Comment 1 Krzesimir Nowak 2009-12-14 01:49:39 UTC
Created attachment 149671 [details] [review]
Updates enum.pl script.

Oops, by mistake all enums were classified as enum, not as flags, when they evidently were flags. I fixed it and attach a new patch with more groovy git commit message.
Comment 2 Murray Cumming 2009-12-17 10:12:49 UTC
Created attachment 149901 [details] [review]
gtkmm_withnewenumsscript.patch

The difference to gtk_enums.patch when using this new version of the script.
Comment 3 Murray Cumming 2009-12-17 10:13:10 UTC
Using this on gtk+ shows some weird stuff compared to the current gtk_enums.defs in gtkmm. See the attached patch. I'd rather fix that before committing this.


Also, should we worry about these warnings that it prints?:

WARNING: G_SIGNAL_RUN_FIRST in GTK_RUN_FIRST in 'GtkSignalRunType' is an unknown token. It probably is:
         - a typo - send a patch to maintainer of this module,
         - preprocessor value - make sure you include a header defining this value,
         - enum value from other header or other module - see above.
WARNING: G_SIGNAL_RUN_LAST in GTK_RUN_LAST in 'GtkSignalRunType' is an unknown token. It probably is:
         - a typo - send a patch to maintainer of this module,
         - preprocessor value - make sure you include a header defining this value,
         - enum value from other header or other module - see above.
WARNING: G_SIGNAL_NO_RECURSE in GTK_RUN_NO_RECURSE in 'GtkSignalRunType' is an unknown token. It probably is:
         - a typo - send a patch to maintainer of this module,
         - preprocessor value - make sure you include a header defining this value,
Comment 4 Krzesimir Nowak 2009-12-17 11:07:46 UTC
Thanks for your response.

1. You probably meant GtkRcTokenType enum by "weird stuff". Problem is that with previous version of enum parser incorrect values were generated, because first value in this enum is G_TOKEN_LAST from Glib module. Neither previous version nor my does not know its value, but difference lies in handling unknown tokens.

Previous parser just puts #error, my - copies it, assuming that, what is written in warnings. When unknown token is found and next enum have no specified value it is assumed that is unknown token + 1.

I know, it could be done better - instead of printing:

'("invalid" "GTK_RC_TOKEN_INVALID" "G_TOKEN_LAST")
'("include" "GTK_RC_TOKEN_INCLUDE" "((G_TOKEN_LAST) + 1)")
'("normal" "GTK_RC_TOKEN_NORMAL" "(((G_TOKEN_LAST) + 1) + 1)")
'("active" "GTK_RC_TOKEN_ACTIVE" "((((G_TOKEN_LAST) + 1) + 1) + 1)")
'("prelight" "GTK_RC_TOKEN_PRELIGHT" "(((((G_TOKEN_LAST) + 1) + 1) + 1) + 1)")

better would be:

'("invalid" "GTK_RC_TOKEN_INVALID" "G_TOKEN_LAST")
'("include" "GTK_RC_TOKEN_INCLUDE" "((G_TOKEN_LAST) + 1)")
'("normal" "GTK_RC_TOKEN_NORMAL" "((G_TOKEN_LAST) + 2)")
'("active" "GTK_RC_TOKEN_ACTIVE" "((G_TOKEN_LAST) + 3)")
'("prelight" "GTK_RC_TOKEN_PRELIGHT" "((G_TOKEN_LAST) + 4)")

I'll try to fix it.

2. As of ToolPaletteDragTargets - I'll fix it. Definition of this enum differs from others in that instead of
typedef enum
{
...
} ToolPaletteDragTargets;

there is
typedef enum
{
...
}
ToolPaletteDragTargets;

Easier would be just putting ToolPaletteDragTargets in the same line as closing bracket.

3. About using hexadecimal values in enums (see: GTK_ANCHOR_N) - I'll look at it, but it is not critical, since number is a number.

===

And by the way - I recommend using --with-typedefs option - very helpful. It prints original typedef before every defs in ;;, like this:

;; From gtkentry.h

;; Original typedef:
;; typedef enum
;; {
;;   GTK_ENTRY_ICON_PRIMARY,
;;   GTK_ENTRY_ICON_SECONDARY
;; } GtkEntryIconPosition;

(define-enum-extended EntryIconPosition
  (in-module "Gtk")
  (c-name "GtkEntryIconPosition")
  (values
    '("primary" "GTK_ENTRY_ICON_PRIMARY" "0")
    '("secondary" "GTK_ENTRY_ICON_SECONDARY" "1")
  )
)

About warnings - no, mostly we should worry about them - enum parser prints them just to let you know that some enums uses values other that earlier defined. It is best seen in Gio module in GSocketMsgFlags.

Also, if you don't want deprecated enum or enum values to be parsed, please use --omit-deprecated option. Maybe omitting deprecated enum and enum values should be enabled by default and option renamed to --parse-deprecated.

I'll be very grateful for your opinions.
Comment 5 Murray Cumming 2009-12-17 11:11:22 UTC
I'm happy as long as we don't create new build problems for gtkmm.

Please make the --with-typedefs option the default. Comments are always good. In fact, you can remove it as an option.

By default, we _do_ want deprecated enums to be shown, because we don't remove wrappers for deprecated API. Well, not until gtkmm3.
Comment 6 Krzesimir Nowak 2009-12-18 00:38:01 UTC
Created attachment 149951 [details]
enum.pl script

This is whole enum.pl script instead of patch. It fixes 1 and 2 from comment 4.

But now I got errors like this:

Broken lisp definition for flags-extended IOFlags.
unknown token (in-module "G") 
unknown token (c-name "GIOFlags") 
unknown token (values '("append" "G_IO_FLAG_APPEND" "1 << 0") '("nonblock" "G_IO_FLAG_NONBLOCK" "1 << 1") '("is-readable" "G_IO_FLAG_IS_READABLE" "1 << 2") '("is-writeable" "G_IO_FLAG_IS_WRITEABLE" "1 << 3") '("is-seekable" "G_IO_FLAG_IS_SEEKABLE" "1 << 4") '("mask" "G_IO_FLAG_MASK" "(1 << 5) - 1") '("get-mask" "G_IO_FLAG_GET_MASK" "0x1F") '("set-mask" "G_IO_FLAG_SET_MASK" "0x3") ) 
unknown token )

def looks like this:

(define-flags-extended IOFlags
  (in-module "G")
  (c-name "GIOFlags")
  (values
    '("append" "G_IO_FLAG_APPEND" "1 << 0")
    '("nonblock" "G_IO_FLAG_NONBLOCK" "1 << 1")
    '("is-readable" "G_IO_FLAG_IS_READABLE" "1 << 2")
    '("is-writeable" "G_IO_FLAG_IS_WRITEABLE" "1 << 3")
    '("is-seekable" "G_IO_FLAG_IS_SEEKABLE" "1 << 4")
    '("mask" "G_IO_FLAG_MASK" "(1 << 5) - 1")
    '("get-mask" "G_IO_FLAG_GET_MASK" "0x1F")
    '("set-mask" "G_IO_FLAG_SET_MASK" "0x3")
  )
)

For now I don't know why I'm getting this.
Comment 7 Krzesimir Nowak 2009-12-20 01:16:33 UTC
Problem is with gmmproc not accepting parentheses (by not parsing them) between quotes, like for example a G_IO_FLAG_MASK element's value in above enum. I'm trying to look at this, but I haven't grasped perl's split function yet.

It would be good to have support for parens inside quotes because of defines like below:

header.h:

#define MY_DEF = 1 << 5

other_header.h:

#include <header.h>

typedef enum
{
  MY_VAL1 = MY_DEF,
  MY_VAL2,
  MY_VAL3,
  ...
} MyEnum

In this case for enum.pl MY_VAL is unknown and produces defs like this:

(define-whatever-extended MyEnum
  ...
  (values
    '("val1" "MY_VAL1" "MY_DEF")
    '("val2" "MY_VAL2" "(MY_DEF) + 1")
    '("val3" "MY_VAL3" "(MY_DEF) + 2")
  )
)

Parens protect against having MY_VAL2 evaluated by preprocessor as '1 << 5 + 1' which equals to '1 << 6' instead of '(1 << 5) + 1'.

Maybe this example is bogus and if such protection is not needed I'll just change enum.pl to not use parens.
Comment 8 Krzesimir Nowak 2009-12-20 01:19:14 UTC
(In reply to comment #7) 
> #define MY_DEF = 1 << 5

should be:
#define MY_DEF 1 << 5
Comment 9 Krzesimir Nowak 2010-01-05 00:28:21 UTC
Created attachment 150807 [details] [review]
Changes splitters in GtkDefs.pm and in Enum.pm

This patch changes token splitters, so parentheses in strings (like in a description of a family property of GInetAddress or G_IO_FLAG_MASK value from defs in comment 6) are correctly parsed.
Comment 10 Krzesimir Nowak 2010-01-05 00:31:03 UTC
Created attachment 150808 [details] [review]
Another updated enum script patch.

This patch provides updated enum.pl. I don't remember if any changes were done in comparison of previous attachment (maybe some trailing whitespace cleanup), but I'm attaching it anyway.
Comment 11 Krzesimir Nowak 2010-01-05 17:31:28 UTC
Created attachment 150849 [details] [review]
Updated patch with new splitters.

Shortened one check with a regexp.

These patches works for me - building tested on glibmm, giomm, pangomm, atkmm, gdkmm and gtkmm. And I'm sure it will also work with libvtemm and gtksourceviewmm.

Hope you'll get the same results.
Comment 12 Jonathon Jongsma 2010-01-05 19:45:19 UTC
When I run this on giomm, I get the following errors.  is there any way to fix them (sorry, I know nothing about perl)?

$ ./tools/enum.pl /home/jonathon/.jhbuild-prefix/include/glib-2.0/gio/*.h ~/.jhbuild-prefix/include/gio-unix-2.0/gio/*.h > gio/src/gio_enums.defs 
WARNING: GLIB_SYSDEF_AF_UNIX in G_SOCKET_FAMILY_UNIX in 'GSocketFamily' is an unknown token. It probably is:
         - a typo - send a patch to maintainer of this module,
         - preprocessor value - make sure you include a header defining this value,
         - enum value from other header or other module - see above.
WARNING: GLIB_SYSDEF_AF_INET in G_SOCKET_FAMILY_IPV4 in 'GSocketFamily' is an unknown token. It probably is:
         - a typo - send a patch to maintainer of this module,
         - preprocessor value - make sure you include a header defining this value,
         - enum value from other header or other module - see above.
WARNING: GLIB_SYSDEF_AF_INET6 in G_SOCKET_FAMILY_IPV6 in 'GSocketFamily' is an unknown token. It probably is:
         - a typo - send a patch to maintainer of this module,
         - preprocessor value - make sure you include a header defining this value,
         - enum value from other header or other module - see above.
WARNING: GLIB_SYSDEF_MSG_OOB in G_SOCKET_MSG_OOB in 'GSocketMsgFlags' is an unknown token. It probably is:
         - a typo - send a patch to maintainer of this module,
         - preprocessor value - make sure you include a header defining this value,
         - enum value from other header or other module - see above.
WARNING: GLIB_SYSDEF_MSG_PEEK in G_SOCKET_MSG_PEEK in 'GSocketMsgFlags' is an unknown token. It probably is:
         - a typo - send a patch to maintainer of this module,
         - preprocessor value - make sure you include a header defining this value,
         - enum value from other header or other module - see above.
WARNING: GLIB_SYSDEF_MSG_DONTROUTE in G_SOCKET_MSG_DONTROUTE in 'GSocketMsgFlags' is an unknown token. It probably is:
         - a typo - send a patch to maintainer of this module,
         - preprocessor value - make sure you include a header defining this value,
         - enum value from other header or other module - see above.
Comment 13 Jonathon Jongsma 2010-01-05 19:46:19 UTC
I should note that this is not a regression since the unpatched enums.pl also failed on these enumerations, but it would still be nice to fix this.
Comment 14 Jonathon Jongsma 2010-01-05 19:53:51 UTC
Hmm.  I guess I should have looked more closely at the output before posting these last comments.  Because even though the warnings above were printed, the output seems to be generated correctly, whereas it was not generated correctly with the old enums.pl script.  Still, I'd like to know what those warnings are trying to tell me.
Comment 15 Krzesimir Nowak 2010-01-05 20:59:29 UTC
These warnings say, that enum.pl script does not know the value of these tokens - it is normal, when value is a preprocessor value [1] or enum value from other module [2] - enum.pl then assumes, that appropriate header defining these unknown values will be included. A typo is a third option, but it does not happen here. So these warnings are mostly harmless.

[1] GSocketMsgFlags is good example of it - GLIB_SYSDEF_MSG_ROUTE is a preprocessor value defined in glibconfig.h.

[2] gtk's GtkRcTokenType has first value defined as glib's GTokenType last value - G_TOKEN_LAST.
Comment 16 Jonathon Jongsma 2010-01-05 21:08:14 UTC
oh, I just noticed that murray had posted about the same warnings farther up.  Sorry for making so much noise about something that was already discussed.  

However, the warning message it prints out ("make sure you include a header defining this value") made me think that maybe I was supposed to add the header containing this symbol as an argument to enums.pl (e.g. './enums.pl header-with-symbol.h /path/to/gio/headers/*.h').  So I tried that but it still printed the same warnings.  But it's really trying to say that the header including this symbol should be included into the file where that enumeration is wrapped.  Perhaps that could be stated more obviously (?)
Comment 17 Krzesimir Nowak 2010-01-05 22:12:52 UTC
Good point - I'll fix it.
Comment 18 Krzesimir Nowak 2010-01-05 22:39:11 UTC
Created attachment 150868 [details] [review]
Reworked another updated enum script patch.

Fixes wording of warnings about unknown token.
Comment 19 Murray Cumming 2010-02-05 23:28:02 UTC
Have you tried using this for gtkmm, for instance?
Comment 20 Krzesimir Nowak 2010-02-06 16:01:41 UTC
Probably yes, but that was some time ago, so I don't remember now. I'll test it after weekend.
Comment 21 Krzesimir Nowak 2010-02-11 15:39:03 UTC
Created attachment 153541 [details]
Comparison scripts.

I tested above patches on glibmm (glib and gio), pangomm, gtkmm (atk, gdk and gtk), libvtemm and gtksourceviewmm - all went well.

I tested it by pulling glibmm from git, applying both patches, then updating all enums.defs in all modules, touching all .hg and .ccg files, compiling and installing.



Also, for just curious, I'm attaching a tarball with four perl scripts doing a nice comparison between old and new enums.defs. I wrote it because diff output is not legible. There is a README inside tarball, so please read it first.
Comment 22 Murray Cumming 2010-03-08 15:12:10 UTC
When I run this on the glib/gio/g*.h headers, to update glib/gio/src/gio_enums.defs, I get a lot of 
"Broken lisp definition for flags-extended"
errors from gmmproc.

I guess it has something to do with ( and ) in the values.
Comment 23 Murray Cumming 2010-03-08 15:13:33 UTC
Sorry, I have already pushed your patch, so it would be nice if you take a look at this.
Comment 24 Krzesimir Nowak 2010-03-08 17:51:53 UTC
Seems that you didn't push a patch with new splitters. I was testing building modules with both patches applied to glibmm.
Comment 25 Murray Cumming 2010-03-09 11:39:49 UTC
I applied your latest patch. Could you please provide a new patch against git master, or just commit a fix if you have access?
Comment 26 Krzesimir Nowak 2010-03-09 18:25:46 UTC
Sure, I just pushed the lacking patch (the "Updated patch with new splitters." in attachments section below). Now should work.
Comment 27 Krzesimir Nowak 2010-03-10 19:57:46 UTC
I'm closing this for now. If any problems with enum defs appear, just reopen this and I'll see to it.
Comment 28 José Alburquerque 2010-03-11 22:22:11 UTC
Sorry to re-open this.  I was just rebuilding all modules in jhbuild and glibmm fails to build because of a stray '#' in an enum declaration in glibmm/unicode.h:

enum NormalizeMode
{
  NORMALIZE_DEFAULT = 0,
  NORMALIZE_NFD = #error,
  NORMALIZE_DEFAULT_COMPOSE = 1,
  NORMALIZE_NFC = 1,
  NORMALIZE_ALL = 2,
  NORMALIZE_NFKD = 2,
  NORMALIZE_ALL_COMPOSE = 3,
  NORMALIZE_NFKC = 3
};

Could you please look into that?  Thanks.
Comment 29 Krzesimir Nowak 2010-03-12 16:05:53 UTC
Seems that new enum splitter does not work with *_enums.defs generated by old enum.pl. But new enum.pl script was pushed to master recently, so could you regenerate glib_enums.defs (and probably other enums.defs too)? That should fix it.
Comment 30 José Alburquerque 2010-03-12 19:26:11 UTC
Yes, that does fix it.  Thanks.
Comment 31 Murray Cumming 2010-03-15 16:55:06 UTC
Could someone do me a favour and use this to fix the glibmm build by regenerating/fixing the .defs file? Sorry, don't have time right now.
Comment 32 José Alburquerque 2010-03-15 17:13:07 UTC
Done.  Please let me know if something is not right.