From 58b60f93f659ca2e16bda367cad11a02a51a7e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Tue, 19 Sep 2023 21:24:23 +0200 Subject: [PATCH] lsteamclient: Generate functions with calling convention. CW-Bug-Id: #22729 --- vrclient_x64/gen_wrapper.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/vrclient_x64/gen_wrapper.py b/vrclient_x64/gen_wrapper.py index 29880f21..4f0bf123 100755 --- a/vrclient_x64/gen_wrapper.py +++ b/vrclient_x64/gen_wrapper.py @@ -308,14 +308,46 @@ def param_needs_conversion(decl): struct_needs_conversion(decl) +def callconv(cursor): + if type(cursor) is not Cursor: + return '' + canon = cursor.type.get_canonical() + if canon.kind != TypeKind.POINTER: + return '' + canon = canon.get_pointee() + if canon.kind != TypeKind.FUNCTIONPROTO: + return '' + if cursor.type.kind == TypeKind.TYPEDEF: + cursor = cursor.type.get_declaration() + + tokens = cursor.get_tokens() + while next(tokens).spelling != '(': pass + token = f'{next(tokens).spelling} ' + return token.replace('*', '__stdcall') \ + .replace('S_CALLTYPE', '__cdecl') + + +def declspec_func(decl, name): + ret = declspec(decl.get_result(), "") + params = [declspec(a, "") for a in decl.argument_types()] + params = ", ".join(params) if len(params) else "void" + return f'{ret} ({name})({params})' + + def declspec(decl, name): + call = callconv(decl) if type(decl) is Cursor: decl = decl.type + canon = decl.get_canonical() + + if canon.kind == TypeKind.POINTER and canon.get_pointee().kind == TypeKind.FUNCTIONPROTO: + canon = canon.get_pointee() + return declspec_func(canon, f"*{call}{name}") const = 'const ' if decl.is_const_qualified() else '' if decl.kind in (TypeKind.POINTER, TypeKind.LVALUEREFERENCE): decl = decl.get_pointee() - return declspec(decl, f"*{const}{name}") + return declspec(decl, f"*{call}{const}{name}") if decl.kind == TypeKind.CONSTANTARRAY: decl, count = decl.element_type, decl.element_count return declspec(decl, f"({const}{name})[{count}]")