On Sun, 09 Jun 2019, Bruno Santos <brunomanuelsantos@xxxxxxxxxxxxxxxxxx> wrote:
If the arguments list of a function is empty, Clang can not rule whether
a function is variadic or not. Previously the test was called
nonetheless only to trigger an exception in Clang. This patch prevents
that situation and will instead behave as if the function had been
declared with a single 'void' parameter.
Solves issue #14.
---
hawkmoth/parser.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/hawkmoth/parser.py b/hawkmoth/parser.py
index 60002bc..fa5e6cb 100644
--- a/hawkmoth/parser.py
+++ b/hawkmoth/parser.py
@@ -37,7 +37,7 @@
import itertools
import sys
-from clang.cindex import CursorKind
+from clang.cindex import CursorKind, TypeKind
from clang.cindex import Index, TranslationUnit
from clang.cindex import SourceLocation, SourceRange
from clang.cindex import TokenKind, TokenGroup
@@ -221,7 +221,10 @@ def _recursive_parse(comments, cursor, nest, compat):
args.append('{ttype} {arg}'.format(ttype=c.type.spelling,
arg=c.spelling))
- if cursor.type.is_function_variadic():
+ # Testing for a variadic function requires a complete function
prototype
+ # to do so.
+ if cursor.type.kind == TypeKind.FUNCTIONPROTO and \
+ cursor.type.is_function_variadic():
args.append('...')
fmt = docstr.Type.FUNC
--
2.21.0