commit - 89a3585c7f3a1a5d10e036050111255e21856058
commit + 7fae216ccfddbb1e5d8e154893cf0e5ebd54e5d6
blob - 79b3c94830bab93d40d0770f2765540fe24ed423
blob + 0b76fe5109ed5a73cc38eafcb1e879f8d1979bd4
--- .idea/misc.xml
+++ .idea/misc.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
+ <component name="CMakePythonSetting">
+ <option name="pythonIntegrationState" value="YES" />
+ </component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>
\ No newline at end of file
blob - fe54997d596620a84bd7c894c88380c50670787d
blob + 4dde872bd863159c446a310946045764595ac6c6
--- include/lfmacos.h
+++ include/lfmacos.h
#if defined(__APPLE__) || defined(__MACH__)
+#include <time.h>
+
typedef struct {
double total_user_time;
double total_kernel_time;
ProcessData *new_ProcessData();
int update_process(pid_t pid, ProcessData *proc);
+void *reallocarray(void *optr, size_t nmemb, size_t size);
#endif /* defined(__APPLE__) || defined(__MACH__) */
#endif /* LIBFLINT_MACOS_H */
blob - 57cd48e94bed6dbcfe054cc06a6ba8fb49e32989
blob + 3bbcf1c246a5b5475ef1fb51e62831f676c6dcf6
--- src/macos.c
+++ src/macos.c
#include <libproc.h>
#include <time.h>
#include <mach/mach_time.h>
+#include <sys/errno.h>
#include <stdlib.h>
#include "lfmacos.h"
return 0;
}
+
+/* reallocarray is reimplemented here for macOS because Apple doesn't expose
+ * their implementation. This is taken straight from the OpenBSD source as
+ * shown in the below copyright notice
+ */
+
+/* $OpenBSD: reallocarray.c,v 1.2 2014/12/08 03:45:00 bcook Exp $ */
+/*
+ * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* OPENBSD ORIGINAL: lib/libc/stdlib/reallocarray.c */
+
+#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
+
+void *reallocarray(void *optr, size_t nmemb, size_t size)
+{
+ if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
+ nmemb > 0 && SIZE_MAX / nmemb < size) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ return realloc(optr, size * nmemb);
+}
blob - 2179fc54a43d3a96847c8ee8d4bd85a7f12a6fb3
blob + bab701fb776df5b8b0f3ea23dc82bea98513860d
--- src/vector.c
+++ src/vector.c
#include <bsd/stdlib.h>
#endif
+#if defined(__APPLE__) || defined(__MACH__)
+#include "lfmacos.h"
+#endif
+
#include "lfvector.h"
#define VEC_INIT_CAP 2
static int vec_grow(Vector *const vec) {
vec->capacity *= 2;
-#ifdef __OpenBSD__
vec->elements = reallocarray(vec->elements, vec->capacity, sizeof(void *));
-#else
- vec->elements = reallocf(vec->elements, sizeof(void *) * vec->capacity);
-#endif
if (vec->elements == NULL) {
return -1;