From: Chia-I Wu Date: Fri, 24 Dec 2010 05:49:01 +0000 (+0800) Subject: mapi: Make struct mapi_stub opaque. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=897bff67734ec9ab213191386cdf09ddd051aebb;p=mesa.git mapi: Make struct mapi_stub opaque. Add accessors for struct mapi_stub and make it opaque. --- diff --git a/src/mapi/mapi/mapi.c b/src/mapi/mapi/mapi.c index 5476d37fdc9..b471c40b144 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 3594eacb4ec..9a5c1d694b3 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 c7e194cf4fc..e72e530e290 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 ca2be568c70..174057d6422 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_ */