What is the best way to keep track of different signatures of shared objects?




This is the general scenario. My application is a server that loads a
large number of similar (i.e. same signature) shared objects at
startup time, to be used on-demand later.

Version 1 was simple in the sense that all the loadable modules had
the same signature. For fast access, I save the addresses of the *.so
files in a C++ map. This is the relevant code:

typedef bool (*address)(const char *, const char *, char *);
typedef map<string, address> module_address;

module_address addressOf;

bool (*function)(const char *, const char *, char *);

handle = dlopen((mod_dir + "/" + filename).c_str(), RTLD_NOW);
*(void **)(&function) = dlsym(handle, fnc_name);

if (function) {
addressOf[unique_id] = function;
roster[unique_id] = true;
}

So far, so good. I have loaded all the shared object files, and I know
how to execute each because I have kept their addresses in a handy
map.

Here comes the troublesome code, when I actually execute the
functions:

address function;
function = addressOf[unique_id];

if (!function) {
throw UNSUPPORTED_ID;
}

bool success = function(arg1, arg2, buffer);

The mentioned scheme works fine as long as I keep the same signature,
but alas, now I need to load and execute some new functions which need
more arguments:

bool success = function(arg1, arg2, buffer, extra_arg);

-Ramon

.


Quantcast