Skip to content

Commit b9f7bea

Browse files
authored
Merge pull request #31 from FirehawkV21/master
Implement LibraryImport instead of DllImport.
2 parents 5d1f57f + caf0beb commit b9f7bea

1 file changed

Lines changed: 40 additions & 27 deletions

File tree

src/Blake3/Hasher.cs

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Blake3;
1717
/// Performance note: The <see cref="Update{T}"/> and <see cref="UpdateWithJoin{T}"/> methods perform poorly when the caller's input buffer is small.
1818
/// See their method docs below. A 16 KiB buffer is large enough to leverage all currently supported SIMD instruction sets.
1919
/// </remarks>
20-
public unsafe struct Hasher : IDisposable
20+
public unsafe partial struct Hasher : IDisposable
2121
{
2222
private const string DllName = "blake3_dotnet";
2323
private void* _hasher;
@@ -375,52 +375,65 @@ private static void ThrowArgumentOutOfRange(int size)
375375
throw new ArgumentOutOfRangeException("output", $"Invalid size {size} of the output buffer. Expecting >= 32");
376376
}
377377

378-
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
378+
[LibraryImport(DllName)]
379379
[SuppressGCTransition]
380-
private static extern void* blake3_new();
380+
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
381+
private static partial void* blake3_new();
381382

382-
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
383+
[LibraryImport(DllName)]
383384
[SuppressGCTransition]
384-
private static extern void* blake3_new_keyed(void* ptr32Bytes);
385+
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
386+
private static partial void* blake3_new_keyed(void* ptr32Bytes);
385387

386-
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
388+
[LibraryImport(DllName)]
387389
[SuppressGCTransition]
388-
private static extern void* blake3_new_derive_key(void* ptr, void* size);
390+
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
391+
private static partial void* blake3_new_derive_key(void* ptr, void* size);
389392

390-
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
393+
[LibraryImport(DllName)]
391394
[SuppressGCTransition]
392-
private static extern void blake3_hash(void* ptr, void* size, void* ptrOut);
395+
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
396+
private static partial void blake3_hash(void* ptr, void* size, void* ptrOut);
393397

394-
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "blake3_hash")]
395-
private static extern void blake3_hash_preemptive(void* ptr, void* size, void* ptrOut);
398+
[LibraryImport(DllName, EntryPoint = "blake3_hash")]
399+
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
400+
private static partial void blake3_hash_preemptive(void* ptr, void* size, void* ptrOut);
396401

397-
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
402+
[LibraryImport(DllName)]
398403
[SuppressGCTransition]
399-
private static extern void blake3_delete(void* hasher);
404+
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
405+
private static partial void blake3_delete(void* hasher);
400406

401-
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
407+
[LibraryImport(DllName)]
402408
[SuppressGCTransition]
403-
private static extern void blake3_reset(void* hasher);
409+
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
410+
private static partial void blake3_reset(void* hasher);
404411

405-
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
412+
[LibraryImport(DllName)]
406413
[SuppressGCTransition]
407-
private static extern void blake3_update(void* hasher, void* ptr, void* size);
414+
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
415+
private static partial void blake3_update(void* hasher, void* ptr, void* size);
408416

409-
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "blake3_update")]
410-
private static extern void blake3_update_preemptive(void* hasher, void* ptr, void* size);
417+
[LibraryImport(DllName, EntryPoint = "blake3_update")]
418+
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
419+
private static partial void blake3_update_preemptive(void* hasher, void* ptr, void* size);
411420

412-
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
413-
private static extern void blake3_update_rayon(void* hasher, void* ptr, void* size);
421+
[LibraryImport(DllName)]
422+
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
423+
private static partial void blake3_update_rayon(void* hasher, void* ptr, void* size);
414424

415-
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
425+
[LibraryImport(DllName)]
416426
[SuppressGCTransition]
417-
private static extern void blake3_finalize(void* hasher, void* ptr);
427+
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
428+
private static partial void blake3_finalize(void* hasher, void* ptr);
418429

419-
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
430+
[LibraryImport(DllName)]
420431
[SuppressGCTransition]
421-
private static extern void blake3_finalize_xof(void* hasher, void* ptr, void* size);
432+
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
433+
private static partial void blake3_finalize_xof(void* hasher, void* ptr, void* size);
422434

423-
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
435+
[LibraryImport(DllName)]
424436
[SuppressGCTransition]
425-
private static extern void blake3_finalize_seek_xof(void* hasher, ulong offset, void* ptr, void* size);
437+
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
438+
private static partial void blake3_finalize_seek_xof(void* hasher, ulong offset, void* ptr, void* size);
426439
}

0 commit comments

Comments
 (0)