From 8410b1383f50189c1e97b526e3aeb65079c5d405 Mon Sep 17 00:00:00 2001 From: Sergey Markelov Date: Wed, 29 Dec 2021 13:42:35 -0700 Subject: [PATCH] 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. --- tools/cef_parser.py | 23 +++++++++++++---------- tools/make_cpptoc_impl.py | 4 ++-- tools/make_libcef_dll_dylib_impl.py | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tools/cef_parser.py b/tools/cef_parser.py index 18b591ef5..ebd49a222 100644 --- a/tools/cef_parser.py +++ b/tools/cef_parser.py @@ -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) diff --git a/tools/make_cpptoc_impl.py b/tools/make_cpptoc_impl.py index b95c16f45..234934c02 100644 --- a/tools/make_cpptoc_impl.py +++ b/tools/make_cpptoc_impl.py @@ -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 \ diff --git a/tools/make_libcef_dll_dylib_impl.py b/tools/make_libcef_dll_dylib_impl.py index 485d2610c..85cd81734 100644 --- a/tools/make_libcef_dll_dylib_impl.py +++ b/tools/make_libcef_dll_dylib_impl.py @@ -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)