From 05e6815d912f0418f6da25a2106dd718796f02fa Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 22 Sep 2010 14:56:43 -0400 Subject: Do not use new/delete to allocate modules, allows modules to always destruct properly and automatically --- include/services.h | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/include/services.h b/include/services.h index 9fd9b2ce3..947a8cc30 100644 --- a/include/services.h +++ b/include/services.h @@ -140,39 +140,26 @@ extern "C" void __pfnBkCheck() {} /** This definition is used as shorthand for the various classes * and functions needed to make a module loadable by the OS. - * It defines the class factory and external AnopeInit and AnopeFini functions. + * It defines the class factory and the external AnopeInit function. */ #ifdef _WIN32 # define MODULE_INIT(x) \ extern "C" DllExport Module *AnopeInit(const Anope::string &, const Anope::string &); \ extern "C" Module *AnopeInit(const Anope::string &modname, const Anope::string &creator) \ { \ - return new x(modname, creator); \ + static x module(modname, creator); \ + return &module; \ } \ - BOOLEAN WINAPI DllMain(HINSTANCE, DWORD nReason, LPVOID) \ + BOOLEAN WINAPI DllMain(HINSTANCE, DWORD, LPVOID) \ { \ - switch (nReason) \ - { \ - case DLL_PROCESS_ATTACH: \ - case DLL_PROCESS_DETACH: \ - break; \ - } \ return TRUE; \ - } \ - extern "C" DllExport void AnopeFini(x *); \ - extern "C" void AnopeFini(x *m) \ - { \ - delete m; \ } #else # define MODULE_INIT(x) \ extern "C" DllExport Module *AnopeInit(const Anope::string &modname, const Anope::string &creator) \ { \ - return new x(modname, creator); \ - } \ - extern "C" DllExport void AnopeFini(x *m) \ - { \ - delete m; \ + static x module(modname, creator); \ + return &module; \ } #endif -- cgit