]> git.rm.cloudns.org Git - xonotic/d0_blind_id.git/commitdiff
on G*nt**, initialized globals seem to be made of fail and crash
authorRudolf Polzer <divverent@xonotic.org>
Sun, 27 Nov 2011 16:03:55 +0000 (17:03 +0100)
committerRudolf Polzer <divverent@xonotic.org>
Sun, 27 Nov 2011 16:03:55 +0000 (17:03 +0100)
Try an alternative...

d0.c
d0.h
d0_blind_id.c

diff --git a/d0.c b/d0.c
index 64d0684a7b6f353cdb41917e2ec8273090d9ecf4..17934f0bfd67526aae41eab9781af94b796e6b07 100644 (file)
--- a/d0.c
+++ b/d0.c
@@ -97,12 +97,12 @@ static int dummy_unlockmutex(void *m)
 }
 #endif
 
-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;
+d0_malloc_t *d0_malloc = NULL;
+d0_free_t *d0_free = NULL;
+d0_createmutex_t *d0_createmutex = NULL;
+d0_destroymutex_t *d0_destroymutex = NULL;
+d0_lockmutex_t *d0_lockmutex = NULL;
+d0_unlockmutex_t *d0_unlockmutex = NULL;
 
 void d0_setmallocfuncs(d0_malloc_t *m, d0_free_t *f)
 {
@@ -117,3 +117,9 @@ void d0_setmutexfuncs(d0_createmutex_t *c, d0_destroymutex_t *d, d0_lockmutex_t
        d0_lockmutex = (l ? l : dummy_lockmutex);
        d0_unlockmutex = (u ? u : dummy_unlockmutex);
 }
+
+void d0_initfuncs(void)
+{
+       d0_setmallocfuncs(d0_malloc, d0_free);
+       d0_setmutexfuncs(d0_createmutex, d0_destroymutex, d0_lockmutex, d0_unlockmutex);
+}
diff --git a/d0.h b/d0.h
index a6b551ba6968466f5bf1003bd1f000cd29beb698..0f9b41999f2a57f07067272a8b89919394c4b04f 100644 (file)
--- a/d0.h
+++ b/d0.h
@@ -58,6 +58,7 @@ extern d0_unlockmutex_t *d0_unlockmutex;
 
 void d0_setmallocfuncs(d0_malloc_t *m, d0_free_t *f);
 void d0_setmutexfuncs(d0_createmutex_t *c, d0_destroymutex_t *d, d0_lockmutex_t *l, d0_unlockmutex_t *u);
+void d0_initfuncs(void); // initializes them, this needs to be only called internally once
 
 extern const char *d0_bsd_license_notice;
 
index 99df20f2f8db062fcee99e3ab1a2ffd28a7e25d8..03670532959a4f3b3c8be4230df0985a79855d84 100644 (file)
@@ -120,6 +120,7 @@ static void *tempmutex = NULL; // hold this mutex when using temp0 to temp4
 D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_INITIALIZE(void)
 {
        USINGTEMPS();
+       d0_initfuncs();
        tempmutex = d0_createmutex();
        LOCKTEMPS();
        CHECK(d0_bignum_INITIALIZE());