fix(macos): define _DARWIN_C_SOURCE and drop dead locals so Apple clang builds under -std=c99 -Werror-prone flags
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-11 05:00:44
Commitd3f9f8e1
Parentsa109c19d
Changed files
src/plugin_sysmon.c+9−13■■■■■
1 file+9−13
Diff
src/plugin_sysmon.c+9−13■■■■■
index 54a63c8..fc8719d 100644
--- a/src/plugin_sysmon.c
+++ b/src/plugin_sysmon.c
@@ -18,10 +18,15 @@
1818 * MIT License. Copyright (c) 2026 SCORPIOX INC.
1919 */
2020
21-#if !defined(_WIN32)
21+#if defined(__APPLE__)
22+ /* sysctl.h pulls in BSD types (u_int) that strict c99 would hide */
23+# define _DARWIN_C_SOURCE 1
24+#elif !defined(_WIN32)
2225 # define _POSIX_C_SOURCE 200809L
2326 # define _DEFAULT_SOURCE 1
24-#elif !defined(_WIN32_WINNT)
27+#endif
28+
29+#if defined(_WIN32) && !defined(_WIN32_WINNT)
2530 # define _WIN32_WINNT 0x0601 /* GetTickCount64 needs Vista or later; must precede windows.h */
2631 #endif
2732
@@ -616,8 +621,6 @@ static void sample_macos(sys_t *s)
616621 integer_t *cpu0 = NULL, *cpu1 = NULL;
617622 natural_t ncpu0 = 0, ncpu1 = 0;
618623 unsigned long long page_kb;
619- unsigned long long tick_hz = 1000ULL; /* we time the window ourselves */
620- double window;
621624
622625 strcpy(s->platform, "macos");
623626
@@ -651,8 +654,6 @@ static void sample_macos(sys_t *s)
651654 cpu1 = NULL;
652655 }
653656
654- window = (double)SAMPLE_MS / 1000.0;
655-
656657 if (cpu0 && cpu1) {
657658 natural_t i;
658659 natural_t n = ncpu1 < ncpu0 ? ncpu1 : ncpu0;
@@ -683,16 +684,12 @@ static void sample_macos(sys_t *s)
683684 s->cpu_pct = t_total ? clamp_pct(100.0 - 100.0 * (double)t_idle / (double)t_total) : 0.0;
684685 }
685686
686- if (cpu0) {
687- vm_size_t freed = 0;
687+ if (cpu0)
688688 (void)vm_deallocate(mach_task_self(), (vm_address_t)cpu0,
689689 (vm_size_t)(ncpu0 * CPU_STATE_MAX * sizeof(integer_t)));
690- }
691- if (cpu1) {
692- vm_size_t freed = 0;
690+ if (cpu1)
693691 (void)vm_deallocate(mach_task_self(), (vm_address_t)cpu1,
694692 (vm_size_t)(ncpu1 * CPU_STATE_MAX * sizeof(integer_t)));
695- }
696693
697694 sz = sizeof(total_mem);
698695 if (sysctlbyname("hw.memsize", &total_mem, &sz, NULL, 0) != 0)
@@ -768,7 +765,6 @@ static void sample_macos(sys_t *s)
768765 }
769766
770767 s->ok = (s->ncores > 0 && s->mem_total_kb > 0.0);
771- (void)tick_hz;
772768 }
773769
774770 #endif /* __APPLE__ */
775771
src/plugin_sysmon.c+9−13■■■■■
index 54a63c8..fc8719d 100644index 54a63c8..fc8719d 100644
--- a/src/plugin_sysmon.c--- a/src/plugin_sysmon.c
+++ b/src/plugin_sysmon.c+++ b/src/plugin_sysmon.c
@@ -18,10 +18,15 @@@@ -18,10 +18,15 @@
18 * MIT License. Copyright (c) 2026 SCORPIOX INC.18 * MIT License. Copyright (c) 2026 SCORPIOX INC.
19 */19 */
20 20
21-#if !defined(_WIN32)21+#if defined(__APPLE__)
22+ /* sysctl.h pulls in BSD types (u_int) that strict c99 would hide */
23+# define _DARWIN_C_SOURCE 1
24+#elif !defined(_WIN32)
22 # define _POSIX_C_SOURCE 200809L25 # define _POSIX_C_SOURCE 200809L
23 # define _DEFAULT_SOURCE 126 # define _DEFAULT_SOURCE 1
24-#elif !defined(_WIN32_WINNT)27+#endif
28+
29+#if defined(_WIN32) && !defined(_WIN32_WINNT)
25 # define _WIN32_WINNT 0x0601 /* GetTickCount64 needs Vista or later; must precede windows.h */30 # define _WIN32_WINNT 0x0601 /* GetTickCount64 needs Vista or later; must precede windows.h */
26 #endif31 #endif
27 32
@@ -616,8 +621,6 @@ static void sample_macos(sys_t *s)@@ -616,8 +621,6 @@ static void sample_macos(sys_t *s)
616 integer_t *cpu0 = NULL, *cpu1 = NULL;621 integer_t *cpu0 = NULL, *cpu1 = NULL;
617 natural_t ncpu0 = 0, ncpu1 = 0;622 natural_t ncpu0 = 0, ncpu1 = 0;
618 unsigned long long page_kb;623 unsigned long long page_kb;
619- unsigned long long tick_hz = 1000ULL; /* we time the window ourselves */
620- double window;
621 624
622 strcpy(s->platform, "macos");625 strcpy(s->platform, "macos");
623 626
@@ -651,8 +654,6 @@ static void sample_macos(sys_t *s)@@ -651,8 +654,6 @@ static void sample_macos(sys_t *s)
651 cpu1 = NULL;654 cpu1 = NULL;
652 }655 }
653 656
654- window = (double)SAMPLE_MS / 1000.0;
655-
656 if (cpu0 && cpu1) {657 if (cpu0 && cpu1) {
657 natural_t i;658 natural_t i;
658 natural_t n = ncpu1 < ncpu0 ? ncpu1 : ncpu0;659 natural_t n = ncpu1 < ncpu0 ? ncpu1 : ncpu0;
@@ -683,16 +684,12 @@ static void sample_macos(sys_t *s)@@ -683,16 +684,12 @@ static void sample_macos(sys_t *s)
683 s->cpu_pct = t_total ? clamp_pct(100.0 - 100.0 * (double)t_idle / (double)t_total) : 0.0;684 s->cpu_pct = t_total ? clamp_pct(100.0 - 100.0 * (double)t_idle / (double)t_total) : 0.0;
684 }685 }
685 686
686- if (cpu0) {687+ if (cpu0)
687- vm_size_t freed = 0;
688 (void)vm_deallocate(mach_task_self(), (vm_address_t)cpu0,688 (void)vm_deallocate(mach_task_self(), (vm_address_t)cpu0,
689 (vm_size_t)(ncpu0 * CPU_STATE_MAX * sizeof(integer_t)));689 (vm_size_t)(ncpu0 * CPU_STATE_MAX * sizeof(integer_t)));
690- }690+ if (cpu1)
691- if (cpu1) {
692- vm_size_t freed = 0;
693 (void)vm_deallocate(mach_task_self(), (vm_address_t)cpu1,691 (void)vm_deallocate(mach_task_self(), (vm_address_t)cpu1,
694 (vm_size_t)(ncpu1 * CPU_STATE_MAX * sizeof(integer_t)));692 (vm_size_t)(ncpu1 * CPU_STATE_MAX * sizeof(integer_t)));
695- }
696 693
697 sz = sizeof(total_mem);694 sz = sizeof(total_mem);
698 if (sysctlbyname("hw.memsize", &total_mem, &sz, NULL, 0) != 0)695 if (sysctlbyname("hw.memsize", &total_mem, &sz, NULL, 0) != 0)
@@ -768,7 +765,6 @@ static void sample_macos(sys_t *s)@@ -768,7 +765,6 @@ static void sample_macos(sys_t *s)
768 }765 }
769 766
770 s->ok = (s->ncores > 0 && s->mem_total_kb > 0.0);767 s->ok = (s->ncores > 0 && s->mem_total_kb > 0.0);
771- (void)tick_hz;
772 }768 }
773 769
774 #endif /* __APPLE__ */770 #endif /* __APPLE__ */
775771