From 15b7cfbb312a65106adfb8b4b69c77ea99462f17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Urba=C5=84czyk?= Date: Thu, 29 Oct 2020 08:51:59 +0100 Subject: [PATCH] Use _underlying_type on return types too --- bindgen/header.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/bindgen/header.py b/bindgen/header.py index efe639bf..98031686 100644 --- a/bindgen/header.py +++ b/bindgen/header.py @@ -1,7 +1,7 @@ from typing import List, Tuple, Any, Mapping, Optional from itertools import chain -from clang.cindex import CursorKind, TypeKind, AccessSpecifier +from clang.cindex import CursorKind, Type, TypeKind, AccessSpecifier from path import Path from .type_parser import parse_type @@ -361,7 +361,7 @@ def __init__(self,cur): self.comment = cur.brief_comment self.full_name = cur.displayname self.mangled_name = cur.mangled_name - self.return_type = cur.result_type.spelling + self.return_type = self._underlying_type(cur.result_type) self.inline = cur.get_definition().is_inline() if cur.get_definition() else False self.pointer_by_ref = any(self._pointer_by_ref(el) for el in cur.get_arguments()) self.args = [(el.spelling,self._underlying_type(el),self._default_value(el)) for el in cur.get_arguments()] @@ -388,18 +388,21 @@ def _underlying_type(self,cur,add_qualifiers=True): '''Tries to resolve the underlying type. Needed for typedefed templates. ''' - ptr = self.KIND_DICT.get(cur.type.kind,'') + T = cur if isinstance(cur, Type) else cur.type + + + ptr = self.KIND_DICT.get(T.kind,'') # if lvaule,rvalue or pointer type if ptr: - const_ptr = ' const ' if cur.type.is_const_qualified() else '' - pointee = cur.type.get_pointee() + const_ptr = ' const ' if T.is_const_qualified() else '' + pointee = T.get_pointee() const = ' const ' if pointee.is_const_qualified() else '' decl = pointee.get_declaration() else: const_ptr = '' - const = ' const ' if cur.type.is_const_qualified() else '' - decl = cur.type.get_declaration() + const = ' const ' if T.is_const_qualified() else '' + decl = T.get_declaration() # if typedef that is not POD if decl.kind == CursorKind.TYPEDEF_DECL and not decl.underlying_typedef_type.is_pod(): @@ -409,7 +412,7 @@ def _underlying_type(self,cur,add_qualifiers=True): else: rv=spelling else: - rv = cur.type.spelling + rv = T.spelling # strip possible opencascade::handle when if not add_qualifiers: