httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Marr <>
Subject Re: Two modules issues. :-(
Date Tue, 12 Dec 2000 17:47:44 GMT
At 12:16 PM 12/12/2000, Ryan wrote:
>The second problem is the one where modules export there own 
>functions.  For this, the module could register their function with 
>the core server, using a key to differentiate the functions.  When 
>another module wants to call that function, they query the core and 
>get back a function pointer which they can use.  This obviously 
>removes all chance of type-safeness, but it is the only solution I 
>can see that will allow for both static and dynamic builds.

There are other ways to do this that preserve type-safeness.  CADKEY 
(the software that I work on at work) has been doing this for about 
10 years.  The type-safeness is only on the caller's side.  The 
module itself is required to maintain its own type-safeness by 
ensuring that its functions match the prototypes it provides.

Here is an excerpt from one of our SDK headers:

#ifdef __cplusplus
extern "C" {

extern int  (**CF_ckcdll_ck_addcoll)(unsigned long id1, unsigned long 
#define ck_addcoll (**CF_ckcdll_ck_addcoll)

extern int  (**CF_ckcdll_ck_addcop)(int tcode, unsigned long csize);
#define ck_addcop (**CF_ckcdll_ck_addcop)

extern int  (**CF_ckcdll_ck_addctype)(const char * name);
#define ck_addctype (**CF_ckcdll_ck_addctype)

The caller uses ck_addcoll(id1, id2), which is translated by the 
preprocessor to (**CF_ckcdll_ck_addcoll)(id1, id2).  The function 
pointer CF_ckcdll_ck_addcoll is actually a pointer to a function 
pointer.  The function pointer starts out pointing to an error 
function.  This function pointer is modified at DLL load time to 
point to the proper function, if the function is available, or a slot 
in the core with a dummy function if the function is not 
available.  If another DLL is loaded that provides the missing 
function, then the core fixes up the slot to point to the real 
function instead of the dummy function.

The CF_ckcdll_ prefix is added by a custom program that takes a file 
that looks like a header file and generates the header file and a .c 
file that is compiled to a static library.  The static library and 
header are distributed to customers.  The .c file in the static 
library is what generates the code to fix up the function pointers.

Greg Marr
"We thought you were dead."
"I was, but I'm better now." - Sheridan, "The Summoning"

View raw message