From f70e1b8772522ac145e8c547d8bbc1d8d8b0ef50 Mon Sep 17 00:00:00 2001 From: krangelov Date: Sun, 8 Aug 2021 16:29:51 +0200 Subject: [PATCH] fix the DB_scope in pgf_read_ngf --- src/runtime/c/pgf.cxx | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/runtime/c/pgf.cxx b/src/runtime/c/pgf.cxx index 3f4c477d6..9c3f34eeb 100644 --- a/src/runtime/c/pgf.cxx +++ b/src/runtime/c/pgf.cxx @@ -103,20 +103,22 @@ PgfPGF *pgf_read_ngf(const char *fpath, PgfExn* err) try { pgf = new PgfPGF(fpath, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); - if (DB::get_root() == 0) { - is_new = true; - + { DB_scope scope(pgf, WRITER_SCOPE); - ref root = DB::malloc(); - root->major_version = 2; - root->minor_version = 0; - root->gflags = 0; - root->abstract.name = DB::malloc(); - root->abstract.name->size = 0; - root->abstract.aflags = 0; - root->abstract.funs = 0; - root->abstract.cats = 0; + if (DB::get_root() == 0) { + is_new = true; + ref root = DB::malloc(); + root->major_version = 2; + root->minor_version = 0; + root->gflags = 0; + root->abstract.name = DB::malloc(); + root->abstract.name->size = 0; + root->abstract.aflags = 0; + root->abstract.funs = 0; + root->abstract.cats = 0; + DB::set_root(root); + } } return pgf;