From d911c41b9cf4bdc5151b54fd2ab6d19de8a57753 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 26 Sep 2023 20:33:38 +0800 Subject: [PATCH] minify `windows.h` and disable implicit struct conversion --- include/pocketpy/cffi.h | 12 ------ include/pocketpy/export.h | 78 +++++++++++++++++++++++++++++++++++++-- include/pocketpy/obj.h | 5 --- 3 files changed, 74 insertions(+), 21 deletions(-) diff --git a/include/pocketpy/cffi.h b/include/pocketpy/cffi.h index f28583ec..eee61796 100644 --- a/include/pocketpy/cffi.h +++ b/include/pocketpy/cffi.h @@ -153,18 +153,6 @@ T to_void_p(VM* vm, PyObject* var){ VoidP& p = CAST(VoidP&, var); return reinterpret_cast(p.ptr); } - -template -T to_c99_struct(VM* vm, PyObject* var){ - static_assert(is_pod::value); - C99Struct& pod = CAST(C99Struct&, var); - return *reinterpret_cast(pod.p); -} - -template -std::enable_if_t::value && !std::is_pointer_v, PyObject*> py_var(VM* vm, const T& data){ - return VAR_T(C99Struct, std::monostate(), data); -} /*****************************************************************/ void add_module_c(VM* vm); diff --git a/include/pocketpy/export.h b/include/pocketpy/export.h index 2d5e39b0..829f0815 100644 --- a/include/pocketpy/export.h +++ b/include/pocketpy/export.h @@ -6,11 +6,81 @@ #define WIN32_LEAN_AND_MEAN #endif - #ifndef NOMINMAX - #define NOMINMAX - #endif +/* + @raysan5: To avoid conflicting windows.h symbols with raylib, some flags are defined + WARNING: Those flags avoid inclusion of some Win32 headers that could be required + by user at some point and won't be included... +*/ - #include +/* If defined, the following flags inhibit definition of the indicated items.*/ +#define NOGDICAPMASKS // CC_*, LC_*, PC_*, CP_*, TC_*, RC_ +#define NOVIRTUALKEYCODES // VK_* +#define NOWINMESSAGES // WM_*, EM_*, LB_*, CB_* +#define NOWINSTYLES // WS_*, CS_*, ES_*, LBS_*, SBS_*, CBS_* +#define NOSYSMETRICS // SM_* +#define NOMENUS // MF_* +#define NOICONS // IDI_* +#define NOKEYSTATES // MK_* +#define NOSYSCOMMANDS // SC_* +#define NORASTEROPS // Binary and Tertiary raster ops +#define NOSHOWWINDOW // SW_* +#define OEMRESOURCE // OEM Resource values +#define NOATOM // Atom Manager routines +#define NOCLIPBOARD // Clipboard routines +#define NOCOLOR // Screen colors +#define NOCTLMGR // Control and Dialog routines +#define NODRAWTEXT // DrawText() and DT_* +#define NOGDI // All GDI defines and routines +#define NOKERNEL // All KERNEL defines and routines +#define NOUSER // All USER defines and routines +/*#define NONLS // All NLS defines and routines*/ +#define NOMB // MB_* and MessageBox() +#define NOMEMMGR // GMEM_*, LMEM_*, GHND, LHND, associated routines +#define NOMETAFILE // typedef METAFILEPICT +#define NOMINMAX // Macros min(a,b) and max(a,b) +#define NOMSG // typedef MSG and associated routines +#define NOOPENFILE // OpenFile(), OemToAnsi, AnsiToOem, and OF_* +#define NOSCROLL // SB_* and scrolling routines +#define NOSERVICE // All Service Controller routines, SERVICE_ equates, etc. +#define NOSOUND // Sound driver routines +#define NOTEXTMETRIC // typedef TEXTMETRIC and associated routines +#define NOWH // SetWindowsHook and WH_* +#define NOWINOFFSETS // GWL_*, GCL_*, associated routines +#define NOCOMM // COMM driver routines +#define NOKANJI // Kanji support stuff. +#define NOHELP // Help engine interface. +#define NOPROFILER // Profiler interface. +#define NODEFERWINDOWPOS // DeferWindowPos routines +#define NOMCX // Modem Configuration Extensions + +/* Type required before windows.h inclusion */ +typedef struct tagMSG *LPMSG; + +#include + +/* Type required by some unused function... */ +typedef struct tagBITMAPINFOHEADER { + DWORD biSize; + LONG biWidth; + LONG biHeight; + WORD biPlanes; + WORD biBitCount; + DWORD biCompression; + DWORD biSizeImage; + LONG biXPelsPerMeter; + LONG biYPelsPerMeter; + DWORD biClrUsed; + DWORD biClrImportant; +} BITMAPINFOHEADER, *PBITMAPINFOHEADER; + +#include +#include +#include + +/* @raysan5: Some required types defined for MSVC/TinyC compiler */ +#if defined(_MSC_VER) || defined(__TINYC__) + #include +#endif #define PK_EXPORT __declspec(dllexport) #define PK_SUPPORT_DYLIB 1 diff --git a/include/pocketpy/obj.h b/include/pocketpy/obj.h index 1ffaf9fb..b578fa7e 100644 --- a/include/pocketpy/obj.h +++ b/include/pocketpy/obj.h @@ -212,7 +212,6 @@ template struct is_py_class : std::false_type {}; template struct is_py_class> : std::true_type {}; template T to_void_p(VM*, PyObject*); -template T to_c99_struct(VM*, PyObject*); template __T py_cast(VM* vm, PyObject* obj) { @@ -224,8 +223,6 @@ __T py_cast(VM* vm, PyObject* obj) { }else if constexpr(is_py_class::value){ T::_check_type(vm, obj); return PK_OBJ_GET(T, obj); - }else if constexpr(is_pod::value){ - return to_c99_struct(vm, obj); }else { return Discarded(); } @@ -240,8 +237,6 @@ __T _py_cast(VM* vm, PyObject* obj) { return to_void_p<__T>(vm, obj); }else if constexpr(is_py_class::value){ return PK_OBJ_GET(T, obj); - }else if constexpr(is_pod::value){ - return to_c99_struct(vm, obj); }else { return Discarded(); }