-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace Cesium.Runtime.Tests; | ||
|
||
public unsafe class PtrTests | ||
{ | ||
[Fact] | ||
public void CPtrTests() | ||
{ | ||
CPtr v = (void*)0x1234; | ||
Assert.Equal(0x1234L, (long)v.AsPtr()); | ||
Assert.Equal(0x1234L, (long)v.AsPtr<byte>()); | ||
|
||
Assert.Equal(sizeof(long), sizeof(CPtr)); | ||
|
||
CPtr<int> t = (int*)0x2345; | ||
Assert.Equal(0x2345L, (long)t.AsPtr()); | ||
Assert.Equal((IntPtr)0x2345, t.AsIntPtr()); | ||
Assert.Equal(0x2345L, (long)t.AsPtr<byte>()); | ||
|
||
Assert.Equal(sizeof(long), sizeof(CPtr<int>)); | ||
} | ||
|
||
[Fact] | ||
public void FPtrTests() | ||
{ | ||
var a = new FPtr<Action>((void*)0x1234); | ||
Assert.Equal(0x1234L, (long)a.AsPtr()); | ||
Assert.Equal(sizeof(long), sizeof(FPtr<Action>)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Cesium.Runtime; | ||
|
||
/// <summary>A class encapsulating a C function pointer.</summary> | ||
public readonly unsafe struct FPtr<TDelegate> where TDelegate : Delegate // TODO: Think about vararg and empty parameter list encoding. | ||
{ | ||
private readonly long _value; | ||
|
||
public FPtr(void* ptr) | ||
{ | ||
_value = (long)ptr; | ||
} | ||
|
||
public void* AsPtr() => (void*)_value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters