[Mono-bugs] [Bug 460608] New: Using [StructLayout (LayoutKind.Sequential, Pack=1)]

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Dec 19 05:33:06 EST 2008


https://bugzilla.novell.com/show_bug.cgi?id=460608

User hoelt at fovea.cc added comment
https://bugzilla.novell.com/show_bug.cgi?id=460608#c1

           Summary: Using [StructLayout (LayoutKind.Sequential, Pack=1)]
           Product: Mono: Compilers
           Version: 1.2.6
          Platform: x86-64
        OS/Version: Ubuntu
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: hoelt at fovea.cc
         QAContact: mono-bugs at lists.ximian.com
          Found By: Development


Created an attachment (id=261184)
 --> (https://bugzilla.novell.com/attachment.cgi?id=261184)
C# example to reproduce the bug

Description of Problem:

For C++ <-> C# structure compatibility, I wanted to force no alignment at all
inside my data structures.

Under some circumstances, the compiler fails to duplicate an instance of a
packed structure. Packed with [StructLayout (LayoutKind.Sequential, Pack=1)].

The duplicated instance is corrupted for Pack=1, Pack=2 and Pack=4.

Steps to reproduce the problem:
1. mcs BugPack.cs
2. mono BugPack.exe

    [StructLayout (LayoutKind.Sequential, Pack=1)]
      struct A
      {
          public IntPtr f1; 
          public IntPtr f2; 
          public IntPtr f3;
          public IntPtr f4; 
          public int f5;
      };

The code
 - Initialize all field of an instance of struct A.
 - Displays the values of the fields ("Original f1...f5").
 - Send this instance to a method "static void CheckA(A a)"
 - CheckA displays the values of the fields ("Duplicated f1..f5").

Actual Results:

Original f1 = 1
Original f2 = 2
Original f3 = 3
Original f4 = 4
Original f5 = 5
Duplicated f1 = 1
Duplicated f2 = 2
Duplicated f3 = 3
Duplicated f4 = 4
Duplicated f5 = 7FFF <- !!! Not duplicated correctly !!!

Expected Results:

Original and duplicated to be identical.

How often does this happen? 

Always.

Additional Information:

- Mono C# compiler version 1.2.6.0
- Linux immunity 2.6.24-19-generic #1 SMP Wed Aug 20 17:53:40 UTC 2008 x86_64
GNU/Linux


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list