apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mladen Turk" <mt...@inet.hr>
Subject RE: Creative solution to a lack of recursive #define's?
Date Sat, 26 Apr 2003 07:22:25 GMT


> -----Original Message-----
> From: William A. Rowe, Jr.
> 
> Anyways, since the recursive #defines below don't work, and 
> we don't want the hook implementor to have to go through any 
> 'extra' hoops, does anyone have some thoughts on the fragment 
> below for stringizing the entry point 'pf's name?
> 
> #define APR_IMPLEMENT_HOOK_TRACE_PROTO(ns,name) \
> #define ns##_hook_##name(pf, aszPre, aszSucc, nOrder) \
>     (ns##_hook_##name)(pf, aszPre, aszSucc, nOrder, #pf)
> 

I would create additional func that will return the function name.
Then you'll be sure that this function exists and can be called when
your trace function needs the name.

You may even create the expoted struct and return full info.
That is how most C++ runtime class name resolvers works.

> /** macro to declare the hook correctly */    
> #define APR_DECLARE_EXTERNAL_HOOK(ns,link,ret,name,args) \ 
> typedef ret ns##_HOOK_##name##_t args; \
> link##_DECLARE(void) ns##_hook_##name(ns##_HOOK_##name##_t *pf, \
>                                       const char * const *aszPre, \
>                                       const char * const 
> *aszSucc, int nOrder\
>                                       const char * szFnName); \
link##_DECLARE(void) ns##_hook_##name(ns##_HOOK_##name##_t *pf, \
                                      const char * const *aszPre, \
                                      const char * const 
					        *aszSucc, int nOrder); \
link##_DECLARE(const char *) ns##_get_name_##name();


> link##_DECLARE(ret) ns##_run_##name args; \ 
> APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name); \
> APR_IMPLEMENT_HOOK_TRACE_PROTO(ns,name) \
> typedef struct ns##_LINK_##name##_t \
>     { \
>     ns##_HOOK_##name##_t *pFunc; \
>     const char *szName; \
>     const char * const *aszPredecessors; \
>     const char * const *aszSuccessors; \
>     int nOrder; \
>     } ns##_LINK_##name##_t;
> 

Then add the implementation like:

link##_DECLARE(const char *) ns##_get_name_##name() { \
	return #name; }

Or even better, create the runtime info struct, implement it and return
that struct when needed.

typedef struct {
	const char *szName;
	const char * const *aszPredecessors;
	const char * const *aszSuccessors;
	int nOrder;
} apr_runtime_hook_info_t;


APR_IMPLEMENT_HOOK_TRACE_PROTO(ns,name) \
typedef struct ns##_LINK_##name##_t \
    { \
    apr_runtime_hook_info info; \
    ns##_HOOK_##name##_t *pFunc; \
    } ns##_LINK_##name##_t; \
link##_DECLARE apr_runtime_hook_info ns##_INFO_##name##_info = { \
	#name, NULL, NULL, 0 }; \
link##_DECLARE(const apr_runtime_hook_info *) ns##_get_info_##name() { \
	return &ns##_INFO_##name##_info; }
...


MT.


Mime
View raw message