On Wed, 25 Sep 2002, Leopold Toetsch wrote:
 
> This patch obsoletes all previous imcc 0.0.9 patches and contains all 
> current fixes and improvements.
 
> I suppose, problems Andy has, to be related with the parser.

Actually, the core dump I got in reg_sort_f turned out to be a simple bug
in reg_sort_f!  That's probably one of the few times I've ever encountered
where a core dump occurred near the bug that caused it :-).

The problem is that the qsort() function wasn't being called with a
correct comparison function.  The supplied comparison function only ever
returned 0 or 1, instead of the required -1, 0, 1.  Why your qsort
was happy anyway, I don't know.

What Solaris's qsort ended up doing was walking off the front of the
reglist[] array, effectively trying to sort reglist[-1], which, of
course, didn't exist.  (*Why* it did that is a bit of a mystery; I'd have
to look at the detailed implementation of Sun's qsort to say for sure.)

Here's the patch that fixes it.

--- parrot-orig/languages/imcc/imc.c    Mon Sep 23 14:05:20 2002
+++ parrot-andy/languages/imcc/imc.c    Wed Sep 25 13:18:34 2002
@@ -153,7 +153,15 @@
 static int reg_sort_f(const void *a, const void *b) {
     SymReg *ra = *(SymReg**) a;
     SymReg *rb = *(SymReg**) b;
-    return ra->first_ins->index > rb->first_ins->index ? 1 : 0;
+    if (ra->first_ins->index < rb->first_ins->index) {
+       return -1;
+    }
+    else if (ra->first_ins->index == rb->first_ins->index) {
+        return 0;
+    }
+    else {
+       return 1;
+    }
 }
 
 static void sort_reglist()

-- 
    Andy Dougherty              [EMAIL PROTECTED]

Reply via email to