[m-rev.] diff: fix label_layout.c

Zoltan Somogyi zs at cs.mu.OZ.AU
Wed Oct 27 15:28:10 AEST 2004


Fix a problem reported by Ian, the symptom being some missing caller contexts
for some events in the tests/debugger/label_layout test. The cause of the
problem was that label_layout.c had two consecutive labels, the first without
a label layout structure, the second with a label layout structure. When
trying to insert the second label into the label table, mercury_label.c
ignored the label, since a label with its address already existed.

runtime/mercury_label.c:
	When inserting a label for an address which is already known, don't
	ignore any label layout structure.

runtime/mercury_hash_table.[ch]:
	Make the function for insertions into hash tables return the old entry
	if one exists, for use in mercury_label.c.

Zoltan.

cvs diff: Diffing .
Index: mercury_hash_table.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_hash_table.c,v
retrieving revision 1.5
diff -u -b -r1.5 mercury_hash_table.c
--- mercury_hash_table.c	18 Feb 2002 07:01:16 -0000	1.5
+++ mercury_hash_table.c	18 Oct 2004 12:04:54 -0000
@@ -73,7 +73,7 @@
 **	Return whether it was there before.
 */
 
-MR_bool 
+void *
 MR_ht_insert_table(const MR_Hash_Table *table, void *entry)
 {
 	MR_Dlist	*ptr;
@@ -95,12 +95,12 @@
 		if (MR_tableequal(table)(key,
 				MR_tablekey(table)(MR_dlist_data(ptr))))
 		{
-			return MR_TRUE;
+			return MR_dlist_data(ptr);
 		}
 	}
 
 	table->MR_ht_store[h] = MR_dlist_addhead(table->MR_ht_store[h], entry);
-	return MR_FALSE;
+	return NULL;
 }
 
 /*
Index: mercury_hash_table.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_hash_table.h,v
retrieving revision 1.3
diff -u -b -r1.3 mercury_hash_table.h
--- mercury_hash_table.h	18 Feb 2002 07:01:16 -0000	1.3
+++ mercury_hash_table.h	18 Oct 2004 12:05:10 -0000
@@ -42,7 +42,7 @@
 extern	void		MR_ht_init_table(MR_Hash_Table *);
 extern	const void	*MR_ht_lookup_table(const MR_Hash_Table *,
 				const void *);
-extern	MR_bool		MR_ht_insert_table(const MR_Hash_Table *, void *);
+extern	void		*MR_ht_insert_table(const MR_Hash_Table *, void *);
 extern	MR_Dlist	*MR_ht_get_all_entries(const MR_Hash_Table *);
 extern	void		MR_ht_process_all_entries(const MR_Hash_Table *,
 				void f(const void *));
Index: mercury_label.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_label.c,v
retrieving revision 1.23
diff -u -b -r1.23 mercury_label.c
--- mercury_label.c	22 Oct 2003 05:56:08 -0000	1.23
+++ mercury_label.c	18 Oct 2004 15:14:54 -0000
@@ -206,6 +206,7 @@
 	const MR_Label_Layout *label_layout)
 {
 	MR_Internal	*internal;
+	MR_Internal	*prev_internal;
 
 	MR_do_init_label_tables();
 
@@ -230,10 +231,29 @@
 	}
 #endif
 
-	/* two labels at same location will happen quite often */
-	/* when the code generated between them turns out to be empty */
+	prev_internal = (MR_Internal *)
+		MR_insert_hash_table(internal_addr_table, internal);
 
-	(void) MR_insert_hash_table(internal_addr_table, internal);
+	if (prev_internal != NULL) {
+		/*
+		** Two labels at same location will happen quite often,
+		** when the code generated between them turns out to be empty.
+		** In this case, MR_insert_hash_table will not have inserted
+		** internal into the table.
+		**
+		** If only one of internal and prev_internal have a layout
+		** structure, make sure that we associate the layout structure
+		** with the label address.
+		**
+		** If both internal and prev_internal have a layout structure,
+		** we rely on the compiler to make sure that it is ok to use
+		** either of their layout structures.
+		*/
+
+		if (prev_internal->i_layout == NULL) {
+			prev_internal->i_layout = label_layout;
+		}
+	}
 }
 
 MR_Internal *
cvs diff: Diffing GETOPT
cvs diff: Diffing machdeps
--------------------------------------------------------------------------
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