giscanner: Don't fail on empty GTK-Doc comment blocks
authorDieter Verfaillie <dieterv@optionexplicit.be>
Thu, 3 Jan 2013 07:01:10 +0000 (08:01 +0100)
committerDieter Verfaillie <dieterv@optionexplicit.be>
Wed, 9 Jan 2013 19:29:55 +0000 (20:29 +0100)
A completely empty GTK-Doc comment block (/**\n*/) resulted
in an unfriendly backtrace, complaining about an
"AttributeError: 'NoneType' object has no attribute 'comment'"

This fixes the issue and adds a test case.

https://bugzilla.gnome.org/show_bug.cgi?id=690850

giscanner/annotationparser.py
tests/scanner/annotationparser/gi/syntax.xml

index f545590..d4b2499 100644 (file)
@@ -1119,20 +1119,23 @@ class AnnotationParser(object):
         ########################################################################
         # Finished parsing this comment block.
         ########################################################################
-        # We have picked up a couple of \n characters that where not
-        # intended. Strip those.
-        if comment_block.comment:
-            comment_block.comment = comment_block.comment.strip()
+        if comment_block:
+            # We have picked up a couple of \n characters that where not
+            # intended. Strip those.
+            if comment_block.comment:
+                comment_block.comment = comment_block.comment.strip()
 
-        for tag in comment_block.tags.values():
-            self._clean_comment_block_part(tag)
+            for tag in comment_block.tags.values():
+                self._clean_comment_block_part(tag)
 
-        for param in comment_block.params.values():
-            self._clean_comment_block_part(param)
+            for param in comment_block.params.values():
+                self._clean_comment_block_part(param)
 
-        # Validate and store block.
-        comment_block.validate()
-        return comment_block
+            # Validate and store block.
+            comment_block.validate()
+            return comment_block
+        else:
+            return None
 
     def _clean_comment_block_part(self, part):
         if part.comment:
index 83c56b9..f07e4fb 100644 (file)
@@ -71,6 +71,14 @@ something */</commentblock>
 
 <test>
   <!--
+  Not GTK-Doc
+  -->
+  <commentblock>/**
+*/</commentblock>
+</test>
+
+<test>
+  <!--
   Technically not GTK-Doc, but we need to support this for backwards compatibility
   -->
   <commentblock>/**