From c9b668a58309025240dc442d01d4a4aa569b3a31 Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Fri, 15 Oct 2021 17:34:19 +0200 Subject: [PATCH] Fix compilation with macOS mmap/malloc workaround. Add Python (macOS) to CI. --- .github/workflows/build-majestic.yml | 27 +++++++++++++++++++++++++++ src/runtime/c/pgf/db.cxx | 22 ++++++++++++++-------- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-majestic.yml b/.github/workflows/build-majestic.yml index c72618d91..54d83ef3b 100644 --- a/.github/workflows/build-majestic.yml +++ b/.github/workflows/build-majestic.yml @@ -160,3 +160,30 @@ jobs: working-directory: ./src/runtime/haskell run: | cabal test --extra-lib-dirs=/usr/local/lib + + macos-python: + name: Python (macOS) + runs-on: macOS-11 + needs: macos-runtime + + steps: + - uses: actions/checkout@v2 + - name: Download artifact + uses: actions/download-artifact@master + with: + name: libpgf-macos + - run: | + sudo mv lib/* /usr/local/lib/ + sudo mv include/* /usr/local/include/ + + - name: Install bindings + working-directory: ./src/runtime/python + run: | + python3 setup.py build + sudo python3 setup.py install + + - name: Run testsuite + working-directory: ./src/runtime/python + run: | + pip3 install pytest + pytest diff --git a/src/runtime/c/pgf/db.cxx b/src/runtime/c/pgf/db.cxx index 645eee378..6e0e80d5f 100644 --- a/src/runtime/c/pgf/db.cxx +++ b/src/runtime/c/pgf/db.cxx @@ -1,3 +1,4 @@ +#include #include #include #include @@ -325,10 +326,10 @@ PgfDB::PgfDB(const char* filepath, int flags, int mode) { #ifndef MREMAP_MAYMOVE if (fd >= 0) { - ms = (malloc_state*) - mmap(NULL, file_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + ms = (malloc_state*) + mmap(NULL, file_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); } else { - ms = (malloc_state*) malloc(file_size); // doesn't compile + ms = (malloc_state*) ::malloc(file_size); } #else int mflags = (fd < 0) ? (MAP_PRIVATE | MAP_ANONYMOUS) : MAP_SHARED; @@ -377,6 +378,11 @@ PgfDB::~PgfDB() { size_t size = ms->top + chunksize(ptr(ms,ms->top)) + sizeof(size_t); +#ifndef MREMAP_MAYMOVE + if (fd < 0) { + ::free(ms); + } else +#endif munmap(ms,size); } @@ -897,12 +903,12 @@ object PgfDB::malloc_internal(size_t bytes) // OSX mman and mman-win32 do not implement mremap or MREMAP_MAYMOVE #ifndef MREMAP_MAYMOVE if (fd >= 0) { - if (munmap(ms, old_size) == -1) - throw pgf_systemerror(errno); - new_ms = - (malloc_state*) mmap(0, new_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (munmap(ms, old_size) == -1) + throw pgf_systemerror(errno); + new_ms = + (malloc_state*) mmap(0, new_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); } else { - new_ms = (malloc_state*) realloc(ms, new_size); + new_ms = (malloc_state*) realloc(ms, new_size); } #else new_ms =