File tree 12 files changed +330
-24
lines changed
tests/ClangSharp.PInvokeGenerator.UnitTests
12 files changed +330
-24
lines changed Original file line number Diff line number Diff line change @@ -1726,15 +1726,38 @@ public partial struct MyStruct3
1726
1726
1727
1727
protected override Task WithPackingTestImpl ( )
1728
1728
{
1729
- const string InputContents = @"struct MyStruct {};" ;
1729
+ const string InputContents = @"struct MyStruct
1730
+ {
1731
+ size_t FixedBuffer[1];
1732
+ };
1733
+ " ;
1730
1734
1731
- const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1735
+ const string ExpectedOutputContents = @"using System;
1736
+ using System.Runtime.InteropServices;
1732
1737
1733
1738
namespace ClangSharp.Test
1734
1739
{
1735
1740
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
1736
1741
public partial struct MyStruct
1737
1742
{
1743
+ [NativeTypeName(""size_t[1]"")]
1744
+ public _FixedBuffer_e__FixedBuffer FixedBuffer;
1745
+
1746
+ public partial struct _FixedBuffer_e__FixedBuffer
1747
+ {
1748
+ public UIntPtr e0;
1749
+
1750
+ public unsafe ref UIntPtr this[int index]
1751
+ {
1752
+ get
1753
+ {
1754
+ fixed (UIntPtr* pThis = &e0)
1755
+ {
1756
+ return ref pThis[index];
1757
+ }
1758
+ }
1759
+ }
1760
+ }
1738
1761
}
1739
1762
}
1740
1763
" ;
Original file line number Diff line number Diff line change @@ -1730,15 +1730,38 @@ public partial struct MyStruct3
1730
1730
1731
1731
protected override Task WithPackingTestImpl ( )
1732
1732
{
1733
- const string InputContents = @"struct MyStruct {};" ;
1733
+ const string InputContents = @"struct MyStruct
1734
+ {
1735
+ size_t FixedBuffer[1];
1736
+ };
1737
+ " ;
1734
1738
1735
- const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1739
+ const string ExpectedOutputContents = @"using System;
1740
+ using System.Runtime.InteropServices;
1736
1741
1737
1742
namespace ClangSharp.Test
1738
1743
{
1739
1744
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
1740
1745
public partial struct MyStruct
1741
1746
{
1747
+ [NativeTypeName(""size_t[1]"")]
1748
+ public _FixedBuffer_e__FixedBuffer FixedBuffer;
1749
+
1750
+ public partial struct _FixedBuffer_e__FixedBuffer
1751
+ {
1752
+ public UIntPtr e0;
1753
+
1754
+ public unsafe ref UIntPtr this[int index]
1755
+ {
1756
+ get
1757
+ {
1758
+ fixed (UIntPtr* pThis = &e0)
1759
+ {
1760
+ return ref pThis[index];
1761
+ }
1762
+ }
1763
+ }
1764
+ }
1742
1765
}
1743
1766
}
1744
1767
" ;
Original file line number Diff line number Diff line change @@ -1704,15 +1704,37 @@ public partial struct MyStruct3
1704
1704
1705
1705
protected override Task WithPackingTestImpl ( )
1706
1706
{
1707
- const string InputContents = @"struct MyStruct {};" ;
1707
+ const string InputContents = @"struct MyStruct
1708
+ {
1709
+ size_t FixedBuffer[1];
1710
+ };
1711
+ " ;
1708
1712
1709
- const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1713
+ const string ExpectedOutputContents = @"using System;
1714
+ using System.Runtime.InteropServices;
1710
1715
1711
1716
namespace ClangSharp.Test
1712
1717
{
1713
1718
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
1714
1719
public partial struct MyStruct
1715
1720
{
1721
+ [NativeTypeName(""size_t[1]"")]
1722
+ public _FixedBuffer_e__FixedBuffer FixedBuffer;
1723
+
1724
+ public partial struct _FixedBuffer_e__FixedBuffer
1725
+ {
1726
+ public nuint e0;
1727
+
1728
+ public ref nuint this[int index]
1729
+ {
1730
+ get
1731
+ {
1732
+ return ref AsSpan(int.MaxValue)[index];
1733
+ }
1734
+ }
1735
+
1736
+ public Span<nuint> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
1737
+ }
1716
1738
}
1717
1739
}
1718
1740
" ;
Original file line number Diff line number Diff line change @@ -1708,15 +1708,37 @@ public partial struct MyStruct3
1708
1708
1709
1709
protected override Task WithPackingTestImpl ( )
1710
1710
{
1711
- const string InputContents = @"struct MyStruct {};" ;
1711
+ const string InputContents = @"struct MyStruct
1712
+ {
1713
+ size_t FixedBuffer[1];
1714
+ };
1715
+ " ;
1712
1716
1713
- const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1717
+ const string ExpectedOutputContents = @"using System;
1718
+ using System.Runtime.InteropServices;
1714
1719
1715
1720
namespace ClangSharp.Test
1716
1721
{
1717
1722
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
1718
1723
public partial struct MyStruct
1719
1724
{
1725
+ [NativeTypeName(""size_t[1]"")]
1726
+ public _FixedBuffer_e__FixedBuffer FixedBuffer;
1727
+
1728
+ public partial struct _FixedBuffer_e__FixedBuffer
1729
+ {
1730
+ public nuint e0;
1731
+
1732
+ public ref nuint this[int index]
1733
+ {
1734
+ get
1735
+ {
1736
+ return ref AsSpan(int.MaxValue)[index];
1737
+ }
1738
+ }
1739
+
1740
+ public Span<nuint> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
1741
+ }
1720
1742
}
1721
1743
}
1722
1744
" ;
Original file line number Diff line number Diff line change @@ -1730,15 +1730,40 @@ public partial struct MyStruct3
1730
1730
1731
1731
protected override Task WithPackingTestImpl ( )
1732
1732
{
1733
- const string InputContents = @"struct MyStruct {};" ;
1733
+ const string InputContents = @"struct MyStruct
1734
+ {
1735
+ size_t FixedBuffer[1];
1736
+ };
1737
+ " ;
1734
1738
1735
- const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1739
+ const string ExpectedOutputContents = @"using System;
1740
+ using System.Diagnostics.CodeAnalysis;
1741
+ using System.Runtime.InteropServices;
1736
1742
1737
1743
namespace ClangSharp.Test
1738
1744
{
1739
1745
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
1740
1746
public partial struct MyStruct
1741
1747
{
1748
+ [NativeTypeName(""size_t[1]"")]
1749
+ public _FixedBuffer_e__FixedBuffer FixedBuffer;
1750
+
1751
+ public partial struct _FixedBuffer_e__FixedBuffer
1752
+ {
1753
+ public nuint e0;
1754
+
1755
+ [UnscopedRef]
1756
+ public ref nuint this[int index]
1757
+ {
1758
+ get
1759
+ {
1760
+ return ref AsSpan(int.MaxValue)[index];
1761
+ }
1762
+ }
1763
+
1764
+ [UnscopedRef]
1765
+ public Span<nuint> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
1766
+ }
1742
1767
}
1743
1768
}
1744
1769
" ;
Original file line number Diff line number Diff line change @@ -1734,15 +1734,40 @@ public partial struct MyStruct3
1734
1734
1735
1735
protected override Task WithPackingTestImpl ( )
1736
1736
{
1737
- const string InputContents = @"struct MyStruct {};" ;
1737
+ const string InputContents = @"struct MyStruct
1738
+ {
1739
+ size_t FixedBuffer[1];
1740
+ };
1741
+ " ;
1738
1742
1739
- const string ExpectedOutputContents = @"using System.Runtime.InteropServices;
1743
+ const string ExpectedOutputContents = @"using System;
1744
+ using System.Diagnostics.CodeAnalysis;
1745
+ using System.Runtime.InteropServices;
1740
1746
1741
1747
namespace ClangSharp.Test
1742
1748
{
1743
1749
[StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
1744
1750
public partial struct MyStruct
1745
1751
{
1752
+ [NativeTypeName(""size_t[1]"")]
1753
+ public _FixedBuffer_e__FixedBuffer FixedBuffer;
1754
+
1755
+ public partial struct _FixedBuffer_e__FixedBuffer
1756
+ {
1757
+ public nuint e0;
1758
+
1759
+ [UnscopedRef]
1760
+ public ref nuint this[int index]
1761
+ {
1762
+ get
1763
+ {
1764
+ return ref AsSpan(int.MaxValue)[index];
1765
+ }
1766
+ }
1767
+
1768
+ [UnscopedRef]
1769
+ public Span<nuint> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
1770
+ }
1746
1771
}
1747
1772
}
1748
1773
" ;
Original file line number Diff line number Diff line change @@ -1727,12 +1727,37 @@ struct MyStruct3
1727
1727
1728
1728
protected override Task WithPackingTestImpl ( )
1729
1729
{
1730
- const string InputContents = @"struct MyStruct {};" ;
1730
+ const string InputContents = @"struct MyStruct
1731
+ {
1732
+ size_t FixedBuffer[1];
1733
+ };
1734
+ " ;
1731
1735
1732
1736
const string ExpectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
1733
1737
<bindings>
1734
1738
<namespace name=""ClangSharp.Test"">
1735
- <struct name=""MyStruct"" access=""public"" layout=""Sequential"" pack=""CustomPackValue""></struct>
1739
+ <struct name=""MyStruct"" access=""public"" layout=""Sequential"" pack=""CustomPackValue"">
1740
+ <field name=""FixedBuffer"" access=""public"">
1741
+ <type native=""size_t[1]"" count=""1"" fixed=""_FixedBuffer_e__FixedBuffer"">UIntPtr</type>
1742
+ </field>
1743
+ <struct name=""_FixedBuffer_e__FixedBuffer"" access=""public"">
1744
+ <field name=""e0"" access=""public"">
1745
+ <type>UIntPtr</type>
1746
+ </field>
1747
+ <indexer access=""public"" unsafe=""true"">
1748
+ <type>ref UIntPtr</type>
1749
+ <param name=""index"">
1750
+ <type>int</type>
1751
+ </param>
1752
+ <get>
1753
+ <code>fixed (UIntPtr* pThis = &e0)
1754
+ {
1755
+ return ref pThis[index];
1756
+ }</code>
1757
+ </get>
1758
+ </indexer>
1759
+ </struct>
1760
+ </struct>
1736
1761
</namespace>
1737
1762
</bindings>
1738
1763
" ;
Original file line number Diff line number Diff line change @@ -1732,12 +1732,37 @@ struct MyStruct3
1732
1732
1733
1733
protected override Task WithPackingTestImpl ( )
1734
1734
{
1735
- const string InputContents = @"struct MyStruct {};" ;
1735
+ const string InputContents = @"struct MyStruct
1736
+ {
1737
+ size_t FixedBuffer[1];
1738
+ };
1739
+ " ;
1736
1740
1737
1741
const string ExpectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
1738
1742
<bindings>
1739
1743
<namespace name=""ClangSharp.Test"">
1740
- <struct name=""MyStruct"" access=""public"" layout=""Sequential"" pack=""CustomPackValue""></struct>
1744
+ <struct name=""MyStruct"" access=""public"" layout=""Sequential"" pack=""CustomPackValue"">
1745
+ <field name=""FixedBuffer"" access=""public"">
1746
+ <type native=""size_t[1]"" count=""1"" fixed=""_FixedBuffer_e__FixedBuffer"">UIntPtr</type>
1747
+ </field>
1748
+ <struct name=""_FixedBuffer_e__FixedBuffer"" access=""public"">
1749
+ <field name=""e0"" access=""public"">
1750
+ <type>UIntPtr</type>
1751
+ </field>
1752
+ <indexer access=""public"" unsafe=""true"">
1753
+ <type>ref UIntPtr</type>
1754
+ <param name=""index"">
1755
+ <type>int</type>
1756
+ </param>
1757
+ <get>
1758
+ <code>fixed (UIntPtr* pThis = &e0)
1759
+ {
1760
+ return ref pThis[index];
1761
+ }</code>
1762
+ </get>
1763
+ </indexer>
1764
+ </struct>
1765
+ </struct>
1741
1766
</namespace>
1742
1767
</bindings>
1743
1768
" ;
Original file line number Diff line number Diff line change @@ -1707,12 +1707,41 @@ struct MyStruct3
1707
1707
1708
1708
protected override Task WithPackingTestImpl ( )
1709
1709
{
1710
- const string InputContents = @"struct MyStruct {};" ;
1710
+ const string InputContents = @"struct MyStruct
1711
+ {
1712
+ size_t FixedBuffer[1];
1713
+ };
1714
+ " ;
1711
1715
1712
1716
const string ExpectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
1713
1717
<bindings>
1714
1718
<namespace name=""ClangSharp.Test"">
1715
- <struct name=""MyStruct"" access=""public"" layout=""Sequential"" pack=""CustomPackValue""></struct>
1719
+ <struct name=""MyStruct"" access=""public"" layout=""Sequential"" pack=""CustomPackValue"">
1720
+ <field name=""FixedBuffer"" access=""public"">
1721
+ <type native=""size_t[1]"" count=""1"" fixed=""_FixedBuffer_e__FixedBuffer"">nuint</type>
1722
+ </field>
1723
+ <struct name=""_FixedBuffer_e__FixedBuffer"" access=""public"">
1724
+ <field name=""e0"" access=""public"">
1725
+ <type>nuint</type>
1726
+ </field>
1727
+ <indexer access=""public"">
1728
+ <type>ref nuint</type>
1729
+ <param name=""index"">
1730
+ <type>int</type>
1731
+ </param>
1732
+ <get>
1733
+ <code>return ref AsSpan(int.MaxValue)[index];</code>
1734
+ </get>
1735
+ </indexer>
1736
+ <function name=""AsSpan"" access=""public"">
1737
+ <type>Span<nuint></type>
1738
+ <param name=""length"">
1739
+ <type>int</type>
1740
+ </param>
1741
+ <code>MemoryMarshal.CreateSpan(ref e0, length);</code>
1742
+ </function>
1743
+ </struct>
1744
+ </struct>
1716
1745
</namespace>
1717
1746
</bindings>
1718
1747
" ;
You can’t perform that action at this time.
0 commit comments