glib-mkenums: fix handling of forward enum declarations
authorDan Winship <danw@gnome.org>
Tue, 7 Feb 2012 15:54:22 +0000 (10:54 -0500)
committerDan Winship <danw@gnome.org>
Tue, 7 Feb 2012 18:32:22 +0000 (13:32 -0500)
Given

    typedef enum MyFoo MyFoo;

glib-mkenums would get confused, not notice the ";", and then keep
skipping lines until it found one that started with a "{", possibly
even going into the next file.

Fix it to just ignore those lines instead (and also, to error out if
it hits eof while parsing an enum).

https://bugzilla.gnome.org/show_bug.cgi?id=669595

gobject/glib-mkenums.in

index 34440aa..b776e1f 100755 (executable)
@@ -290,6 +290,9 @@ while (<>) {
        ([^*]+|\*(?!/))*
        \*/@@gx;
        
+    # ignore forward declarations
+    next if /^\s*typedef\s+enum.*;/;
+
     if (m@^\s*typedef\s+enum\s*
            ({)?\s*
            (?:/\*<
@@ -321,6 +324,9 @@ while (<>) {
        # Didn't have trailing '{' look on next lines
        if (!defined $1 && !defined $4) {
            while (<>) {
+               if (eof) {
+                   die "Hit end of file while parsing enum in $ARGV";
+               }
                if (s/^\s*\{//) {
                    last;
                }