[Mono-bugs] [Bug 29488][Maj] New - Delegate marshalling bug

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
27 Aug 2002 02:48:46 -0000


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 nick@chemlab.org.

http://bugzilla.ximian.com/show_bug.cgi?id=29488

--- shadow/29488	Mon Aug 26 22:48:46 2002
+++ shadow/29488.tmp.7789	Mon Aug 26 22:48:46 2002
@@ -0,0 +1,102 @@
+Bug#: 29488
+Product: Mono/Runtime
+Version: unspecified
+OS: 
+OS Details: Debian/Unstable
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: nick@chemlab.org               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Delegate marshalling bug
+
+Steps to reproduce the problem:
+
+1. Compile the following C code as a shared library called libdelegate.so.
+
+-- START --
+#include <stdio.h>
+
+void CallDelegate (void (*ptr)(void))
+{
+	ptr();
+	printf("Pointer address: %p\n", ptr);
+}
+-- END --
+
+2. Compile and run the following C# code.
+
+-- START --
+using System;
+using System.Runtime.InteropServices;
+
+public delegate void Foobar();
+
+public class DelTest {
+	private static int InstCount = 0;
+
+	private int inst;
+	private Foobar del;
+
+	public DelTest()
+	{
+		inst = InstCount++;
+		del = new Foobar(Raboof);
+		Console.WriteLine(this+": New instance: " + inst);
+	}
+
+	private void Raboof()
+	{
+		Console.WriteLine("DelTest: Instance "+inst+": Invoked");
+	}
+
+	public void Invoke()
+	{
+		CallDelegate(del);
+	}
+
+	[DllImport("libdelegate", CharSet=CharSet.Ansi)]
+	private static extern void CallDelegate(Foobar d);
+
+	public static void Main()
+	{
+		DelTest dt1 = new DelTest();
+		DelTest dt2 = new DelTest();
+
+		dt1.Invoke();
+		dt2.Invoke();
+	}
+}
+-- END --
+
+Actual Results:
+
+ganymede:~/public_html/deltest$ cli deltest.exe
+DelTest: New instance: 0
+DelTest: New instance: 1
+DelTest: Instance 0: Invoked
+Pointer address: 0x827c0e4
+DelTest: Instance 0: Invoked
+Pointer address: 0x827c0e4
+
+Expected Results:
+
+ganymede:~/public_html/deltest$ cli deltest.exe
+DelTest: New instance: 0
+DelTest: New instance: 1
+DelTest: Instance 0: Invoked
+Pointer address: 0x827c0e4
+DelTest: Instance 1: Invoked
+Pointer address: <different pointer address>
+
+How often does this happen? 
+
+Always.
+
+Additional Information: