Use strict C function prototypes

This fixes warnings when compiling with `-Wstrict-prototypes`.

Functions with empty parameter lists behave differently in C and C++:
- void func() in C is same as void func(...) in C++.
- void func() in C++ is same as void func(void) in C.
This commit is contained in:
Sergey Markelov 2021-12-29 13:42:35 -07:00 committed by Marshall Greenblatt
parent ce891b57e1
commit 8410b1383f
3 changed files with 16 additions and 13 deletions

View File

@ -449,10 +449,11 @@ def get_function_impls(content, ident, has_impl=True):
# parse the arguments
args = []
for v in argval.split(','):
v = v.strip()
if len(v) > 0:
args.append(v)
if argval != 'void':
for v in argval.split(','):
v = v.strip()
if len(v) > 0:
args.append(v)
result.append({
'retval': retval.strip(),
@ -1208,7 +1209,7 @@ class obj_function:
for cls in self.arguments:
cls.get_types(list)
def get_capi_parts(self, defined_structs=[], prefix=None):
def get_capi_parts(self, defined_structs=[], isimpl=False, prefix=None):
""" Return the parts of the C API function definition. """
retval = ''
dict = self.retval.get_type().get_capi(defined_structs)
@ -1225,6 +1226,8 @@ class obj_function:
# const virtual functions get const self pointers
str = 'const ' + str
args.append(str)
elif not isimpl and len(self.arguments) == 0:
args.append('void')
if len(self.arguments) > 0:
for cls in self.arguments:
@ -1245,9 +1248,9 @@ class obj_function:
return {'retval': retval, 'name': name, 'args': args}
def get_capi_proto(self, defined_structs=[], prefix=None):
def get_capi_proto(self, defined_structs=[], isimpl=False, prefix=None):
""" Return the prototype of the C API function. """
parts = self.get_capi_parts(defined_structs, prefix)
parts = self.get_capi_parts(defined_structs, isimpl, prefix)
result = parts['retval']+' '+parts['name']+ \
'('+', '.join(parts['args'])+')'
return result
@ -2098,7 +2101,7 @@ if __name__ == "__main__":
funcs = header.get_funcs()
if len(funcs) > 0:
for func in funcs:
result += func.get_capi_proto(defined_names) + ';\n'
result += func.get_capi_proto(defined_names, True) + ';\n'
result += '\n'
classes = header.get_classes()
@ -2108,7 +2111,7 @@ if __name__ == "__main__":
funcs = cls.get_virtual_funcs()
if len(funcs) > 0:
for func in funcs:
result += '\t' + func.get_capi_proto(defined_names) + ';\n'
result += '\t' + func.get_capi_proto(defined_names, True) + ';\n'
result += '}\n\n'
defined_names.append(cls.get_capi_name())
@ -2117,6 +2120,6 @@ if __name__ == "__main__":
funcs = cls.get_static_funcs()
if len(funcs) > 0:
for func in funcs:
result += func.get_capi_proto(defined_names) + ';\n'
result += func.get_capi_proto(defined_names, True) + ';\n'
result += '\n'
sys.stdout.write(result)

View File

@ -20,7 +20,7 @@ def make_cpptoc_function_impl_existing(cls, name, func, impl, defined_names):
notify(name + ' has manual edits')
# retrieve the C API prototype parts
parts = func.get_capi_parts(defined_names)
parts = func.get_capi_parts(defined_names, True)
changes = format_translation_changes(impl, parts)
if len(changes) > 0:
@ -36,7 +36,7 @@ def make_cpptoc_function_impl_new(cls, name, func, defined_names, base_scoped):
func.parent, obj_header)
# retrieve the C API prototype parts
parts = func.get_capi_parts(defined_names)
parts = func.get_capi_parts(defined_names, True)
result = make_cpptoc_impl_proto(name, func, parts) + ' {'
if isinstance(func.parent, obj_class) and \

View File

@ -52,7 +52,7 @@ def make_libcef_dll_dylib_impl_parts(name, retval, args):
def make_libcef_dll_dylib_impl_func(func):
name = func.get_capi_name()
parts = func.get_capi_parts([])
parts = func.get_capi_parts([], True)
retval = parts['retval']
args = parts['args']
return make_libcef_dll_dylib_impl_parts(name, retval, args)