[m-rev.] for review: agc: fix bug with arrays

Simon Taylor stayl at cs.mu.OZ.AU
Wed Jun 5 03:50:42 AEST 2002


On 04-Jun-2002, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Estimated hours taken: 8
> Branches: main
> 
> library/array.m:
> extras/trailed_update/tr_array.m:
> runtime/mercury_deep_copy_body.h:
> runtime/mercury_library_types.h:
> 	Allocate arrays on the Mercury heap, using MR_incr_hp_msg(),
> 	rather than using MR_GC_malloc().  This is needed for accurate
> 	GC, to ensure that the objects pointed to by the array elements
> 	will get traced by the collector.
 
> Index: extras/trailed_update/tr_array.m
> ===================================================================
> +void
> +ML_tr_resize_array(MR_ArrayType *array, const MR_ArrayType *old_array,
> +	MR_Integer array_size, MR_Word item)
>  {
>  	MR_Integer i;
> -	MR_ArrayType* array;
>  	MR_Integer elements_to_copy;
>  
>  	elements_to_copy = old_array->size;
> -	if (elements_to_copy == array_size) return old_array;
>  	if (elements_to_copy > array_size) {
>  		elements_to_copy = array_size;
>  	}
>  
> -	array = (MR_ArrayType *) MR_GC_NEW_ARRAY(MR_Word, array_size + 1);
>  	array->size = array_size;
>  	for (i = 0; i < elements_to_copy; i++) {
>  		array->elements[i] = old_array->elements[i];
> @@ -327,7 +322,8 @@
>  		Array::array_uo),
>  	will_not_call_mercury,
>  "
> -	Array = (MR_Word) ML_tr_resize_array((MR_ArrayType *) Array0,
> +	MR_incr_hp_msg(Array, Size + 1, MR_PROC_LABEL, ""array:array/1"");
> +	ML_tr_resize_array((MR_ArrayType *)Array, (const MR_ArrayType *)Array0,
>  		Size, Item);
>  ").

It's probably best to maintain the old behaviour of returning
the old array if the size hasn't changed, as you've done for
array__resize (same for tr_array__shrink).

Otherwise, this change is fine.

Simon.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list