From 83b943802906a2dce7656b04c1b5779d90cc50e8 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 30 Jan 2019 13:48:46 +0100 Subject: [PATCH] widl: Fix handling context handle return type in mixed mode. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/rpcrt4/tests/server.c | 2 -- tools/widl/server.c | 20 ++++++++++++++------ tools/widl/typegen.c | 16 +++++++++++----- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/dlls/rpcrt4/tests/server.c b/dlls/rpcrt4/tests/server.c index 4f8f043bc13..d68918b25c7 100644 --- a/dlls/rpcrt4/tests/server.c +++ b/dlls/rpcrt4/tests/server.c @@ -1839,8 +1839,6 @@ static void test_handle_return(void) { ctx_handle_t handle, handle2; - if (!is_interp) return; /* broken in widl */ - handle = get_handle(); test_handle(handle); get_handle_by_ptr(&handle2); diff --git a/tools/widl/server.c b/tools/widl/server.c index d165bbb0490..59c17d661f9 100644 --- a/tools/widl/server.c +++ b/tools/widl/server.c @@ -55,6 +55,7 @@ static void write_function_stub(const type_t *iface, const var_t *func, unsigned unsigned char explicit_fc, implicit_fc; int has_full_pointer = is_full_pointer_function(func); const var_t *handle_var = get_func_handle_var( iface, func, &explicit_fc, &implicit_fc ); + type_t *ret_type = type_function_get_rettype(func->type); if (is_interpreted_func( iface, func )) return; @@ -75,7 +76,7 @@ static void write_function_stub(const type_t *iface, const var_t *func, unsigned indent++; write_remoting_arguments(server, indent, func, "__frame->", PASS_OUT, PHASE_FREE); - if (!is_void(type_function_get_rettype(func->type))) + if (!is_void(ret_type)) write_remoting_arguments(server, indent, func, "__frame->", PASS_RETURN, PHASE_FREE); if (has_full_pointer) @@ -154,9 +155,16 @@ static void write_function_stub(const type_t *iface, const var_t *func, unsigned assign_stub_out_args(server, indent, func, "__frame->"); /* Call the real server function */ - print_server("%s%s%s", - is_void(type_function_get_rettype(func->type)) ? "" : "__frame->_RetVal = ", - prefix_server, get_name(func)); + if (is_context_handle(ret_type)) + { + print_server("__frame->_RetVal = NDRSContextUnmarshall((char*)0, _pRpcMessage->DataRepresentation);\n"); + print_server("*(("); + write_type_decl(server, ret_type, NULL); + fprintf(server, "*)NDRSContextValue(__frame->_RetVal)) = "); + } + else + print_server("%s", is_void(ret_type) ? "" : "__frame->_RetVal = "); + fprintf(server, "%s%s", prefix_server, get_name(func)); if (type_get_function_args(func->type)) { @@ -197,7 +205,7 @@ static void write_function_stub(const type_t *iface, const var_t *func, unsigned { write_remoting_arguments(server, indent, func, "__frame->", PASS_OUT, PHASE_BUFFERSIZE); - if (!is_void(type_function_get_rettype(func->type))) + if (!is_void(ret_type)) write_remoting_arguments(server, indent, func, "__frame->", PASS_RETURN, PHASE_BUFFERSIZE); print_server("_pRpcMessage->BufferLength = __frame->_StubMsg.BufferLength;\n"); @@ -216,7 +224,7 @@ static void write_function_stub(const type_t *iface, const var_t *func, unsigned write_remoting_arguments(server, indent, func, "__frame->", PASS_OUT, PHASE_MARSHAL); /* marshall the return value */ - if (!is_void(type_function_get_rettype(func->type))) + if (!is_void(ret_type)) write_remoting_arguments(server, indent, func, "__frame->", PASS_RETURN, PHASE_MARSHAL); indent--; diff --git a/tools/widl/typegen.c b/tools/widl/typegen.c index 7a81277afd3..e5fb20c55fb 100644 --- a/tools/widl/typegen.c +++ b/tools/widl/typegen.c @@ -4246,13 +4246,14 @@ static void write_remoting_arg(FILE *file, int indent, const var_t *func, const } else if (phase == PHASE_UNMARSHAL) { - if (pass == PASS_OUT) + if (pass == PASS_OUT || pass == PASS_RETURN) { if (!in_attr) print_file(file, indent, "*%s%s = 0;\n", local_var_prefix, var->name); print_file(file, indent, "NdrClientContextUnmarshall(\n"); print_file(file, indent + 1, "&__frame->_StubMsg,\n"); - print_file(file, indent + 1, "(NDR_CCONTEXT *)%s%s,\n", local_var_prefix, var->name); + print_file(file, indent + 1, "(NDR_CCONTEXT *)%s%s%s,\n", + pass == PASS_RETURN ? "&" : "", local_var_prefix, var->name); print_file(file, indent + 1, "__frame->_Handle);\n"); } else @@ -4605,9 +4606,14 @@ void declare_stub_args( FILE *file, int indent, const var_t *func ) /* declare return value */ if (!is_void(var->type)) { - print_file(file, indent, "%s", ""); - write_type_decl(file, var->type, var->name); - fprintf(file, ";\n"); + if (is_context_handle(var->type)) + print_file(file, indent, "NDR_SCONTEXT %s;\n", var->name); + else + { + print_file(file, indent, "%s", ""); + write_type_decl(file, var->type, var->name); + fprintf(file, ";\n"); + } } if (!type_get_function_args(func->type))