From: Rudolf Polzer Date: Tue, 25 Oct 2011 14:03:21 +0000 (+0200) Subject: add an interface to define malloc/free and mutex functions; 0.4 X-Git-Tag: v0.5~12 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f7da8d1de2caccf9e3b3523ac33585592f2f3777;p=xonotic%2Fd0_blind_id.git add an interface to define malloc/free and mutex functions; 0.4 --- diff --git a/Makefile.am b/Makefile.am index aa3e6e5..3cb22c7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,7 +23,7 @@ else libd0_blind_id_la_SOURCES += d0_bignum-gmp.c endif endif -libd0_blind_id_la_LDFLAGS = -versioninfo 5:0:5 +libd0_blind_id_la_LDFLAGS = -versioninfo 6:0:6 libd0_blind_id_la_CFLAGS = -fvisibility=hidden -Wold-style-definition -Wstrict-prototypes -Wsign-compare -Wdeclaration-after-statement library_includedir = $(includedir)/d0_blind_id library_include_HEADERS = d0_blind_id.h d0.h diff --git a/configure.ac b/configure.ac index b5d4e11..d84940f 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([d0_blind_id], [0.3], [divVerent@xonotic.org]) +AC_INIT([d0_blind_id], [0.4], [divVerent@xonotic.org]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([-Wall foreign]) AC_PROG_CC diff --git a/d0.c b/d0.c index 4692d35..c9372eb 100644 --- a/d0.c +++ b/d0.c @@ -45,9 +45,6 @@ const char *d0_bsd_license_notice = "\n" //#define MUTEX_DEBUG -void *(*d0_malloc)(size_t len) = malloc; -void (*d0_free)(void *p) = free; - #ifdef MUTEX_DEBUG #define NUM_MUTEXES 2 #include @@ -100,7 +97,23 @@ static int dummy_unlockmutex(void *m) } #endif -void *(*d0_createmutex)(void) = dummy_createmutex; -void (*d0_destroymutex)(void *) = dummy_destroymutex; -int (*d0_lockmutex)(void *) = dummy_lockmutex; -int (*d0_unlockmutex)(void *) = dummy_unlockmutex; +d0_malloc_t *d0_malloc = malloc; +d0_free_t *d0_free = free; +d0_createmutex_t *d0_createmutex = dummy_createmutex; +d0_destroymutex_t *d0_destroymutex = dummy_destroymutex; +d0_lockmutex_t *d0_lockmutex = dummy_lockmutex; +d0_unlockmutex_t *d0_unlockmutex = dummy_unlockmutex; + +void d0_setmallocfuncs(d0_malloc_t *m, d0_free_t *f) +{ + d0_malloc = (m ? m : malloc); + d0_free = (f ? f : free); +} + +void d0_setmutexfuncs(d0_createmutex_t *c, d0_destroymutex_t *d, d0_lockmutex_t *l, d0_unlockmutex_t *u) +{ + d0_createmutex = (c ? c : dummy_createmutex); + d0_destroymutex = (d ? d : dummy_destroymutex); + d0_lockmutex = (l ? l : dummy_lockmutex); + d0_unlockmutex = (u ? u : dummy_unlockmutex); +} diff --git a/d0.h b/d0.h index bd07765..9ccf540 100644 --- a/d0.h +++ b/d0.h @@ -42,13 +42,22 @@ #define D0_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) #define D0_BOOL int -extern void *(*d0_malloc)(size_t len); -extern void (*d0_free)(void *p); +typedef void *(d0_malloc_t)(size_t len); +typedef void (d0_free_t)(void *p); +typedef void *(d0_createmutex_t)(void); +typedef void (d0_destroymutex_t)(void *); +typedef int (d0_lockmutex_t)(void *); // zero on success +typedef int (d0_unlockmutex_t)(void *); // zero on success -extern void *(*d0_createmutex)(void); -extern void (*d0_destroymutex)(void *); -extern int (*d0_lockmutex)(void *); // zero on success -extern int (*d0_unlockmutex)(void *); // zero on success +extern d0_malloc_t *d0_malloc; +extern d0_free_t *d0_free; +extern d0_createmutex_t *d0_createmutex; +extern d0_destroymutex_t *d0_destroymutex; +extern d0_lockmutex_t *d0_lockmutex; +extern d0_unlockmutex_t *d0_unlockmutex; + +D0_EXPORT void d0_setmallocfuncs(d0_malloc_t *m, d0_free_t *f); +D0_EXPORT void d0_setmutexfuncs(d0_createmutex_t *c, d0_destroymutex_t *d, d0_lockmutex_t *l, d0_unlockmutex_t *u); extern const char *d0_bsd_license_notice;