lsteamclient: Replace do_cb_wrap with (alloc|convert)_callback.

CW-Bug-Id: #22729
This commit is contained in:
Rémi Bernon 2023-09-23 20:55:11 +02:00 committed by Arkadiusz Hiler
parent 31e7035f64
commit 7b11b2a3a6
4 changed files with 141 additions and 42 deletions

View file

@ -930,6 +930,11 @@ def handle_method_c(method, winclassname, cppname, cfile):
if not returns_record and not returns_void:
cfile.write(f' {ret}_ret;\n')
should_gen_callback = "GetAPICallResult" in method.name
if should_gen_callback:
cfile.write(" int u_callback_len = cubCallback, w_callback_len = cubCallback;\n");
cfile.write(" void *u_callback, *w_callback = pCallback;\n")
path_conv = get_path_converter(method)
if path_conv:
@ -944,6 +949,11 @@ def handle_method_c(method, winclassname, cppname, cfile):
cfile.write(" TRACE(\"%p\\n\", _this);\n")
if should_gen_callback:
cfile.write(" if (!(u_callback = alloc_callback_wtou(iCallbackExpected, w_callback, &u_callback_len))) return FALSE;\n")
cfile.write(" cubCallback = u_callback_len;\n")
cfile.write(" pCallback = u_callback;\n\n")
if returns_record:
cfile.write(u' *_ret = ')
elif not returns_void:
@ -951,14 +961,9 @@ def handle_method_c(method, winclassname, cppname, cfile):
else:
cfile.write(u' ')
should_do_cb_wrap = "GetAPICallResult" in method.name
should_gen_wrapper = not method_needs_manual_handling(cppname, method.name) and \
(method.result_type.spelling.startswith("ISteam") or \
method.name.startswith("GetISteamGenericInterface"))
if should_do_cb_wrap:
cfile.write(f"do_cb_wrap(0, &{cppname}_{method.name}, ")
else:
if should_gen_wrapper:
cfile.write("create_win_interface(pchVersion,\n ")
cfile.write(f"{cppname}_{method.name}(")
@ -977,6 +982,14 @@ def handle_method_c(method, winclassname, cppname, cfile):
cfile.write(")")
cfile.write(");\n")
if should_gen_callback:
cfile.write(" if (_ret && u_callback != w_callback)\n")
cfile.write(" {\n")
cfile.write(" convert_callback_utow(iCallbackExpected, u_callback, u_callback_len, w_callback, w_callback_len);\n")
cfile.write(" HeapFree(GetProcessHeap(), 0, u_callback);\n")
cfile.write(" }\n\n")
if path_conv and len(path_conv["l2w_names"]) > 0:
for i in range(len(path_conv["l2w_names"])):
cfile.write(" ")

View file

@ -1000,7 +1000,7 @@ static int get_callback_len(int cb)
return 0;
}
static void *alloc_callback_wtou( int id, void *callback, int *callback_len )
void *alloc_callback_wtou( int id, void *callback, int *callback_len )
{
int len;
@ -1011,7 +1011,7 @@ static void *alloc_callback_wtou( int id, void *callback, int *callback_len )
return callback;
}
static void convert_callback_utow( int id, void *lin_callback, int lin_callback_len, void *callback, int callback_len )
void convert_callback_utow( int id, void *lin_callback, int lin_callback_len, void *callback, int callback_len )
{
switch (id)
{
@ -1019,37 +1019,28 @@ static void convert_callback_utow( int id, void *lin_callback, int lin_callback_
}
}
bool do_cb_wrap( HSteamPipe pipe, bool (*cpp_func)( void *, SteamAPICall_t, void *, int, int, bool * ),
void *linux_side, SteamAPICall_t call, void *callback, int callback_len, int id, bool *failed )
bool CDECL Steam_GetAPICallResult( HSteamPipe pipe, SteamAPICall_t call, void *w_callback,
int w_callback_len, int id, bool *failed )
{
int lin_callback_len = callback_len;
void *lin_callback;
int u_callback_len = w_callback_len;
void *u_callback;
bool ret;
if (!(lin_callback = alloc_callback_wtou( id, callback, &lin_callback_len ))) return FALSE;
TRACE( "%u, x, %p, %u, %u, %p\n", pipe, w_callback, w_callback_len, id, failed );
if(!cpp_func){
if(!load_steamclient())
return 0;
ret = steamclient_GetAPICallResult(pipe, call, callback, callback_len, id, failed);
}else
ret = cpp_func(linux_side, call, callback, callback_len, id, failed);
if (!load_steamclient()) return FALSE;
if (ret && lin_callback != callback)
if (!(u_callback = alloc_callback_wtou( id, w_callback, &u_callback_len ))) return FALSE;
ret = steamclient_GetAPICallResult( pipe, call, u_callback, u_callback_len, id, failed );
if (ret && u_callback != w_callback)
{
convert_callback_utow( id, lin_callback, lin_callback_len, callback, callback_len );
HeapFree( GetProcessHeap(), 0, lin_callback );
convert_callback_utow( id, u_callback, u_callback_len, w_callback, w_callback_len );
HeapFree( GetProcessHeap(), 0, u_callback );
}
return ret;
}
bool CDECL Steam_GetAPICallResult(HSteamPipe pipe, SteamAPICall_t call,
void *callback, int callback_len, int cb_expected, bool *failed)
{
TRACE("%u, x, %p, %u, %u, %p\n", pipe, callback, callback_len, cb_expected, failed);
return do_cb_wrap(pipe, NULL, NULL, call, callback, callback_len, cb_expected, failed);
}
bool CDECL Steam_FreeLastCallback(HSteamPipe pipe)
{
TRACE("%u\n", pipe);

View file

@ -66,9 +66,8 @@ void *manual_convert_SteamAPI_CheckCallbackRegistered_t(void *win_func);
extern char g_tmppath[PATH_MAX];
typedef uint64 SteamAPICall_t; //for ancient SDKs
bool do_cb_wrap( HSteamPipe pipe, bool (*cpp_func)( void *, SteamAPICall_t, void *, int, int, bool * ),
void *linux_side, SteamAPICall_t call, void *callback, int callback_len,
int cb_expected, bool *failed );
void *alloc_callback_wtou( int id, void *callback, int *callback_len );
void convert_callback_utow( int id, void *lin_callback, int lin_callback_len, void *callback, int callback_len );
void *alloc_mem_for_iface(size_t size, const char *iface_version);
void *alloc_vtable(void *vtable, unsigned int method_count, const char *iface_version);

View file

@ -142,8 +142,20 @@ ESteamAPICallFailure __thiscall winISteamUtils_SteamUtils002_GetAPICallFailureRe
bool __thiscall winISteamUtils_SteamUtils002_GetAPICallResult(winISteamUtils_SteamUtils002 *_this, SteamAPICall_t hSteamAPICall, void *pCallback, int cubCallback, int iCallbackExpected, bool *pbFailed)
{
bool _ret;
int u_callback_len = cubCallback, w_callback_len = cubCallback;
void *u_callback, *w_callback = pCallback;
TRACE("%p\n", _this);
_ret = do_cb_wrap(0, &cppISteamUtils_SteamUtils002_GetAPICallResult, _this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (!(u_callback = alloc_callback_wtou(iCallbackExpected, w_callback, &u_callback_len))) return FALSE;
cubCallback = u_callback_len;
pCallback = u_callback;
_ret = cppISteamUtils_SteamUtils002_GetAPICallResult(_this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (_ret && u_callback != w_callback)
{
convert_callback_utow(iCallbackExpected, u_callback, u_callback_len, w_callback, w_callback_len);
HeapFree(GetProcessHeap(), 0, u_callback);
}
return _ret;
}
@ -312,8 +324,20 @@ ESteamAPICallFailure __thiscall winISteamUtils_SteamUtils004_GetAPICallFailureRe
bool __thiscall winISteamUtils_SteamUtils004_GetAPICallResult(winISteamUtils_SteamUtils004 *_this, SteamAPICall_t hSteamAPICall, void *pCallback, int cubCallback, int iCallbackExpected, bool *pbFailed)
{
bool _ret;
int u_callback_len = cubCallback, w_callback_len = cubCallback;
void *u_callback, *w_callback = pCallback;
TRACE("%p\n", _this);
_ret = do_cb_wrap(0, &cppISteamUtils_SteamUtils004_GetAPICallResult, _this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (!(u_callback = alloc_callback_wtou(iCallbackExpected, w_callback, &u_callback_len))) return FALSE;
cubCallback = u_callback_len;
pCallback = u_callback;
_ret = cppISteamUtils_SteamUtils004_GetAPICallResult(_this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (_ret && u_callback != w_callback)
{
convert_callback_utow(iCallbackExpected, u_callback, u_callback_len, w_callback, w_callback_len);
HeapFree(GetProcessHeap(), 0, u_callback);
}
return _ret;
}
@ -519,8 +543,20 @@ ESteamAPICallFailure __thiscall winISteamUtils_SteamUtils005_GetAPICallFailureRe
bool __thiscall winISteamUtils_SteamUtils005_GetAPICallResult(winISteamUtils_SteamUtils005 *_this, SteamAPICall_t hSteamAPICall, void *pCallback, int cubCallback, int iCallbackExpected, bool *pbFailed)
{
bool _ret;
int u_callback_len = cubCallback, w_callback_len = cubCallback;
void *u_callback, *w_callback = pCallback;
TRACE("%p\n", _this);
_ret = do_cb_wrap(0, &cppISteamUtils_SteamUtils005_GetAPICallResult, _this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (!(u_callback = alloc_callback_wtou(iCallbackExpected, w_callback, &u_callback_len))) return FALSE;
cubCallback = u_callback_len;
pCallback = u_callback;
_ret = cppISteamUtils_SteamUtils005_GetAPICallResult(_this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (_ret && u_callback != w_callback)
{
convert_callback_utow(iCallbackExpected, u_callback, u_callback_len, w_callback, w_callback_len);
HeapFree(GetProcessHeap(), 0, u_callback);
}
return _ret;
}
@ -775,8 +811,20 @@ ESteamAPICallFailure __thiscall winISteamUtils_SteamUtils006_GetAPICallFailureRe
bool __thiscall winISteamUtils_SteamUtils006_GetAPICallResult(winISteamUtils_SteamUtils006 *_this, SteamAPICall_t hSteamAPICall, void *pCallback, int cubCallback, int iCallbackExpected, bool *pbFailed)
{
bool _ret;
int u_callback_len = cubCallback, w_callback_len = cubCallback;
void *u_callback, *w_callback = pCallback;
TRACE("%p\n", _this);
_ret = do_cb_wrap(0, &cppISteamUtils_SteamUtils006_GetAPICallResult, _this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (!(u_callback = alloc_callback_wtou(iCallbackExpected, w_callback, &u_callback_len))) return FALSE;
cubCallback = u_callback_len;
pCallback = u_callback;
_ret = cppISteamUtils_SteamUtils006_GetAPICallResult(_this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (_ret && u_callback != w_callback)
{
convert_callback_utow(iCallbackExpected, u_callback, u_callback_len, w_callback, w_callback_len);
HeapFree(GetProcessHeap(), 0, u_callback);
}
return _ret;
}
@ -1050,8 +1098,20 @@ ESteamAPICallFailure __thiscall winISteamUtils_SteamUtils007_GetAPICallFailureRe
bool __thiscall winISteamUtils_SteamUtils007_GetAPICallResult(winISteamUtils_SteamUtils007 *_this, SteamAPICall_t hSteamAPICall, void *pCallback, int cubCallback, int iCallbackExpected, bool *pbFailed)
{
bool _ret;
int u_callback_len = cubCallback, w_callback_len = cubCallback;
void *u_callback, *w_callback = pCallback;
TRACE("%p\n", _this);
_ret = do_cb_wrap(0, &cppISteamUtils_SteamUtils007_GetAPICallResult, _this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (!(u_callback = alloc_callback_wtou(iCallbackExpected, w_callback, &u_callback_len))) return FALSE;
cubCallback = u_callback_len;
pCallback = u_callback;
_ret = cppISteamUtils_SteamUtils007_GetAPICallResult(_this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (_ret && u_callback != w_callback)
{
convert_callback_utow(iCallbackExpected, u_callback, u_callback_len, w_callback, w_callback_len);
HeapFree(GetProcessHeap(), 0, u_callback);
}
return _ret;
}
@ -1334,8 +1394,20 @@ ESteamAPICallFailure __thiscall winISteamUtils_SteamUtils008_GetAPICallFailureRe
bool __thiscall winISteamUtils_SteamUtils008_GetAPICallResult(winISteamUtils_SteamUtils008 *_this, SteamAPICall_t hSteamAPICall, void *pCallback, int cubCallback, int iCallbackExpected, bool *pbFailed)
{
bool _ret;
int u_callback_len = cubCallback, w_callback_len = cubCallback;
void *u_callback, *w_callback = pCallback;
TRACE("%p\n", _this);
_ret = do_cb_wrap(0, &cppISteamUtils_SteamUtils008_GetAPICallResult, _this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (!(u_callback = alloc_callback_wtou(iCallbackExpected, w_callback, &u_callback_len))) return FALSE;
cubCallback = u_callback_len;
pCallback = u_callback;
_ret = cppISteamUtils_SteamUtils008_GetAPICallResult(_this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (_ret && u_callback != w_callback)
{
convert_callback_utow(iCallbackExpected, u_callback, u_callback_len, w_callback, w_callback_len);
HeapFree(GetProcessHeap(), 0, u_callback);
}
return _ret;
}
@ -1640,8 +1712,20 @@ ESteamAPICallFailure __thiscall winISteamUtils_SteamUtils009_GetAPICallFailureRe
bool __thiscall winISteamUtils_SteamUtils009_GetAPICallResult(winISteamUtils_SteamUtils009 *_this, SteamAPICall_t hSteamAPICall, void *pCallback, int cubCallback, int iCallbackExpected, bool *pbFailed)
{
bool _ret;
int u_callback_len = cubCallback, w_callback_len = cubCallback;
void *u_callback, *w_callback = pCallback;
TRACE("%p\n", _this);
_ret = do_cb_wrap(0, &cppISteamUtils_SteamUtils009_GetAPICallResult, _this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (!(u_callback = alloc_callback_wtou(iCallbackExpected, w_callback, &u_callback_len))) return FALSE;
cubCallback = u_callback_len;
pCallback = u_callback;
_ret = cppISteamUtils_SteamUtils009_GetAPICallResult(_this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (_ret && u_callback != w_callback)
{
convert_callback_utow(iCallbackExpected, u_callback, u_callback_len, w_callback, w_callback_len);
HeapFree(GetProcessHeap(), 0, u_callback);
}
return _ret;
}
@ -2002,8 +2086,20 @@ ESteamAPICallFailure __thiscall winISteamUtils_SteamUtils010_GetAPICallFailureRe
bool __thiscall winISteamUtils_SteamUtils010_GetAPICallResult(winISteamUtils_SteamUtils010 *_this, SteamAPICall_t hSteamAPICall, void *pCallback, int cubCallback, int iCallbackExpected, bool *pbFailed)
{
bool _ret;
int u_callback_len = cubCallback, w_callback_len = cubCallback;
void *u_callback, *w_callback = pCallback;
TRACE("%p\n", _this);
_ret = do_cb_wrap(0, &cppISteamUtils_SteamUtils010_GetAPICallResult, _this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (!(u_callback = alloc_callback_wtou(iCallbackExpected, w_callback, &u_callback_len))) return FALSE;
cubCallback = u_callback_len;
pCallback = u_callback;
_ret = cppISteamUtils_SteamUtils010_GetAPICallResult(_this->linux_side, hSteamAPICall, pCallback, cubCallback, iCallbackExpected, pbFailed);
if (_ret && u_callback != w_callback)
{
convert_callback_utow(iCallbackExpected, u_callback, u_callback_len, w_callback, w_callback_len);
HeapFree(GetProcessHeap(), 0, u_callback);
}
return _ret;
}