[gobject-introspection] scanner: make using bool without stdbool include work again. Fixes #247



commit 6d17dd7c29fd4e25e8f6b78cef915e67db6826fd
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Fri Dec 21 12:32:34 2018 +0100

    scanner: make using bool without stdbool include work again. Fixes #247
    
    With !45 special casing of bool in the lexer was removed which previously allowed the usage of
    bool without including stdbool.h. This breaks scanning of graphene headers
    which guarded the stdbool include with __GI_SCANNER__ (I haven't figured out why).
    
    Add back the special handling for bool in the lexer and also map it to gboolean like
    _Bool as if stdbool.h was included.

 giscanner/scannerlexer.l            | 1 +
 giscanner/transformer.py            | 2 +-
 tests/scanner/test_sourcescanner.py | 5 +++++
 3 files changed, 7 insertions(+), 1 deletion(-)
---
diff --git a/giscanner/scannerlexer.l b/giscanner/scannerlexer.l
index d3a6017e..4d9657a6 100644
--- a/giscanner/scannerlexer.l
+++ b/giscanner/scannerlexer.l
@@ -183,6 +183,7 @@ stringtext                          ([^\\\"])|(\\.)
 "__volatile"                           { return VOLATILE; }
 "__volatile__"                         { return VOLATILE; }
 "_Bool"                                        { return BASIC_TYPE; }
+"bool"                                 { return BASIC_TYPE; }
 "typedef char __static_assert_t".*"\n" { ++lineno; /* Ignore */ }
 "__cdecl"                              { /* Ignore */ }
 "__declspec(deprecated(".*"))"         { /* Ignore */ }
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 1c406e98..a74cb6ba 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -699,7 +699,7 @@ raise ValueError."""
         # because of different ABI, but this usually works fine,
         # so for backward compatibility lets continue for now:
         # https://gitlab.gnome.org/GNOME/gobject-introspection/merge_requests/24#note_92792
-        if canonical == '_Bool':
+        if canonical in ('_Bool', 'bool'):
             canonical = 'gboolean'
             base = canonical
 
diff --git a/tests/scanner/test_sourcescanner.py b/tests/scanner/test_sourcescanner.py
index c731049b..b31af194 100644
--- a/tests/scanner/test_sourcescanner.py
+++ b/tests/scanner/test_sourcescanner.py
@@ -78,6 +78,11 @@ void foo(int bar) {
         self.assertEqual(len(list(scanner.get_symbols())), 1)
         self.assertFalse(scanner.get_errors())
 
+    def test_bool_no_include(self):
+        # https://gitlab.gnome.org/GNOME/gobject-introspection/issues/247
+        scanner = self._parse_files("bool foo;")
+        self.assertFalse(scanner.get_errors())
+
 
 if __name__ == '__main__':
     unittest.main()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]