Skip to content

Commit 0cb5ff3

Browse files
committed
Updated pointer:
Updated this construction. Added new implicit operators for Span and ReadOnylSpan and float*
1 parent a271590 commit 0cb5ff3

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

DotnetNativeBase.sln renamed to Base.sln

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.8.34330.188
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotnetNativeBase", "DotnetNativeBase\DotnetNativeBase.csproj", "{A2C99A9B-A862-48B0-AAC0-323BAD1FB9DF}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotnetNativeBase", "Base\Base.csproj", "{A2C99A9B-A862-48B0-AAC0-323BAD1FB9DF}"
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2D567AF0-62E8-42C3-8B92-72B00F24DFFC}"
99
ProjectSection(SolutionItems) = preProject
@@ -14,12 +14,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1414
EndProject
1515
Global
1616
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17-
Debug|x64 = Debug|x64
1817
Release|x64 = Release|x64
1918
EndGlobalSection
2019
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21-
{A2C99A9B-A862-48B0-AAC0-323BAD1FB9DF}.Debug|x64.ActiveCfg = Debug|x64
22-
{A2C99A9B-A862-48B0-AAC0-323BAD1FB9DF}.Debug|x64.Build.0 = Debug|x64
2320
{A2C99A9B-A862-48B0-AAC0-323BAD1FB9DF}.Release|x64.ActiveCfg = Release|x64
2421
{A2C99A9B-A862-48B0-AAC0-323BAD1FB9DF}.Release|x64.Build.0 = Release|x64
2522
EndGlobalSection

DotnetNativeBase/DotnetNativeBase.csproj renamed to Base/Base.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFramework>net8.0-windows</TargetFramework>
44
<ImplicitUsings>enable</ImplicitUsings>
55
<Nullable>enable</Nullable>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7-
<Title>DotnetNativeBase</Title>
7+
<Title>DotnetNative.Base</Title>
88
<Authors>Yotic</Authors>
99
<Description>Library containing structures for easy use of C# in native build</Description>
1010
<PackageProjectUrl>https://github.com/DotnetNative/DotnetNativeBase</PackageProjectUrl>
1111
<RepositoryUrl>https://github.com/DotnetNative/DotnetNativeBase</RepositoryUrl>
1212
<PackageTags>naot korn dnb native</PackageTags>
13-
<Version>1.0.7</Version>
13+
<Version>1.0.0</Version>
1414
<Platforms>x64</Platforms>
1515
<PackageReadmeFile>PACK.md</PackageReadmeFile>
1616
<IncludeContentInPack>true</IncludeContentInPack>
1717
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
1818
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1919
<PackageIcon>DotnetNativeLogo.png</PackageIcon>
20+
<PackageId>DotnetNative.Base</PackageId>
21+
<Product>DotnetNative.Base</Product>
22+
<AssemblyName>DotnetNative.Base</AssemblyName>
23+
<RootNamespace>DotnetNative.Base</RootNamespace>
2024
</PropertyGroup>
2125
<ItemGroup>
2226
<Using Include="System.Runtime.CompilerServices" />
2327
<Using Include="System.Runtime.CompilerServices.MethodImplOptions">
2428
<Static>True</Static>
2529
</Using>
2630
<Using Include="System.Runtime.InteropServices" />
27-
<None Include="..\..\..\..\..\..\DotnetNativeLogo.png">
31+
<None Include="..\..\DotnetNative\DotnetNativeLogo.png">
2832
<Pack>True</Pack>
2933
<PackagePath>\</PackagePath>
3034
<Visible>False</Visible>
File renamed without changes.

DotnetNativeBase/pointer.cs renamed to Base/pointer.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
[StructLayout(LayoutKind.Sequential)]
1+
#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type
22
public unsafe struct pointer
33
{
44
public pointer(nint address) => Address = address;
55

66
public nint Address;
77

8-
public byte this[nint index] => ((byte*)Address)[index];
8+
public byte this[nint index] { get => ((byte*)Address)[index]; set => *((byte*)Address + index) = value; }
99

1010
public override string ToString() => $"0x{Address:X}";
1111
public override bool Equals(object? obj) => obj is null ? false : obj is pointer ? (((pointer)obj).Address == Address) : false;
@@ -45,23 +45,58 @@ public unsafe struct pointer
4545
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(void** pointer) => new((nint)pointer);
4646
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(void*** pointer) => new((nint)pointer);
4747
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(delegate* unmanaged<void> ptr) => new((nint)ptr);
48+
49+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(ReadOnlySpan<bool> span) => new(*(nint*)&span);
50+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(ReadOnlySpan<byte> span) => new(*(nint*)&span);
51+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(ReadOnlySpan<sbyte> span) => new(*(nint*)&span);
52+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(ReadOnlySpan<char> span) => new(*(nint*)&span);
53+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(ReadOnlySpan<short> span) => new(*(nint*)&span);
54+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(ReadOnlySpan<ushort> span) => new(*(nint*)&span);
55+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(ReadOnlySpan<int> span) => new(*(nint*)&span);
56+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(ReadOnlySpan<uint> span) => new(*(nint*)&span);
57+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(ReadOnlySpan<float> span) => new(*(nint*)&span);
58+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(ReadOnlySpan<long> span) => new(*(nint*)&span);
59+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(ReadOnlySpan<ulong> span) => new(*(nint*)&span);
60+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(ReadOnlySpan<double> span) => new(*(nint*)&span);
61+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(ReadOnlySpan<nint> span) => new(*(nint*)&span);
62+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(ReadOnlySpan<nuint> span) => new(*(nint*)&span);
63+
64+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(Span<bool> span) => new(*(nint*)&span);
65+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(Span<byte> span) => new(*(nint*)&span);
66+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(Span<sbyte> span) => new(*(nint*)&span);
67+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(Span<char> span) => new(*(nint*)&span);
68+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(Span<short> span) => new(*(nint*)&span);
69+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(Span<ushort> span) => new(*(nint*)&span);
70+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(Span<int> span) => new(*(nint*)&span);
71+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(Span<uint> span) => new(*(nint*)&span);
72+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(Span<float> span) => new(*(nint*)&span);
73+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(Span<long> span) => new(*(nint*)&span);
74+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(Span<ulong> span) => new(*(nint*)&span);
75+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(Span<double> span) => new(*(nint*)&span);
76+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(Span<nint> span) => new(*(nint*)&span);
77+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(Span<nuint> span) => new(*(nint*)&span);
78+
4879
[MethodImpl(AggressiveInlining)] public static implicit operator nint(pointer pointer) => pointer.Address;
4980
[MethodImpl(AggressiveInlining)] public static implicit operator nuint(pointer pointer) => (nuint)pointer.Address;
5081
[MethodImpl(AggressiveInlining)] public static implicit operator long(pointer pointer) => pointer.Address;
5182
[MethodImpl(AggressiveInlining)] public static implicit operator ulong(pointer pointer) => (ulong)pointer.Address;
5283
[MethodImpl(AggressiveInlining)] public static implicit operator void*(pointer pointer) => (void*)pointer.Address;
5384
[MethodImpl(AggressiveInlining)] public static implicit operator void**(pointer pointer) => (void**)pointer.Address;
5485
[MethodImpl(AggressiveInlining)] public static implicit operator void***(pointer Sudden_Reference_To_Bocchi_The_Rock) => (void***)Sudden_Reference_To_Bocchi_The_Rock.Address;
86+
[MethodImpl(AggressiveInlining)] public static implicit operator bool*(pointer pointer) => (bool*)pointer.Address;
5587
[MethodImpl(AggressiveInlining)] public static implicit operator byte*(pointer pointer) => (byte*)pointer.Address;
5688
[MethodImpl(AggressiveInlining)] public static implicit operator sbyte*(pointer pointer) => (sbyte*)pointer.Address;
5789
[MethodImpl(AggressiveInlining)] public static implicit operator short*(pointer pointer) => (short*)pointer.Address;
5890
[MethodImpl(AggressiveInlining)] public static implicit operator ushort*(pointer pointer) => (ushort*)pointer.Address;
5991
[MethodImpl(AggressiveInlining)] public static implicit operator int*(pointer pointer) => (int*)pointer.Address;
6092
[MethodImpl(AggressiveInlining)] public static implicit operator uint*(pointer pointer) => (uint*)pointer.Address;
93+
[MethodImpl(AggressiveInlining)] public static implicit operator float*(pointer pointer) => (float*)pointer.Address;
6194
[MethodImpl(AggressiveInlining)] public static implicit operator long*(pointer pointer) => (long*)pointer.Address;
6295
[MethodImpl(AggressiveInlining)] public static implicit operator ulong*(pointer pointer) => (ulong*)pointer.Address;
6396
[MethodImpl(AggressiveInlining)] public static implicit operator nint*(pointer pointer) => (nint*)pointer.Address;
6497
[MethodImpl(AggressiveInlining)] public static implicit operator nuint*(pointer pointer) => (nuint*)pointer.Address;
98+
[MethodImpl(AggressiveInlining)] public static implicit operator double*(pointer pointer) => (double*)pointer.Address;
6599
[MethodImpl(AggressiveInlining)] public static implicit operator delegate* unmanaged<void>(pointer pointer) => (delegate* unmanaged<void>)pointer;
66100
#endregion
67-
}
101+
}
102+
#pragma warning restore CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type

0 commit comments

Comments
 (0)