summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2015-01-18 13:17:51 -0200
committershennetsind <ind@henn.et>2015-01-18 13:17:51 -0200
commit57789fb70b899eda61206a59283e1a849e544397 (patch)
treee90451205624140f8e47628f39fb2a6a9ec4e30b /src/common
parentfb5d412a6a9813e1486b7a411ec6b5297209ca51 (diff)
downloadhercules-57789fb70b899eda61206a59283e1a849e544397.tar.gz
hercules-57789fb70b899eda61206a59283e1a849e544397.tar.bz2
hercules-57789fb70b899eda61206a59283e1a849e544397.tar.xz
hercules-57789fb70b899eda61206a59283e1a849e544397.zip
Implementing nullpo interface for plugin use
As proposed in pull request #361 Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/HPM.c2
-rw-r--r--src/common/core.c2
-rw-r--r--src/common/nullpo.c11
-rw-r--r--src/common/nullpo.h12
4 files changed, 24 insertions, 3 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index c361ad31c..6d9a2cb6b 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -23,6 +23,7 @@
#include "../common/sysinfo.h"
#include "../common/timer.h"
#include "../common/utils.h"
+#include "../common/nullpo.h"
#ifndef WIN32
# include <unistd.h>
@@ -784,6 +785,7 @@ void hplugins_share_defaults(void) {
HPM->share(&SERVER_TYPE,"SERVER_TYPE");
HPM->share(DB, "DB");
HPM->share(HPMiMalloc, "iMalloc");
+ HPM->share(nullpo,"nullpo");
/* socket */
HPM->share(sockt,"sockt");
/* strlib */
diff --git a/src/common/core.c b/src/common/core.c
index 04434a5dd..e1bb9ed0b 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -20,6 +20,7 @@
#include "../common/showmsg.h"
#include "../common/strlib.h"
#include "../common/sysinfo.h"
+#include "../common/nullpo.h"
#ifndef MINICORE
# include "../common/HPM.h"
@@ -168,6 +169,7 @@ void usercheck(void) {
}
void core_defaults(void) {
+ nullpo_defaults();
#ifndef MINICORE
hpm_defaults();
HCache_defaults();
diff --git a/src/common/nullpo.c b/src/common/nullpo.c
index 0333c02ef..e61d52257 100644
--- a/src/common/nullpo.c
+++ b/src/common/nullpo.c
@@ -12,6 +12,8 @@
#include "../common/showmsg.h"
+struct nullpo_interface nullpo_s;
+
/**
* Reports failed assertions or NULL pointers
*
@@ -32,3 +34,12 @@ void assert_report(const char *file, int line, const char *func, const char *tar
ShowError("%s:%d: '%s' in function `%s'\n", file, line, targetname, func);
ShowError("--- end %s ----------------------------------------\n", title);
}
+
+/**
+ *
+ **/
+void nullpo_defaults(void) {
+ nullpo = &nullpo_s;
+
+ nullpo->assert_report = assert_report;
+}
diff --git a/src/common/nullpo.h b/src/common/nullpo.h
index 407f45403..573e351e0 100644
--- a/src/common/nullpo.h
+++ b/src/common/nullpo.h
@@ -27,7 +27,7 @@
#include <crtdbg.h>
#endif // !DEFCPP && WIN && !MINGW
#define Assert(EX) assert(EX)
-#define Assert_chk(EX) ( (EX) ? false : (assert_report(__FILE__, __LINE__, __func__, #EX, "failed assertion"), true) )
+#define Assert_chk(EX) ( (EX) ? false : (nullpo->assert_report(__FILE__, __LINE__, __func__, #EX, "failed assertion"), true) )
#else // ! ASSERT_CHECK
#define Assert(EX) (EX)
#define Assert_chk(EX) ((EX), false)
@@ -40,7 +40,7 @@
* @param t pointer to check
* @return true if the passed pointer is NULL, false otherwise
*/
-#define nullpo_chk(t) ( (t) != NULL ? false : (assert_report(__FILE__, __LINE__, __func__, #t, "nullpo info"), true) )
+#define nullpo_chk(t) ( (t) != NULL ? false : (nullpo->assert_report(__FILE__, __LINE__, __func__, #t, "nullpo info"), true) )
#else // ! NULLPO_CHECK
#define nullpo_chk(t) ((void)(t), false)
#endif // NULLPO_CHECK
@@ -123,8 +123,14 @@
if (Assert_chk(t)) break; else (void)0
+struct nullpo_interface {
+ void (*assert_report) (const char *file, int line, const char *func, const char *targetname, const char *title);
+};
+
+struct nullpo_interface *nullpo;
+
#ifdef HERCULES_CORE
-void assert_report(const char *file, int line, const char *func, const char *targetname, const char *title);
+void nullpo_defaults(void);
#endif // HERCULES_CORE
#endif /* COMMON_NULLPO_H */