Patchwork [7,of,7] rust-cpython: leverage py_shared_iterator::from_inner() where appropriate

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 8, 2019, 10:05 a.m.
Message ID <8174e0c96c14e5b5e230.1567937147@mimosa>
Download mbox | patch
Permalink /patch/41577/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 8, 2019, 10:05 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1567916635 -32400
#      Sun Sep 08 13:23:55 2019 +0900
# Node ID 8174e0c96c14e5b5e2309a9de1a90b7c446b5aab
# Parent  1fa833aa2e43f6b3055d618755f10daeefacb0ae
rust-cpython: leverage py_shared_iterator::from_inner() where appropriate
Raphaël Gomès - Sept. 9, 2019, 1:59 p.m.
Looking back, my initial macro was a bit over-engineered, the concrete 
types should be an improvement to maintainability, since they're 
restricted to one `py_class!`.

This whole series looks good to me, thanks a lot.

On 9/8/19 12:05 PM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1567916635 -32400
> #      Sun Sep 08 13:23:55 2019 +0900
> # Node ID 8174e0c96c14e5b5e2309a9de1a90b7c446b5aab
> # Parent  1fa833aa2e43f6b3055d618755f10daeefacb0ae
> rust-cpython: leverage py_shared_iterator::from_inner() where appropriate
>
> 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
> @@ -90,10 +90,10 @@ py_class!(pub class Dirs |py| {
>       }
>       def __iter__(&self) -> PyResult<DirsMultisetKeysIterator> {
>           let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? };
> -        DirsMultisetKeysIterator::create_instance(
> +        DirsMultisetKeysIterator::from_inner(
>               py,
> -            RefCell::new(Some(leak_handle)),
> -            RefCell::new(leaked_ref.iter()),
> +            leak_handle,
> +            leaked_ref.iter(),
>           )
>       }
>   
> diff --git a/rust/hg-cpython/src/ref_sharing.rs b/rust/hg-cpython/src/ref_sharing.rs
> --- a/rust/hg-cpython/src/ref_sharing.rs
> +++ b/rust/hg-cpython/src/ref_sharing.rs
> @@ -309,10 +309,10 @@ macro_rules! py_shared_ref {
>   ///
>   ///     def __iter__(&self) -> PyResult<MyTypeItemsIterator> {
>   ///         let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? };
> -///         MyTypeItemsIterator::create_instance(
> +///         MyTypeItemsIterator::from_inner(
>   ///             py,
> -///             RefCell::new(Some(leak_handle)),
> -///             RefCell::new(leaked_ref.iter()),
> +///             leak_handle,
> +///             leaked_ref.iter(),
>   ///         )
>   ///     }
>   /// });
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Augie Fackler - Sept. 9, 2019, 2:57 p.m.
On Mon, Sep 09, 2019 at 03:59:56PM +0200, Raphaël Gomès wrote:
> Looking back, my initial macro was a bit over-engineered, the concrete types
> should be an improvement to maintainability, since they're restricted to one
> `py_class!`.
>
> This whole series looks good to me, thanks a lot.
>
> On 9/8/19 12:05 PM, Yuya Nishihara wrote:
> > # HG changeset patch
> > # User Yuya Nishihara <yuya@tcha.org>
> > # Date 1567916635 -32400
> > #      Sun Sep 08 13:23:55 2019 +0900
> > # Node ID 8174e0c96c14e5b5e2309a9de1a90b7c446b5aab
> > # Parent  1fa833aa2e43f6b3055d618755f10daeefacb0ae
> > rust-cpython: leverage py_shared_iterator::from_inner() where appropriate

queued per Raphael's review, thanks

Patch

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
@@ -90,10 +90,10 @@  py_class!(pub class Dirs |py| {
     }
     def __iter__(&self) -> PyResult<DirsMultisetKeysIterator> {
         let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? };
-        DirsMultisetKeysIterator::create_instance(
+        DirsMultisetKeysIterator::from_inner(
             py,
-            RefCell::new(Some(leak_handle)),
-            RefCell::new(leaked_ref.iter()),
+            leak_handle,
+            leaked_ref.iter(),
         )
     }
 
diff --git a/rust/hg-cpython/src/ref_sharing.rs b/rust/hg-cpython/src/ref_sharing.rs
--- a/rust/hg-cpython/src/ref_sharing.rs
+++ b/rust/hg-cpython/src/ref_sharing.rs
@@ -309,10 +309,10 @@  macro_rules! py_shared_ref {
 ///
 ///     def __iter__(&self) -> PyResult<MyTypeItemsIterator> {
 ///         let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? };
-///         MyTypeItemsIterator::create_instance(
+///         MyTypeItemsIterator::from_inner(
 ///             py,
-///             RefCell::new(Some(leak_handle)),
-///             RefCell::new(leaked_ref.iter()),
+///             leak_handle,
+///             leaked_ref.iter(),
 ///         )
 ///     }
 /// });