tools: translator: Add void* return value support (fixes #3591)

This commit is contained in:
Marshall Greenblatt 2024-10-03 12:36:31 -04:00
parent 467a0d6a85
commit 330534a2e7
3 changed files with 28 additions and 5 deletions

View File

@ -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'

View File

@ -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();'

View File

@ -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;'