Skip to content

Commit

Permalink
python314-devel: add compatibility patches for macOS < 10.15
Browse files Browse the repository at this point in the history
  • Loading branch information
aeiouaeiouaeiouaeiouaeiouaeiou committed Dec 13, 2024
1 parent e0d531d commit 27ca4c1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lang/python314-devel/Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ if {${os.platform} eq "darwin" && ${os.major} <= 10} {
patch-threadid-older-systems.diff
}

patchfiles-append patch-lib-memzero0-remove-memset-s.diff \
patch-target-mm-malloc.diff

depends_build path:bin/pkg-config:pkgconfig
depends_lib port:bzip2 \
port:expat \
Expand Down
23 changes: 23 additions & 0 deletions lang/python314-devel/files/patch-lib-memzero0-remove-memset-s.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
memset_s() is not available on macOS < 10.9, use simple volatile implementation.
--- Modules/_hacl/Lib_Memzero0.c
+++ Modules/_hacl/Lib_Memzero0.c
@@ -8,6 +8,10 @@
#include <windows.h>
#endif

+#if defined(__APPLE__) && defined(__MACH__)
+#include <AvailabilityMacros.h>
+#endif
+
#if (defined(__APPLE__) && defined(__MACH__)) || defined(__linux__)
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
@@ -37,7 +41,7 @@ void Lib_Memzero0_memzero0(void *dst, uint64_t len) {

#ifdef _WIN32
SecureZeroMemory(dst, len_);
- #elif defined(__APPLE__) && defined(__MACH__)
+ #elif defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
memset_s(dst, len_, 0, len_);
#elif (defined(__linux__) && !defined(LINUX_NO_EXPLICIT_BZERO)) || defined(__FreeBSD__)
explicit_bzero(dst, len_);
37 changes: 37 additions & 0 deletions lang/python314-devel/files/patch-target-mm-malloc.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
There is no support for aligned_malloc() in macOS < 10.15. Instead of blocking SIMD, just fallback to using _mm_malloc().
--- Modules/_hacl/include/krml/internal/target.h
+++ Modules/_hacl/include/krml/internal/target.h
@@ -19,6 +19,11 @@
# define inline __inline__
#endif

+/* Include Apple-specific macros for use in defining KRML_ALIGNED_MALLOC. */
+#if defined(__APPLE__) && defined(__MACH__)
+#include <AvailabilityMacros.h>
+#endif
+
/******************************************************************************/
/* Macros that KaRaMeL will generate. */
/******************************************************************************/
@@ -123,7 +128,8 @@
#endif

/* MinGW-W64 does not support C11 aligned_alloc, but it supports
- * MSVC's _aligned_malloc.
+ * MSVC's _aligned_malloc. Also, fallback to use mm_malloc.h
+ * implementation for macOS systems prior to 10.15 Catalina.
*/
#ifndef KRML_ALIGNED_MALLOC
# ifdef __MINGW32__
@@ -133,6 +139,11 @@
defined(_MSC_VER) || \
(defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR)))
# define KRML_ALIGNED_MALLOC(X, Y) _aligned_malloc(Y, X)
+# elif defined(__APPLE__) && defined(__MACH__) && \
+ defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
+ (MAC_OS_X_VERSION_MIN_REQUIRED < 101500)
+# include <mm_malloc.h>
+# define KRML_ALIGNED_MALLOC(X, Y) _mm_malloc(Y, X)
# else
# define KRML_ALIGNED_MALLOC(X, Y) aligned_alloc(X, Y)
# endif

0 comments on commit 27ca4c1

Please sign in to comment.