From bd7f0829f44d467d0849724f30926489817f93d6 Mon Sep 17 00:00:00 2001 From: Medusa Slockbower Date: Sun, 22 Jun 2025 17:06:50 -0400 Subject: [PATCH 1/2] Compatibility for MSVC and MinGW --- include/fennec/lang/float.h | 16 ++++++------- include/fennec/lang/integer.h | 42 +++++++++++++++++++++++++---------- metaprogramming/float.h | 16 ++++++------- metaprogramming/integer.h | 22 ++++++++++++++++-- source/memory/new.cpp | 26 ++++++++++++++++------ 5 files changed, 85 insertions(+), 37 deletions(-) diff --git a/include/fennec/lang/float.h b/include/fennec/lang/float.h index f3d143b..a931521 100644 --- a/include/fennec/lang/float.h +++ b/include/fennec/lang/float.h @@ -75,13 +75,13 @@ #define DBL_MAX_10_EXP 308 #define DBL_TRAPS 0 #define DBL_TINYNESS_BEFORE 0 -#define DBL_MIN fennec::bit_cast(0x10000000000000l) -#define DBL_MAX fennec::bit_cast(0x7fefffffffffffffl) -#define DBL_EPSILON fennec::bit_cast(0x3cb0000000000000l) -#define DBL_INF fennec::bit_cast(0x7ff0000000000000l) -#define DBL_QUIET_NAN fennec::bit_cast(0x7ff8000000000000l) -#define DBL_SIGNALING_NAN fennec::bit_cast(0x7ff4000000000000l) -#define DBL_DENORM_MIN fennec::bit_cast(0x1l) -#define DBL_ROUND_ERR fennec::bit_cast(0x3fe0000000000000l) +#define DBL_MIN fennec::bit_cast(0x10000000000000ll) +#define DBL_MAX fennec::bit_cast(0x7fefffffffffffffll) +#define DBL_EPSILON fennec::bit_cast(0x3cb0000000000000ll) +#define DBL_INF fennec::bit_cast(0x7ff0000000000000ll) +#define DBL_QUIET_NAN fennec::bit_cast(0x7ff8000000000000ll) +#define DBL_SIGNALING_NAN fennec::bit_cast(0x7ff4000000000000ll) +#define DBL_DENORM_MIN fennec::bit_cast(0x1ll) +#define DBL_ROUND_ERR fennec::bit_cast(0x3fe0000000000000ll) #endif // FENNEC_LANG_FLOAT_H diff --git a/include/fennec/lang/integer.h b/include/fennec/lang/integer.h index e660af9..954eedc 100644 --- a/include/fennec/lang/integer.h +++ b/include/fennec/lang/integer.h @@ -30,8 +30,26 @@ #ifndef FENNEC_LANG_INTEGER_H #define FENNEC_LANG_INTEGER_H +#undef CHAR_MIN +#undef CHAR_MAX #undef WCHAR_MIN #undef WCHAR_MAX +#undef SCHAR_MIN +#undef SCHAR_MAX +#undef UCHAR_MIN +#undef UCHAR_MAX +#undef INT_MIN +#undef INT_MAX +#undef UINT_MIN +#undef UINT_MAX +#undef LONG_MIN +#undef LONG_MAX +#undef ULONG_MIN +#undef ULONG_MAX +#undef LLONG_MIN +#undef LLONG_MAX +#undef ULLONG_MIN +#undef ULLONG_MAX #define CHAR_IS_SIGNED true #define CHAR_ROUNDS 0x0 @@ -43,15 +61,15 @@ #define CHAR_MIN 0xffffff80 #define CHAR_MAX 0x7f -#define WCHAR_IS_SIGNED true +#define WCHAR_IS_SIGNED false #define WCHAR_ROUNDS 0x0 -#define WCHAR_RADIX_DIG 0x1f -#define WCHAR_DIG 0x9 +#define WCHAR_RADIX_DIG 0x10 +#define WCHAR_DIG 0x4 #define WCHAR_DECIMAL_DIG 0x0 #define WCHAR_RADIX 0x2 #define WCHAR_TRAPS 0xtrue -#define WCHAR_MIN 0x80000000 -#define WCHAR_MAX 0x7fffffff +#define WCHAR_MIN 0x0 +#define WCHAR_MAX 0xffff #define SCHAR_ROUNDS 0x0 #define SCHAR_RADIX_DIG 0x7 @@ -108,22 +126,22 @@ #define UINT_MAX 0xffffffff #define LONG_ROUNDS 0x0 -#define LONG_RADIX_DIG 0x3f -#define LONG_DIG 0x12 +#define LONG_RADIX_DIG 0x1f +#define LONG_DIG 0x9 #define LONG_DECIMAL_DIG 0x0 #define LONG_RADIX 0x2 #define LONG_TRAPS 0xtrue -#define LONG_MIN 0x8000000000000000 -#define LONG_MAX 0x7fffffffffffffff +#define LONG_MIN 0x80000000 +#define LONG_MAX 0x7fffffff #define ULONG_ROUNDS 0x0 -#define ULONG_RADIX_DIG 0x40 -#define ULONG_DIG 0x13 +#define ULONG_RADIX_DIG 0x20 +#define ULONG_DIG 0x9 #define ULONG_DECIMAL_DIG 0x0 #define ULONG_RADIX 0x2 #define ULONG_TRAPS 0xtrue #define ULONG_MIN 0x0 -#define ULONG_MAX 0xffffffffffffffff +#define ULONG_MAX 0xffffffff #define LLONG_ROUNDS 0x0 #define LLONG_RADIX_DIG 0x3f diff --git a/metaprogramming/float.h b/metaprogramming/float.h index 20cfa84..6b516f1 100644 --- a/metaprogramming/float.h +++ b/metaprogramming/float.h @@ -102,14 +102,14 @@ inline void float_h() out << "#define DBL_TRAPS " << std::dec << std::numeric_limits::traps << std::endl; out << "#define DBL_TINYNESS_BEFORE " << std::dec << std::numeric_limits::tinyness_before << std::endl; - out << "#define DBL_MIN " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::min() ) << "l)" << std::endl; - out << "#define DBL_MAX " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::max() ) << "l)" << std::endl; - out << "#define DBL_EPSILON " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::epsilon() ) << "l)" << std::endl; - out << "#define DBL_INF " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::infinity() ) << "l)" << std::endl; - out << "#define DBL_QUIET_NAN " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::quiet_NaN() ) << "l)" << std::endl; - out << "#define DBL_SIGNALING_NAN " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::signaling_NaN()) << "l)" << std::endl; - out << "#define DBL_DENORM_MIN " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::denorm_min() ) << "l)" << std::endl; - out << "#define DBL_ROUND_ERR " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::round_error() ) << "l)" << std::endl; + out << "#define DBL_MIN " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::min() ) << "ll)" << std::endl; + out << "#define DBL_MAX " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::max() ) << "ll)" << std::endl; + out << "#define DBL_EPSILON " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::epsilon() ) << "ll)" << std::endl; + out << "#define DBL_INF " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::infinity() ) << "ll)" << std::endl; + out << "#define DBL_QUIET_NAN " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::quiet_NaN() ) << "ll)" << std::endl; + out << "#define DBL_SIGNALING_NAN " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::signaling_NaN()) << "ll)" << std::endl; + out << "#define DBL_DENORM_MIN " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::denorm_min() ) << "ll)" << std::endl; + out << "#define DBL_ROUND_ERR " << "fennec::bit_cast(0x" << std::hex << std::bit_cast(std::numeric_limits::round_error() ) << "ll)" << std::endl; out << "" << std::endl; diff --git a/metaprogramming/integer.h b/metaprogramming/integer.h index af7307a..935a69e 100644 --- a/metaprogramming/integer.h +++ b/metaprogramming/integer.h @@ -64,8 +64,26 @@ inline void integer_h() out << "" << std::endl; + out << "#undef CHAR_MIN" << std::endl; + out << "#undef CHAR_MAX" << std::endl; out << "#undef WCHAR_MIN" << std::endl; out << "#undef WCHAR_MAX" << std::endl; + out << "#undef SCHAR_MIN" << std::endl; + out << "#undef SCHAR_MAX" << std::endl; + out << "#undef UCHAR_MIN" << std::endl; + out << "#undef UCHAR_MAX" << std::endl; + out << "#undef INT_MIN" << std::endl; + out << "#undef INT_MAX" << std::endl; + out << "#undef UINT_MIN" << std::endl; + out << "#undef UINT_MAX" << std::endl; + out << "#undef LONG_MIN" << std::endl; + out << "#undef LONG_MAX" << std::endl; + out << "#undef ULONG_MIN" << std::endl; + out << "#undef ULONG_MAX" << std::endl; + out << "#undef LLONG_MIN" << std::endl; + out << "#undef LLONG_MAX" << std::endl; + out << "#undef ULLONG_MIN" << std::endl; + out << "#undef ULLONG_MAX" << std::endl; out << "" << std::endl; @@ -212,7 +230,7 @@ inline void integer_h() out << "#define ULONG_DIG " << "0x" << std::hex << std::numeric_limits::digits10 << std::endl; out << "#define ULONG_DECIMAL_DIG " << "0x" << std::hex << std::numeric_limits::max_digits10 << std::endl; out << "#define ULONG_RADIX " << "0x" << std::hex << std::numeric_limits::radix << std::endl; - out << "#define ULONG_TRAPS " << "0x" << std::boolalpha << std::numeric_limits::traps << std::endl; + out << "#define ULONG_TRAPS " << "0x" << std::boolalpha << std::numeric_limits::traps << std::endl; out << "#define ULONG_MIN " << "0x" << std::hex << std::numeric_limits::min() << std::endl; out << "#define ULONG_MAX " << "0x" << std::hex << std::numeric_limits::max() << std::endl; @@ -224,7 +242,7 @@ inline void integer_h() out << "#define LLONG_DIG " << "0x" << std::hex << std::numeric_limits::digits10 << std::endl; out << "#define LLONG_DECIMAL_DIG " << "0x" << std::hex << std::numeric_limits::max_digits10 << std::endl; out << "#define LLONG_RADIX " << "0x" << std::hex << std::numeric_limits::radix << std::endl; - out << "#define LLONG_TRAPS " << "0x" << std::boolalpha << std::numeric_limits::traps << std::endl; + out << "#define LLONG_TRAPS " << "0x" << std::boolalpha << std::numeric_limits::traps << std::endl; out << "#define LLONG_MIN " << "0x" << std::hex << std::numeric_limits::min() << std::endl; out << "#define LLONG_MAX " << "0x" << std::hex << std::numeric_limits::max() << std::endl; diff --git a/source/memory/new.cpp b/source/memory/new.cpp index f3ce24a..46abbc2 100644 --- a/source/memory/new.cpp +++ b/source/memory/new.cpp @@ -17,6 +17,7 @@ // ===================================================================================================================== #include + #include #ifdef FENNEC_MEMORY_DEBUGGER @@ -33,15 +34,28 @@ inline void* operator new[](fennec::size_t size) { ret inline void* operator new (fennec::size_t size, const fennec::nothrow_t&) { return malloc(size); } inline void* operator new[](fennec::size_t size, const fennec::nothrow_t&) { return malloc(size); } -// Aligned allocation functions +// Aligned allocation & deallocation functions +#ifdef _WIN32 +inline void operator delete (void* ptr) noexcept { _aligned_free(ptr); } +inline void operator delete[](void* ptr) noexcept { _aligned_free(ptr); } +inline void operator delete (void* ptr, fennec::align_t, const fennec::nothrow_t&) noexcept { _aligned_free(ptr); } +inline void operator delete[](void* ptr, fennec::align_t, const fennec::nothrow_t&) noexcept { _aligned_free(ptr); } + +inline void* operator new (fennec::size_t size, fennec::align_t align) { return _aligned_malloc(static_cast(align), size); } +inline void* operator new[](fennec::size_t size, fennec::align_t align) { return _aligned_malloc(static_cast(align), size); } +inline void* operator new (fennec::size_t size, fennec::align_t align, const fennec::nothrow_t&) { return _aligned_malloc(static_cast(align), size); } +inline void* operator new[](fennec::size_t size, fennec::align_t align, const fennec::nothrow_t&) { return _aligned_malloc(static_cast(align), size); } +#else +inline void operator delete (void* ptr) noexcept { free(ptr); } +inline void operator delete[](void* ptr) noexcept { free(ptr); } +inline void operator delete (void* ptr, fennec::align_t, const fennec::nothrow_t&) noexcept { free(ptr); } +inline void operator delete[](void* ptr, fennec::align_t, const fennec::nothrow_t&) noexcept { free(ptr); } + inline void* operator new (fennec::size_t size, fennec::align_t align) { return aligned_alloc(static_cast(align), size); } inline void* operator new[](fennec::size_t size, fennec::align_t align) { return aligned_alloc(static_cast(align), size); } inline void* operator new (fennec::size_t size, fennec::align_t align, const fennec::nothrow_t&) { return aligned_alloc(static_cast(align), size); } inline void* operator new[](fennec::size_t size, fennec::align_t align, const fennec::nothrow_t&) { return aligned_alloc(static_cast(align), size); } - -// Deallocation functions -inline void operator delete (void* ptr) noexcept { free(ptr); } -inline void operator delete[](void* ptr) noexcept { free(ptr); } +#endif // Aligned deallocation functions inline void operator delete (void* ptr, fennec::align_t) noexcept { free(ptr); } @@ -56,8 +70,6 @@ inline void operator delete[](void* ptr, fennec::size_t, fennec::align_t) noexce // Non-throwing deallocation functions inline void operator delete (void* ptr, const fennec::nothrow_t&) noexcept { free(ptr); } inline void operator delete[](void* ptr, const fennec::nothrow_t&) noexcept { free(ptr); } -inline void operator delete (void* ptr, fennec::align_t, const fennec::nothrow_t&) noexcept { free(ptr); } -inline void operator delete[](void* ptr, fennec::align_t, const fennec::nothrow_t&) noexcept { free(ptr); } inline void operator delete (void* ptr, fennec::size_t, const fennec::nothrow_t&) noexcept { free(ptr); } inline void operator delete[](void* ptr, fennec::size_t, const fennec::nothrow_t&) noexcept { free(ptr); } From 2541c8c63704447bffa9785efa4300c60e7ff39b Mon Sep 17 00:00:00 2001 From: Medusa Slockbower Date: Sun, 22 Jun 2025 18:53:23 -0400 Subject: [PATCH 2/2] Added missing copyright headers --- include/fennec/memory/detail/__memory.h | 16 +++++++++++++++- metaprogramming/float.h | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/fennec/memory/detail/__memory.h b/include/fennec/memory/detail/__memory.h index 78fbb57..906091f 100644 --- a/include/fennec/memory/detail/__memory.h +++ b/include/fennec/memory/detail/__memory.h @@ -1,6 +1,20 @@ +// ===================================================================================================================== +// fennec, a free and open source game engine +// Copyright © 2025 Medusa Slockbower // -// Created by medusa on 5/19/25. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// ===================================================================================================================== #ifndef FENNEC_MEMORY_DETAIL_MEMORY_H #define FENNEC_MEMORY_DETAIL_MEMORY_H diff --git a/metaprogramming/float.h b/metaprogramming/float.h index 6b516f1..30c0427 100644 --- a/metaprogramming/float.h +++ b/metaprogramming/float.h @@ -1,6 +1,20 @@ +// ===================================================================================================================== +// fennec, a free and open source game engine +// Copyright © 2025 Medusa Slockbower // -// Created by medusa on 6/14/25. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// ===================================================================================================================== #ifndef FENNEC_METAPROGRAMMING_FLOAT_H #define FENNEC_METAPROGRAMMING_FLOAT_H