From e0b908968dd0981c5a3ddef567b4bae1e37830b1 Mon Sep 17 00:00:00 2001
From: Ryan Lortie <desrt@desrt.ca>
Date: Thu, 12 Mar 2015 18:50:50 -0400
Subject: [PATCH] gtkdoc-scan: fix regex for get_type() functions

The regexp /(void|)/ was apparently trying to look for "(void)" or "()",
but in fact, the parens here were only acting as (redundant) grouping,
so the expression would match any string containing either "void" or "",
which is every string.

It turns out that we don't want to look for parens anyway, since they
are already stripped out above.  We do want to look for exactly "void"
or "", however, so add ^ and $.

Unfortunately, some code above also replaces all whitespace surrounding
newlines with a single space character, and a trailing newline is left
at the end of the declaration by another regular expression above,
resulting in seeing "void " at this point.  Fix that expression up to
also clean up the newline at the end, by adding /s as a regexp flag.

This fixes the inappropriate matching of non-void functions, such as
g_io_extension_get_type().

https://bugzilla.gnome.org/show_bug.cgi?id=746118
---
 gtkdoc-scan.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gtkdoc-scan.in b/gtkdoc-scan.in
index a45744a..567b5b0 100755
--- a/gtkdoc-scan.in
+++ b/gtkdoc-scan.in
@@ -774,7 +774,7 @@ sub ScanHeader {
         # Note that sometimes functions end in ') G_GNUC_PRINTF (2, 3);' or
         # ') __attribute__ (...);'.
         if ($in_declaration eq 'function') {
-            if ($decl =~ s/\)\s*(G_GNUC_.*|.*DEPRECATED.*|${IGNORE_DECORATORS}\s*|__attribute__\s*\(.*\)\s*)*;.*$//) {
+            if ($decl =~ s/\)\s*(G_GNUC_.*|.*DEPRECATED.*|${IGNORE_DECORATORS}\s*|__attribute__\s*\(.*\)\s*)*;.*$//s) {
                 if ($internal == 0) {
                      $decl =~ s%/\*.*?\*/%%gs;        # remove comments.
                      #$decl =~ s/^\s+//;                # remove leading whitespace.
@@ -786,7 +786,7 @@ sub ScanHeader {
                          print DECL "<FUNCTION>\n<NAME>$symbol</NAME>\n$deprecated<RETURNS>$ret_type</RETURNS>\n$decl\n</FUNCTION>\n";
                          if ($REBUILD_TYPES) {
                              # check if this looks like a get_type function and if so remember
-                             if (($symbol =~ m/_get_type$/) && ($ret_type =~ m/GType/) && ($decl =~ m/(void|)/)) {
+                             if (($symbol =~ m/_get_type$/) && ($ret_type =~ m/GType/) && ($decl =~ m/^(void|)$/)) {
                                  @TRACE@("Adding get-type: [$ret_type] [$symbol] [$decl]\tfrom $input_file");
                                  push (@get_types, $symbol);
                              }
-- 
2.1.4