[m-rev.] diff: fix erlang off-by-one errors

Peter Ross pro at missioncriticalit.com
Wed Jun 6 18:23:52 AEST 2007


Hi,


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


Estimated hours taken: 2
Branches: main

library/private_builtin.m:
	Fix some off by one errors in the type-info extraction
	code.

Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.168
diff -u -r1.168 private_builtin.m
--- library/private_builtin.m	30 May 2007 08:16:06 -0000	1.168
+++ library/private_builtin.m	6 Jun 2007 08:21:43 -0000
@@ -699,14 +699,14 @@
         (Object[]) TypeClassInfo0, Index);
 ").
 
-% XXX untested
-
 :- pragma foreign_proc("Erlang",
     type_info_from_typeclass_info(TypeClassInfo::in, Index::in,
         TypeInfo::out),
     [will_not_call_mercury, promise_pure, thread_safe],
 "
-    TypeInfo = element(Index, TypeClassInfo)
+        % Indexes start at 1 in Erlang,
+        % while in C they start at 0
+    TypeInfo = element(Index + 1, TypeClassInfo)
 ").
 
 :- pragma foreign_proc("Erlang",
@@ -714,7 +714,9 @@
         Index::in, TypeInfo::out),
     [will_not_call_mercury, promise_pure, thread_safe],
 "
-    TypeInfo = element(Index, TypeClassInfo)
+        % Indexes start at 1 in Erlang,
+        % while in C they start at 0
+    TypeInfo = element(Index + 1, TypeClassInfo)
 ").
 
 :- pragma foreign_proc("Erlang",
@@ -722,7 +724,9 @@
         TypeClassInfo::out),
     [will_not_call_mercury, promise_pure, thread_safe],
 "
-    TypeClassInfo = element(Index, TypeClassInfo0)
+        % Indexes start at 1 in Erlang,
+        % while in C they start at 0
+    TypeClassInfo = element(Index + 1, TypeClassInfo0)
 ").
 
 :- pragma foreign_proc("Erlang",
@@ -730,7 +734,9 @@
         Index::in, TypeClassInfo::out),
     [will_not_call_mercury, promise_pure, thread_safe],
 "
-    TypeClassInfo = element(Index, TypeClassInfo0)
+        % Indexes start at 1 in Erlang,
+        % while in C they start at 0
+    TypeClassInfo = element(Index + 1, TypeClassInfo0)
 ").
 
 %-----------------------------------------------------------------------------%

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list