summaryrefslogtreecommitdiff
path: root/src/mapi
diff options
context:
space:
mode:
authorChia-I Wu <olv@lunarg.com>2010-12-24 13:49:01 +0800
committerChia-I Wu <olv@lunarg.com>2010-12-24 17:28:52 +0800
commit897bff67734ec9ab213191386cdf09ddd051aebb (patch)
treec2ab54441b42333b8e501158317f05698607444f /src/mapi
parent0c205484bfe3de23c370deeba43dff7939179b5a (diff)
mapi: Make struct mapi_stub opaque.
Add accessors for struct mapi_stub and make it opaque.
Diffstat (limited to 'src/mapi')
-rw-r--r--src/mapi/mapi/mapi.c7
-rw-r--r--src/mapi/mapi/stub.c41
-rw-r--r--src/mapi/mapi/stub.h15
-rw-r--r--src/mapi/mapi/table.h13
4 files changed, 61 insertions, 15 deletions
diff --git a/src/mapi/mapi/mapi.c b/src/mapi/mapi/mapi.c
index 5476d37fdc..b471c40b14 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 3594eacb4e..9a5c1d694b 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 c7e194cf4f..e72e530e29 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 ca2be568c7..174057d642 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_ */