comparison rust/hg-cpython/src/dirstate/dirs_multiset.rs @ 43177:5cb8867c9e2b

rust-cpython: move $leaked struct out of macro It wasn't easy to hack the $leaked struct since errors in macro would generate lots of compile errors. Let's make it a plain struct so we can easily extend it. PyLeakedRef keeps a more generic PyObject instead of the $name struct since it no longer has to call any specific methods implemented by the $name class. $leaked parameter in py_shared_iterator!() is kept for future change.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 08 Sep 2019 20:26:55 +0900
parents 070a38737334
children 1b2200bd06b6
comparison
equal deleted inserted replaced
43176:aaec70a5f9a8 43177:5cb8867c9e2b
14 use cpython::{ 14 use cpython::{
15 exc, ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyObject, PyResult, 15 exc, ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyObject, PyResult,
16 Python, 16 Python,
17 }; 17 };
18 18
19 use crate::{dirstate::extract_dirstate, ref_sharing::PySharedRefCell}; 19 use crate::dirstate::extract_dirstate;
20 use crate::ref_sharing::{PyLeakedRef, PySharedRefCell};
20 use hg::{ 21 use hg::{
21 utils::hg_path::{HgPath, HgPathBuf}, 22 utils::hg_path::{HgPath, HgPathBuf},
22 DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError, 23 DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError,
23 EntryState, 24 EntryState,
24 }; 25 };
104 item.extract::<PyBytes>(py)?.data(py).as_ref(), 105 item.extract::<PyBytes>(py)?.data(py).as_ref(),
105 ))) 106 )))
106 } 107 }
107 }); 108 });
108 109
109 py_shared_ref!(Dirs, DirsMultiset, inner, DirsMultisetLeakedRef,); 110 py_shared_ref!(Dirs, DirsMultiset, inner);
110 111
111 impl Dirs { 112 impl Dirs {
112 pub fn from_inner(py: Python, d: DirsMultiset) -> PyResult<Self> { 113 pub fn from_inner(py: Python, d: DirsMultiset) -> PyResult<Self> {
113 Self::create_instance(py, PySharedRefCell::new(d)) 114 Self::create_instance(py, PySharedRefCell::new(d))
114 } 115 }
121 } 122 }
122 } 123 }
123 124
124 py_shared_iterator!( 125 py_shared_iterator!(
125 DirsMultisetKeysIterator, 126 DirsMultisetKeysIterator,
126 DirsMultisetLeakedRef, 127 PyLeakedRef,
127 DirsMultisetIter<'static>, 128 DirsMultisetIter<'static>,
128 Dirs::translate_key, 129 Dirs::translate_key,
129 Option<PyBytes> 130 Option<PyBytes>
130 ); 131 );