forked from GitHub/gf-core
Compare commits
6 Commits
majestic-c
...
majestic-m
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac93f2dd10 | ||
|
|
a2d843f8ed | ||
|
|
61e95bcfeb | ||
|
|
c9b668a583 | ||
|
|
8cd0bb5ec1 | ||
|
|
a5fb51ff3d |
54
.github/workflows/build-majestic.yml
vendored
54
.github/workflows/build-majestic.yml
vendored
@@ -84,6 +84,7 @@ jobs:
|
||||
name: JavaScript (Ubuntu)
|
||||
runs-on: ubuntu-20.04
|
||||
needs: ubuntu-runtime
|
||||
if: false
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
@@ -160,3 +161,56 @@ 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
|
||||
|
||||
macos-javascript:
|
||||
name: JavaScript (macOS)
|
||||
runs-on: macOS-11
|
||||
needs: macos-runtime
|
||||
if: false
|
||||
|
||||
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 dependencies
|
||||
working-directory: ./src/runtime/javascript
|
||||
run: |
|
||||
npm ci
|
||||
|
||||
- name: Run testsuite
|
||||
working-directory: ./src/runtime/javascript
|
||||
run: |
|
||||
npm run test
|
||||
|
||||
@@ -40,3 +40,24 @@ The shared libraries are installed in `/usr/local/lib`.
|
||||
|
||||
- Compiling GF with this runtime will require flag `--extra-lib-dirs=/usr/local/lib`.
|
||||
- Running GF with this runtime will require environment variable `LD_LIBRARY_PATH=/usr/local/lib`
|
||||
|
||||
## Uninstalling
|
||||
|
||||
To remove the _old_ C runtime from your system, do:
|
||||
```
|
||||
rm /usr/local/lib/libpgf.*
|
||||
rm /usr/local/lib/libgu.*
|
||||
rm /usr/local/lib/libsg.*
|
||||
rm -rf /usr/local/include/pgf
|
||||
```
|
||||
|
||||
To remove _this_ version of the runtime from your system, do:
|
||||
```
|
||||
rm /usr/local/lib/libpgf.*
|
||||
rm -rf /usr/local/include/pgf
|
||||
```
|
||||
|
||||
To clean all generated build files from this directory, use:
|
||||
```
|
||||
git clean -Xdf
|
||||
```
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
@@ -323,10 +324,19 @@ PgfDB::PgfDB(const char* filepath, int flags, int mode) {
|
||||
this->filepath = strdup(filepath);
|
||||
}
|
||||
|
||||
#ifndef MREMAP_MAYMOVE
|
||||
if (fd >= 0) {
|
||||
ms = (malloc_state*)
|
||||
mmap(NULL, file_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
} else {
|
||||
ms = (malloc_state*) ::malloc(file_size);
|
||||
}
|
||||
#else
|
||||
int mflags = (fd < 0) ? (MAP_PRIVATE | MAP_ANONYMOUS) : MAP_SHARED;
|
||||
ms = (malloc_state*)
|
||||
mmap(NULL, file_size, PROT_READ | PROT_WRITE, mflags, fd, 0);
|
||||
if (ms == MAP_FAILED) {
|
||||
#endif
|
||||
if (ms == MAP_FAILED || ms == NULL) {
|
||||
ms = NULL; // mark that ms is not created.
|
||||
::free((void *) this->filepath);
|
||||
int code = errno;
|
||||
@@ -368,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);
|
||||
}
|
||||
|
||||
@@ -884,14 +899,19 @@ object PgfDB::malloc_internal(size_t bytes)
|
||||
throw pgf_systemerror(errno, filepath);
|
||||
}
|
||||
|
||||
malloc_state* new_ms;
|
||||
// OSX mman and mman-win32 do not implement mremap or MREMAP_MAYMOVE
|
||||
#ifndef MREMAP_MAYMOVE
|
||||
if (munmap(ms, old_size) == -1)
|
||||
throw pgf_systemerror(errno);
|
||||
malloc_state* new_ms =
|
||||
(malloc_state*) mmap(0, new_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
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);
|
||||
} else {
|
||||
new_ms = (malloc_state*) realloc(ms, new_size);
|
||||
}
|
||||
#else
|
||||
malloc_state* new_ms =
|
||||
new_ms =
|
||||
(malloc_state*) mremap(ms, old_size, new_size, MREMAP_MAYMOVE);
|
||||
#endif
|
||||
if (new_ms == MAP_FAILED)
|
||||
@@ -1057,7 +1077,13 @@ void PgfDB::sync()
|
||||
size_t size =
|
||||
ms->top + chunksize(ptr(ms,ms->top)) + sizeof(size_t);
|
||||
|
||||
int res = msync((void *) ms, size, MS_SYNC | MS_INVALIDATE);
|
||||
int res;
|
||||
#ifndef MREMAP_MAYMOVE
|
||||
if (current_db->fd < 0) {
|
||||
res = 0;
|
||||
} else
|
||||
#endif
|
||||
res = msync((void *) ms, size, MS_SYNC | MS_INVALIDATE);
|
||||
if (res != 0)
|
||||
throw pgf_systemerror(errno);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# Python bindings to C runtime
|
||||
|
||||
## Compatibility
|
||||
|
||||
These bindings do not support Python 2. Python 3 is assumed in all these instructions.
|
||||
|
||||
## Pre-requisites
|
||||
|
||||
1. You must have installed the PGF C runtime (see `../c/README.md`)
|
||||
@@ -26,10 +30,3 @@ pytest
|
||||
```
|
||||
|
||||
Requires: `pip install pytest`
|
||||
|
||||
|
||||
## Debugging
|
||||
|
||||
valgrind --leak-check=full --show-leak-kinds=all pytest 2> valgrind.txt
|
||||
|
||||
valgrind --leak-check=full --show-leak-kinds=all -- python -c 'import pgf; s = pgf.readType("A -> B"); print(s)' 2> valgrind.txt
|
||||
|
||||
@@ -13,7 +13,7 @@ typedef struct {
|
||||
PyObject *exprs; // PyTupleObject of ExprObject
|
||||
} TypeObject;
|
||||
|
||||
PyTypeObject pgf_TypeType;
|
||||
extern PyTypeObject pgf_TypeType;
|
||||
|
||||
// typedef struct {
|
||||
// PyObject_HEAD
|
||||
@@ -72,14 +72,14 @@ typedef struct {
|
||||
ExprObject *expr;
|
||||
} ExprImplArgObject;
|
||||
|
||||
PyTypeObject pgf_ExprType;
|
||||
PyTypeObject pgf_ExprAbsType;
|
||||
PyTypeObject pgf_ExprAppType;
|
||||
PyTypeObject pgf_ExprLitType;
|
||||
PyTypeObject pgf_ExprMetaType;
|
||||
PyTypeObject pgf_ExprFunType;
|
||||
PyTypeObject pgf_ExprVarType;
|
||||
PyTypeObject pgf_ExprTypedType;
|
||||
PyTypeObject pgf_ExprImplArgType;
|
||||
extern PyTypeObject pgf_ExprType;
|
||||
extern PyTypeObject pgf_ExprAbsType;
|
||||
extern PyTypeObject pgf_ExprAppType;
|
||||
extern PyTypeObject pgf_ExprLitType;
|
||||
extern PyTypeObject pgf_ExprMetaType;
|
||||
extern PyTypeObject pgf_ExprFunType;
|
||||
extern PyTypeObject pgf_ExprVarType;
|
||||
extern PyTypeObject pgf_ExprTypedType;
|
||||
extern PyTypeObject pgf_ExprImplArgType;
|
||||
|
||||
#endif // PYPGF_EXPR_H_
|
||||
|
||||
@@ -12,7 +12,7 @@ typedef struct {
|
||||
PgfRevision revision;
|
||||
} PGFObject;
|
||||
|
||||
PyObject *PGFError;
|
||||
extern PyObject *PGFError;
|
||||
PgfExnType handleError(PgfExn err);
|
||||
|
||||
PgfText *CString_AsPgfText(const char *s, size_t size);
|
||||
@@ -29,7 +29,7 @@ void FreePgfText(PgfText *txt);
|
||||
void FreeHypos(PgfTypeHypo *hypos, Py_ssize_t n_hypos);
|
||||
void FreePgfPrintContext(PgfPrintContext *ctxt);
|
||||
|
||||
PgfUnmarshaller unmarshaller;
|
||||
PgfMarshaller marshaller;
|
||||
extern PgfUnmarshaller unmarshaller;
|
||||
extern PgfMarshaller marshaller;
|
||||
|
||||
#endif // PYPGF_FFI_H_
|
||||
|
||||
@@ -12,7 +12,7 @@ typedef struct {
|
||||
PgfRevision revision; // transient branch
|
||||
} TransactionObject;
|
||||
|
||||
PyTypeObject pgf_TransactionType;
|
||||
extern PyTypeObject pgf_TransactionType;
|
||||
|
||||
PyObject *PGF_checkoutBranch(PGFObject *self, PyObject *args);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user