Patchwork [6,of,7] rust-cpython: remove Option<_> from interface of py_shared_iterator

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

Comments

Yuya Nishihara - Sept. 8, 2019, 10:05 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1567915739 -32400
#      Sun Sep 08 13:08:59 2019 +0900
# Node ID 1fa833aa2e43f6b3055d618755f10daeefacb0ae
# Parent  d242b7375817f26ace0196768df8956033396903
rust-cpython: remove Option<_> from interface of py_shared_iterator

It's the implementation detail of the py_shared_iterator that the leaked
reference is kept in Option<_> so that it can be dropped early.

Patch

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
@@ -323,7 +323,7 @@  py_class!(pub class DirstateMap |py| {
         let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? };
         DirstateMapKeysIterator::from_inner(
             py,
-            Some(leak_handle),
+            leak_handle,
             leaked_ref.iter(),
         )
     }
@@ -332,7 +332,7 @@  py_class!(pub class DirstateMap |py| {
         let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? };
         DirstateMapItemsIterator::from_inner(
             py,
-            Some(leak_handle),
+            leak_handle,
             leaked_ref.iter(),
         )
     }
@@ -341,7 +341,7 @@  py_class!(pub class DirstateMap |py| {
         let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? };
         DirstateMapKeysIterator::from_inner(
             py,
-            Some(leak_handle),
+            leak_handle,
             leaked_ref.iter(),
         )
     }
@@ -438,7 +438,7 @@  py_class!(pub class DirstateMap |py| {
         let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? };
         CopyMapKeysIterator::from_inner(
             py,
-            Some(leak_handle),
+            leak_handle,
             leaked_ref.copy_map.iter(),
         )
     }
@@ -447,7 +447,7 @@  py_class!(pub class DirstateMap |py| {
         let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? };
         CopyMapItemsIterator::from_inner(
             py,
-            Some(leak_handle),
+            leak_handle,
             leaked_ref.copy_map.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
@@ -378,12 +378,12 @@  macro_rules! py_shared_iterator {
         impl $name {
             pub fn from_inner(
                 py: Python,
-                leaked: Option<$leaked>,
+                leaked: $leaked,
                 it: $iterator_type
             ) -> PyResult<Self> {
                 Self::create_instance(
                     py,
-                    RefCell::new(leaked),
+                    RefCell::new(Some(leaked)),
                     RefCell::new(it)
                 )
             }