fix t_harrPartial freeing

This commit is contained in:
dzaima 2022-01-11 00:55:57 +02:00
parent 675a0e8045
commit 65c856693f
2 changed files with 18 additions and 21 deletions

View File

@ -124,16 +124,18 @@ static bool harr_canStore(B x) { return true; }
DEF_FREE(harrP) { assert(x->type==t_harrPartial|x->type==t_freed);
assert(prnk(x)>1? true : ((Arr*)x)->sh!=&((Arr*)x)->ia);
B* p = ((HArr*)x)->a;
usz am = *((HArr*)x)->sh;
// printf("partfree %d/%d %p\n", am, a(x)->ia, (void*)x.u);
B* p = ((HArr*)x)->a;
usz am = ((HArr*)x)->ia;
for (usz i = 0; i < am; i++) dec(p[i]);
}
static void harrP_visit(Value* x) { assert(x->type==t_harrPartial);
assert(prnk(x)>1? true : ((Arr*)x)->sh!=&((Arr*)x)->ia);
B* p = ((HArr*)x)->a;
usz am = *((HArr*)x)->sh;
void harr_abandon_impl(HArr* p) { assert(p->type == t_harrPartial);
gsPop();
harrP_freeO((Value*) p);
mm_free((Value*) p);
}
static void harrP_visit(Value* x) { assert(x->type == t_harrPartial);
B* p = ((HArr*)x)->a;
usz am = ((HArr*)x)->ia;
for (usz i = 0; i < am; i++) mm_visit(p[i]);
}
static B harrP_get(Arr* x, usz n) { err("getting item from t_harrPartial"); }
@ -151,13 +153,13 @@ static void harrP_print(B x) {
}
void harr_init() {
TIi(t_harr,get) = harr_get; TIi(t_hslice,get) = hslice_get;
TIi(t_harr,getU) = harr_getU; TIi(t_hslice,getU) = hslice_getU;
TIi(t_harr,get) = harr_get; TIi(t_hslice,get) = hslice_get; TIi(t_harrPartial,get) = harrP_get;
TIi(t_harr,getU) = harr_getU; TIi(t_hslice,getU) = hslice_getU; TIi(t_harrPartial,getU) = harrP_get;
TIi(t_harr,slice) = harr_slice; TIi(t_hslice,slice) = hslice_slice;
TIi(t_harr,freeO) = harr_freeO; TIi(t_hslice,freeO) = slice_freeO;
TIi(t_harr,freeF) = harr_freeF; TIi(t_hslice,freeF) = slice_freeF;
TIi(t_harr,visit) = harr_visit; TIi(t_hslice,visit) = slice_visit;
TIi(t_harr,print) = arr_print; TIi(t_hslice,print) = arr_print;
TIi(t_harr,freeO) = harr_freeO; TIi(t_hslice,freeO) = slice_freeO; TIi(t_harrPartial,freeO) = harrP_freeO;
TIi(t_harr,freeF) = harr_freeF; TIi(t_hslice,freeF) = slice_freeF; TIi(t_harrPartial,freeF) = harrP_freeF;
TIi(t_harr,visit) = harr_visit; TIi(t_hslice,visit) = slice_visit; TIi(t_harrPartial,visit) = harrP_visit;
TIi(t_harr,print) = arr_print; TIi(t_hslice,print) = arr_print; TIi(t_harrPartial,print) = harrP_print;
TIi(t_harr,isArr) = true; TIi(t_hslice,isArr) = true;
TIi(t_harr,canStore) = harr_canStore;
bi_emptyHVec = m_harrUv(0).b; gc_add(bi_emptyHVec);

View File

@ -41,7 +41,7 @@ static HArr_p m_harr_impl(usz ia) {
#define HARR_FC(N, X) ({ assert(N##_v.c->ia == N##_len); harr_fc_impl(N##_v, X); })
#define HARR_FCD(N, X) ({ assert(N##_v.c->ia == N##_len); harr_fcd_impl(N##_v, X); })
#define HARR_FA(N, R) ({ assert(N##_v.c->ia == N##_len); harr_fa_impl(N##_v, R); })
#define HARR_ABANDON(N) harr_abandon_impl(N##_v)
#define HARR_ABANDON(N) harr_abandon_impl(N##_v.c)
static B harr_fv_impl(HArr_p p) { VTY(p.b, t_harrPartial);
p.c->type = t_harr;
p.c->sh = &p.c->ia;
@ -67,12 +67,7 @@ static usz* harr_fa_impl(HArr_p p, ur r) { VTY(p.b, t_harrPartial);
gsPop();
return arr_shAlloc((Arr*)p.c, r);
}
static void harr_abandon_impl(HArr_p p) { VTY(p.b, t_harrPartial);
gsPop();
p.c->sh = &p.c->ia; // TODO more direct freeing
sprnk(p.c, 1);
value_free((Value*)p.c);
}
void harr_abandon_impl(HArr* p);
// unsafe-ish things - don't allocate/GC anything before having written to all items