Bugzilla – Bug 320185
[GMCS] consistent crash using SortedList with non-primitive key
Last modified: 2007-09-15 21:24:46 UTC
---- Reported by bcs26@cornell.edu 2006-01-29 20:36:38 MST ---- The mono runtime crashes consistently on programs using the SortedList generic collection with a class or struct key implementing the IComparable generic interface. A very simple example case (TestSortedList.cs) is attached. Observed behavior: " $ gmcs TestSortedList.cs $ mono TestSortedList.exe ** (TestSortedList.exe:6475): WARNING **: Missing method CompareTo in assembly /usr/lib64/mono/2.0/mscorlib.dll token 6000046 ================================================================= Got a SIGSEGV while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application. ================================================================= Stacktrace: in <0xffffffffffffffff> System.Collections.Generic.SortedList`2:Find (ClassA) in <0xe9> System.Collections.Generic.SortedList`2:Find (ClassA) in <0x70> System.Collections.Generic.SortedList`2:PutImpl (ClassA,bool,bool) in <0x30> System.Collections.Generic.SortedList`2:Add (ClassA,bool) in <0x7d> TestCompareTo:Main (string[]) in <0xffffffffc04780fe> (wrapper runtime-invoke) System.Object:runtime_invoke_void_string[] (object,intptr,intptr,intptr) Native stacktrace: mono(mono_handle_native_sigsegv+0x88) [0x506558] mono [0x4f327c] /lib/tls/libpthread.so.0 [0x2aaaab17b270] mono(mono_get_inflated_method+0x28) [0x4ab458] [0x7ffffface520] Aborted " The runtime appears to operate correctly if an int key is used (or, presumably, any other primitive key). Incorrect behavior is consistently observed with mono 1.1.12.1 and 1.1.13.1 on both amd64 and x86, under Gentoo. It's unclear whether this is a compiler, library, or runtime issue. ---- Additional Comments From bcs26@cornell.edu 2006-01-29 20:37:39 MST ---- Created an attachment (id=169199) simple test case ---- Additional Comments From vargaz@gmail.com 2006-02-09 11:12:43 MST ---- This is a runtime problem. Here is a small testcase: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< using System; using System.Collections.Generic; public class ClassA : IComparable<ClassA> { public int CompareTo(ClassA other) { return 0; } } public class TestCompareTo { public static void Main(string[] args) { SortedList<ClassA, bool> list = new SortedList<ClassA, bool>(); list.Add(new ClassA(), true); list.Add(new ClassA(), true); } } <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ---- Additional Comments From martin@ximian.com 2006-02-10 04:18:47 MST ---- The underlying problem here is that MakeGenericType() doesn't check the constraints. This test case is supposed to throw a TypeLoadException. I'm fixing this in Comparer.cs, but we still need to add constraints checking to the runtime at some point. ---- Additional Comments From martin@ximian.com 2006-02-10 05:25:10 MST ---- . ---- Additional Comments From vargaz@gmail.com 2006-02-10 08:56:06 MST ---- The testcase I attached compiles and runs on MS.NET, and doesn't throw any exception. ---- Additional Comments From martin@ximian.com 2006-02-10 10:19:39 MST ---- It does throw an exception if you have a broken Comparer<T>.Default implementation. Before I fixed it, Comparer<T>.Default returned an instance of ---- class IComparableOfT<T> : Comparer<T> where T : IComparable { .... } ---- this is wrong because ClassA only implements IComparable<T> and not IComparable - so the constraint is not met. The bug is that our runtime doesn't catch this. I fixed that to ---- class IComparableOfT<T> : Comparer<T> where T : IComparable<T> { .... } ---- Imported an attachment (id=169199) Unknown operating system unknown. Setting to default OS "Other".