Undefine _WIN32 to generate only platform-agnostic APIs

Probably needs similar undefines on Linux and macOS.

Notice that the signatures of `SDL_CreateThread` and `SDL_CreateThreadWithStackSize`
have changed.
This commit is contained in:
Susko3 2024-04-06 00:12:39 +02:00
parent 61bf25730a
commit 5d61c2483e
9 changed files with 40 additions and 66 deletions

View File

@ -40,19 +40,19 @@ namespace SDL
public unsafe partial struct SDL_IOStreamInterface
{
[NativeTypeName("Sint64 (*)(void *) __attribute__((cdecl))")]
[NativeTypeName("Sint64 (*)(void *)")]
public delegate* unmanaged[Cdecl]<void*, long> size;
[NativeTypeName("Sint64 (*)(void *, Sint64, int) __attribute__((cdecl))")]
[NativeTypeName("Sint64 (*)(void *, Sint64, int)")]
public delegate* unmanaged[Cdecl]<void*, long, int, long> seek;
[NativeTypeName("size_t (*)(void *, void *, size_t, SDL_IOStatus *) __attribute__((cdecl))")]
[NativeTypeName("size_t (*)(void *, void *, size_t, SDL_IOStatus *)")]
public delegate* unmanaged[Cdecl]<void*, void*, nuint, SDL_IOStatus*, nuint> read;
[NativeTypeName("size_t (*)(void *, const void *, size_t, SDL_IOStatus *) __attribute__((cdecl))")]
[NativeTypeName("size_t (*)(void *, const void *, size_t, SDL_IOStatus *)")]
public delegate* unmanaged[Cdecl]<void*, void*, nuint, SDL_IOStatus*, nuint> write;
[NativeTypeName("int (*)(void *) __attribute__((cdecl))")]
[NativeTypeName("int (*)(void *)")]
public delegate* unmanaged[Cdecl]<void*, int> close;
}

View File

@ -91,22 +91,22 @@ namespace SDL
public void* userdata;
[NativeTypeName("void (*)(void *) __attribute__((cdecl))")]
[NativeTypeName("void (*)(void *)")]
public delegate* unmanaged[Cdecl]<void*, void> Update;
[NativeTypeName("void (*)(void *, int) __attribute__((cdecl))")]
[NativeTypeName("void (*)(void *, int)")]
public delegate* unmanaged[Cdecl]<void*, int, void> SetPlayerIndex;
[NativeTypeName("int (*)(void *, Uint16, Uint16) __attribute__((cdecl))")]
[NativeTypeName("int (*)(void *, Uint16, Uint16)")]
public delegate* unmanaged[Cdecl]<void*, ushort, ushort, int> Rumble;
[NativeTypeName("int (*)(void *, Uint16, Uint16) __attribute__((cdecl))")]
[NativeTypeName("int (*)(void *, Uint16, Uint16)")]
public delegate* unmanaged[Cdecl]<void*, ushort, ushort, int> RumbleTriggers;
[NativeTypeName("int (*)(void *, Uint8, Uint8, Uint8) __attribute__((cdecl))")]
[NativeTypeName("int (*)(void *, Uint8, Uint8, Uint8)")]
public delegate* unmanaged[Cdecl]<void*, byte, byte, byte, int> SetLED;
[NativeTypeName("int (*)(void *, const void *, int) __attribute__((cdecl))")]
[NativeTypeName("int (*)(void *, const void *, int)")]
public delegate* unmanaged[Cdecl]<void*, void*, int, int> SendEffect;
}

View File

@ -40,14 +40,5 @@ namespace SDL
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int SDL_EnterAppMainCallbacks(int argc, [NativeTypeName("char *[]")] sbyte** argv, [NativeTypeName("SDL_AppInit_func")] delegate* unmanaged[Cdecl]<void**, int, sbyte**, int> appinit, [NativeTypeName("SDL_AppIterate_func")] delegate* unmanaged[Cdecl]<void*, int> appiter, [NativeTypeName("SDL_AppEvent_func")] delegate* unmanaged[Cdecl]<void*, SDL_Event*, int> appevent, [NativeTypeName("SDL_AppQuit_func")] delegate* unmanaged[Cdecl]<void*, void> appquit);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int SDL_RegisterApp([NativeTypeName("const char *")] sbyte* name, [NativeTypeName("Uint32")] uint style, void* hInst);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void SDL_UnregisterApp();
[NativeTypeName("#define main SDL_main")]
public static readonly delegate*<int, sbyte**, int> main = &SDL_main;
}
}

View File

@ -57,7 +57,7 @@ namespace SDL
public static extern void SDL_UnlockProperties([NativeTypeName("SDL_PropertiesID")] uint props);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int SDL_SetPropertyWithCleanup([NativeTypeName("SDL_PropertiesID")] uint props, [NativeTypeName("const char *")] sbyte* name, void* value, [NativeTypeName("void (*)(void *, void *) __attribute__((cdecl))")] delegate* unmanaged[Cdecl]<void*, void*, void> cleanup, void* userdata);
public static extern int SDL_SetPropertyWithCleanup([NativeTypeName("SDL_PropertiesID")] uint props, [NativeTypeName("const char *")] sbyte* name, void* value, [NativeTypeName("void (*)(void *, void *)")] delegate* unmanaged[Cdecl]<void*, void*, void> cleanup, void* userdata);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int SDL_SetProperty([NativeTypeName("SDL_PropertiesID")] uint props, [NativeTypeName("const char *")] sbyte* name, void* value);

View File

@ -77,16 +77,16 @@ namespace SDL
public static extern int SDL_setenv([NativeTypeName("const char *")] sbyte* name, [NativeTypeName("const char *")] sbyte* value, int overwrite);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void SDL_qsort(void* @base, [NativeTypeName("size_t")] nuint nmemb, [NativeTypeName("size_t")] nuint size, [NativeTypeName("int (*)(const void *, const void *) __attribute__((cdecl))")] delegate* unmanaged[Cdecl]<void*, void*, int> compare);
public static extern void SDL_qsort(void* @base, [NativeTypeName("size_t")] nuint nmemb, [NativeTypeName("size_t")] nuint size, [NativeTypeName("int (*)(const void *, const void *)")] delegate* unmanaged[Cdecl]<void*, void*, int> compare);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void* SDL_bsearch([NativeTypeName("const void *")] void* key, [NativeTypeName("const void *")] void* @base, [NativeTypeName("size_t")] nuint nmemb, [NativeTypeName("size_t")] nuint size, [NativeTypeName("int (*)(const void *, const void *) __attribute__((cdecl))")] delegate* unmanaged[Cdecl]<void*, void*, int> compare);
public static extern void* SDL_bsearch([NativeTypeName("const void *")] void* key, [NativeTypeName("const void *")] void* @base, [NativeTypeName("size_t")] nuint nmemb, [NativeTypeName("size_t")] nuint size, [NativeTypeName("int (*)(const void *, const void *)")] delegate* unmanaged[Cdecl]<void*, void*, int> compare);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void SDL_qsort_r(void* @base, [NativeTypeName("size_t")] nuint nmemb, [NativeTypeName("size_t")] nuint size, [NativeTypeName("int (*)(void *, const void *, const void *) __attribute__((cdecl))")] delegate* unmanaged[Cdecl]<void*, void*, void*, int> compare, void* userdata);
public static extern void SDL_qsort_r(void* @base, [NativeTypeName("size_t")] nuint nmemb, [NativeTypeName("size_t")] nuint size, [NativeTypeName("int (*)(void *, const void *, const void *)")] delegate* unmanaged[Cdecl]<void*, void*, void*, int> compare, void* userdata);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void* SDL_bsearch_r([NativeTypeName("const void *")] void* key, [NativeTypeName("const void *")] void* @base, [NativeTypeName("size_t")] nuint nmemb, [NativeTypeName("size_t")] nuint size, [NativeTypeName("int (*)(void *, const void *, const void *) __attribute__((cdecl))")] delegate* unmanaged[Cdecl]<void*, void*, void*, int> compare, void* userdata);
public static extern void* SDL_bsearch_r([NativeTypeName("const void *")] void* key, [NativeTypeName("const void *")] void* @base, [NativeTypeName("size_t")] nuint nmemb, [NativeTypeName("size_t")] nuint size, [NativeTypeName("int (*)(void *, const void *, const void *)")] delegate* unmanaged[Cdecl]<void*, void*, void*, int> compare, void* userdata);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int SDL_abs(int x);
@ -612,17 +612,17 @@ namespace SDL
[NativeTypeName("#define SDL_FLT_EPSILON 1.1920928955078125e-07F")]
public const float SDL_FLT_EPSILON = 1.1920928955078125e-07F;
[NativeTypeName("#define SDL_PRIs64 \"I64d\"")]
public static ReadOnlySpan<byte> SDL_PRIs64 => "I64d"u8;
[NativeTypeName("#define SDL_PRIs64 \"lld\"")]
public static ReadOnlySpan<byte> SDL_PRIs64 => "lld"u8;
[NativeTypeName("#define SDL_PRIu64 \"I64u\"")]
public static ReadOnlySpan<byte> SDL_PRIu64 => "I64u"u8;
[NativeTypeName("#define SDL_PRIu64 \"llu\"")]
public static ReadOnlySpan<byte> SDL_PRIu64 => "llu"u8;
[NativeTypeName("#define SDL_PRIx64 \"I64x\"")]
public static ReadOnlySpan<byte> SDL_PRIx64 => "I64x"u8;
[NativeTypeName("#define SDL_PRIx64 \"llx\"")]
public static ReadOnlySpan<byte> SDL_PRIx64 => "llx"u8;
[NativeTypeName("#define SDL_PRIX64 \"I64X\"")]
public static ReadOnlySpan<byte> SDL_PRIX64 => "I64X"u8;
[NativeTypeName("#define SDL_PRIX64 \"llX\"")]
public static ReadOnlySpan<byte> SDL_PRIX64 => "llX"u8;
[NativeTypeName("#define SDL_PRIs32 \"d\"")]
public static ReadOnlySpan<byte> SDL_PRIs32 => "d"u8;

View File

@ -29,34 +29,34 @@ namespace SDL
{
public unsafe partial struct SDL_StorageInterface
{
[NativeTypeName("int (*)(void *) __attribute__((cdecl))")]
[NativeTypeName("int (*)(void *)")]
public delegate* unmanaged[Cdecl]<void*, int> close;
[NativeTypeName("SDL_bool (*)(void *) __attribute__((cdecl))")]
[NativeTypeName("SDL_bool (*)(void *)")]
public delegate* unmanaged[Cdecl]<void*, int> ready;
[NativeTypeName("int (*)(void *, const char *, SDL_EnumerateDirectoryCallback, void *) __attribute__((cdecl))")]
[NativeTypeName("int (*)(void *, const char *, SDL_EnumerateDirectoryCallback, void *)")]
public delegate* unmanaged[Cdecl]<void*, sbyte*, delegate* unmanaged[Cdecl]<void*, sbyte*, sbyte*, int>, void*, int> enumerate;
[NativeTypeName("int (*)(void *, const char *, SDL_PathInfo *) __attribute__((cdecl))")]
[NativeTypeName("int (*)(void *, const char *, SDL_PathInfo *)")]
public delegate* unmanaged[Cdecl]<void*, sbyte*, SDL_PathInfo*, int> info;
[NativeTypeName("int (*)(void *, const char *, void *, Uint64) __attribute__((cdecl))")]
[NativeTypeName("int (*)(void *, const char *, void *, Uint64)")]
public delegate* unmanaged[Cdecl]<void*, sbyte*, void*, ulong, int> read_file;
[NativeTypeName("int (*)(void *, const char *, const void *, Uint64) __attribute__((cdecl))")]
[NativeTypeName("int (*)(void *, const char *, const void *, Uint64)")]
public delegate* unmanaged[Cdecl]<void*, sbyte*, void*, ulong, int> write_file;
[NativeTypeName("int (*)(void *, const char *) __attribute__((cdecl))")]
[NativeTypeName("int (*)(void *, const char *)")]
public delegate* unmanaged[Cdecl]<void*, sbyte*, int> mkdir;
[NativeTypeName("int (*)(void *, const char *) __attribute__((cdecl))")]
[NativeTypeName("int (*)(void *, const char *)")]
public delegate* unmanaged[Cdecl]<void*, sbyte*, int> remove;
[NativeTypeName("int (*)(void *, const char *, const char *) __attribute__((cdecl))")]
[NativeTypeName("int (*)(void *, const char *, const char *)")]
public delegate* unmanaged[Cdecl]<void*, sbyte*, sbyte*, int> rename;
[NativeTypeName("Uint64 (*)(void *) __attribute__((cdecl))")]
[NativeTypeName("Uint64 (*)(void *)")]
public delegate* unmanaged[Cdecl]<void*, ulong> space_remaining;
}

View File

@ -27,10 +27,6 @@ using System.Runtime.InteropServices;
namespace SDL
{
public partial struct tagMSG
{
}
[StructLayout(LayoutKind.Explicit)]
public partial struct _XEvent
{
@ -38,16 +34,6 @@ namespace SDL
public static unsafe partial class SDL3
{
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void SDL_SetWindowsMessageHook([NativeTypeName("SDL_WindowsMessageHook")] delegate* unmanaged[Cdecl]<void*, tagMSG*, int> callback, void* userdata);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int SDL_Direct3D9GetAdapterIndex([NativeTypeName("SDL_DisplayID")] uint displayID);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("SDL_bool")]
public static extern int SDL_DXGIGetOutputInfo([NativeTypeName("SDL_DisplayID")] uint displayID, int* adapterIndex, int* outputIndex);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void SDL_SetX11EventHook([NativeTypeName("SDL_X11EventHook")] delegate* unmanaged[Cdecl]<void*, _XEvent*, int> callback, void* userdata);

View File

@ -42,10 +42,10 @@ namespace SDL
public static unsafe partial class SDL3
{
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern SDL_Thread* SDL_CreateThread([NativeTypeName("SDL_ThreadFunction")] delegate* unmanaged[Cdecl]<void*, int> fn, [NativeTypeName("const char *")] sbyte* name, void* data, [NativeTypeName("pfnSDL_CurrentBeginThread")] delegate* unmanaged[Cdecl]<void*, uint, delegate* unmanaged[Stdcall]<void*, uint>, void*, uint, uint*, nuint> pfnBeginThread, [NativeTypeName("pfnSDL_CurrentEndThread")] delegate* unmanaged[Cdecl]<uint, void> pfnEndThread);
public static extern SDL_Thread* SDL_CreateThread([NativeTypeName("SDL_ThreadFunction")] delegate* unmanaged[Cdecl]<void*, int> fn, [NativeTypeName("const char *")] sbyte* name, void* data);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern SDL_Thread* SDL_CreateThreadWithStackSize([NativeTypeName("SDL_ThreadFunction")] delegate* unmanaged[Cdecl]<void*, int> fn, [NativeTypeName("const char *")] sbyte* name, [NativeTypeName("const size_t")] nuint stacksize, void* data, [NativeTypeName("pfnSDL_CurrentBeginThread")] delegate* unmanaged[Cdecl]<void*, uint, delegate* unmanaged[Stdcall]<void*, uint>, void*, uint, uint*, nuint> pfnBeginThread, [NativeTypeName("pfnSDL_CurrentEndThread")] delegate* unmanaged[Cdecl]<uint, void> pfnEndThread);
public static extern SDL_Thread* SDL_CreateThreadWithStackSize([NativeTypeName("SDL_ThreadFunction")] delegate* unmanaged[Cdecl]<void*, int> fn, [NativeTypeName("const char *")] sbyte* name, [NativeTypeName("const size_t")] nuint stacksize, void* data);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const char *")]
@ -76,15 +76,9 @@ namespace SDL
public static extern void* SDL_GetTLS([NativeTypeName("SDL_TLSID")] uint id);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int SDL_SetTLS([NativeTypeName("SDL_TLSID")] uint id, [NativeTypeName("const void *")] void* value, [NativeTypeName("void (*)(void *) __attribute__((cdecl))")] delegate* unmanaged[Cdecl]<void*, void> destructor);
public static extern int SDL_SetTLS([NativeTypeName("SDL_TLSID")] uint id, [NativeTypeName("const void *")] void* value, [NativeTypeName("void (*)(void *)")] delegate* unmanaged[Cdecl]<void*, void> destructor);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void SDL_CleanupTLS();
[NativeTypeName("#define SDL_beginthread _beginthreadex")]
public static readonly delegate*<void*, uint, delegate* unmanaged[Stdcall]<void*, uint>, void*, uint, uint*, nuint> SDL_beginthread = &_beginthreadex;
[NativeTypeName("#define SDL_endthread _endthreadex")]
public static readonly delegate*<uint, void> SDL_endthread = &_endthreadex;
}
}

View File

@ -123,6 +123,9 @@ base_command = [
"--libraryPath", "SDL3",
"--methodClassName", "SDL3",
"--namespace", "SDL",
"--additional",
"--undefine-macro=_WIN32",
]