[PATCH 5 of 6] rust-cpython: switch to upstreamed version of PySharedRefCell

Yuya Nishihara yuya at tcha.org
Thu Jan 30 11:22:19 EST 2020


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1579940783 -32400
#      Sat Jan 25 17:26:23 2020 +0900
# Node ID daf8dc5bb62f80794c12ddaede649d73cc4a4f33
# Parent  641a0f64ae5a289a476dceac692ecf7d665b6ff3
rust-cpython: switch to upstreamed version of PySharedRefCell

Our PyLeaked is identical to cpython::UnsafePyLeaked. I've renamed it because
it provides mostly unsafe functions.

diff --git a/rust/hg-cpython/src/dirstate/copymap.rs b/rust/hg-cpython/src/dirstate/copymap.rs
--- a/rust/hg-cpython/src/dirstate/copymap.rs
+++ b/rust/hg-cpython/src/dirstate/copymap.rs
@@ -8,11 +8,12 @@
 //! Bindings for `hg::dirstate::dirstate_map::CopyMap` provided by the
 //! `hg-core` package.
 
-use cpython::{PyBytes, PyClone, PyDict, PyObject, PyResult, Python};
+use cpython::{
+    PyBytes, PyClone, PyDict, PyObject, PyResult, Python, UnsafePyLeaked,
+};
 use std::cell::RefCell;
 
 use crate::dirstate::dirstate_map::DirstateMap;
-use crate::ref_sharing::PyLeaked;
 use hg::{utils::hg_path::HgPathBuf, CopyMapIter};
 
 py_class!(pub class CopyMap |py| {
@@ -104,14 +105,14 @@ impl CopyMap {
 
 py_shared_iterator!(
     CopyMapKeysIterator,
-    PyLeaked<CopyMapIter<'static>>,
+    UnsafePyLeaked<CopyMapIter<'static>>,
     CopyMap::translate_key,
     Option<PyBytes>
 );
 
 py_shared_iterator!(
     CopyMapItemsIterator,
-    PyLeaked<CopyMapIter<'static>>,
+    UnsafePyLeaked<CopyMapIter<'static>>,
     CopyMap::translate_key_value,
     Option<(PyBytes, PyBytes)>
 );
diff --git a/rust/hg-cpython/src/dirstate/dirs_multiset.rs b/rust/hg-cpython/src/dirstate/dirs_multiset.rs
--- a/rust/hg-cpython/src/dirstate/dirs_multiset.rs
+++ b/rust/hg-cpython/src/dirstate/dirs_multiset.rs
@@ -13,11 +13,10 @@ use std::convert::TryInto;
 
 use cpython::{
     exc, ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyObject, PyResult,
-    Python,
+    Python, UnsafePyLeaked,
 };
 
 use crate::dirstate::extract_dirstate;
-use crate::ref_sharing::{PyLeaked, PySharedRefCell};
 use hg::{
     utils::hg_path::{HgPath, HgPathBuf},
     DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError,
@@ -25,7 +24,7 @@ use hg::{
 };
 
 py_class!(pub class Dirs |py| {
-    data inner_: PySharedRefCell<DirsMultiset>;
+    @shared data inner: DirsMultiset;
 
     // `map` is either a `dict` or a flat iterator (usually a `set`, sometimes
     // a `list`)
@@ -65,10 +64,7 @@ py_class!(pub class Dirs |py| {
                 })?
         };
 
-        Self::create_instance(
-            py,
-            PySharedRefCell::new(inner),
-        )
+        Self::create_instance(py, inner)
     }
 
     def addpath(&self, path: PyObject) -> PyResult<PyObject> {
@@ -123,11 +119,9 @@ py_class!(pub class Dirs |py| {
     }
 });
 
-py_shared_ref!(Dirs, DirsMultiset, inner_, inner);
-
 impl Dirs {
     pub fn from_inner(py: Python, d: DirsMultiset) -> PyResult<Self> {
-        Self::create_instance(py, PySharedRefCell::new(d))
+        Self::create_instance(py, d)
     }
 
     fn translate_key(
@@ -140,7 +134,7 @@ impl Dirs {
 
 py_shared_iterator!(
     DirsMultisetKeysIterator,
-    PyLeaked<DirsMultisetIter<'static>>,
+    UnsafePyLeaked<DirsMultisetIter<'static>>,
     Dirs::translate_key,
     Option<PyBytes>
 );
diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs b/rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs
@@ -14,13 +14,12 @@ use std::time::Duration;
 
 use cpython::{
     exc, ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyObject,
-    PyResult, PyTuple, Python, PythonObject, ToPyObject,
+    PyResult, PyTuple, Python, PythonObject, ToPyObject, UnsafePyLeaked,
 };
 
 use crate::{
     dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator},
     dirstate::{dirs_multiset::Dirs, make_dirstate_tuple},
-    ref_sharing::{PyLeaked, PySharedRefCell},
 };
 use hg::{
     utils::hg_path::{HgPath, HgPathBuf},
@@ -42,14 +41,11 @@ use hg::{
 //     All attributes also have to have a separate refcount data attribute for
 //     leaks, with all methods that go along for reference sharing.
 py_class!(pub class DirstateMap |py| {
-    data inner_: PySharedRefCell<RustDirstateMap>;
+    @shared data inner: RustDirstateMap;
 
     def __new__(_cls, _root: PyObject) -> PyResult<Self> {
         let inner = RustDirstateMap::default();
-        Self::create_instance(
-            py,
-            PySharedRefCell::new(inner),
-        )
+        Self::create_instance(py, inner)
     }
 
     def clear(&self) -> PyResult<PyObject> {
@@ -497,18 +493,16 @@ impl DirstateMap {
     }
 }
 
-py_shared_ref!(DirstateMap, RustDirstateMap, inner_, inner);
-
 py_shared_iterator!(
     DirstateMapKeysIterator,
-    PyLeaked<StateMapIter<'static>>,
+    UnsafePyLeaked<StateMapIter<'static>>,
     DirstateMap::translate_key,
     Option<PyBytes>
 );
 
 py_shared_iterator!(
     DirstateMapItemsIterator,
-    PyLeaked<StateMapIter<'static>>,
+    UnsafePyLeaked<StateMapIter<'static>>,
     DirstateMap::translate_key_value,
     Option<(PyBytes, PyObject)>
 );


More information about the Mercurial-devel mailing list