Skip to content

Commit fe9e1ec

Browse files
python314-freethreading: fix build on macOS >=10.7 and =<10.12
Co-authored-by: Sergey Fedorov <[email protected]>
1 parent 4dbc66f commit fe9e1ec

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

lang/python314/Portfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ subport python314-freethreading {
9999
lock (GIL).
100100
notes-append "Python with free threading has a different ABI and is thus\
101101
incompatible with extension modules built for the standard ABI."
102-
# task_vm_info.phys_footprint
103-
platforms {darwin >= 15}
102+
platforms {darwin >= 11}
104103
# Needs stdatomic.h
105104
compiler.blacklist {clang < 700}
106105
set abiflags t
@@ -120,6 +119,10 @@ if {$subport eq $name} {
120119
}
121120

122121
platform darwin {
122+
# task_vm_info.phys_footprint
123+
if {${os.major} < 16} {
124+
patchfiles-append patch-gc_free_threading.diff
125+
}
123126
if {${os.major} < 11} {
124127
configure.args-append --without-mimalloc
125128
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--- Python/gc_free_threading.c 2025-07-23 00:42:44.000000000 +0800
2+
+++ Python/gc_free_threading.c 2025-07-30 14:51:41.000000000 +0800
3+
@@ -25,8 +25,9 @@
4+
#include <unistd.h> // For sysconf, getpid
5+
#elif defined(__APPLE__)
6+
#include <mach/mach.h>
7+
- #include <mach/task.h> // Required for TASK_VM_INFO
8+
+ #include <mach/task.h> // Required for TASK_VM_INFO/TASK_BASIC_INFO
9+
#include <unistd.h> // For sysconf, getpid
10+
+ #include <AvailabilityMacros.h>
11+
#elif defined(__FreeBSD__)
12+
#include <sys/types.h>
13+
#include <sys/sysctl.h>
14+
@@ -1956,6 +1957,7 @@
15+
16+
#elif defined(__APPLE__)
17+
// --- MacOS (Darwin) ---
18+
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
19+
// Returns phys_footprint (RAM + compressed memory)
20+
task_vm_info_data_t vm_info;
21+
mach_msg_type_number_t count = TASK_VM_INFO_COUNT;
22+
@@ -1967,7 +1969,18 @@
23+
}
24+
// phys_footprint is in bytes. Convert to KB.
25+
return (Py_ssize_t)(vm_info.phys_footprint / 1024);
26+
+#else
27+
+ task_basic_info_data_t info;
28+
+ mach_msg_type_number_t count = TASK_BASIC_INFO_COUNT;
29+
+ kern_return_t kerr;
30+
31+
+ kerr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &count);
32+
+ if (kerr != KERN_SUCCESS) {
33+
+ return -1;
34+
+ }
35+
+ // resident_size is in bytes. Convert to KB.
36+
+ return (Py_ssize_t)(info.resident_size / 1024);
37+
+#endif
38+
#elif defined(__FreeBSD__)
39+
// NOTE: Returns RSS only. Per-process swap usage isn't readily available
40+
long page_size_kb = sysconf(_SC_PAGESIZE) / 1024;

0 commit comments

Comments
 (0)