]> git.xonotic.org Git - xonotic/d0_blind_id.git/commitdiff
add an interface to define malloc/free and mutex functions; 0.4
authorRudolf Polzer <divverent@xonotic.org>
Tue, 25 Oct 2011 14:03:21 +0000 (16:03 +0200)
committerRudolf Polzer <divverent@xonotic.org>
Tue, 25 Oct 2011 14:03:21 +0000 (16:03 +0200)
Makefile.am
configure.ac
d0.c
d0.h

index aa3e6e5625e34cc79614b5b49234d25665ddafc7..3cb22c7101a2a3153372f7e42d7647c49ba87969 100644 (file)
@@ -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
index b5d4e11ebac567cd265832f45e5684f96c8a4788..d84940fa76c9b40f2e36d4377617660264b9a693 100644 (file)
@@ -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 4692d35027c43d180842c326e732cd2dd3760cb4..c9372eb01aa8e8ffe6fcda4d8ad86c3581513145 100644 (file)
--- 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 <stdio.h>
@@ -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 bd0776539c898e20ccbb1c4a8bbc19df78374196..9ccf540e04b9abdb036f95b5f3bc0ae00b2d737d 100644 (file)
--- a/d0.h
+++ b/d0.h
 #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;