summaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'memory.c')
-rw-r--r--memory.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/memory.c b/memory.c
index 33c30d7..8bca068 100644
--- a/memory.c
+++ b/memory.c
@@ -57,34 +57,33 @@ freearray(Array *a)
{
if(a == nil)
return;
+ if(a->refs == 0){
+ print("NEGATIVE REF COUNT (array)! %p\n", a);
+ threadexitsall(nil);
+ }
a->refs--;
if(a->refs == 0){
- if(a->type == AtypeArray)
- for(int i = 0; i < a->size; i++)
+ if(GetType(a) == AtypeArray)
+ for(int i = 0; i < GetSize(a); i++)
freearray(a->arraydata[i]);
free(a->shape);
free(a->rawdata);
free(a);
arrayalloccounts--;
- }else if(a->refs < 0){
- print("NEGATIVE REF COUNT (array)! %p\n", a);
- threadexitsall(nil);
}
-
}
Array *
allocarray(arrayDataType t, int rank, int size)
{
Array *a = emalloc(sizeof(Array));
- a->rank = rank;
- a->type = t;
- a->size = size;
- a->stranded = 0;
- a->shape = emalloc(sizeof(int) * rank);
+ SetRank(a, rank);
+ SetType(a, t);
+ SetSize(a, size);
+ SetStrand(a, 0);
+ a->shape = emalloc(sizeof(*a->shape) * rank);
a->rawdata = emalloc(datasizes[t] * size);
- a->type = t;
a->refs = 1;
arrayalloccounts++;
return a;