From: TimePath Date: Wed, 25 Nov 2015 05:16:26 +0000 (+1100) Subject: ArrayList: free on shutdown X-Git-Tag: xonotic-v0.8.2~1621 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2dfb98fcdea4804fc14273442abc2fb3854a2258;p=xonotic%2Fxonotic-data.pk3dir.git ArrayList: free on shutdown --- diff --git a/qcsrc/common/ent_cs.qh b/qcsrc/common/ent_cs.qh index 6d9685c4b..c853ac1a1 100644 --- a/qcsrc/common/ent_cs.qh +++ b/qcsrc/common/ent_cs.qh @@ -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) diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 3e380ca69..9b6d43362 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -1340,6 +1340,7 @@ void m_shutdown() { shutdown_running = 1; Shutdown(); + shutdownhooks(); } cvar_settemp_restore(); // this must be done LAST, but in any case } diff --git a/qcsrc/lib/arraylist.qh b/qcsrc/lib/arraylist.qh index c05914947..c2aae2b7b 100644 --- a/qcsrc/lib/arraylist.qh +++ b/qcsrc/lib/arraylist.qh @@ -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) diff --git a/qcsrc/lib/registry.qh b/qcsrc/lib/registry.qh index 40a39395b..3b5e3305c 100644 --- a/qcsrc/lib/registry.qh +++ b/qcsrc/lib/registry.qh @@ -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; } diff --git a/qcsrc/lib/static.qh b/qcsrc/lib/static.qh index 70eafd1b7..534c2de02 100644 --- a/qcsrc/lib/static.qh +++ b/qcsrc/lib/static.qh @@ -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