for review: deep_copy() bug fix

Fergus Henderson fjh at cs.mu.oz.au
Fri Apr 11 01:59:28 AEST 1997


Hi Tyson,

Could you please review this one?

-----------------------------------------------------------------------------

Fix a bug that Tom reported where calling solutions/3 with an
equivalence type caused a crash in deep_copy().

runtime/deep_copy.c:
	Fix a bug in the copying of equivalence types and no_tag types.
	It was using `entry_value' instead of `entry_value[1]'.

tests/hard_coded/Mmake:
tests/hard_coded/.cvsignore:
tests/hard_coded/deep_copy_bug.m:
tests/hard_coded/deep_copy_bug.exp:
	Add a regression test for this bug.

Index: deep_copy.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/deep_copy.c,v
retrieving revision 1.9
diff -u -r1.9 deep_copy.c
--- deep_copy.c	1997/02/18 15:49:47	1.9
+++ deep_copy.c	1997/04/10 15:40:47
@@ -239,8 +239,14 @@
 		    (Word *) type_info[(Word) entry_value],
                     lower_limit, upper_limit);
             } else {
+		/*
+		** offset 0 is no-tag indicator
+		** offset 1 is the pseudo-typeinfo
+		** (as per comments in base_type_layout.m)
+		** XXX should avoid use of hard-coded offset `1' here
+		*/
                 new_type_info = make_type_info(type_info, 
-                    entry_value, &allocated);
+                    (Word *) entry_value[1], &allocated);
                 new_data = deep_copy(data, new_type_info, 
                     lower_limit, upper_limit);
                 if (allocated) {

-----------------------------------------------------------------------------
tests/hard_coded/deep_copy_bug.m
-----------------------------------------------------------------------------
% This is a regression test.
% The Mercury compiler of Apr 11 1997 failed for this in non-gc grades,
% because of a bug in deep_copy() of equivalence types.

:- module deep_copy_bug.

:- interface.

:- import_module io.

:- pred main(io__state::di, io__state::uo) is det.

:- implementation.

:- import_module int, std_util, list, term, varset.

main -->
	{ Lambda = lambda([X::out] is nondet,
	(
		varset__init(Varset0),
		varset__new_vars(Varset0, 10, Vars, _),
		list__member(X, Vars)
	)) },
	{ solutions(Lambda, List) },
	io__write(List),
	io__write_string("\n").

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list