More changes to compile on macOS (incomplete)

This commit is contained in:
John J. Camilleri
2021-10-12 15:29:29 +02:00
parent f9c6e94672
commit ead1160a75
7 changed files with 49 additions and 16 deletions

View File

@@ -28,7 +28,7 @@ libpgf_la_SOURCES = \
pgf/namespace.h pgf/namespace.h
libpgf_la_LDFLAGS = -no-undefined libpgf_la_LDFLAGS = -no-undefined
libpgf_la_LIBADD = -lrt libpgf_la_LIBADD =
libpgf_la_CXXFLAGS = -fno-rtti -std=c++11 libpgf_la_CXXFLAGS = -fno-rtti -std=c++11
bin_PROGRAMS = bin_PROGRAMS =

View File

@@ -123,7 +123,13 @@ struct PGF_INTERNAL_DECL PgfPGF {
static void release(ref<PgfPGF> pgf); static void release(ref<PgfPGF> pgf);
}; };
// extern PGF_INTERNAL_DECL
// PgfText master;
extern PGF_INTERNAL_DECL extern PGF_INTERNAL_DECL
PgfText master; size_t master_size;
extern PGF_INTERNAL_DECL
char master_text[];
#endif #endif

View File

@@ -883,8 +883,16 @@ object PgfDB::malloc_internal(size_t bytes)
throw pgf_systemerror(errno, filepath); throw pgf_systemerror(errno, filepath);
} }
// 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);
#else
malloc_state* new_ms = malloc_state* new_ms =
(malloc_state*) mremap(ms, old_size, new_size, MREMAP_MAYMOVE); (malloc_state*) mremap(ms, old_size, new_size, MREMAP_MAYMOVE);
#endif
if (new_ms == MAP_FAILED) if (new_ms == MAP_FAILED)
throw pgf_systemerror(errno); throw pgf_systemerror(errno);

View File

@@ -256,7 +256,7 @@ void PgfExprParser::putc(uint32_t ucs)
ucs < 0x10000 ? 3 : ucs < 0x10000 ? 3 :
ucs < 0x200000 ? 4 : ucs < 0x200000 ? 4 :
ucs < 0x4000000 ? 5 : ucs < 0x4000000 ? 5 :
6 6
); );
size_t len = token_value ? token_value->size : 0; size_t len = token_value ? token_value->size : 0;
@@ -365,9 +365,10 @@ void PgfExprParser::token()
} }
switch (ch) { switch (ch) {
case EOF: // TODO
token_tag = PGF_TOKEN_EOF; // case EOF:
break; // token_tag = PGF_TOKEN_EOF;
// break;
case '(': case '(':
ch = getc(); ch = getc();
token_tag = PGF_TOKEN_LPAR; token_tag = PGF_TOKEN_LPAR;
@@ -615,7 +616,8 @@ PgfExpr PgfExprParser::parse_arg()
return arg; return arg;
} }
PGF_INTERNAL PgfText wildcard = {size: 1, text: {'_',0}}; // PGF_INTERNAL PgfText wildcard = {size: 1, text: {'_',0}};
PGF_INTERNAL PgfText wildcard = {size: 1, text: {}}; // TODO
PgfBind *PgfExprParser::parse_bind(PgfBind *next) PgfBind *PgfExprParser::parse_bind(PgfBind *next)
{ {
@@ -826,7 +828,7 @@ PgfType PgfExprParser::parse_type()
size_t n_start = n_hypos; size_t n_start = n_hypos;
if ((token_tag == PGF_TOKEN_IDENT && if ((token_tag == PGF_TOKEN_IDENT &&
(lookahead(',') || (lookahead(',') ||
lookahead(':'))) || lookahead(':'))) ||
(token_tag == PGF_TOKEN_LCURLY) || (token_tag == PGF_TOKEN_LCURLY) ||
(token_tag == PGF_TOKEN_WILD)) { (token_tag == PGF_TOKEN_WILD)) {

View File

@@ -2,6 +2,9 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include <pthread.h>
#include "pgf/data.h" #include "pgf/data.h"
typedef struct { typedef struct {

View File

@@ -1,5 +1,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <math.h> #include <math.h>
#include <errno.h>
#include "data.h" #include "data.h"
#include "reader.h" #include "reader.h"
#include "writer.h" #include "writer.h"
@@ -28,8 +30,14 @@ pgf_exn_clear(PgfExn* err)
err->msg = strdup(e.what()); \ err->msg = strdup(e.what()); \
} }
// PGF_INTERNAL
// PgfText master = {size: 6, text: {}};
PGF_INTERNAL PGF_INTERNAL
PgfText master = {size: 6, text: {'m','a','s','t','e','r',0}}; size_t master_size = 6;
PGF_INTERNAL
char master_text[] = {'m','a','s','t','e','r',0};
PGF_API PGF_API
PgfDB *pgf_read_pgf(const char* fpath, PgfDB *pgf_read_pgf(const char* fpath,
@@ -124,10 +132,14 @@ PgfDB *pgf_read_ngf(const char *fpath,
PGF_API_BEGIN { PGF_API_BEGIN {
db = new PgfDB(fpath, O_RDWR, 0); db = new PgfDB(fpath, O_RDWR, 0);
PgfText *master = (PgfText *)alloca(sizeof(PgfText)+master_size+1);
master->size = master_size;
strcpy(master->text, master_text);
{ {
DB_scope scope(db, WRITER_SCOPE); DB_scope scope(db, WRITER_SCOPE);
ref<PgfPGF> pgf = PgfDB::get_revision(&master); ref<PgfPGF> pgf = PgfDB::get_revision(master);
Node<PgfPGF>::add_value_ref(pgf); Node<PgfPGF>::add_value_ref(pgf);
*revision = pgf.as_object(); *revision = pgf.as_object();
} }
@@ -159,7 +171,7 @@ PgfDB *pgf_new_ngf(PgfText *abstract_name,
{ {
DB_scope scope(db, WRITER_SCOPE); DB_scope scope(db, WRITER_SCOPE);
ref<PgfPGF> pgf = PgfDB::malloc<PgfPGF>(master.size+1); ref<PgfPGF> pgf = PgfDB::malloc<PgfPGF>(master_size+1);
pgf->ref_count = 1; pgf->ref_count = 1;
pgf->major_version = PGF_MAJOR_VERSION; pgf->major_version = PGF_MAJOR_VERSION;
pgf->minor_version = PGF_MINOR_VERSION; pgf->minor_version = PGF_MINOR_VERSION;
@@ -171,7 +183,8 @@ PgfDB *pgf_new_ngf(PgfText *abstract_name,
pgf->abstract.cats = 0; pgf->abstract.cats = 0;
pgf->prev = 0; pgf->prev = 0;
pgf->next = 0; pgf->next = 0;
memcpy(&pgf->name, &master, sizeof(PgfText)+master.size+1); pgf->name.size = master_size;
memcpy(&pgf->name.text, master_text, master_size+1);
PgfDB::set_revision(pgf); PgfDB::set_revision(pgf);
*revision = pgf.as_object(); *revision = pgf.as_object();
@@ -269,7 +282,7 @@ void pgf_iter_categories(PgfDB *db, PgfRevision revision,
PGF_API_BEGIN { PGF_API_BEGIN {
DB_scope scope(db, READER_SCOPE); DB_scope scope(db, READER_SCOPE);
ref<PgfPGF> pgf = PgfDB::revision2pgf(revision); ref<PgfPGF> pgf = PgfDB::revision2pgf(revision);
namespace_iter(pgf->abstract.cats, itor, err); namespace_iter(pgf->abstract.cats, itor, err);
} PGF_API_END } PGF_API_END
} }
@@ -671,7 +684,7 @@ void pgf_create_function(PgfDB *db, PgfRevision revision,
ref<PgfExprFun>::from_ptr((PgfExprFun*) &absfun->name); ref<PgfExprFun>::from_ptr((PgfExprFun*) &absfun->name);
absfun->ep.expr = ref<PgfExprFun>::tagged(efun); absfun->ep.expr = ref<PgfExprFun>::tagged(efun);
memcpy(&absfun->name, name, sizeof(PgfText)+name->size+1); memcpy(&absfun->name, name, sizeof(PgfText)+name->size+1);
Namespace<PgfAbsFun> funs = Namespace<PgfAbsFun> funs =
namespace_insert(pgf->abstract.funs, absfun); namespace_insert(pgf->abstract.funs, absfun);
namespace_release(pgf->abstract.funs); namespace_release(pgf->abstract.funs);

View File

@@ -430,7 +430,7 @@ void PgfReader::read_abstract(ref<PgfAbstr> abstract)
ref<PgfPGF> PgfReader::read_pgf() ref<PgfPGF> PgfReader::read_pgf()
{ {
ref<PgfPGF> pgf = PgfDB::malloc<PgfPGF>(master.size+1); ref<PgfPGF> pgf = PgfDB::malloc<PgfPGF>(master_size+1);
pgf->ref_count = 1; pgf->ref_count = 1;
pgf->major_version = read_u16be(); pgf->major_version = read_u16be();
@@ -448,7 +448,8 @@ ref<PgfPGF> PgfReader::read_pgf()
pgf->prev = 0; pgf->prev = 0;
pgf->next = 0; pgf->next = 0;
memcpy(&pgf->name, &master, sizeof(PgfText)+master.size+1); pgf->name.size = master_size;
memcpy(&pgf->name.text, master_text, master_size+1);
return pgf; return pgf;
} }