[Mono-bugs] [Bug 41330][Nor] New - Crash on Marshal.StructToPtr: Python.NET support.
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
Mon, 14 Apr 2003 14:42:58 -0400 (EDT)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by miguel@ximian.com.
http://bugzilla.ximian.com/show_bug.cgi?id=41330
--- shadow/41330 Mon Apr 14 14:42:58 2003
+++ shadow/41330.tmp.31379 Mon Apr 14 14:42:58 2003
@@ -0,0 +1,81 @@
+Bug#: 41330
+Product: Mono/Runtime
+Version: unspecified
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: miguel@ximian.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Crash on Marshal.StructToPtr: Python.NET support.
+
+The following program crashes on Mono, this is a small test case that
+happens when running the Python.NET on Mono (the Python binding, not the
+Python CIL compiler):
+
+using System;
+using System.Runtime.InteropServices;
+using System.Reflection;
+
+[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
+struct D {
+ public Delegate x;
+
+ public D (Delegate a)
+ {
+ x = a;
+ }
+}
+
+class T {
+ delegate void N ();
+
+ static void M () {}
+
+ static public void Main ()
+ {
+ IntPtr p = Marshal.AllocHGlobal (1024);
+ N m = new N (M);
+
+ D d = new D (Delegate.CreateDelegate (typeof (N), m.Method));
+ Marshal.StructureToPtr(d, p, false);
+ }
+}
+
+The crash is:
+Unhandled Exception: System.NullReferenceException: A null value was found
+where an object instance was required
+in (unmanaged) mono(mono_type_to_unmanaged+0x4c7) [0x80f3abf]
+in (unmanaged) mono(mono_marshal_type_size+0x29) [0x80f3b39]
+in (unmanaged) mono(mono_marshal_load_type_info+0x2a2) [0x80fed9e]
+in (unmanaged) mono(mono_class_native_size+0x2a) [0x81032b2]
+in (unmanaged) mono(mono_marshal_type_size+0x1c5) [0x80f3cd5]
+in (unmanaged) mono(mono_marshal_load_type_info+0x2a2) [0x80fed9e]
+in (unmanaged) mono [0x80d2388]
+in (unmanaged) mono(mono_marshal_get_struct_to_ptr+0x267) [0x80d85d3]
+in (unmanaged)
+mono(ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr+0x88)
+[0x80d91f8]
+in <0x000cd> 00 .T:Main ()
+
+The problem seems to be that one of the fields in Delegate is not properly
+initialized:
+
+(gdb) p klass->fields [1]
+$17 = {type = 0x81fd588, offset = 12, name = 0x4040da03 "m_target", data =
+0x0, parent = 0x8196ba0}
+(gdb) p klass->fields [1].type
+$25 = (MonoType *) 0x81fd588
+(gdb) p *klass->fields [1].type
+$26 = {data = {klass = 0x0, type = 0x0, array = 0x0, method = 0x0,
+type_param = 0, generic_inst = 0x0}, attrs = 4, type = 28,
+ num_mods = 0, byref = 0, pinned = 0, modifiers = 0x81fd590}
+
+For some reason the m_target contains an unitialized value.