[m-rev.] diff: fix failure of general/read_line_as_string in .profdeep grades

Julien Fischer juliensf at cs.mu.OZ.AU
Tue Jun 14 19:42:11 AEST 2005


Estimated hours taken: 9
Branches: main, release

runtime/mercury_deep_profiling.c:
	Fix a bug that causes general/read_line_as_string to seg fault
	in the .profdeep grades.  The problem was that the slots in the hash
	tables were not being initialised to NULL.

	The above test case triggered this problem because the start of
	the MR_call_site_dynamic_table was reusing memory that
	io.read_line_as_string_2/6 had previously used as a temporary buffer.
	Consequently, the initial values of many of the slots in the hash table
	contained rubbish; moreover they contained inaccessible rubbish which
	was the code that writes out the Deep.data files was seg faulting.

library/io.m:
library/string.m:
	A little bit of preventative maintenance: s/memcpy/MR_memcpy/

Julien.

Workspace:/home/aral/juliensf/ws-deep-profile
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.331
diff -u -r1.331 io.m
--- library/io.m	20 May 2005 07:14:35 -0000	1.331
+++ library/io.m	14 Jun 2005 04:04:27 -0000
@@ -1911,7 +1911,7 @@
 			if (read_buffer == initial_read_buffer) {
 				read_buffer = MR_NEW_ARRAY(MR_Char,
 					read_buf_size);
-				memcpy(read_buffer, initial_read_buffer,
+				MR_memcpy(read_buffer, initial_read_buffer,
 					ML_IO_READ_LINE_START);
 			} else {
 				read_buffer = MR_RESIZE_ARRAY(read_buffer,
@@ -1925,7 +1925,7 @@
 			0, ML_IO_BYTES_TO_WORDS((i + 1) * sizeof(MR_Char)),
 			MR_PROC_LABEL, ""string:string/0"");
 		RetString = (MR_String) ret_string_word;
-		memcpy(RetString, read_buffer, i * sizeof(MR_Char));
+		MR_memcpy(RetString, read_buffer, i * sizeof(MR_Char));
 		RetString[i] = '\\0';
 	} else {
 		/*
@@ -3270,9 +3270,9 @@
 			MR_PROC_LABEL, ""io:buffer/0"");
 		Buffer = (MR_Char *) buf;
 		if (OldSize > NewSize) {
-			memcpy(Buffer, Buffer0, NewSize);
+			MR_memcpy(Buffer, Buffer0, NewSize);
 		} else {
-			memcpy(Buffer, Buffer0, OldSize);
+			MR_memcpy(Buffer, Buffer0, OldSize);
 		}
 	}
 #endif
Index: library/string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.231
diff -u -r1.231 string.m
--- library/string.m	30 Mar 2005 10:52:04 -0000	1.231
+++ library/string.m	14 Jun 2005 04:04:50 -0000
@@ -3639,7 +3639,7 @@
 	[will_not_call_mercury, promise_pure, thread_safe],
 "{
 	MR_allocate_aligned_string_msg(S1, S1Len, MR_PROC_LABEL);
-	memcpy(S1, S3, S1Len);
+	MR_memcpy(S1, S3, S1Len);
 	S1[S1Len] = '\\0';
 	MR_allocate_aligned_string_msg(S2, S3Len - S1Len, MR_PROC_LABEL);
 	strcpy(S2, S3 + S1Len);
@@ -3702,7 +3702,7 @@
 		if (Start > len) Start = len;
 		if (Count > len - Start) Count = len - Start;
 		MR_allocate_aligned_string_msg(SubString, Count, MR_PROC_LABEL);
-		memcpy(SubString, Str + Start, Count);
+		MR_memcpy(SubString, Str + Start, Count);
 		SubString[Count] = '\\0';
 	}
 }").
@@ -3714,7 +3714,7 @@
 	MR_Integer len;

 	MR_allocate_aligned_string_msg(SubString, Count, MR_PROC_LABEL);
-	memcpy(SubString, Str + Start, Count);
+	MR_memcpy(SubString, Str + Start, Count);
 	SubString[Count] = '\\0';
 }").
 :- pragma foreign_proc("C#",
@@ -3744,7 +3744,7 @@
 		len = strlen(Str);
 		if (Count > len) Count = len;
 		MR_allocate_aligned_string_msg(Left, Count, MR_PROC_LABEL);
-		memcpy(Left, Str, Count);
+		MR_memcpy(Left, Str, Count);
 		Left[Count] = '\\0';
 		/*
 		** We need to make a copy to ensure that the pointer is
Index: runtime/mercury_deep_profiling.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_profiling.c,v
retrieving revision 1.17
diff -u -r1.17 mercury_deep_profiling.c
--- runtime/mercury_deep_profiling.c	2 Jun 2005 19:30:33 -0000	1.17
+++ runtime/mercury_deep_profiling.c	14 Jun 2005 08:28:09 -0000
@@ -1243,12 +1243,17 @@
 MR_create_hash_table(int size)
 {
     MR_ProfilingHashTable *ptr;
+    int i;

     ptr = MR_NEW(MR_ProfilingHashTable);
     ptr->length = size;
     ptr->last_id = 0;
     ptr->nodes = MR_NEW_ARRAY(MR_ProfilingHashNode *, size);
-
+
+    for (i = 0; i < size; i++) {
+        ptr->nodes[i] = NULL;
+    }
+
     return ptr;
 }


--------------------------------------------------------------------------
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