preserve array reading through DONT_FREE

This commit is contained in:
dzaima 2021-06-01 17:52:51 +03:00
parent b8c362247b
commit b47e52db9e
2 changed files with 20 additions and 1 deletions

View File

@ -284,6 +284,21 @@ static B def_m1_d(B m, B f ) { thrM("cannot derive this"); }
static B def_m2_d(B m, B f, B g) { thrM("cannot derive this"); }
static B def_slice(B x, usz s) { thrM("cannot slice non-array!"); }
#ifdef DONT_FREE
static B empty_get(B x, usz n) {
v(x)->type = v(x)->flags;
B r = TI(x).get(x, n);
v(x)->type = t_empty;
return r;
}
static B empty_getU(B x, usz n) {
v(x)->type = v(x)->flags;
B r = TI(x).getU(x, n);
v(x)->type = t_empty;
return r;
}
#endif
static inline void base_init() { // very first init function
for (i32 i = 0; i < t_COUNT; i++) {
ti[i].free = def_free;
@ -310,6 +325,10 @@ static inline void base_init() { // very first init function
ti[t_empty].free = empty_free;
ti[t_freed].free = def_free;
ti[t_freed].visit = freed_visit;
#ifdef DONT_FREE
ti[t_empty].get = empty_get;
ti[t_empty].getU = empty_getU;
#endif
ti[t_shape].visit = noop_visit;
ti[t_funBI].visit = ti[t_md1BI].visit = ti[t_md2BI].visit = noop_visit;
ti[t_funBI].free = ti[t_md1BI].free = ti[t_md2BI].free = builtin_free;

View File

@ -45,7 +45,7 @@ static void* BN(allocL)(u8 bucket, u8 type) {
x->flags = x->extra = x->type = 0;
x->refc = 1;
x->type = type;
#ifdef DEBUG
#if defined(DEBUG) && !defined(DONT_FREE)
u64* p = (u64*)x;
u64* s = p + sizeof(Value)/8;
u64* e = p + BSZ(bucket)/8;