Mesa (master): mapi: Make struct mapi_stub opaque.

Chia-I Wu olv at kemper.freedesktop.org
Fri Dec 24 09:34:22 UTC 2010


Module: Mesa
Branch: master
Commit: 897bff67734ec9ab213191386cdf09ddd051aebb
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=897bff67734ec9ab213191386cdf09ddd051aebb

Author: Chia-I Wu <olv at lunarg.com>
Date:   Fri Dec 24 13:49:01 2010 +0800

mapi: Make struct mapi_stub opaque.

Add accessors for struct mapi_stub and make it opaque.

---

 src/mapi/mapi/mapi.c  |    7 ++++---
 src/mapi/mapi/stub.c  |   41 +++++++++++++++++++++++++++++++++++++++++
 src/mapi/mapi/stub.h  |   15 ++++++++++-----
 src/mapi/mapi/table.h |   13 ++++++-------
 4 files changed, 61 insertions(+), 15 deletions(-)

diff --git a/src/mapi/mapi/mapi.c b/src/mapi/mapi/mapi.c
index 5476d37..b471c40 100644
--- a/src/mapi/mapi/mapi.c
+++ b/src/mapi/mapi/mapi.c
@@ -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);
    }
 }
 
diff --git a/src/mapi/mapi/stub.c b/src/mapi/mapi/stub.c
index 3594eac..9a5c1d6 100644
--- a/src/mapi/mapi/stub.c
+++ b/src/mapi/mapi/stub.c
@@ -39,6 +39,12 @@
 
 #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;
+}
diff --git a/src/mapi/mapi/stub.h b/src/mapi/mapi/stub.h
index c7e194c..e72e530 100644
--- a/src/mapi/mapi/stub.h
+++ b/src/mapi/mapi/stub.h
@@ -31,11 +31,7 @@
 
 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_ */
diff --git a/src/mapi/mapi/table.h b/src/mapi/mapi/table.h
index ca2be56..174057d 100644
--- a/src/mapi/mapi/table.h
+++ b/src/mapi/mapi/table.h
@@ -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_ */




More information about the mesa-commit mailing list