]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
ArrayList: free on shutdown
authorTimePath <andrew.hardaker1995@gmail.com>
Wed, 25 Nov 2015 05:16:26 +0000 (16:16 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Wed, 25 Nov 2015 05:16:26 +0000 (16:16 +1100)
qcsrc/common/ent_cs.qh
qcsrc/common/util.qc
qcsrc/lib/arraylist.qh
qcsrc/lib/registry.qh
qcsrc/lib/static.qh

index 6d9685c4be8dbe86eab14157456166b1ccc3812e..c853ac1a19a8bf2bb320546580da43c916ea098f 100644 (file)
@@ -45,6 +45,10 @@ STATIC_INIT(_entcs)
 {
     AL_init(_entcs, 255, NULL, e); // 255 is the engine limit on maxclients
 }
+SHUTDOWN(_entcs)
+{
+    AL_delete(_entcs);
+}
 #define entcs_receiver(...) EVAL(OVERLOAD(entcs_receiver, __VA_ARGS__))
 #define entcs_receiver_1(i) AL_gete(_entcs, i)
 #define entcs_receiver_2(i, v) AL_sete(_entcs, i, v)
index 3e380ca696d06e0a66b0d3bde2423c997fccaa93..9b6d433621066cd36349d1ae793f9ece062d3cd7 100644 (file)
@@ -1340,6 +1340,7 @@ void m_shutdown()
        {
                shutdown_running = 1;
                Shutdown();
+               shutdownhooks();
        }
        cvar_settemp_restore(); // this must be done LAST, but in any case
 }
index c059149473075de5d68041b927d9df3ae006bf86..c2aae2b7b5476f529eaa977840852bdb5fa55045 100644 (file)
@@ -16,6 +16,7 @@ typedef int ArrayList;
                } \
        } \
        while (0)
+#define AL_delete(this) buf_del(this)
 
 #define _AL_type__s() string
 #define AL_gets(this, idx) bufstr_get(this, idx)
index 40a39395bcf34884e6d9b2610d6a2c108b295cab..3b5e3305c600b55a343fb36e888267aff21f2b52 100644 (file)
@@ -7,10 +7,12 @@
        #define _R_MAP(r, max) AL_declare(r); STATIC_INIT(r) { AL_init(r, max, NULL, e); }
        #define _R_GET(r, i) AL_gete(r, i)
        #define _R_SET(r, i, e) AL_sete(r, i, e)
+       #define _R_DEL(r) AL_delete(r)
 #else
        #define _R_MAP(r, max) entity r[max]
        #define _R_GET(r, i) r[i]
        #define _R_SET(r, i, e) r[i] = e
+       #define _R_DEL(r)
 #endif
 
 /**
@@ -24,6 +26,7 @@
        const int id##_MAX = max; \
        noref entity id##_first, id##_last; \
        _R_MAP(_##id, id##_MAX); \
+       SHUTDOWN(id) { _R_DEL(_##id); } \
        int id##_COUNT; \
        entity _##id##_from(int i, entity null) { if (i >= 0 && i < id##_COUNT) { entity e = _R_GET(_##id, i); if (e) return e; } return null; }
 
index 70eafd1b7d16ad89eb06e16d9d7d93bdae1dc983..534c2de02131cc3dc2737db2add776978bc192aa 100644 (file)
@@ -7,6 +7,8 @@ void __static_init_late() {}
 #define static_init_late() CALL_ACCUMULATED_FUNCTION(__static_init_late)
 void __static_init_precache() {}
 #define static_init_precache() CALL_ACCUMULATED_FUNCTION(__static_init_precache)
+void __shutdown() {}
+#define shutdownhooks() CALL_ACCUMULATED_FUNCTION(__shutdown)
 
 #define _STATIC_INIT(where, func) \
        void _static_##func(); \
@@ -16,5 +18,6 @@ void __static_init_precache() {}
 #define STATIC_INIT(func) _STATIC_INIT(__static_init,           func)
 #define STATIC_INIT_LATE(func) _STATIC_INIT(__static_init_late, func##_late)
 #define PRECACHE(func) _STATIC_INIT(__static_init_precache,     func##_precache)
+#define SHUTDOWN(func) _STATIC_INIT(__shutdown,                        func##_shutdown)
 
 #endif