diff options
-rw-r--r-- | apl9.h | 7 | ||||
-rw-r--r-- | main.c | 4 | ||||
-rw-r--r-- | memory.c | 10 |
3 files changed, 11 insertions, 10 deletions
@@ -75,7 +75,7 @@ typedef struct Mail Mail; struct Mixed { - int type; + u8int type; union { vlong i; double f; @@ -87,10 +87,12 @@ struct Mixed #define GetRank(a) ((u8int)((a->info & 0x0000000F00000000) >> 32)) #define GetType(a) ((u8int)((a->info & 0x000000F000000000) >> 36)) #define GetStrand(a) ((u8int)((a->info & 0x0000010000000000) >> 40)) +#define GetRefs(a) ((u32int)((a->info & 0xFFFFFE0000000000) >> 41)) #define SetSize(a,v) (a->info ^= ((u64int)GetSize(a)^v)) #define SetRank(a,v) (a->info ^= ((u64int)(GetRank(a)^v) << 32)) #define SetType(a,v) (a->info ^= ((u64int)(GetType(a)^v) << 36)) #define SetStrand(a,v) (a->info ^= ((u64int)(GetStrand(a)^v) << 40)) +#define SetRefs(a,v) (a->info ^= ((u64int)(GetRefs(a)^v) << 41)) struct Array { @@ -109,10 +111,9 @@ struct Array * 32-35: 4 bits for the rank (max rank 15) * 36-39: 4 bits for the type (16 options) * 40: 1 bit for stranding - * 41-63: unused + * 41-63: 23 bits for reference counting (max refs = 8388608) * NOTE: should only be modified through the macros defined above */ - ulong refs; }; struct Statement @@ -55,10 +55,10 @@ restart: if(result && !result->shy) print("%S\n", ppdatum(result)); freedatum(result); -/* + print("Unfreed arrays: %d\n", arrayalloccounts); print("Unfreed datums: %d\n", datumalloccounts); -*/ + } threadexitsall(nil); } @@ -57,13 +57,13 @@ freearray(Array *a) { if(a == nil) return; - if(a->refs == 0){ + if(GetRefs(a) == 0){ print("NEGATIVE REF COUNT (array)! %p\n", a); threadexitsall(nil); } - a->refs--; - if(a->refs == 0){ + SetRefs(a, GetRefs(a)-1); + if(GetRefs(a) == 0){ if(GetType(a) == AtypeArray) for(int i = 0; i < GetSize(a); i++) freearray(a->arraydata[i]); @@ -82,9 +82,9 @@ allocarray(arrayDataType t, int rank, int size) SetType(a, t); SetSize(a, size); SetStrand(a, 0); + SetRefs(a, 1); a->shape = emalloc(sizeof(*a->shape) * rank); a->rawdata = emalloc(datasizes[t] * size); - a->refs = 1; arrayalloccounts++; return a; } @@ -92,7 +92,7 @@ allocarray(arrayDataType t, int rank, int size) void incarrayref(Array *a) { - a->refs++; + SetRefs(a, GetRefs(a)+1); } Datum * |