mapi: Make struct mapi_stub opaque.
authorChia-I Wu <olv@lunarg.com>
Fri, 24 Dec 2010 05:49:01 +0000 (13:49 +0800)
committerChia-I Wu <olv@lunarg.com>
Fri, 24 Dec 2010 09:28:52 +0000 (17:28 +0800)
Add accessors for struct mapi_stub and make it opaque.

src/mapi/mapi/mapi.c
src/mapi/mapi/stub.c
src/mapi/mapi/stub.h
src/mapi/mapi/table.h

index 5476d37..b471c40 100644 (file)
@@ -132,7 +132,7 @@ mapi_get_proc_address(const char *name)
    if (!stub)
       stub = stub_find_dynamic(name, 0);
 
-   return (stub) ? (mapi_proc) stub->addr : NULL;
+   return (stub) ? (mapi_proc) stub_get_addr(stub) : NULL;
 }
 
 /**
@@ -172,11 +172,12 @@ mapi_table_fill(struct mapi_table *tbl, const mapi_proc *procs)
 
    for (i = 0; i < mapi_num_stubs; i++) {
       const struct mapi_stub *stub = mapi_stub_map[i];
+      int slot = stub_get_slot(stub);
       mapi_func func = (mapi_func) procs[i];
 
       if (!func)
-         func = table_get_func(noop, stub);
-      table_set_func(tbl, stub, func);
+         func = table_get_func(noop, slot);
+      table_set_func(tbl, slot, func);
    }
 }
 
index 3594eac..9a5c1d6 100644 (file)
 
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
 
+struct mapi_stub {
+   mapi_func addr;
+   int slot;
+   const void *name;
+};
+
 /* define public_string_pool and public_stubs */
 #define MAPI_TMP_PUBLIC_STUBS
 #include "mapi_tmp.h"
@@ -164,3 +170,38 @@ stub_fix_dynamic(struct mapi_stub *stub, const struct mapi_stub *alias)
    entry_patch(stub->addr, slot);
    stub->slot = slot;
 }
+
+/**
+ * Return the name of a stub.
+ */
+const char *
+stub_get_name(const struct mapi_stub *stub)
+{
+   const char *name;
+
+   if (stub >= public_stubs &&
+       stub < public_stubs + ARRAY_SIZE(public_stubs))
+      name = &public_string_pool[(unsigned long) stub->name];
+   else
+      name = (const char *) stub->name;
+
+   return name;
+}
+
+/**
+ * Return the slot of a stub.
+ */
+int
+stub_get_slot(const struct mapi_stub *stub)
+{
+   return stub->slot;
+}
+
+/**
+ * Return the address of a stub.
+ */
+mapi_func
+stub_get_addr(const struct mapi_stub *stub)
+{
+   return stub->addr;
+}
index c7e194c..e72e530 100644 (file)
 
 typedef void (*mapi_func)(void);
 
-struct mapi_stub {
-   mapi_func addr;
-   int slot;
-   const void *name;
-};
+struct mapi_stub;
 
 void
 stub_init_once(void);
@@ -49,4 +45,13 @@ stub_find_dynamic(const char *name, int generate);
 void
 stub_fix_dynamic(struct mapi_stub *stub, const struct mapi_stub *alias);
 
+const char *
+stub_get_name(const struct mapi_stub *stub);
+
+int
+stub_get_slot(const struct mapi_stub *stub);
+
+mapi_func
+stub_get_addr(const struct mapi_stub *stub);
+
 #endif /* _STUB_H_ */
index ca2be56..174057d 100644 (file)
@@ -51,24 +51,23 @@ table_get_noop(void)
 }
 
 /**
- * Update the dispatch table to dispatch a stub to the given function.
+ * Set the function of a slot.
  */
 static INLINE void
-table_set_func(struct mapi_table *tbl,
-               const struct mapi_stub *stub, mapi_func func)
+table_set_func(struct mapi_table *tbl, int slot, mapi_func func)
 {
    mapi_func *funcs = (mapi_func *) tbl;
-   funcs[stub->slot] = func;
+   funcs[slot] = func;
 }
 
 /**
- * Return the dispatched function of a stub.
+ * Return the function of a slot.
  */
 static INLINE mapi_func
-table_get_func(const struct mapi_table *tbl, const struct mapi_stub *stub)
+table_get_func(const struct mapi_table *tbl, int slot)
 {
    const mapi_func *funcs = (const mapi_func *) tbl;
-   return funcs[stub->slot];
+   return funcs[slot];
 }
 
 #endif /* _TABLE_H_ */