On 10/15/21 3:32 AM, Mattias EngdegÄrd wrote:
This code in lib/nproc.c:
if (sysctl (mib[i], ARRAY_SIZE (mib[i]), &nprocs, &len, NULL, 0) == 0
elicits a warning on macOS 10.14 because `mib[i]` is `const int *` but the
sysctl argument is `int *`.
Thanks for reporting this; I installed the attached.
>From 720d73c395bb2fcbae3566339a4102b485aa491d Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Fri, 15 Oct 2021 19:33:46 -0700
Subject: [PATCH] nproc: port better to macOS 10.14
* lib/nproc.c (num_processors_ignoring_omp)
[HAVE_SYSCTL && !defined __GLIBC__ && defined HW_NCPU]:
Do not use a const mib, as macOS 10.14 rejects this.
---
ChangeLog | 7 +++++++
lib/nproc.c | 5 +++--
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ea71de0b2..87fd99f6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2021-10-15 Paul Eggert <egg...@cs.ucla.edu>
+
+ nproc: port better to macOS 10.14
+ * lib/nproc.c (num_processors_ignoring_omp)
+ [HAVE_SYSCTL && !defined __GLIBC__ && defined HW_NCPU]:
+ Do not use a const mib, as macOS 10.14 rejects this.
+
2021-10-13 Paul Eggert <egg...@cs.ucla.edu>
sigsegv: fix quoting problem
diff --git a/lib/nproc.c b/lib/nproc.c
index a9e369dd3..1af989d6d 100644
--- a/lib/nproc.c
+++ b/lib/nproc.c
@@ -307,10 +307,11 @@ num_processors_ignoring_omp (enum nproc_query query)
NPROC_CURRENT and NPROC_ALL. */
#if HAVE_SYSCTL && ! defined __GLIBC__ && defined HW_NCPU
- { /* This works on Mac OS X, FreeBSD, NetBSD, OpenBSD. */
+ { /* This works on macOS, FreeBSD, NetBSD, OpenBSD.
+ macOS 10.14 does not allow mib to be const. */
int nprocs;
size_t len = sizeof (nprocs);
- static int const mib[][2] = {
+ static int mib[][2] = {
# ifdef HW_NCPUONLINE
{ CTL_HW, HW_NCPUONLINE },
# endif
--
2.30.2