libcef_dll/wrapper: Let the compiler deduce types of func ptr

This commit is contained in:
Sergey Markelov 2022-07-08 11:37:12 +00:00 committed by Marshall Greenblatt
parent 64a5754959
commit f8ce93ba3c

View File

@ -34,9 +34,7 @@ def make_libcef_dll_dylib_impl_parts(name, retval, args):
arg_types += arg[0:pos] arg_types += arg[0:pos]
arg_names += arg[pos + 1:] arg_names += arg[pos + 1:]
typedef = 'typedef %s (*%s_ptr)(%s);\n' % (retval, name, arg_types) declare = 'decltype(&%s) %s;\n' % (name, name)
declare = '%s_ptr %s;\n' % (name, name)
init = ' INIT_ENTRY(%s);' % name init = ' INIT_ENTRY(%s);' % name
@ -47,7 +45,7 @@ def make_libcef_dll_dylib_impl_parts(name, retval, args):
""" % (retval, name, ', '.join(args), 'return ' """ % (retval, name, ', '.join(args), 'return '
if retval != 'void' else '', name, arg_names) if retval != 'void' else '', name, arg_names)
return (typedef, declare, init, impl) return (declare, init, impl)
def make_libcef_dll_dylib_impl_func(func): def make_libcef_dll_dylib_impl_func(func):
@ -64,15 +62,13 @@ def make_libcef_dll_dylib_impl(header):
'#include "include/base/cef_compiler_specific.h"', '#include "include/base/cef_compiler_specific.h"',
'#include "include/wrapper/cef_library_loader.h"', '#include "include/wrapper/cef_library_loader.h"',
] ]
ptr_typedef = ''
ptr_declare = '' ptr_declare = ''
ptr_init = '' ptr_init = ''
ptr_impl = '' ptr_impl = ''
# Include required headers for global functions. # Include required headers for global functions.
for func in header.get_funcs(): for func in header.get_funcs():
typedef, declare, init, impl = make_libcef_dll_dylib_impl_func(func) declare, init, impl = make_libcef_dll_dylib_impl_func(func)
ptr_typedef += typedef
ptr_declare += declare ptr_declare += declare
ptr_init += init ptr_init += init
ptr_impl += impl ptr_impl += impl
@ -87,8 +83,7 @@ def make_libcef_dll_dylib_impl(header):
for cls in allclasses: for cls in allclasses:
funcs = cls.get_static_funcs() funcs = cls.get_static_funcs()
for func in funcs: for func in funcs:
typedef, declare, init, impl = make_libcef_dll_dylib_impl_func(func) declare, init, impl = make_libcef_dll_dylib_impl_func(func)
ptr_typedef += typedef
ptr_declare += declare ptr_declare += declare
ptr_init += init ptr_init += init
ptr_impl += impl ptr_impl += impl
@ -106,9 +101,8 @@ def make_libcef_dll_dylib_impl(header):
content = read_file(path) content = read_file(path)
funcs = get_function_impls(content, 'CEF_EXPORT', False) funcs = get_function_impls(content, 'CEF_EXPORT', False)
for func in funcs: for func in funcs:
typedef, declare, init, impl = make_libcef_dll_dylib_impl_parts( declare, init, impl = make_libcef_dll_dylib_impl_parts(
func['name'], func['retval'], func['args']) func['name'], func['retval'], func['args'])
ptr_typedef += typedef
ptr_declare += declare ptr_declare += declare
ptr_init += init ptr_init += init
ptr_impl += impl ptr_impl += impl
@ -137,14 +131,12 @@ void* libcef_get_ptr(const char* path, const char* name) {
return ptr; return ptr;
} }
""" + ptr_typedef + """
struct libcef_pointers { struct libcef_pointers {
""" + ptr_declare + """ """ + ptr_declare + """
} g_libcef_pointers = {0}; } g_libcef_pointers = {0};
#define INIT_ENTRY(name) \ #define INIT_ENTRY(name) \
g_libcef_pointers.name = (name##_ptr)libcef_get_ptr(path, #name); \ g_libcef_pointers.name = (decltype(&name))libcef_get_ptr(path, #name); \
if (!g_libcef_pointers.name) { \ if (!g_libcef_pointers.name) { \
return 0; \ return 0; \
} }