Skip to content

Commit

Permalink
Added return_value_async
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Feb 24, 2025
1 parent b0452f5 commit 3925f4c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/BUTR.NativeAOT.Generator/HeaderBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,9 @@ typedef struct return_value_ptr
param_string *const error;
param_ptr *const value;
} return_value_ptr;
typedef struct return_value_async
{
param_string *const error;
} return_value_async;
";
}
5 changes: 3 additions & 2 deletions src/BUTR.NativeAOT.Shared/AllocationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
#endregion

#nullable enable
using System.Runtime.CompilerServices;
#if !BUTR_NATIVEAOT_ENABLE_WARNING
#pragma warning disable
#endif

[assembly: InternalsVisibleTo("Bannerlord.VortexExtension.Native")]
#if BUTR_NATIVEAOT_ENABLE_VISIBLETO
[assembly: global::System.Runtime.CompilerServices.InternalsVisibleTo("Bannerlord.VortexExtension.Native")]
#endif

namespace BUTR.NativeAOT.Shared
{
Expand Down
2 changes: 1 addition & 1 deletion src/BUTR.NativeAOT.Shared/Allocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#endregion

#nullable enable
using System.Runtime.InteropServices;
#if !BUTR_NATIVEAOT_ENABLE_WARNING
#pragma warning disable
#endif
Expand All @@ -32,6 +31,7 @@ namespace BUTR.NativeAOT.Shared
{
using global::System;
using global::System.Diagnostics;
using global::System.Runtime.InteropServices;

public static unsafe class Allocator
{
Expand Down
2 changes: 1 addition & 1 deletion src/BUTR.NativeAOT.Shared/BUTR.NativeAOT.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<VersionOverride>0</VersionOverride>
<Version>1.0.$(VersionOverride)</Version>
<DefineConstants>$(DefineConstants);BUTR_NATIVEAOT_ENABLE_WARNING;TRACK_ALLOCATIONS;</DefineConstants>
<DefineConstants>$(DefineConstants);BUTR_NATIVEAOT_ENABLE_WARNING;TRACK_ALLOCATIONS;BUTR_NATIVEAOT_ENABLE_VISIBLETO;</DefineConstants>
</PropertyGroup>

<!--NuGet Package-->
Expand Down
18 changes: 18 additions & 0 deletions src/BUTR.NativeAOT.Shared/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,24 @@ private return_value_ptr(void* value, char* error)
Error = error;
}
}

[StructLayout(LayoutKind.Sequential)]
public readonly unsafe struct return_value_async :
IReturnValueWithNoValue<return_value_async>,
IReturnValueWithError<return_value_async>,
IReturnValueWithException<return_value_async>
{
public static return_value_async* AsValue(bool isOwner) => Utils.Create(new return_value_async(null), isOwner);
public static return_value_async* AsError(char* error, bool isOwner) => Utils.Create(new return_value_async(error), isOwner);
public static return_value_async* AsException(Exception e, bool isOwner) => Utils.AsException<return_value_async>(e, isOwner);

public readonly char* Error;

private return_value_async(char* error)
{
Error = error;
}
}
}
#nullable restore
#if !BUTR_NATIVEAOT_ENABLE_WARNING
Expand Down

0 comments on commit 3925f4c

Please sign in to comment.