Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 12880 invoked by uid 500); 26 Apr 2003 07:24:28 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 12846 invoked from network); 26 Apr 2003 07:24:27 -0000 Reply-To: From: "Mladen Turk" To: "'William A. Rowe, Jr.'" Cc: Subject: RE: Creative solution to a lack of recursive #define's? Date: Sat, 26 Apr 2003 09:22:25 +0200 Organization: Apache Software Foundation Message-ID: <000001c30bc4$971afe10$0b89bfd5@GISDATA.ZG> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.4024 In-Reply-To: <5.2.0.9.2.20030425133729.03b894d8@pop3.rowe-clan.net> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Importance: Normal X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N > -----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.