Mercurial > hg-stable
changeset 42943:06080afd0565
rust-cpython: add sanity check to PySharedState::decrease_leak_count()
If decrease_leak_count() were called unnecessarily, there must be a serious
bug. It's better to not silently ignore such cases.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 15 Sep 2019 22:43:32 +0900 |
parents | a2dffe68b4ea |
children | c04e0836f039 |
files | rust/hg-cpython/src/ref_sharing.rs |
diffstat | 1 files changed, 6 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-cpython/src/ref_sharing.rs Sat Sep 14 12:11:03 2019 -0400 +++ b/rust/hg-cpython/src/ref_sharing.rs Sun Sep 15 22:43:32 2019 +0900 @@ -85,10 +85,14 @@ /// It's unsafe to update the reference count without knowing the /// reference is deleted. Do not call this function directly. pub unsafe fn decrease_leak_count(&self, _py: Python, mutable: bool) { - self.leak_count - .replace(self.leak_count.get().saturating_sub(1)); if mutable { + assert_eq!(self.leak_count.get(), 0); + assert!(self.mutably_borrowed.get()); self.mutably_borrowed.replace(false); + } else { + let count = self.leak_count.get(); + assert!(count > 0); + self.leak_count.replace(count - 1); } } }