Skip to content

gir: Don't crash on unlabled elements

Guido Günther requested to merge guidog/gi-docgen:unlabled-array-type into main

Without this an array member of a class without a name element for type:

     <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

With this patch the result renders as:

   class Foo.Bar : GObject.Object {
         xwayland_atoms: None,
   }

Merge request reports