[gi-docgen: 2/3] gir: Don't crash on unlabled elements




commit 8a7a855b61a10f4087bcb8c37350f9e2a6bffd9f
Author: Guido Günther <agx sigxcpu org>
Date:   Mon Aug 9 18:06:02 2021 +0200

    gir: Don't crash on unlabled elements
    
    Without this a class member of
    
         <field name="xwayland_atoms" introspectable="0">
            <array zero-terminated="0">
              <type c:type="xcb_atom_t"/>
            </array>
         </field>
    
    crashes like
    
      gi-docgen.py generate --quiet --add-include-path=... --config=doc/foo.toml --output-dir=doc/foo-0 
--no-namespace-dir --content-dir=/tmp/doc src/Foo-0.gir
      Traceback (most recent call last):
        File "/tmp/foo/subprojects/gi-docgen/gidocgen/gidocmain.py", line 74, in run
          res = options.run_func(options)
        File "/tmp/foo/subprojects/gi-docgen/gidocgen/gdgenerate.py", line 2827, in run
          parser.parse(options.infile)
        File "/tmp/foo/subprojects/gi-docgen/gidocgen/gir/parser.py", line 85, in parse
          repository = self._parse_tree(tree.getroot())
        File "/tmp/foo/subprojects/gi-docgen/gidocgen/gir/parser.py", line 248, in _parse_tree
          parser_method(node, repository, namespace)
        File "/tmp/foo/subprojects/gi-docgen/gidocgen/gir/parser.py", line 790, in _parse_class
          fields.append(self._parse_field(child))
        File "/tmp/foo/subprojects/gi-docgen/gidocgen/gir/parser.py", line 752, in _parse_field
          ctype = self._parse_ctype(node)
        File "/subprojects/gi-docgen/gidocgen/gir/parser.py", line 344, in _parse_ctype
          target = self._lookup_type(name=tname, ctype=ttype)
        File "/tmp/foo/subprojects/gi-docgen/gidocgen/gir/parser.py", line 131, in _lookup_type
          elif '.' in name:
      TypeError: argument of type 'NoneType' is not iterable
    
    due to the lack of a typename.

 gidocgen/gir/parser.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
---
diff --git a/gidocgen/gir/parser.py b/gidocgen/gir/parser.py
index d42615e..7000541 100644
--- a/gidocgen/gir/parser.py
+++ b/gidocgen/gir/parser.py
@@ -340,8 +340,10 @@ class GirParser:
                 elif tname != 'gpointer' and ttype == 'gpointer':
                     # API returning gpointer to avoid casting
                     target = self._lookup_type(name=tname)
-                else:
+                elif tname:
                     target = self._lookup_type(name=tname, ctype=ttype)
+                else:
+                    target = ast.VoidType()
             else:
                 target = ast.VoidType()
             ctype = ast.ArrayType(name=name, zero_terminated=zero_terminated, fixed_size=fixed_size, 
length=length,


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