[1/3] widl: Protect from duplicated method names in C-style vtable struct (resend)

Nikolay Sivov nsivov at codeweavers.com
Fri Jul 27 11:09:36 CDT 2012


Protect from duplicated method names in C-style vtable struct
-------------- next part --------------
>From 81b0388a2f9c500318e3c5a6c2becd3ca2e279e3 Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov at codeweavers.com>
Date: Fri, 27 Jul 2012 19:18:04 +0400
Subject: [PATCH 2/4] Protect from duplicated method names in C-style vtable struct

---
 tools/widl/header.c |   39 ++++++++++++++++++++++++++++++++++++---
 1 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/tools/widl/header.c b/tools/widl/header.c
index f19929a..9b1a2ca 100644
--- a/tools/widl/header.c
+++ b/tools/widl/header.c
@@ -151,9 +151,9 @@ static const char *uuid_string(const UUID *uuid)
   return buf;
 }
 
-const char *get_name(const var_t *v)
+static const char *get_propmethod_prefix(const var_t *v)
 {
-    static char buffer[256];
+    static char buffer[10];
 
     if (is_attr( v->attrs, ATTR_PROPGET ))
         strcpy( buffer, "get_" );
@@ -163,6 +163,14 @@ const char *get_name(const var_t *v)
         strcpy( buffer, "putref_" );
     else
         buffer[0] = 0;
+    return buffer;
+}
+
+const char *get_name(const var_t *v)
+{
+    static char buffer[256];
+
+    strcpy( buffer, get_propmethod_prefix(v) );
     strcat( buffer, v->name );
     return buffer;
 }
@@ -946,6 +954,28 @@ static void write_inline_wrappers(FILE *header, const type_t *iface, const char
   }
 }
 
+static int is_inherited_method(const type_t *iface, const var_t *func)
+{
+  while ((iface = type_iface_get_inherit(iface)))
+  {
+    const statement_t *stmt;
+    STATEMENTS_FOR_EACH_FUNC(stmt, type_iface_get_stmts(iface))
+    {
+      const var_t *funccmp = stmt->u.var;
+
+      if (!is_callas(func->attrs))
+      {
+         char inherit_name[256];
+         /* compare full name including property prefix */
+         strcpy(inherit_name, get_name(funccmp));
+         if (!strcmp(inherit_name, get_name(func))) return 1;
+      }
+    }
+  }
+
+  return 0;
+}
+
 static void do_write_c_method_def(FILE *header, const type_t *iface, const char *name)
 {
   const statement_t *stmt;
@@ -967,7 +997,10 @@ static void do_write_c_method_def(FILE *header, const type_t *iface, const char
       if (!callconv) callconv = "STDMETHODCALLTYPE";
       indent(header, 0);
       write_type_decl_left(header, type_function_get_rettype(func->type));
-      fprintf(header, " (%s *%s)(\n", callconv, get_name(func));
+      if (is_inherited_method(iface, func))
+        fprintf(header, " (%s *%s%s%s)(\n", callconv, get_propmethod_prefix(func), iface->name, func->name);
+      else
+        fprintf(header, " (%s *%s)(\n", callconv, get_name(func));
       write_args(header, type_get_function_args(func->type), name, 1, TRUE);
       fprintf(header, ");\n");
       fprintf(header, "\n");
-- 
1.5.6.5




More information about the wine-patches mailing list