summaryrefslogtreecommitdiff
path: root/src/mapi/mapi/stub.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mapi/mapi/stub.c')
-rw-r--r--src/mapi/mapi/stub.c34
1 files changed, 10 insertions, 24 deletions
diff --git a/src/mapi/mapi/stub.c b/src/mapi/mapi/stub.c
index 8ceaec3132..3594eacb4e 100644
--- a/src/mapi/mapi/stub.c
+++ b/src/mapi/mapi/stub.c
@@ -37,23 +37,15 @@
#include "stub.h"
#include "table.h"
-#define MAPI_TABLE_FIRST_DYNAMIC \
- (offsetof(struct mapi_table, dynamic0) / sizeof(mapi_func))
-#define MAPI_TABLE_NUM_DYNAMIC \
- ((offsetof(struct mapi_table, last) - \
- offsetof(struct mapi_table, dynamic0)) / sizeof(mapi_func))
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
-/*
- * This will define public_string_pool, public_sorted_indices, and
- * public_stubs.
- */
+/* define public_string_pool and public_stubs */
#define MAPI_TMP_PUBLIC_STUBS
#include "mapi_tmp.h"
static struct mapi_stub dynamic_stubs[MAPI_TABLE_NUM_DYNAMIC];
static int num_dynamic_stubs;
-static int next_dynamic_slot = MAPI_TABLE_FIRST_DYNAMIC;
+static int next_dynamic_slot = MAPI_TABLE_NUM_STATIC;
void
stub_init_once(void)
@@ -74,11 +66,9 @@ static int
stub_compare(const void *key, const void *elem)
{
const char *name = (const char *) key;
- const int *index = (const int *) elem;
- const struct mapi_stub *stub;
+ const struct mapi_stub *stub = (const struct mapi_stub *) elem;
const char *stub_name;
- stub = &public_stubs[*index];
stub_name = &public_string_pool[(unsigned long) stub->name];
return strcmp(name, stub_name);
@@ -90,13 +80,8 @@ stub_compare(const void *key, const void *elem)
const struct mapi_stub *
stub_find_public(const char *name)
{
- const int *index;
-
- index = (const int *) bsearch(name, public_sorted_indices,
- ARRAY_SIZE(public_sorted_indices) - 1,
- sizeof(public_sorted_indices[0]), stub_compare);
-
- return (index) ? &public_stubs[*index] : NULL;
+ return (const struct mapi_stub *) bsearch(name, public_stubs,
+ ARRAY_SIZE(public_stubs), sizeof(public_stubs[0]), stub_compare);
}
/**
@@ -109,14 +94,15 @@ stub_add_dynamic(const char *name)
int idx;
idx = num_dynamic_stubs;
- if (idx >= MAPI_TABLE_NUM_DYNAMIC)
+ /* minus 1 to make sure we can never reach the last slot */
+ if (idx >= MAPI_TABLE_NUM_DYNAMIC - 1)
return NULL;
stub = &dynamic_stubs[idx];
- /* dispatch to mapi_table->last, which is always no-op */
- stub->addr =
- entry_generate(MAPI_TABLE_FIRST_DYNAMIC + MAPI_TABLE_NUM_DYNAMIC);
+ /* dispatch to the last slot, which is reserved for no-op */
+ stub->addr = entry_generate(
+ MAPI_TABLE_NUM_STATIC + MAPI_TABLE_NUM_DYNAMIC - 1);
if (!stub->addr)
return NULL;