Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdd6842a

Browse files
dsymelatkin
authored andcommitted
fix 342 - emit StructLayout attributes correctly in FSI
fixesdotnet#342closesdotnet#431
1 parente5cdef9 commitdd6842a

File tree

2 files changed

+102
-6
lines changed

2 files changed

+102
-6
lines changed

‎src/absil/ilreflect.fs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,20 +1659,20 @@ let typeAttributesOfTypeEncoding x =
16591659

16601660

16611661
lettypeAttributesOfTypeLayout cenv emEnv x=
1662-
letattr p=
1662+
letattrxp=
16631663
if p.Size=None&& p.Pack= Nonethen None
16641664
else
16651665
Some(convCustomAttr cenv emEnv
16661666
(IL.mkILCustomAttribute cenv.ilg
16671667
(mkILTyRef(cenv.ilg.traits.ScopeRef,"System.Runtime.InteropServices.StructLayoutAttribute"),
16681668
[mkILNonGenericValueTy(mkILTyRef(cenv.ilg.traits.ScopeRef,"System.Runtime.InteropServices.LayoutKind"))],
1669-
[ ILAttribElem.Int320x02],
1669+
[ ILAttribElem.Int32x],
16701670
(p.Pack|> Option.toList|> List.map(fun x->("Pack", cenv.ilg.typ_int32,false, ILAttribElem.Int32(int32 x))))@
16711671
(p.Size|> Option.toList|> List.map(fun x->("Size", cenv.ilg.typ_int32,false, ILAttribElem.Int32 x))))))in
16721672
match xwith
16731673
| ILTypeDefLayout.Auto-> TypeAttributes.AutoLayout,None
1674-
| ILTypeDefLayout.Explicit p-> TypeAttributes.ExplicitLayout,(attr p)
1675-
| ILTypeDefLayout.Sequential p-> TypeAttributes.SequentialLayout,(attr p)
1674+
| ILTypeDefLayout.Explicit p-> TypeAttributes.ExplicitLayout,(attr0x02p)
1675+
| ILTypeDefLayout.Sequential p-> TypeAttributes.SequentialLayout,(attr0x00p)
16761676

16771677

16781678
//----------------------------------------------------------------------------
Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,100 @@
11
#r"TestLibrary.dll"
22

3-
letx= TestType.Get(100)
4-
if x=100then System.IO.File.WriteAllText("test.ok","")
3+
let mutableerrors:string list=[]
4+
letfail msg=
5+
printfn"FAILURE:%s" msg
6+
errors<- errors@[msg]
7+
8+
moduleTest1=
9+
letx= TestType.Get(100)
10+
if x<>100then fail"Test 1 failed, expected 100"
11+
12+
13+
14+
moduleTestPack1=
15+
openSystem.Runtime.InteropServices
16+
[<type:StructLayout(LayoutKind.Sequential)>]
17+
typeLayoutType=
18+
struct
19+
vala:int
20+
end
21+
if(sizeof<LayoutType>)<>4then fail"TestPack1, expected size 4"
22+
23+
moduleTestPack2=
24+
openSystem.Runtime.InteropServices
25+
[<type:StructLayout(LayoutKind.Sequential, Pack=2)>]
26+
typeLayoutType=
27+
struct
28+
val mutableb:byte
29+
val mutablea:int
30+
end
31+
letsz=(sizeof<LayoutType>)
32+
let mutablen= LayoutType()
33+
leta1= NativeInterop.NativePtr.toNativeInt&&n.a- NativeInterop.NativePtr.toNativeInt&&n
34+
letb1= NativeInterop.NativePtr.toNativeInt&&n.b- NativeInterop.NativePtr.toNativeInt&&n
35+
letgot=(sz, a1, b1)
36+
printfn"got%A" got
37+
letexpected=(6,2n,0n)
38+
if got<> expectedthen fail(sprintf"TestPack2: got%A, expected%A" got expected)
39+
40+
// From http://bytes.com/topic/c-sharp/answers/654343-what-does-structlayoutattribute-pack-do
41+
moduleTestPack3=
42+
openSystem.Runtime.InteropServices
43+
[<type:StructLayout(LayoutKind.Sequential, Pack=8, Size=128)>]
44+
typeLayoutType=
45+
struct
46+
val mutableb1:byte
47+
val mutableb2:byte
48+
val mutablel1:int64
49+
val mutablei1:int
50+
end
51+
letsz=(sizeof<LayoutType>)
52+
let mutablen= LayoutType()
53+
letb1off= NativeInterop.NativePtr.toNativeInt&&n.b1- NativeInterop.NativePtr.toNativeInt&&n
54+
letb2off= NativeInterop.NativePtr.toNativeInt&&n.b2- NativeInterop.NativePtr.toNativeInt&&n
55+
letl1off= NativeInterop.NativePtr.toNativeInt&&n.l1- NativeInterop.NativePtr.toNativeInt&&n
56+
leti1off= NativeInterop.NativePtr.toNativeInt&&n.i1- NativeInterop.NativePtr.toNativeInt&&n
57+
letgot=(sz, b1off, b2off, l1off, i1off)
58+
letexpected=(128,0n,1n,8n,16n)
59+
printfn"got%A" got
60+
if got<> expectedthen fail(sprintf"TestPack3: got%A, expected%A" got expected)
61+
62+
63+
// Test explicit layout
64+
moduleTestPack4=
65+
openSystem.Runtime.InteropServices
66+
[<type:StructLayout(LayoutKind.Explicit, Pack=8, Size=128)>]
67+
typeLayoutType=
68+
struct
69+
[<FieldOffset(0)>]
70+
val mutableb1:byte
71+
[<FieldOffset(4)>]
72+
val mutableb2:byte
73+
[<FieldOffset(8)>]
74+
val mutablel1:int64
75+
[<FieldOffset(12)>]
76+
val mutablei1:int
77+
end
78+
letsz=(sizeof<LayoutType>)
79+
let mutablen= LayoutType()
80+
letb1off= NativeInterop.NativePtr.toNativeInt&&n.b1- NativeInterop.NativePtr.toNativeInt&&n
81+
letb2off= NativeInterop.NativePtr.toNativeInt&&n.b2- NativeInterop.NativePtr.toNativeInt&&n
82+
letl1off= NativeInterop.NativePtr.toNativeInt&&n.l1- NativeInterop.NativePtr.toNativeInt&&n
83+
leti1off= NativeInterop.NativePtr.toNativeInt&&n.i1- NativeInterop.NativePtr.toNativeInt&&n
84+
letgot=(sz, b1off, b2off, l1off, i1off)
85+
letexpected=(128,0n,4n,8n,12n)
86+
printfn"got%A" got
87+
if got<> expectedthen fail(sprintf"TestPack4: got%A, expected%A" got expected)
88+
89+
90+
if errors.IsEmptythen
91+
System.IO.File.WriteAllText("test.ok","")
92+
else
93+
for errorin errorsdo
94+
printfn"ERROR:%s" error
95+
96+
if errors.IsEmptythen System.IO.File.WriteAllText("test.ok","")
97+
else
98+
for errorin errorsdo
99+
printfn"ERROR:%s" error
100+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp