Commit c0982b42 authored by Dan Hipschman's avatar Dan Hipschman Committed by Alexandre Julliard

widl: Handle wire_marshal types.

parent c2bf60b0
......@@ -225,6 +225,13 @@ s_sum_cps(cps_t *cps)
return sum;
}
int
s_square_puint(puint_t p)
{
int n = atoi(p);
return n * n;
}
void
s_stop(void)
{
......@@ -388,12 +395,44 @@ free_list(test_list_t *list)
HeapFree(GetProcessHeap(), 0, list);
}
ULONG __RPC_USER
puint_t_UserSize(ULONG *flags, ULONG start, puint_t *p)
{
return start + sizeof(int);
}
unsigned char * __RPC_USER
puint_t_UserMarshal(ULONG *flags, unsigned char *buffer, puint_t *p)
{
int n = atoi(*p);
memcpy(buffer, &n, sizeof n);
return buffer + sizeof n;
}
unsigned char * __RPC_USER
puint_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, puint_t *p)
{
int n;
memcpy(&n, buffer, sizeof n);
*p = HeapAlloc(GetProcessHeap(), 0, 10);
sprintf(*p, "%d", n);
return buffer + sizeof n;
}
void __RPC_USER
puint_t_UserFree(ULONG *flags, puint_t *p)
{
HeapFree(GetProcessHeap(), 0, *p);
}
static void
pointer_tests(void)
{
static char p1[] = "11";
test_list_t *list = make_list(make_list(make_list(null_list())));
ok(test_list_length(list) == 3, "RPC test_list_length\n");
ok(square_puint(p1) == 121, "RPC square_puint\n");
free_list(list);
}
......
......@@ -130,5 +130,7 @@ interface IServer
int sum_cs(cs_t *cs);
int sum_cps(cps_t *cps);
typedef [wire_marshal(int)] void *puint_t;
int square_puint(puint_t p);
void stop(void);
}
......@@ -305,7 +305,7 @@ static void write_stubdescriptor(type_t *iface, int expr_eval_routines)
print_client("0,\n");
print_client("0x50100a4, /* MIDL Version 5.1.164 */\n");
print_client("0,\n");
print_client("0,\n");
print_client("%s,\n", list_empty(&user_type_list) ? "0" : "UserMarshalRoutines");
print_client("0, /* notify & notify_flag routine table */\n");
print_client("1, /* Flags */\n");
print_client("0, /* Reserved3 */\n");
......@@ -434,6 +434,7 @@ void write_client(ifref_list_t *ifaces)
expr_eval_routines = write_expr_eval_routines(client, iface->iface->name);
if (expr_eval_routines)
write_expr_eval_routine_list(client, iface->iface->name);
write_user_quad_list(client);
write_stubdescriptor(iface->iface, expr_eval_routines);
}
}
......
......@@ -285,25 +285,18 @@ void write_type(FILE *h, type_t *t, int is_field, const char *fmt, ...)
write_type_right(h, t, is_field);
}
struct user_type
{
struct user_type *next;
char name[1];
};
static struct user_type *user_type_list;
user_type_list_t user_type_list = LIST_INIT(user_type_list);
static int user_type_registered(const char *name)
{
struct user_type *ut;
for (ut = user_type_list; ut; ut = ut->next)
user_type_t *ut;
LIST_FOR_EACH_ENTRY(ut, &user_type_list, user_type_t, entry)
if (!strcmp(name, ut->name))
return 1;
return 1;
return 0;
}
static void check_for_user_types(const var_list_t *list)
void check_for_user_types(const var_list_t *list)
{
const var_t *v;
......@@ -318,10 +311,9 @@ static void check_for_user_types(const var_list_t *list)
if (is_attr(type->attrs, ATTR_WIREMARSHAL)) {
if (!user_type_registered(name))
{
struct user_type *ut = xmalloc(sizeof(struct user_type) + strlen(name));
strcpy(ut->name, name);
ut->next = user_type_list;
user_type_list = ut;
user_type_t *ut = xmalloc(sizeof *ut);
ut->name = xstrdup(name);
list_add_tail(&user_type_list, &ut->entry);
}
/* don't carry on parsing fields within this type as we are already
* using a wire marshaled type */
......@@ -337,8 +329,8 @@ static void check_for_user_types(const var_list_t *list)
void write_user_types(void)
{
struct user_type *ut;
for (ut = user_type_list; ut; ut = ut->next)
user_type_t *ut;
LIST_FOR_EACH_ENTRY(ut, &user_type_list, user_type_t, entry)
{
const char *name = ut->name;
fprintf(header, "ULONG __RPC_USER %s_UserSize (ULONG *, ULONG, %s *);\n", name, name);
......@@ -668,7 +660,6 @@ static void write_method_proto(const type_t *iface)
fprintf(header, " IRpcChannelBuffer* pRpcChannelBuffer,\n");
fprintf(header, " PRPC_MESSAGE pRpcMessage,\n");
fprintf(header, " DWORD* pdwStubPhase);\n");
check_for_user_types(cur->args);
}
if (cas) {
const func_t *m;
......
......@@ -125,6 +125,7 @@ static int compute_method_indexes(type_t *iface);
static char *gen_name(void);
static void process_typedefs(var_list_t *names);
static void check_arg(var_t *arg);
static void check_all_user_types(ifref_list_t *ifaces);
#define tsENUM 1
#define tsSTRUCT 2
......@@ -275,6 +276,7 @@ static void check_arg(var_t *arg);
%%
input: gbl_statements { fix_incomplete();
check_all_user_types($1);
write_proxies($1);
write_client($1);
write_server($1);
......@@ -1932,3 +1934,16 @@ static void check_arg(var_t *arg)
if (t->type == 0 && ! is_var_ptr(arg))
yyerror("argument '%s' has void type", arg->name);
}
static void check_all_user_types(ifref_list_t *ifrefs)
{
const ifref_t *ifref;
const func_t *f;
if (ifrefs) LIST_FOR_EACH_ENTRY(ifref, ifrefs, const ifref_t, entry)
{
const func_list_t *fs = ifref->iface->funcs;
if (fs) LIST_FOR_EACH_ENTRY(f, fs, const func_t, entry)
check_for_user_types(f->args);
}
}
......@@ -85,7 +85,7 @@ static void write_stubdesc(void)
print_proxy( "0,\n");
print_proxy( "0x50100a4, /* MIDL Version 5.1.164 */\n");
print_proxy( "0,\n");
print_proxy( "0,\n");
print_proxy("%s,\n", list_empty(&user_type_list) ? "0" : "UserMarshalRoutines");
print_proxy( "0, /* notify & notify_flag routine table */\n");
print_proxy( "1, /* Flags */\n");
print_proxy( "0, /* Reserved3 */\n");
......@@ -373,9 +373,7 @@ static void gen_stub(type_t *iface, const func_t *cur, const char *cas,
print_proxy("NdrStubInitialize(_pRpcMessage, &_StubMsg, &Object_StubDesc, _pRpcChannelBuffer);\n");
fprintf(proxy, "\n");
if (cur->args)
LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry )
print_proxy("%s = 0;\n", arg->name);
write_parameters_init(cur);
print_proxy("RpcTryFinally\n");
print_proxy("{\n");
......@@ -589,6 +587,7 @@ void write_proxies(ifref_list_t *ifaces)
if (is_object(cur->iface->attrs) && !is_local(cur->iface->attrs))
write_proxy(cur->iface, &proc_offset);
write_user_quad_list(proxy);
write_stubdesc();
print_proxy( "#if !defined(__RPC_WIN32__)\n");
......
......@@ -61,7 +61,7 @@ static int print_server(const char *format, ...)
}
static void write_parameters_init(const func_t *func)
void write_parameters_init(const func_t *func)
{
const var_t *var;
......@@ -69,8 +69,14 @@ static void write_parameters_init(const func_t *func)
return;
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
if (var->type->type != RPC_FC_BIND_PRIMITIVE)
print_server("%s = 0;\n", var->name);
{
const type_t *t = var->type;
const char *n = var->name;
if (decl_indirect(t))
print_server("MIDL_memset(&%s, 0, sizeof %s);\n", n, n);
else if (is_ptr(t) || is_array(t))
print_server("%s = 0;\n", n);
}
fprintf(server, "\n");
}
......@@ -337,7 +343,7 @@ static void write_stubdescriptor(type_t *iface, int expr_eval_routines)
print_server("0,\n");
print_server("0x50100a4, /* MIDL Version 5.1.164 */\n");
print_server("0,\n");
print_server("0,\n");
print_server("%s,\n", list_empty(&user_type_list) ? "0" : "UserMarshalRoutines");
print_server("0, /* notify & notify_flag routine table */\n");
print_server("1, /* Flags */\n");
print_server("0, /* Reserved3 */\n");
......@@ -454,6 +460,7 @@ void write_server(ifref_list_t *ifaces)
if (expr_eval_routines)
write_expr_eval_routine_list(server, iface->iface->name);
write_user_quad_list(server);
write_stubdescriptor(iface->iface, expr_eval_routines);
write_dispatchtable(iface->iface);
}
......
......@@ -48,5 +48,8 @@ void assign_stub_out_args( FILE *file, int indent, const func_t *func );
void declare_stub_args( FILE *file, int indent, const func_t *func );
int write_expr_eval_routines(FILE *file, const char *iface);
void write_expr_eval_routine_list(FILE *file, const char *iface);
void write_user_quad_list(FILE *file);
void write_endpoints( FILE *f, const char *prefix, const str_list_t *list );
size_t type_memsize(const type_t *t, unsigned int *align);
int decl_indirect(const type_t *t);
void write_parameters_init(const func_t *func);
......@@ -46,6 +46,7 @@ typedef struct _typelib_entry_t typelib_entry_t;
typedef struct _importlib_t importlib_t;
typedef struct _importinfo_t importinfo_t;
typedef struct _typelib_t typelib_t;
typedef struct _user_type_t user_type_t;
typedef struct list attr_list_t;
typedef struct list str_list_t;
......@@ -55,6 +56,7 @@ typedef struct list var_list_t;
typedef struct list pident_list_t;
typedef struct list ifref_list_t;
typedef struct list array_dims_t;
typedef struct list user_type_list_t;
enum attr_type
{
......@@ -295,6 +297,14 @@ struct _typelib_t {
struct list importlibs;
};
struct _user_type_t {
struct list entry;
const char *name;
};
extern user_type_list_t user_type_list;
void check_for_user_types(const var_list_t *list);
void init_types(void);
type_t *duptype(type_t *t, int dupname);
......
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