Skip to content

Commit 9816b9c

Browse files
LLT21“llt”
andauthored
More modern native aot interface (#9994)
Co-authored-by: “llt” <“[email protected]”>
1 parent 5917260 commit 9816b9c

File tree

1 file changed

+33
-49
lines changed

1 file changed

+33
-49
lines changed
Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,46 @@
11
using System;
2+
using System.Runtime.CompilerServices;
23
using System.Runtime.InteropServices;
34

4-
public unsafe partial class NativeMethods
5+
public static partial class NativeMethods
56
{
67
#if DEBUG
7-
[DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
8+
private const string LibName = "appMpower.Orm.dylib";
89
#else
9-
[DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
10-
#endif
11-
public static extern void Dbms(int dbms);
10+
private const string LibName = "appMpower.Orm.so";
11+
#endif
1212

13-
#if DEBUG
14-
[DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
15-
#else
16-
[DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
17-
#endif
18-
public static extern void DbProvider(int dbProvider);
13+
[LibraryImport(LibName, EntryPoint = "Dbms", StringMarshalling = StringMarshalling.Utf16)]
14+
[UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
15+
public static partial void Dbms(int dbms);
1916

20-
#if DEBUG
21-
[DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl)]
22-
#else
23-
[DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl)]
24-
#endif
25-
public static extern void FreeHandlePointer(IntPtr handlePointer);
17+
[LibraryImport(LibName, EntryPoint = "DbProvider", StringMarshalling = StringMarshalling.Utf16)]
18+
[UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
19+
public static partial void DbProvider(int dbProvider);
2620

27-
#if DEBUG
28-
[DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
29-
#else
30-
[DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
31-
#endif
32-
//public static extern byte* Db(out int length);
33-
public static extern IntPtr Db(out int length, out IntPtr handlePointer);
21+
[LibraryImport(LibName, EntryPoint = "FreeHandlePointer")]
22+
[UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
23+
public static partial void FreeHandlePointer(IntPtr handlePointer);
3424

35-
#if DEBUG
36-
[DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
37-
#else
38-
[DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
39-
#endif
40-
public static extern IntPtr Fortunes(out int length, out IntPtr handlePointer);
25+
[LibraryImport(LibName, EntryPoint = "Db", StringMarshalling = StringMarshalling.Utf16)]
26+
[UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
27+
public static partial IntPtr Db(out int length, out IntPtr handlePointer);
4128

42-
#if DEBUG
43-
[DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
44-
#else
45-
[DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
46-
#endif
47-
public static extern IntPtr Query(int queries, out int length, out IntPtr handlePointer);
29+
[LibraryImport(LibName, EntryPoint = "Fortunes", StringMarshalling = StringMarshalling.Utf16)]
30+
[UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
4831

49-
#if DEBUG
50-
[DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
51-
#else
52-
[DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
53-
#endif
54-
public static extern IntPtr Updates(int queries, out int length, out IntPtr handlePointer);
32+
public static partial IntPtr Fortunes(out int length, out IntPtr handlePointer);
5533

56-
#if DEBUG
57-
[DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
58-
#else
59-
[DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
60-
#endif
61-
public static extern IntPtr DbById(int id, out int length, out IntPtr handlePointer);
62-
}
34+
[LibraryImport(LibName, EntryPoint = "Query", StringMarshalling = StringMarshalling.Utf16)]
35+
[UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
36+
public static partial IntPtr Query(int queries, out int length, out IntPtr handlePointer);
37+
38+
[LibraryImport(LibName, EntryPoint = "Updates", StringMarshalling = StringMarshalling.Utf16)]
39+
[UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
40+
public static partial IntPtr Updates(int queries, out int length, out IntPtr handlePointer);
41+
42+
[LibraryImport(LibName, StringMarshalling = StringMarshalling.Utf16)]
43+
[UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
44+
public static partial IntPtr DbById(int id, out int length, out IntPtr handlePointer);
45+
46+
}

0 commit comments

Comments
 (0)