mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-25 10:48:54 -06:00
transactions should always start with the last revision and release it when done
This commit is contained in:
@@ -260,7 +260,7 @@ public:
|
|||||||
return node->right;
|
return node->right;
|
||||||
} else {
|
} else {
|
||||||
ref<Node> left = pop_first(node->left, res);
|
ref<Node> left = pop_first(node->left, res);
|
||||||
ref<Node> node = upd_node(node, left, node->right);
|
node = upd_node(node, left, node->right);
|
||||||
return balanceR(node);
|
return balanceR(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -275,7 +275,7 @@ public:
|
|||||||
return node->left;
|
return node->left;
|
||||||
} else {
|
} else {
|
||||||
ref<Node> right = pop_last(node->right, res);
|
ref<Node> right = pop_last(node->right, res);
|
||||||
ref<Node> node = upd_node(node, node->left, right);
|
node = upd_node(node, node->left, right);
|
||||||
return balanceL(node);
|
return balanceL(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1057,13 +1057,12 @@ void pgf_check_type(PgfDB *db, PgfRevision revision,
|
|||||||
}
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
PgfRevision pgf_start_transaction(PgfDB *db, PgfRevision revision,
|
PgfRevision pgf_start_transaction(PgfDB *db, PgfExn *err)
|
||||||
PgfExn *err)
|
|
||||||
{
|
{
|
||||||
PGF_API_BEGIN {
|
PGF_API_BEGIN {
|
||||||
DB_scope scope(db, WRITER_SCOPE);
|
DB_scope scope(db, WRITER_SCOPE);
|
||||||
|
|
||||||
ref<PgfPGF> pgf = db->revision2pgf(revision);
|
ref<PgfPGF> pgf = db->get_active_revision();
|
||||||
|
|
||||||
db->start_transaction();
|
db->start_transaction();
|
||||||
|
|
||||||
@@ -1079,6 +1078,8 @@ PgfRevision pgf_start_transaction(PgfDB *db, PgfRevision revision,
|
|||||||
|
|
||||||
object rev = db->register_revision(new_pgf.tagged(), PgfDB::get_txn_id());
|
object rev = db->register_revision(new_pgf.tagged(), PgfDB::get_txn_id());
|
||||||
|
|
||||||
|
PgfDB::free(pgf);
|
||||||
|
|
||||||
db->ref_count++;
|
db->ref_count++;
|
||||||
return rev;
|
return rev;
|
||||||
} PGF_API_END
|
} PGF_API_END
|
||||||
|
|||||||
@@ -462,8 +462,7 @@ void pgf_check_type(PgfDB *db, PgfRevision revision,
|
|||||||
PgfExn *err);
|
PgfExn *err);
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
PgfRevision pgf_start_transaction(PgfDB *db, PgfRevision revision,
|
PgfRevision pgf_start_transaction(PgfDB *db, PgfExn *err);
|
||||||
PgfExn *err);
|
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
void pgf_commit_transaction(PgfDB *db, PgfRevision revision,
|
void pgf_commit_transaction(PgfDB *db, PgfRevision revision,
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ foreign import ccall pgf_infer_expr :: Ptr PgfDB -> Ptr PGF -> Ptr (StablePtr Ex
|
|||||||
|
|
||||||
foreign import ccall pgf_check_type :: Ptr PgfDB -> Ptr PGF -> Ptr (StablePtr Type) -> Ptr PgfMarshaller -> Ptr PgfUnmarshaller -> Ptr PgfExn -> IO ()
|
foreign import ccall pgf_check_type :: Ptr PgfDB -> Ptr PGF -> Ptr (StablePtr Type) -> Ptr PgfMarshaller -> Ptr PgfUnmarshaller -> Ptr PgfExn -> IO ()
|
||||||
|
|
||||||
foreign import ccall pgf_start_transaction :: Ptr PgfDB -> Ptr PGF -> Ptr PgfExn -> IO (Ptr PGF)
|
foreign import ccall pgf_start_transaction :: Ptr PgfDB -> Ptr PgfExn -> IO (Ptr PGF)
|
||||||
|
|
||||||
foreign import ccall pgf_commit_transaction :: Ptr PgfDB -> Ptr PGF -> Ptr PgfExn -> IO ()
|
foreign import ccall pgf_commit_transaction :: Ptr PgfDB -> Ptr PGF -> Ptr PgfExn -> IO ()
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ modifyPGF p (Transaction f) =
|
|||||||
withForeignPtr (a_revision p) $ \c_revision ->
|
withForeignPtr (a_revision p) $ \c_revision ->
|
||||||
withPgfExn "modifyPGF" $ \c_exn ->
|
withPgfExn "modifyPGF" $ \c_exn ->
|
||||||
mask $ \restore -> do
|
mask $ \restore -> do
|
||||||
c_revision <- pgf_start_transaction (a_db p) c_revision c_exn
|
c_revision <- pgf_start_transaction (a_db p) c_exn
|
||||||
ex_type <- (#peek PgfExn, type) c_exn
|
ex_type <- (#peek PgfExn, type) c_exn
|
||||||
if (ex_type :: (#type PgfExnType)) == (#const PGF_EXN_NONE)
|
if (ex_type :: (#type PgfExnType)) == (#const PGF_EXN_NONE)
|
||||||
then do ((restore (f (a_db p) c_revision c_revision c_exn))
|
then do ((restore (f (a_db p) c_revision c_revision c_exn))
|
||||||
|
|||||||
@@ -9,10 +9,8 @@ main = do
|
|||||||
gr1 <- readPGF "tests/basic.pgf"
|
gr1 <- readPGF "tests/basic.pgf"
|
||||||
let Just ty = readType "(N -> N) -> P (s z)"
|
let Just ty = readType "(N -> N) -> P (s z)"
|
||||||
|
|
||||||
print 1
|
|
||||||
gr2 <- modifyPGF gr1 (createFunction "foo" ty 0 [] pi >>
|
gr2 <- modifyPGF gr1 (createFunction "foo" ty 0 [] pi >>
|
||||||
createCategory "Q" [(Explicit,"x",ty)] pi)
|
createCategory "Q" [(Explicit,"x",ty)] pi)
|
||||||
print 2
|
|
||||||
|
|
||||||
gr4 <- checkoutPGF gr1
|
gr4 <- checkoutPGF gr1
|
||||||
|
|
||||||
@@ -21,6 +19,7 @@ main = do
|
|||||||
gr7 <- modifyPGF gr1 $
|
gr7 <- modifyPGF gr1 $
|
||||||
createConcrete "basic_eng" $ do
|
createConcrete "basic_eng" $ do
|
||||||
setConcreteFlag "test_flag" (LStr "test")
|
setConcreteFlag "test_flag" (LStr "test")
|
||||||
|
|
||||||
let Just cnc = Map.lookup "basic_eng" (languages gr7)
|
let Just cnc = Map.lookup "basic_eng" (languages gr7)
|
||||||
|
|
||||||
c <- runTestTT $
|
c <- runTestTT $
|
||||||
@@ -31,8 +30,8 @@ main = do
|
|||||||
,TestCase (assertEqual "original categories" ["Float","Int","N","P","S","String"] (categories gr1))
|
,TestCase (assertEqual "original categories" ["Float","Int","N","P","S","String"] (categories gr1))
|
||||||
,TestCase (assertEqual "extended categories" ["Float","Int","N","P","Q","S","String"] (categories gr2))
|
,TestCase (assertEqual "extended categories" ["Float","Int","N","P","Q","S","String"] (categories gr2))
|
||||||
,TestCase (assertEqual "Q context" (Just [(Explicit,"x",ty)]) (categoryContext gr2 "Q"))
|
,TestCase (assertEqual "Q context" (Just [(Explicit,"x",ty)]) (categoryContext gr2 "Q"))
|
||||||
,TestCase (assertEqual "reduced functions" ["c","floatLit","intLit","nat","s","stringLit","z"] (functions gr6))
|
,TestCase (assertEqual "reduced functions" ["c","floatLit","foo","intLit","nat","s","stringLit","z"] (functions gr6))
|
||||||
,TestCase (assertEqual "reduced categories" ["Float","Int","N","P","String"] (categories gr6))
|
,TestCase (assertEqual "reduced categories" ["Float","Int","N","P","Q","String"] (categories gr6))
|
||||||
,TestCase (assertEqual "old function type" Nothing (functionType gr1 "foo"))
|
,TestCase (assertEqual "old function type" Nothing (functionType gr1 "foo"))
|
||||||
,TestCase (assertEqual "new function type" (Just ty) (functionType gr2 "foo"))
|
,TestCase (assertEqual "new function type" (Just ty) (functionType gr2 "foo"))
|
||||||
,TestCase (assertEqual "old function prob" (-log 0) (functionProbability gr1 "foo"))
|
,TestCase (assertEqual "old function prob" (-log 0) (functionProbability gr1 "foo"))
|
||||||
@@ -49,3 +48,4 @@ main = do
|
|||||||
if (errors c == 0) && (failures c == 0)
|
if (errors c == 0) && (failures c == 0)
|
||||||
then exitSuccess
|
then exitSuccess
|
||||||
else exitFailure
|
else exitFailure
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ export const runtime = ffi.Library('libpgf', {
|
|||||||
pgf_print_context: [PgfTextPtr, [size_t, PgfTypeHypoPtr, PgfPrintContextPtr, ref.types.int, PgfMarshallerPtr]],
|
pgf_print_context: [PgfTextPtr, [size_t, PgfTypeHypoPtr, PgfPrintContextPtr, ref.types.int, PgfMarshallerPtr]],
|
||||||
pgf_read_type: [PgfType, [PgfTextPtr, PgfUnmarshallerPtr]],
|
pgf_read_type: [PgfType, [PgfTextPtr, PgfUnmarshallerPtr]],
|
||||||
|
|
||||||
pgf_start_transaction: [PgfRevision, [PgfDBPtr, PgfRevision, PgfExnPtr]],
|
pgf_start_transaction: [PgfRevision, [PgfDBPtr, PgfExnPtr]],
|
||||||
pgf_commit_transaction: [ref.types.void, [PgfDBPtr, PgfRevision, PgfExnPtr]],
|
pgf_commit_transaction: [ref.types.void, [PgfDBPtr, PgfRevision, PgfExnPtr]],
|
||||||
pgf_rollback_transaction: [ref.types.void, [PgfDBPtr, PgfRevision]],
|
pgf_rollback_transaction: [ref.types.void, [PgfDBPtr, PgfRevision]],
|
||||||
pgf_checkout_revision: [PgfRevision, [PgfDBPtr, PgfExnPtr]],
|
pgf_checkout_revision: [PgfRevision, [PgfDBPtr, PgfExnPtr]],
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ PGF_newTransaction(PGFObject *self, PyObject *args)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
PgfExn err;
|
PgfExn err;
|
||||||
PgfRevision rev = pgf_start_transaction(self->db, self->revision, &err);
|
PgfRevision rev = pgf_start_transaction(self->db, &err);
|
||||||
if (handleError(err) != PGF_EXN_NONE) {
|
if (handleError(err) != PGF_EXN_NONE) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user