Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1322cc7
add p/invoke wrappers for new functions/structs/types in extism 0.2
mhmd-azeez Jan 23, 2023
c2de709
fix: use IntPtr for ExtismPlugin
mhmd-azeez Jan 23, 2023
77666bf
Update description on method to match implementation
ubiquitous-dev Jan 30, 2023
71c331b
Implement async plugin invocation with timeout and cancellation
ubiquitous-dev Jan 30, 2023
08a8dc9
feat: add more p/invoke methods
mhmd-azeez Feb 3, 2023
82f5c47
fix: build error
mhmd-azeez Feb 3, 2023
b05b04b
Merge branch 'extism:main' into feature/dotnet-host-functions
ubiquitous-dev Feb 11, 2023
73e7226
Update plugin exception handling to use isCompletedSuccessfuly instead
ubiquitous-dev Feb 11, 2023
8055dda
Add test for canceling longrunning task
ubiquitous-dev Feb 11, 2023
e38d439
Create readme to explain test wasm files
ubiquitous-dev Feb 11, 2023
b965e19
Troubleshoot async task issues
ubiquitous-dev Feb 11, 2023
3a7ab27
Implement threadsafe cancellation support into library
ubiquitous-dev Feb 25, 2023
63222d8
Add working test case for canceling function early
ubiquitous-dev Feb 25, 2023
851042b
Split async tests into a separate file
ubiquitous-dev Feb 25, 2023
d1436d4
Add test case for auto-cancellation of plugin with cancellationToken
ubiquitous-dev Feb 26, 2023
18b0fb6
Add Host Function unit test and fix error handling
ubiquitous-dev Feb 26, 2023
c84186d
Merge branch 'extism:main' into feature/dotnet-host-functions
ubiquitous-dev Feb 26, 2023
78506b6
Add Rider settings to consider `extism` as a word for spell check
ubiquitous-dev Mar 1, 2023
f9443b5
Update plugin reference datatype
ubiquitous-dev Mar 1, 2023
8aacf6c
Add tests to call unknown function and verify exception is thrown
ubiquitous-dev Mar 1, 2023
e4d0488
Fix implementation of async exception handling
ubiquitous-dev Mar 1, 2023
facef77
Add some temporary notes
ubiquitous-dev Mar 2, 2023
51386c0
Merge branch 'extism:main' into feature/dotnet-host-functions
ubiquitous-dev Mar 4, 2023
296ac64
Merge branch 'feature/dotnet-host-functions' of https://github.com/ub…
ubiquitous-dev Mar 4, 2023
6fb752e
Merge branch 'feature/dotnet-host-functions' into pr/1
ubiquitous-dev Mar 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dotnet/Extism.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=extism/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
4 changes: 4 additions & 0 deletions dotnet/samples/Extism.Sdk.Sample/Extism.Sdk.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Extism.runtime.win-x64" Version="0.3.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Extism.Sdk\Extism.Sdk.csproj" />
</ItemGroup>
Expand Down
19 changes: 15 additions & 4 deletions dotnet/src/Extism.Sdk/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Extism.Sdk.Native;
/// <summary>
/// Represents an Extism context through which you can load <see cref="Plugin"/>s.
/// </summary>
public class Context : IDisposable
public unsafe class Context : IDisposable
{
private const int DisposedMarker = 1;

Expand All @@ -17,13 +17,16 @@ public class Context : IDisposable
/// </summary>
public Context()
{
NativeHandle = LibExtism.extism_context_new();
unsafe
{
NativeHandle = LibExtism.extism_context_new();
}
}

/// <summary>
/// Native pointer to the Extism Context.
/// </summary>
internal IntPtr NativeHandle { get; }
internal LibExtism.ExtismContext* NativeHandle { get; }

/// <summary>
/// Loads an Extism <see cref="Plugin"/>.
Expand All @@ -34,12 +37,18 @@ public Plugin CreatePlugin(ReadOnlySpan<byte> wasm, bool withWasi)
{
CheckNotDisposed();


unsafe
{
fixed (byte* wasmPtr = wasm)
{
var plugin = LibExtism.extism_plugin_new(NativeHandle, wasmPtr, wasm.Length, null, 0, withWasi);
return new Plugin(this, plugin);
if (plugin == -1)
{
throw new ExtismException(GetError() ?? "Unknown exception when calling extism_plugin_new");
}
var cancelHandle = LibExtism.extism_plugin_cancel_handle(NativeHandle, plugin);
return new Plugin(this, plugin, cancelHandle);
}
}
}
Expand Down Expand Up @@ -131,6 +140,7 @@ public static string GetExtismVersion()
return Marshal.PtrToStringUTF8(pointer);
}

// TODO: this should not be within the context, neither should the version.
/// <summary>
/// Set Extism's log file and level. This is applied for all <see cref="Context"/>s.
/// </summary>
Expand All @@ -152,6 +162,7 @@ public static bool SetExtismLogFile(string logPath, LogLevel level)
}
}

// TODO: check if the enums are correctly set
/// <summary>
/// Extism Log Levels
/// </summary>
Expand Down
Loading