[5/5] widl: Fix a write_parameters_init bug

Dan Hipschman dsh at linux.ucla.edu
Thu Jun 14 20:30:26 CDT 2007


This patch fixes a bug with one of the patches I submitted yesterday.
The write_parameters_init function is used to write both the server
and proxy files, but it used the print_server function, so it only
actually worked for the server, and crashed if used for the proxy when
the server file was not open.  This moves the function into typegen.c
instead of server.c, and writes to the correct file.

---
 tools/widl/proxy.c   |    2 +-
 tools/widl/server.c  |   24 +-----------------------
 tools/widl/typegen.c |   20 ++++++++++++++++++++
 tools/widl/typegen.h |    2 +-
 4 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/tools/widl/proxy.c b/tools/widl/proxy.c
index 93eddf5..4911caf 100644
--- a/tools/widl/proxy.c
+++ b/tools/widl/proxy.c
@@ -367,7 +367,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");
 
-  write_parameters_init(cur);
+  write_parameters_init(proxy, indent, cur);
 
   print_proxy("RpcTryFinally\n");
   print_proxy("{\n");
diff --git a/tools/widl/server.c b/tools/widl/server.c
index e3740ce..fd94c9a 100644
--- a/tools/widl/server.c
+++ b/tools/widl/server.c
@@ -54,28 +54,6 @@ static void print_server(const char *format, ...)
     va_end(va);
 }
 
-
-void write_parameters_init(const func_t *func)
-{
-    const var_t *var;
-
-    if (!func->args)
-        return;
-
-    LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
-    {
-        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");
-}
-
-
 static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
 {
     char *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
@@ -137,7 +115,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
         indent--;
         fprintf(server, "\n");
 
-        write_parameters_init(func);
+        write_parameters_init(server, indent, func);
 
         if (explicit_handle_var)
         {
diff --git a/tools/widl/typegen.c b/tools/widl/typegen.c
index 6da96f5..a1e4e6d 100644
--- a/tools/widl/typegen.c
+++ b/tools/widl/typegen.c
@@ -273,6 +273,26 @@ void print(FILE *file, int indent, const char *format, va_list va)
     }
 }
 
+void write_parameters_init(FILE *file, int indent, const func_t *func)
+{
+    const var_t *var;
+
+    if (!func->args)
+        return;
+
+    LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
+    {
+        const type_t *t = var->type;
+        const char *n = var->name;
+        if (decl_indirect(t))
+            print_file(file, indent, "MIDL_memset(&%s, 0, sizeof %s);\n", n, n);
+        else if (is_ptr(t) || is_array(t))
+            print_file(file, indent, "%s = 0;\n", n);
+    }
+
+    fprintf(file, "\n");
+}
+
 static void write_formatdesc(FILE *f, int indent, const char *str)
 {
     print_file(f, indent, "typedef struct _MIDL_%s_FORMAT_STRING\n", str);
diff --git a/tools/widl/typegen.h b/tools/widl/typegen.h
index 77b207e..eefecd7 100644
--- a/tools/widl/typegen.h
+++ b/tools/widl/typegen.h
@@ -53,5 +53,5 @@ 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);
+void write_parameters_init(FILE *file, int indent, const func_t *func);
 void print(FILE *file, int indent, const char *format, va_list ap);



More information about the wine-patches mailing list