From 330534a2e7165f2b78b8cba2ebd1d1d8f6a80647 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Thu, 3 Oct 2024 12:36:31 -0400 Subject: [PATCH] tools: translator: Add void* return value support (fixes #3591) --- tools/cef_parser.py | 25 +++++++++++++++++++++++-- tools/make_cpptoc_impl.py | 4 ++-- tools/make_ctocpp_impl.py | 4 +++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/tools/cef_parser.py b/tools/cef_parser.py index f4e7df19b..094ee5b3e 100644 --- a/tools/cef_parser.py +++ b/tools/cef_parser.py @@ -1514,6 +1514,7 @@ class obj_argument: if self.type.is_result_vector(): # all vector types must be passed by reference if not self.type.is_byref(): + print('ERROR: Invalid (vector not byref) type') return 'invalid' if self.type.is_result_vector_string(): @@ -1549,6 +1550,8 @@ class obj_argument: # string single map type if self.type.is_result_map_single(): if not self.type.is_byref(): + print('ERROR: Invalid (single map not byref) type for %s' % + self.type.get_name()) return 'invalid' if self.type.is_const(): return 'string_map_single_byref_const' @@ -1557,11 +1560,14 @@ class obj_argument: # string multi map type if self.type.is_result_map_multi(): if not self.type.is_byref(): + print('ERROR: Invalid (multi map not byref) type for %s' % + self.type.get_name()) return 'invalid' if self.type.is_const(): return 'string_map_multi_byref_const' return 'string_map_multi_byref' + print('ERROR: Invalid (unknown) type for %s' % self.type.get_name()) return 'invalid' def get_retval_type(self): @@ -1569,9 +1575,19 @@ class obj_argument: if self.type.has_name(): raise Exception('Cannot be called for argument types') + # special case for void* return value (may also be const) + if self.type.get_type() == 'void' and self.type.is_byaddr(): + return 'simple_byaddr' + # unsupported modifiers - if self.type.is_const() or self.type.is_byref() or \ - self.type.is_byaddr(): + if self.type.is_const(): + print('ERROR: Invalid (const) type for retval') + return 'invalid' + if self.type.is_byref(): + print('ERROR: Invalid (byref) type for retval') + return 'invalid' + if self.type.is_byaddr(): + print('ERROR: Invalid (byaddr) type for retval') return 'invalid' # void types don't have a return value @@ -1596,6 +1612,7 @@ class obj_argument: else: return prefix + 'ptr_diff' + print('ERROR: Invalid (unknown) type for retval') return 'invalid' def get_retval_default(self, for_capi): @@ -1615,6 +1632,10 @@ class obj_argument: type = self.get_retval_type() if type == 'simple': return self.get_type().get_result_simple_default() + elif type == 'simple_byaddr': + if for_capi: + return 'NULL' + return 'nullptr' elif type == 'bool': if for_capi: return '0' diff --git a/tools/make_cpptoc_impl.py b/tools/make_cpptoc_impl.py index 4ae23faf9..5284d3813 100644 --- a/tools/make_cpptoc_impl.py +++ b/tools/make_cpptoc_impl.py @@ -325,7 +325,7 @@ def make_cpptoc_function_impl_new(cls, name, func, defined_names, base_scoped): if retval_type != 'none': # has a return value - if retval_type == 'simple': + if retval_type == 'simple' or retval_type == 'simple_byaddr': result += retval.get_type().get_result_simple_type() else: result += retval.get_type().get_type() @@ -446,7 +446,7 @@ def make_cpptoc_function_impl_new(cls, name, func, defined_names, base_scoped): if retval_type != 'none': # has a return value result += '\n // Return type: ' + retval_type - if retval_type == 'simple' or retval_type == 'bool': + if retval_type == 'simple' or retval_type == 'simple_byaddr' or retval_type == 'bool': result += '\n return _retval;' elif retval_type == 'string': result += '\n return _retval.DetachToUserFree();' diff --git a/tools/make_ctocpp_impl.py b/tools/make_ctocpp_impl.py index 374923e4c..0d3e66b35 100644 --- a/tools/make_ctocpp_impl.py +++ b/tools/make_ctocpp_impl.py @@ -342,6 +342,8 @@ def make_ctocpp_function_impl_new(clsname, name, func, base_scoped): # has a return value if retval_type == 'simple' or retval_type == 'bool': result += retval.get_type().get_result_simple_type_root() + elif retval_type == 'simple_byaddr': + result += retval.get_type().get_result_simple_type() elif retval_type == 'string': result += 'cef_string_userfree_t' elif retval_type == 'refptr_same' or retval_type == 'refptr_diff' or \ @@ -485,7 +487,7 @@ def make_ctocpp_function_impl_new(clsname, name, func, base_scoped): if retval_type != 'none': # has a return value result += '\n // Return type: ' + retval_type - if retval_type == 'simple': + if retval_type == 'simple' or retval_type == 'simple_byaddr': result += '\n return _retval;' elif retval_type == 'bool': result += '\n return _retval?true:false;'