Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SymbolTable's add_symbol Could not get a mutable reference to the symbol table #211

Merged
merged 2 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rustfst-ffi/src/symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub extern "C" fn symt_copy(
) -> RUSTFST_FFI_RESULT {
wrap(|| {
let symt = get!(CSymbolTable, symt);
let clone = symt.clone();
let clone = Arc::new(SymbolTable::clone(symt));
let raw_ptr = CSymbolTable(clone).into_raw_pointer();
unsafe { *cloned_symt = raw_ptr };
Ok(())
Expand Down
11 changes: 11 additions & 0 deletions rustfst-python/tests/test_symt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rustfst import SymbolTable
from rustfst import VectorFst

EPS_SYMBOL = "<eps>"

Expand Down Expand Up @@ -74,3 +75,13 @@ def test_symt_iterator():
symt.add_symbol("b")

assert list(symt) == [(0, "<eps>"), (1, "a"), (2, "b")]


def test_symt_copy_add():
fst = VectorFst()
symt = SymbolTable.from_symbols(["a", "b"])
fst.set_input_symbols(symt)
fst.set_output_symbols(symt)
symt2 = fst.input_symbols().copy()
symt2.add_symbol("c")
assert symt2.num_symbols() == symt.num_symbols() + 1