httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Noordhuis <i...@bnoordhuis.nl>
Subject Re: DSO question
Date Tue, 09 Mar 2010 18:33:50 GMT
> What I need is to tell to APR, hey APR please find the function "f10" in all
> loaded libraries, then execute the function and give me back the result.

That is not how it works in C. Function names only exist in source
code, at run-time it is nothing but an address in memory. Google
'function pointers'. The best you can do is a lookup table like this:

static int my_f10_fun(int arg) {
  return arg * arg;
}

/* ... */

static struct {
  const char *name;
  int (*fun)(int arg);
} lookup = {
  { "f10", my_f10_fun },
  { "f11", my_f11_fun }
};

/* ... */
int arg = /* ... */;
const char *func_name = /* ... */;
int result = 0;

for (i = 0; i < sizeof(lookup) / sizeof(lookup[0]); i++) {
  if (!strcmp(lookup[i].name, func_name)) {
    result = lookup[i].fun(arg);
    break;
  }
}

Mime
View raw message