Anki/rslib/src
Aleksa Sarai 312393e825
rs: remove most &mut references in BackendService
The previous implementation had some slightly questionable memory safety
properties (older versions of PyO3 didn't uphold the Rust aliasing rules
and would thus create multiple &mut references to #[pyclass] objects).
This explains why Backend has internal Mutex<T>s even though all of its
methods took &mut self.

The solution is to simply make all methods take &self, which luckily
doesn't pose too make issues -- most of the code inside Backend already
has sufficient locking. The only two things which needed to be
explicitly handled where:

1. "self.runtime" which was fairly easy to handle. All usages of
   the Runtime only require an immutable reference to create a new
   Handle, so we could switch to OnceCell which provides
   lazy-initialisation semantics without needing a more heavy-handed
   Mutex<tokio::runtime::Handle>.

2. "self.sync_abort" was simply wrapped in a Mutex<>, though some of the
   odd semantics of sync_abort (not being able to handle multiple
   processes synchronising at the same time) become pretty obvious with
   this change (for now we just log a warning in that case). In
   addition, switch to an RAII-style guard to make sure we don't forget
   to clear the abort_handle.

As a result, we now no longer break Rust's aliasing rules and we can
build with newer versions of PyO3 which have runtime checks for these
things (and build on stable Rust).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2020-09-05 19:37:59 +10:00
..
backend rs: remove most &mut references in BackendService 2020-09-05 19:37:59 +10:00
deckconf move bury/suspend into backend 2020-09-01 10:24:38 +10:00
decks set_deck() 2020-09-03 17:42:46 +10:00
i18n get i18n working in typescript 2020-06-29 15:48:01 +10:00
media handle quoted html chars in media check 2020-09-04 09:36:38 +10:00
notetype rename some card+note fields in backend 2020-09-01 10:24:38 +10:00
sched set_deck() 2020-09-03 17:42:46 +10:00
search set_deck() 2020-09-03 17:42:46 +10:00
stats move card sorting and resetting to backend 2020-09-03 15:54:15 +10:00
storage set_deck() 2020-09-03 17:42:46 +10:00
sync rename some card+note fields in backend 2020-09-01 10:24:38 +10:00
card.rs set_deck() 2020-09-03 17:42:46 +10:00
cloze.rs handle multiple clozes in cloze-only filter 2020-07-29 12:54:29 +10:00
collection.rs on upgrade, mark decks modified that are renamed 2020-06-14 14:48:58 +10:00
config.rs move card sorting and resetting to backend 2020-09-03 15:54:15 +10:00
dbcheck.rs rename some card+note fields in backend 2020-09-01 10:24:38 +10:00
err.rs catch timeout error 2020-08-21 19:03:23 +10:00
filtered.rs set_deck() 2020-09-03 17:42:46 +10:00
findreplace.rs fix some clippy lints 2020-08-26 19:02:56 +10:00
latex.rs expand clozes before rendering LaTeX 2020-02-24 18:34:08 +10:00
lib.rs set_deck() 2020-09-03 17:42:46 +10:00
log.rs skip terminal logging unless LOGTERM defined 2020-04-07 10:25:47 +10:00
notes.rs rename some card+note fields in backend 2020-09-01 10:24:38 +10:00
preferences.rs set local offset when saving preferences 2020-09-03 12:43:18 +10:00
prelude.rs migrate card stats to backend 2020-06-15 17:22:16 +10:00
revlog.rs log manual reschedule, but ignore the log entry in the stats 2020-09-02 17:56:23 +10:00
serde.rs handle negative review times in sync 2020-08-07 15:02:03 +10:00
tags.rs fix unanchored regex in bulk tag add routine 2020-08-28 16:21:23 -05:00
template.rs fix some clippy lints 2020-08-26 19:02:56 +10:00
template_filters.rs add cloze-only filter 2020-07-21 12:59:28 +10:00
text.rs handle quoted html chars in media check 2020-09-04 09:36:38 +10:00
timestamp.rs log manual reschedule, but ignore the log entry in the stats 2020-09-02 17:56:23 +10:00
types.rs add note/card removal to backend 2020-06-04 18:21:04 +10:00
undo.rs move unbury/unsuspend routines into backend 2020-09-01 10:24:38 +10:00
version.rs add platform version back into sync metadata 2020-07-16 10:12:41 +10:00