summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--functions.c8
-rw-r--r--memory.c12
2 files changed, 10 insertions, 10 deletions
diff --git a/functions.c b/functions.c
index b2e4d9f..576fc4c 100644
--- a/functions.c
+++ b/functions.c
@@ -579,7 +579,7 @@ fnSplit(Array *right)
{
Rune *code = L"0≡≢⍴⍵: ⍵ ⋄ 1≡≢⍴⍵: ⊂⍵ ⋄ (⊂⍵)⌷⍨¨⍳¯1↓⍴⍵";
Array *result = rundfn(code, nil, nil, nil, right);
- if(GetSize(result) == 0)
+ if(GetSize(result) == 0 && GetType(result) == AtypeArray)
result->prototype = rundfn(L"⊂(⊃⌽⍴⍵)↑⎕proto ⍵", nil, nil, nil, right);
return result;
}
@@ -1327,7 +1327,7 @@ fnTake(Array *left, Array *right)
for(i = 0; i < GetRank(right); i++)
result->shape[i] = shape[i];
- if(size == 0)
+ if(size == 0 && GetType(result) == AtypeArray)
result->prototype = fnSame(fill);
int *index = emallocz(sizeof(int) * GetSize(left), 1);
@@ -1788,7 +1788,7 @@ fnCatenateFirst(Array *left, Array *right)
freearray(leftarr);
freearray(rightarr);
- if(GetSize(result) == 0)
+ if(GetSize(result) == 0 && GetType(result) == AtypeArray)
result->prototype = fillelement(left);
return result;
}
@@ -1805,7 +1805,7 @@ fnReshape(Array *left, Array *right)
return arrayitem(right, 0);
Array *res = allocarray(GetType(right), GetSize(left), size);
- if(size == 0)
+ if(size == 0 && GetType(res) == AtypeArray)
res->prototype = fillelement(right);
for(i = 0; i < GetSize(left); i++)
diff --git a/memory.c b/memory.c
index c94993c..533e159 100644
--- a/memory.c
+++ b/memory.c
@@ -65,13 +65,13 @@ freearray(Array *a)
SetRefs(a, GetRefs(a)-1);
if(GetRefs(a) == 0){
if(GetType(a) == AtypeArray){
- if(GetSize(a) > 0){
- for(int i = 0; i < GetSize(a); i++)
- freearray(a->arraydata[i]);
- free(a->rawdata);
- }else
- freearray(a->prototype);
+ for(int i = 0; i < GetSize(a); i++)
+ freearray(a->arraydata[i]);
}
+ if(GetType(a) == AtypeArray && GetSize(a) == 0)
+ freearray(a->prototype);
+ else
+ free(a->rawdata);
free(a->shape);
free(a);
arrayalloccounts--;