for review: fix copy bug.

Tyson Dowd trd at cs.mu.OZ.AU
Mon Nov 2 23:53:44 AEDT 1998


Hi,

Here's a bug fix for the copy bug that occured in a few
programs -- for example samples/diff.

===================================================================


Estimated hours taken: 3

Fix the bug in deep_copy that meant it didn't work on Linux-x86.
It didn't affect the 64 bit builds because the type being copied needed
to be a complicated constant (which doesn't happen unless you
only have 2 tag bits).

runtime/mercury_deep_copy_body.h:
	Strip the tags from the layouts before dereferencing.
	This was causing the problems -- on the x86 it was
	getting the wrong arity and allocating far too much
	memory.

runtime/mercury_table_any.c:
	Use MR_TYPELAYOUT_COMPLICATED_VECTOR_GET_SIMPLE_VECTOR
	instead of manipulating the layout information by hand.

runtime/mercury_type_info.h:
	Fix MR_TYPELAYOUT_COMPLICATED_VECTOR_GET_SIMPLE_VECTOR
	to strip the tag.
	

Index: runtime//mercury_deep_copy_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_copy_body.h,v
retrieving revision 1.1
diff -u -r1.1 mercury_deep_copy_body.h
--- mercury_deep_copy_body.h	1998/07/22 07:52:35	1.1
+++ mercury_deep_copy_body.h	1998/11/02 11:35:48
@@ -68,7 +68,9 @@
             if (in_range(data_value)) {
                 secondary_tag = *data_value;
                 argument_vector = data_value + 1;
-                new_entry = (Word *) entry_value[secondary_tag +1];
+
+                new_entry = MR_TYPELAYOUT_COMPLICATED_VECTOR_GET_SIMPLE_VECTOR(
+			entry_value, secondary_tag);
                 arity = new_entry[TYPELAYOUT_SIMPLE_ARITY_OFFSET];
                 type_info_vector = new_entry + TYPELAYOUT_SIMPLE_ARGS_OFFSET;
 
Index: runtime//mercury_table_any.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_table_any.c,v
retrieving revision 1.4
diff -u -r1.4 mercury_table_any.c
--- mercury_table_any.c	1998/08/24 08:24:51	1.4
+++ mercury_table_any.c	1998/11/02 08:35:20
@@ -98,9 +98,9 @@
 
             num_sharers = MR_TYPELAYOUT_COMPLICATED_VECTOR_NUM_SHARERS(
             			layout_vector_for_tag);
-	    /* XXX trd: this operation should have a macro */
-            new_layout_vector = (Word *) strip_tag(
-				layout_vector_for_tag[secondary_tag + 1]);
+            new_layout_vector =
+                MR_TYPELAYOUT_COMPLICATED_VECTOR_GET_SIMPLE_VECTOR(
+                    layout_vector_for_tag, secondary_tag);
             arity = new_layout_vector[TYPELAYOUT_SIMPLE_ARITY_OFFSET];
             type_info_vector =
 		    &new_layout_vector[TYPELAYOUT_SIMPLE_ARGS_OFFSET];
Index: runtime//mercury_type_info.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.h,v
retrieving revision 1.12
diff -u -r1.12 mercury_type_info.h
--- mercury_type_info.h	1998/09/10 06:53:56	1.12
+++ mercury_type_info.h	1998/11/02 08:34:01
@@ -613,7 +613,8 @@
 	((MR_TypeLayout_ComplicatedVector *) (Vector))->num_sharers
 
 #define MR_TYPELAYOUT_COMPLICATED_VECTOR_GET_SIMPLE_VECTOR(Vector, N) 	\
-	( (&((MR_TypeLayout_ComplicatedVector *)(Vector))->simple_vector1) [N] )
+	( (Word *) strip_tag((&((MR_TypeLayout_ComplicatedVector *)	\
+		(Vector))->simple_vector1) [N]) )
 		
 	/* 
 	** Macros for dealing with no_tag vectors 


-- 
       Tyson Dowd           # There isn't any reason why Linux can't be
                            # implemented as an enterprise computing solution.
     trd at cs.mu.oz.au        # Find out what you've been missing while you've
http://www.cs.mu.oz.au/~trd # been rebooting Windows NT. -- InfoWorld, 1998.



More information about the developers mailing list