summaryrefslogtreecommitdiff
path: root/numpy/_build_utils
diff options
context:
space:
mode:
authorBran <bran_avan@hotmail.co.uk>2019-02-27 23:30:09 +0000
committerBran <bran_avan@hotmail.co.uk>2019-02-27 23:30:09 +0000
commit680cd30daf763a87d9f8490b7a799daaea1d17a2 (patch)
treef2b97becb0af13debc0ce165ca53fef5bd793788 /numpy/_build_utils
parent71aab215e5865a9e83bff087fa50177e98fdd0d7 (diff)
downloadnumpy-680cd30daf763a87d9f8490b7a799daaea1d17a2.tar.gz
AVX detection fails on MacOS if $PATH doesn't contain /usr/sbin #7801 -- fix
Diffstat (limited to 'numpy/_build_utils')
-rw-r--r--numpy/_build_utils/src/apple_sgemv_fix.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/numpy/_build_utils/src/apple_sgemv_fix.c b/numpy/_build_utils/src/apple_sgemv_fix.c
index 4c9c82ece..934aba49d 100644
--- a/numpy/_build_utils/src/apple_sgemv_fix.c
+++ b/numpy/_build_utils/src/apple_sgemv_fix.c
@@ -29,6 +29,9 @@
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <string.h>
/* ----------------------------------------------------------------- */
/* Original cblas_sgemv */
@@ -66,12 +69,21 @@ static int AVX_and_10_9 = 0;
/* Dynamic check for AVX support
* __builtin_cpu_supports("avx") is available in gcc 4.8,
* but clang and icc do not currently support it. */
-#define cpu_supports_avx()\
-(system("sysctl -n machdep.cpu.features | grep -q AVX") == 0)
-
+#define cpu_supports_avx() ({\
+ int enabled, r;\
+ size_t length = sizeof(enabled);\
+ r = sysctlbyname("hw.optional.avx1_0", &enabled, &length, NULL, 0);\
+ r == 0 && enabled != 0;\
+})
+
/* Check if we are using MacOS X version 10.9 */
-#define using_mavericks()\
-(system("sw_vers -productVersion | grep -q 10\\.9\\.") == 0)
+#define using_mavericks() ({\
+ int r;\
+ char str[32] = {0};\
+ size_t size = sizeof(str);\
+ r = sysctlbyname("kern.osproductversion", str, &size, NULL, 0);\
+ r == 0 && strncmp(str, "10.9", strlen("10.9")) == 0;\
+})
__attribute__((destructor))
static void unloadlib(void)