diff --git a/src/runtime/c/Makefile.am b/src/runtime/c/Makefile.am index c0c96b46b..9018df159 100644 --- a/src/runtime/c/Makefile.am +++ b/src/runtime/c/Makefile.am @@ -28,7 +28,7 @@ libpgf_la_SOURCES = \ pgf/namespace.h libpgf_la_LDFLAGS = -no-undefined -libpgf_la_LIBADD = -lrt +libpgf_la_LIBADD = libpgf_la_CXXFLAGS = -fno-rtti -std=c++11 bin_PROGRAMS = diff --git a/src/runtime/c/pgf/data.h b/src/runtime/c/pgf/data.h index 054a2bce7..1f2592520 100644 --- a/src/runtime/c/pgf/data.h +++ b/src/runtime/c/pgf/data.h @@ -123,7 +123,13 @@ struct PGF_INTERNAL_DECL PgfPGF { static void release(ref pgf); }; +// extern PGF_INTERNAL_DECL +// PgfText master; + extern PGF_INTERNAL_DECL -PgfText master; +size_t master_size; + +extern PGF_INTERNAL_DECL +char master_text[]; #endif diff --git a/src/runtime/c/pgf/db.cxx b/src/runtime/c/pgf/db.cxx index 50020df83..4ebb39d03 100644 --- a/src/runtime/c/pgf/db.cxx +++ b/src/runtime/c/pgf/db.cxx @@ -883,8 +883,16 @@ object PgfDB::malloc_internal(size_t bytes) 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*) mremap(ms, old_size, new_size, MREMAP_MAYMOVE); +#endif if (new_ms == MAP_FAILED) throw pgf_systemerror(errno); diff --git a/src/runtime/c/pgf/expr.cxx b/src/runtime/c/pgf/expr.cxx index dc8f4b316..e8e9caebf 100644 --- a/src/runtime/c/pgf/expr.cxx +++ b/src/runtime/c/pgf/expr.cxx @@ -256,7 +256,7 @@ void PgfExprParser::putc(uint32_t ucs) ucs < 0x10000 ? 3 : ucs < 0x200000 ? 4 : ucs < 0x4000000 ? 5 : - 6 + 6 ); size_t len = token_value ? token_value->size : 0; @@ -365,9 +365,10 @@ void PgfExprParser::token() } switch (ch) { - case EOF: - token_tag = PGF_TOKEN_EOF; - break; + // TODO + // case EOF: + // token_tag = PGF_TOKEN_EOF; + // break; case '(': ch = getc(); token_tag = PGF_TOKEN_LPAR; @@ -615,7 +616,8 @@ PgfExpr PgfExprParser::parse_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) { @@ -826,7 +828,7 @@ PgfType PgfExprParser::parse_type() size_t n_start = n_hypos; if ((token_tag == PGF_TOKEN_IDENT && - (lookahead(',') || + (lookahead(',') || lookahead(':'))) || (token_tag == PGF_TOKEN_LCURLY) || (token_tag == PGF_TOKEN_WILD)) { diff --git a/src/runtime/c/pgf/ipc.cxx b/src/runtime/c/pgf/ipc.cxx index c84c9e7a2..c56d4f489 100644 --- a/src/runtime/c/pgf/ipc.cxx +++ b/src/runtime/c/pgf/ipc.cxx @@ -2,6 +2,9 @@ #include #include #include +#include +#include + #include "pgf/data.h" typedef struct { diff --git a/src/runtime/c/pgf/pgf.cxx b/src/runtime/c/pgf/pgf.cxx index 9d3230dff..960dd62d4 100644 --- a/src/runtime/c/pgf/pgf.cxx +++ b/src/runtime/c/pgf/pgf.cxx @@ -1,5 +1,7 @@ #include #include +#include + #include "data.h" #include "reader.h" #include "writer.h" @@ -28,8 +30,14 @@ pgf_exn_clear(PgfExn* err) err->msg = strdup(e.what()); \ } +// PGF_INTERNAL +// PgfText master = {size: 6, text: {}}; + 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 PgfDB *pgf_read_pgf(const char* fpath, @@ -124,10 +132,14 @@ PgfDB *pgf_read_ngf(const char *fpath, PGF_API_BEGIN { 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); - ref pgf = PgfDB::get_revision(&master); + ref pgf = PgfDB::get_revision(master); Node::add_value_ref(pgf); *revision = pgf.as_object(); } @@ -159,7 +171,7 @@ PgfDB *pgf_new_ngf(PgfText *abstract_name, { DB_scope scope(db, WRITER_SCOPE); - ref pgf = PgfDB::malloc(master.size+1); + ref pgf = PgfDB::malloc(master_size+1); pgf->ref_count = 1; pgf->major_version = PGF_MAJOR_VERSION; pgf->minor_version = PGF_MINOR_VERSION; @@ -171,7 +183,8 @@ PgfDB *pgf_new_ngf(PgfText *abstract_name, pgf->abstract.cats = 0; pgf->prev = 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); *revision = pgf.as_object(); @@ -269,7 +282,7 @@ void pgf_iter_categories(PgfDB *db, PgfRevision revision, PGF_API_BEGIN { DB_scope scope(db, READER_SCOPE); ref pgf = PgfDB::revision2pgf(revision); - + namespace_iter(pgf->abstract.cats, itor, err); } PGF_API_END } @@ -671,7 +684,7 @@ void pgf_create_function(PgfDB *db, PgfRevision revision, ref::from_ptr((PgfExprFun*) &absfun->name); absfun->ep.expr = ref::tagged(efun); memcpy(&absfun->name, name, sizeof(PgfText)+name->size+1); - + Namespace funs = namespace_insert(pgf->abstract.funs, absfun); namespace_release(pgf->abstract.funs); diff --git a/src/runtime/c/pgf/reader.cxx b/src/runtime/c/pgf/reader.cxx index cb0e7098a..5e090c154 100644 --- a/src/runtime/c/pgf/reader.cxx +++ b/src/runtime/c/pgf/reader.cxx @@ -430,7 +430,7 @@ void PgfReader::read_abstract(ref abstract) ref PgfReader::read_pgf() { - ref pgf = PgfDB::malloc(master.size+1); + ref pgf = PgfDB::malloc(master_size+1); pgf->ref_count = 1; pgf->major_version = read_u16be(); @@ -448,7 +448,8 @@ ref PgfReader::read_pgf() pgf->prev = 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; }