Hi,

The algorithm used to sort index elements is 'qsort', which is unstable,
which means the output from makeinfo is non-deterministic.
The following patch addresses the issue (assuming not more than 1 index
entry is allowed per line.)

Apart from the inherent desirability of having a deterministic tool, the
non-deterministic approach can lead to duplicated index items for the same
node if these index items are made non-adjacent during the search.
When this occurs the netry is not detected as duplicate in the
make_index_entries_unique function.

Thanks,

Benno

diff --git a/makeinfo/index.c b/makeinfo/index.c
index 65d7484..b34025c 100644
--- a/makeinfo/index.c
+++ b/makeinfo/index.c
@@ -505,10 +505,23 @@ cm_tindex (void)                    /* Data Type
index. */
 static int
 index_element_compare (const void *element1, const void *element2)
 {
+  int cmp;
   INDEX_ELT **elt1 = (INDEX_ELT **) element1;
   INDEX_ELT **elt2 = (INDEX_ELT **) element2;

-  return index_compare_fn ((*elt1)->entry, (*elt2)->entry);
+  cmp = index_compare_fn ((*elt1)->entry, (*elt2)->entry);
+  if (cmp != 0)
+    {
+      return cmp;
+    }
+  /* entries are equal, should compare node names */
+  cmp = index_compare_fn ((*elt1)->node, (*elt2)->node);
+  if (cmp != 0)
+    {
+      return cmp;
+    }
+  /* entries and nodes are equal, finally compare by line number */
+  return (*elt1)->defining_line - (*elt2)->defining_line;
 }

 /* Force all index entries to be unique. */

Reply via email to