diff runtime/array.c @ 119:72c648bca43b

Improved memory debug output and fixed memory leak in Array
author Mike Pavone <pavone@retrodev.com>
date Mon, 18 Oct 2010 00:50:18 -0400
parents 439db471f595
children
line wrap: on
line diff
--- a/runtime/array.c	Fri Oct 15 00:55:02 2010 -0400
+++ b/runtime/array.c	Mon Oct 18 00:50:18 2010 -0400
@@ -12,7 +12,15 @@
 
 void _internal_array_copyin(object * array, int32_t index, object * val)
 {
+	char *dest;
 	t_Array * arr = (t_Array *)array;
+	t_Blueprint * bp = arr->payload.Eltype;
+	if(bp->bp->type_id >= TYPE_ARRAY && index < arr->payload.Length)
+	{
+		//Ugly hack
+		dest = ((char *)(arr+1))-sizeof(object) + bp->bp->size * index;
+		bp->bp->cleanup((object *)dest);
+	}
 	memcpy(((char *)array) + sizeof(t_Array) + arr->payload.Eltype->bp->size * index, ((char *)val) + sizeof(object), arr->payload.Eltype->bp->size);
 	get_blueprint(val)->copy(val);
 	release_ref(val);
@@ -47,6 +55,10 @@
 void _internal_array_setboxed(object *array, int32_t index, object * val)
 {
 	object ** intarr = (object **)(((char *) array) + sizeof(t_BoxedSP_Array));
+	if (index < ((t_BoxedSP_Array *)array)->payload.Length)
+	{
+		release_ref(intarr[index]);
+	}
 	intarr[index] = val;
 }