[m-dev.] diff: fix MR_get_arg_type_info() bug

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Dec 13 01:28:34 AEDT 1999


On 11-Dec-1999, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Fix a bug that zs reported in dgj's recent change:
> MR_get_arg_type_info() was crashing on the fake type_infos
> created by MR_materialize_typeinfos_base().
> 
> runtime/mercury_layout_util.c:
> 	Change MR_materialize_typeinfos_base() to set
> 	the type_ctor_info field to NULL.
> 
> runtime/mercury_type_info.c:
> 	Change the code for MR_get_arg_type_info() so
> 	that it handles the case where the type_ctor_info
> 	field is NULL.

If at first you don't succeed, then try, try again...

----------

Estimated hours taken: 2

Fix a problem with my recent attempted bug fix for
the bug that zs reported in dgj's recent change, where
MR_get_arg_type_info() was crashing on the fake type_infos
created by MR_materialize_typeinfos_base().

runtime/mercury_type_info.c:
	Delete the code in MR_get_arg_type_info() for
        handling the case where the type_ctor_info
        field is NULL. 

runtime/mercury_layout_util.c:
        Change MR_materialize_typeinfos_base() to set
        the type_ctor_info field to a dummy type_ctor_info,
	not to NULL.
	Using a null pointer didn't work because the code for
	MR_TYPEINFO_GET_TYPE_CTOR_INFO() relies on
	the type_ctor_info never being null.

Workspace: /d-drive/home/hg/fjh/ws-hg2/mercury
Index: runtime/mercury_layout_util.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_layout_util.c,v
retrieving revision 1.14
diff -u -d -r1.14 mercury_layout_util.c
--- runtime/mercury_layout_util.c	1999/12/10 15:53:32	1.14
+++ runtime/mercury_layout_util.c	1999/12/12 13:56:06
@@ -63,6 +63,30 @@
 	save_transient_registers();
 }
 
+	/* 
+	** Dummy type_ctor_info for stack layouts.
+	** This is used by MR_materialize_type_infos_base().
+	** The only important thing about the contents
+	** of this dummy type_ctor_info is that the
+	** arity should be the maximum arity,
+	** so that any type variables are treated as
+	** universally quantified when the type_info is
+	** passed to MR_get_arg_type_info().
+	*/
+MR_STATIC_CODE_CONST struct MR_TypeCtorInfo_struct
+mercury_data___type_ctor_info_stack_layout_0 = {
+	TYPE_CTOR_LAYOUT_MAX_VARINT, /* arity = maximum */
+	0,
+	0,
+	0,
+	MR_TYPECTOR_REP_UNKNOWN,
+	0,
+	0,
+	string_const("private_builtin", 7),
+	string_const("stack_layout", 4),
+	MR_RTTI_VERSION
+};
+
 Word *
 MR_materialize_typeinfos(const MR_Stack_Layout_Vars *vars,
 	Word *saved_regs)
@@ -85,11 +109,11 @@
 		type_params = MR_NEW_ARRAY(Word, count + 1);
 
 		/*
-		** type_params should look like a typeinfo; but
-		** type_params[0], which normally holds the type_ctor_info,
-		** will be a null pointer.
+		** type_params should look like a typeinfo, so
+		** we need to fill in type_params[0] with a dummy type_ctor_info.
 		*/
-		type_params[0] = (Word) NULL;
+		type_params[0] = (Word)
+			&mercury_data___type_ctor_info_stack_layout_0;
 		for (i = 0; i < count; i++) {
 			if (vars->MR_slvs_tvars->MR_tp_param_locns[i] != 0) {
 				type_params[i + 1] = MR_lookup_long_lval_base(
Index: runtime/mercury_type_info.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.c,v
retrieving revision 1.29
diff -u -d -r1.29 mercury_type_info.c
--- runtime/mercury_type_info.c	1999/12/11 15:32:32	1.29
+++ runtime/mercury_type_info.c	1999/12/12 14:13:11
@@ -131,8 +131,8 @@
 	** MR_create_type_info():
 	**
 	** Given a type_info `term_type_info' which contains a
-	** type_ctor_info pointer (which may be NULL) and possibly other
-	** type_infos giving the values of the type parameters of this type,
+	** type_ctor_info pointer and possibly other type_infos
+	** giving the values of the type parameters of this type,
 	** and given a pseudo-type_info `arg_pseudo_type_info', which contains
 	** a type_ctor_info pointer and possibly other type_infos
 	** giving EITHER
@@ -276,18 +276,6 @@
 	arg_num = (Unsigned) arg_pseudo_type_info;
 
 	type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO(term_type_info);
-	if (type_ctor_info == NULL) {
-		/*
-		** The term_type_info is not a real type_info, it is just
-		** a vector of type_infos for the arguments with a null
-		** type_ctor_info.  Such fake type_infos are created
-		** by MR_materialize_type_infos().  For them, we treat
-		** all the type variables as being universally quantified,
-		** i.e. coming from the arg_pseudo_type_info.
-		*/
-		arg_type_info = (Word *) term_type_info[arg_num];
-		return arg_type_info;
-	}
 
 	num_univ_type_infos = type_ctor_info->arity;
 	if (arg_num <= num_univ_type_infos) {
@@ -511,8 +499,8 @@
 
 	/* 
 	** Given a type_info `term_type_info' which contains a
-	** type_ctor_info pointer (which may be NULL) and possibly other
-	** type_infos giving the values of the type parameters of this type,
+	** type_ctor_info pointer and possibly other type_infos
+	** giving the values of the type parameters of this type,
 	** and given a pseudo-type_info `arg_pseudo_type_info', which contains
 	** a type_ctor_info pointer and possibly other type_infos
 	** giving EITHER

-- 
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.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list