|
| 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