From 893a631aa598fc0dc3af53f1e2fb91ac4bcba8f8 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 10 Sep 2011 14:00:58 +0200 Subject: [PATCH] Wrap MODULECALL macros in a do-while This makes sure that there is a semicolon after his macro call and that this macro works correctly in an if, e.g. if (foo) MODULECALL(foo); Signed-off-by: Uli Schlachter --- main.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/main.h b/main.h index 4967be5e..18f8e52d 100644 --- a/main.h +++ b/main.h @@ -62,8 +62,8 @@ } while (false) #define USERMODULECALL(macFUNC, macUSER, macNETWORK, macCLIENT, macEXITER) \ - assert(macUSER != NULL); \ - if (macUSER) { \ + do { \ + assert(macUSER != NULL); \ CModules& UMods = macUSER->GetModules(); \ CIRCNetwork* pOldUNetwork = UMods.GetNetwork(); \ CClient* pOldUClient = UMods.GetClient(); \ @@ -76,12 +76,12 @@ } \ UMods.SetNetwork(pOldUNetwork); \ UMods.SetClient(pOldUClient); \ - } + } while (false) #define NETWORKMODULECALL(macFUNC, macUSER, macNETWORK, macCLIENT, macEXITER) \ - assert(macUSER != NULL); \ - assert(macNETWORK != NULL); \ - if (macNETWORK) { \ + do { \ + assert(macUSER != NULL); \ + assert(macNETWORK != NULL); \ CModules& NMods = ((CIRCNetwork*)macNETWORK)->GetModules(); \ CClient* pOldNClient = NMods.GetClient(); \ NMods.SetClient(macCLIENT); \ @@ -90,12 +90,14 @@ macEXITER; \ } \ NMods.SetClient(pOldNClient); \ - } + } while (false) #define MODULECALL(macFUNC, macUSER, macNETWORK, macCLIENT, macEXITER) \ - GLOBALMODULECALL(macFUNC, macUSER, macNETWORK, macCLIENT, macEXITER); \ - USERMODULECALL(macFUNC, macUSER, macNETWORK, macCLIENT, macEXITER); \ - NETWORKMODULECALL(macFUNC, macUSER, macNETWORK, macCLIENT, macEXITER); + do { \ + GLOBALMODULECALL(macFUNC, macUSER, macNETWORK, macCLIENT, macEXITER); \ + USERMODULECALL(macFUNC, macUSER, macNETWORK, macCLIENT, macEXITER); \ + NETWORKMODULECALL(macFUNC, macUSER, macNETWORK, macCLIENT, macEXITER); \ + } while (false) /** @mainpage * Welcome to the API documentation for ZNC.