Commit e0dd7b6e authored by Robert Shearman's avatar Robert Shearman Committed by Alexandre Julliard

widl: Remove some duplication.

Remove some duplicated code by calling an improved get_required_buffer_size. Add some more newlines in the generated code to separate separate stages. Calculate the buffer size of [out] arguments in generated server code. Fix the direction passed into unmarshall_arguments.
parent 7e5cf94f
......@@ -76,43 +76,11 @@ static void print_message_buffer_size(func_t *func)
while (NEXT_LINK(var)) var = NEXT_LINK(var);
while (var)
{
unsigned int alignment = 8;
switch (var->type->type)
{
case RPC_FC_BYTE:
case RPC_FC_CHAR:
case RPC_FC_USMALL:
case RPC_FC_SMALL:
total_size += 1;
alignment = 1;
break;
case RPC_FC_WCHAR:
case RPC_FC_USHORT:
case RPC_FC_SHORT:
total_size += 2 + alignment % 2;
alignment = 2;
break;
case RPC_FC_ULONG:
case RPC_FC_LONG:
case RPC_FC_FLOAT:
case RPC_FC_ERROR_STATUS_T:
total_size += 4 + alignment % 4;
alignment = 4;
break;
case RPC_FC_HYPER:
case RPC_FC_DOUBLE:
total_size += 8 + alignment % 8;
alignment = 8;
break;
default:
alignment = 1;
}
unsigned int alignment;
total_size += get_required_buffer_size(var, &alignment);
total_size += alignment;
var = PREV_LINK(var);
}
}
......@@ -236,11 +204,11 @@ static void write_function_stubs(type_t *iface)
print_client("NdrSendReceive(\n");
indent++;
print_client("(PMIDL_STUB_MESSAGE)&_StubMsg,\n");
print_client("(unsigned char *)_StubMsg.Buffer);\n");
print_client("(unsigned char *)_StubMsg.Buffer);\n\n");
indent--;
print_client("_StubMsg.BufferStart = (unsigned char *)_RpcMessage.Buffer;\n");
print_client("_StubMsg.BufferEnd = _StubMsg.BufferStart + _RpcMessage.BufferLength;\n");
print_client("_StubMsg.BufferEnd = _StubMsg.BufferStart + _RpcMessage.BufferLength;\n\n");
/* unmarshal return value */
if (!is_void(def->type, NULL))
......
......@@ -101,6 +101,7 @@ static void write_function_stubs(type_t *iface)
while (func)
{
var_t *def = func->def;
unsigned long buffer_size = 0;
/* check for a defined binding handle */
explicit_handle_var = get_explicit_handle_var(func);
......@@ -198,7 +199,7 @@ static void write_function_stubs(type_t *iface)
indent -= 2;
fprintf(server, "\n");
unmarshall_arguments(server, indent, func, &type_offset, PASS_OUT);
unmarshall_arguments(server, indent, func, &type_offset, PASS_IN);
}
print_server("if (_StubMsg.Buffer > _StubMsg.BufferEnd)\n");
......@@ -252,11 +253,34 @@ static void write_function_stubs(type_t *iface)
fprintf(server, "();\n");
}
/* marshall the return value */
if (func->args)
{
var_t *var = func->args;
while (NEXT_LINK(var)) var = NEXT_LINK(var);
while (var)
{
if (is_attr(var->attrs, ATTR_OUT))
{
unsigned int alignment;
buffer_size += get_required_buffer_size(var, &alignment);
buffer_size += alignment;
}
var = PREV_LINK(var);
}
}
if (!is_void(def->type, NULL))
{
unsigned int alignment;
buffer_size += get_required_buffer_size(def, &alignment);
buffer_size += alignment;
}
if (buffer_size)
{
fprintf(server, "\n");
print_server("_StubMsg.BufferLength = %uU;\n", get_required_buffer_size(def->type));
print_server("_StubMsg.BufferLength = %uU;\n", buffer_size);
print_server("_pRpcMessage->BufferLength = _StubMsg.BufferLength;\n");
fprintf(server, "\n");
print_server("_Status = I_RpcGetBuffer(_pRpcMessage);\n");
......@@ -267,7 +291,11 @@ static void write_function_stubs(type_t *iface)
fprintf(server, "\n");
print_server("_StubMsg.Buffer = (unsigned char *)_pRpcMessage->Buffer;\n");
fprintf(server, "\n");
}
/* marshall the return value */
if (!is_void(def->type, NULL))
{
print_server("*(");
write_type(server, def->type, def, def->tname);
fprintf(server, " *)_StubMsg.Buffer = _RetVal;\n");
......
......@@ -253,32 +253,43 @@ void write_typeformatstring(FILE *file, type_t *iface)
}
unsigned int get_required_buffer_size(type_t *type)
unsigned int get_required_buffer_size(const var_t *var, unsigned int *alignment)
{
switch(type->type)
*alignment = 0;
if (var->ptr_level == 0 && !var->array)
{
switch (var->type->type)
{
case RPC_FC_BYTE:
case RPC_FC_CHAR:
case RPC_FC_USMALL:
case RPC_FC_SMALL:
return 1;
case RPC_FC_WCHAR:
case RPC_FC_USHORT:
case RPC_FC_SHORT:
case RPC_FC_USMALL:
case RPC_FC_SMALL:
*alignment = 2;
return 2;
case RPC_FC_ULONG:
case RPC_FC_LONG:
case RPC_FC_FLOAT:
case RPC_FC_IGNORE:
case RPC_FC_ERROR_STATUS_T:
*alignment = 4;
return 4;
case RPC_FC_HYPER:
case RPC_FC_DOUBLE:
*alignment = 8;
return 8;
default:
error("Unknown/unsupported type: %s (0x%02x)\n", type->name, type->type);
error("get_required_buffer_size: Unknown/unsupported type: %s (0x%02x)\n", var->name, var->type->type);
return 0;
}
}
return 0;
}
void marshall_arguments(FILE *file, int indent, func_t *func,
......
......@@ -29,7 +29,7 @@ enum pass
void write_procformatstring(FILE *file, type_t *iface);
void write_typeformatstring(FILE *file, type_t *iface);
unsigned int get_required_buffer_size(type_t *type);
unsigned int get_required_buffer_size(const var_t *var, unsigned int *alignment);
void marshall_arguments(FILE *file, int indent, func_t *func, unsigned int *type_offset, enum pass pass);
void unmarshall_arguments(FILE *file, int indent, func_t *func, unsigned int *type_offset, enum pass pass);
size_t get_size_procformatstring_var(var_t *var);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment