[Mono-bugs] [Bug 29256][Wis] New - Structure not properly marshalled on callback

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
21 Aug 2002 17:04:20 -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 jason@379.com.

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

--- shadow/29256	Wed Aug 21 13:04:20 2002
+++ shadow/29256.tmp.15316	Wed Aug 21 13:04:20 2002
@@ -0,0 +1,101 @@
+Bug#: 29256
+Product: Mono/Runtime
+Version: unspecified
+OS: 
+OS Details: RH7.3
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: jason@379.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Structure not properly marshalled on callback
+
+Description of Problem:
+Structure values appear to be improperly marshalled on callback function.
+
+
+Steps to reproduce the problem:
+Source code follows:
+ 
+  -----------------------------------------------------------------------
+  FILE: source.c
+  -----------------------------------------------------------------------
+  struct Event {
+    double timestamp;
+  };
+
+  typedef void (*EventHandler)(Event*);
+  EventHandler handler;
+
+  void SetEventHandler(EventHandler eh)
+  {
+    handler = eh;
+  }
+
+  void GenerateEvent();
+  {
+    Event e;
+    e.timestamp = 22.0;
+    handler(&e);
+  }
+  -----------------------------------------------------------------------
+
+  -----------------------------------------------------------------------
+  FILE: CallbackTest.cs
+  -----------------------------------------------------------------------
+  using System;
+  using System.Runtime.InteropServices;
+
+  public class CallbackTest
+  {
+    // --- begin DLL interface ---
+
+    [StructLayout(LayoutKind.Sequential)]
+    public struct Event {
+      public readonly double Timestamp;
+    }
+
+    public delegate void EventHandler(Event e);
+
+    [DllImport("source")]
+    private static extern void SetEventHandler(EventHandler eh);
+
+    [DllImport("source")]
+    private static extern void GenerateEvent();
+
+    // --- end DLL interface ---
+
+    public EventHandler Handlers;
+
+    static void Main()
+    {
+      Handlers += new EventHandler(myHandler);
+      SetEventHandler(Handlers);
+
+      GenerateEvent();
+    }
+
+    private void myHandler(Event e)
+    {
+      Console.WriteLine("Received event, timestamp={0}", e.timestamp);
+    }
+  }
+  -----------------------------------------------------------------------
+
+    
+Actual Results:
+"Received event, timestamp=7.12748"
+
+Expected Results:
+"Received event, timestamp=22.0"
+
+How often does this happen? 
+Every time.
+
+Additional Information: