Fix compilation with macOS mmap/malloc workaround. Add Python (macOS) to CI.

This commit is contained in:
John J. Camilleri
2021-10-15 17:34:19 +02:00
parent 8cd0bb5ec1
commit c9b668a583
2 changed files with 41 additions and 8 deletions

View File

@@ -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

View File

@@ -1,3 +1,4 @@
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
@@ -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 =