Sync to trunk r38250
[reactos.git] / reactos / tools / widl / typegen.c
index 52fb956..8df2ad5 100644 (file)
@@ -823,7 +823,13 @@ size_t type_memsize(const type_t *t, unsigned int *align)
     }
     else if (is_ptr(t) || is_conformant_array(t))
     {
-        size = sizeof(void *);
+#if defined(TARGET_i386)
+        size = 4;
+#elif defined(TARGET_amd64)
+        size = 8;
+#else
+#error Unsupported CPU
+#endif
         if (size > *align) *align = size;
     }
     else switch (t->type)
@@ -984,7 +990,7 @@ static void write_user_tfs(FILE *file, type_t *type, unsigned int *tfsoff)
 {
     unsigned int start, absoff, flags;
     unsigned int align = 0, ualign = 0;
-    const char *name;
+    const char *name = NULL;
     type_t *utype = get_user_type(type, &name);
     size_t usize = user_type_has_variable_size(utype) ? 0 : type_memsize(utype, &ualign);
     size_t size = type_memsize(type, &align);
@@ -2457,11 +2463,12 @@ void write_typeformatstring(FILE *file, const statement_list_t *stmts, type_pred
 static unsigned int get_required_buffer_size_type(
     const type_t *type, const char *name, unsigned int *alignment)
 {
+    const char *uname;
+    const type_t *utype;
+
     *alignment = 0;
-    if (is_user_type(type))
+    if ((utype = get_user_type(type, &uname)))
     {
-        const char *uname;
-        const type_t *utype = get_user_type(type, &uname);
         return get_required_buffer_size_type(utype, uname, alignment);
     }
     else
@@ -2727,8 +2734,8 @@ void print_phase_basetype(FILE *file, int indent, enum remoting_phase phase,
     }
 
     if (phase == PHASE_MARSHAL)
-        print_file(file, indent, "MIDL_memset(_StubMsg.Buffer, 0, (0x%x - (long)_StubMsg.Buffer) & 0x%x);\n", alignment, alignment - 1);
-    print_file(file, indent, "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + %u) & ~0x%x);\n",
+        print_file(file, indent, "MIDL_memset(_StubMsg.Buffer, 0, (0x%x - (size_t)_StubMsg.Buffer) & 0x%x);\n", alignment, alignment - 1);
+    print_file(file, indent, "_StubMsg.Buffer = (unsigned char *)(((size_t)_StubMsg.Buffer + %u) & ~0x%x);\n",
                 alignment - 1, alignment - 1);
 
     if (phase == PHASE_MARSHAL)
@@ -3195,11 +3202,9 @@ void declare_stub_args( FILE *file, int indent, const func_t *func )
             write_type_decl_left(file, var->type);
             fprintf(file, " ");
             if (var->type->declarray) {
-                fprintf(file, "( *");
-                write_name(file, var);
-                fprintf(file, " )");
+                fprintf(file, "(*%s)", get_name(var));
             } else
-                write_name(file, var);
+                fprintf(file, "%s", get_name(var));
             write_type_right(file, var->type, FALSE);
             fprintf(file, ";\n");
 
@@ -3230,8 +3235,7 @@ void assign_stub_out_args( FILE *file, int indent, const func_t *func )
 
         if (!in_attr)
         {
-            print_file(file, indent, "");
-            write_name(file, var);
+            print_file(file, indent, "%s", get_name(var));
 
             if (is_context_handle(var->type))
             {