[gi-docgen: 1/2] Fix correctness issues caused by reusing boilerplate code




commit 97f4e2a70ab41df80660701309e5c143797cfa67
Author: Alexandre Macabies <web+oss zopieux com>
Date:   Thu Apr 8 00:48:37 2021 +0200

    Fix correctness issues caused by reusing boilerplate code
    
    There are two instances where a variable from a previous for-loop body
    is reused in an unrelated for-loop. It works by accident, but stores or
    prints the wrong element. The one for unions is particularly concerning
    since it maps the same random record (from the previous loop) to all
    union identifiers, leading to an incorrect index.
    
    There is another location where an assignment was forgotten. It is a
    "time bomb" since some codebase could trigger the code reading
    cls_method_desc when it's not previously defined
    (cls_method.doc is None branch), causing a runtime exception.

 gidocgen/gdgenindices.py | 2 +-
 gidocgen/gdindex.py      | 2 +-
 gidocgen/gir/ast.py      | 6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/gidocgen/gdgenindices.py b/gidocgen/gdgenindices.py
index 09005f8..d0ef6e6 100644
--- a/gidocgen/gdgenindices.py
+++ b/gidocgen/gdgenindices.py
@@ -248,7 +248,7 @@ def _gen_classes(config, stemmer, index, repository, symbols):
                 if cls_method.doc is not None:
                     cls_method_desc = cls_method.doc.content
                 else:
-                    MISSING_DESCRIPTION
+                    cls_method_desc = MISSING_DESCRIPTION
                 index_symbols.append({
                     "type": "class_method",
                     "name": cls_method.name,
diff --git a/gidocgen/gdindex.py b/gidocgen/gdindex.py
index 638ecda..a2bcf5e 100644
--- a/gidocgen/gdindex.py
+++ b/gidocgen/gdindex.py
@@ -444,7 +444,7 @@ def gen_tree(repository):
                 _print_class_methods(iface, sections, is_last_iface)
             if 'functions' in sections:
                 sections.remove('functions')
-                _print_class_functions(cls, sections, is_last_iface)
+                _print_class_functions(iface, sections, is_last_iface)
 
     title = str(log.color('Records', 36))
     log.log(f'    ├── {title}')
diff --git a/gidocgen/gir/ast.py b/gidocgen/gir/ast.py
index 76fe3c3..dd13343 100644
--- a/gidocgen/gir/ast.py
+++ b/gidocgen/gir/ast.py
@@ -1094,11 +1094,11 @@ class Repository:
                 symbols[m.identifier] = record
         for union in self.namespace.get_unions():
             for m in union.constructors:
-                symbols[m.identifier] = record
+                symbols[m.identifier] = union
             for m in union.methods:
-                symbols[m.identifier] = record
+                symbols[m.identifier] = union
             for m in union.functions:
-                symbols[m.identifier] = record
+                symbols[m.identifier] = union
         self.namespace._symbols = symbols
 
     @property


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