Show More
@@ -86,10 +86,11 b' py_class!(pub class Dirs |py| {' | |||
|
86 | 86 | }) |
|
87 | 87 | } |
|
88 | 88 | def __iter__(&self) -> PyResult<DirsMultisetKeysIterator> { |
|
89 | let (leak_handle, leaked_ref) = self.leak_immutable(py)?; | |
|
89 | 90 | DirsMultisetKeysIterator::create_instance( |
|
90 | 91 | py, |
|
91 |
RefCell::new(Some( |
|
|
92 |
RefCell::new(Box::new( |
|
|
92 | RefCell::new(Some(leak_handle)), | |
|
93 | RefCell::new(Box::new(leaked_ref.iter())), | |
|
93 | 94 | ) |
|
94 | 95 | } |
|
95 | 96 |
@@ -319,26 +319,29 b' py_class!(pub class DirstateMap |py| {' | |||
|
319 | 319 | } |
|
320 | 320 | |
|
321 | 321 | def keys(&self) -> PyResult<DirstateMapKeysIterator> { |
|
322 | let (leak_handle, leaked_ref) = self.leak_immutable(py)?; | |
|
322 | 323 | DirstateMapKeysIterator::from_inner( |
|
323 | 324 | py, |
|
324 | Some(DirstateMapLeakedRef::new(py, &self)), | |
|
325 |
Box::new( |
|
|
325 | Some(leak_handle), | |
|
326 | Box::new(leaked_ref.iter()), | |
|
326 | 327 | ) |
|
327 | 328 | } |
|
328 | 329 | |
|
329 | 330 | def items(&self) -> PyResult<DirstateMapItemsIterator> { |
|
331 | let (leak_handle, leaked_ref) = self.leak_immutable(py)?; | |
|
330 | 332 | DirstateMapItemsIterator::from_inner( |
|
331 | 333 | py, |
|
332 | Some(DirstateMapLeakedRef::new(py, &self)), | |
|
333 |
Box::new( |
|
|
334 | Some(leak_handle), | |
|
335 | Box::new(leaked_ref.iter()), | |
|
334 | 336 | ) |
|
335 | 337 | } |
|
336 | 338 | |
|
337 | 339 | def __iter__(&self) -> PyResult<DirstateMapKeysIterator> { |
|
340 | let (leak_handle, leaked_ref) = self.leak_immutable(py)?; | |
|
338 | 341 | DirstateMapKeysIterator::from_inner( |
|
339 | 342 | py, |
|
340 | Some(DirstateMapLeakedRef::new(py, &self)), | |
|
341 |
Box::new( |
|
|
343 | Some(leak_handle), | |
|
344 | Box::new(leaked_ref.iter()), | |
|
342 | 345 | ) |
|
343 | 346 | } |
|
344 | 347 | |
@@ -431,18 +434,20 b' py_class!(pub class DirstateMap |py| {' | |||
|
431 | 434 | } |
|
432 | 435 | |
|
433 | 436 | def copymapiter(&self) -> PyResult<CopyMapKeysIterator> { |
|
437 | let (leak_handle, leaked_ref) = self.leak_immutable(py)?; | |
|
434 | 438 | CopyMapKeysIterator::from_inner( |
|
435 | 439 | py, |
|
436 | Some(DirstateMapLeakedRef::new(py, &self)), | |
|
437 |
Box::new( |
|
|
440 | Some(leak_handle), | |
|
441 | Box::new(leaked_ref.copy_map.iter()), | |
|
438 | 442 | ) |
|
439 | 443 | } |
|
440 | 444 | |
|
441 | 445 | def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> { |
|
446 | let (leak_handle, leaked_ref) = self.leak_immutable(py)?; | |
|
442 | 447 | CopyMapItemsIterator::from_inner( |
|
443 | 448 | py, |
|
444 | Some(DirstateMapLeakedRef::new(py, &self)), | |
|
445 |
Box::new( |
|
|
449 | Some(leak_handle), | |
|
450 | Box::new(leaked_ref.copy_map.iter()), | |
|
446 | 451 | ) |
|
447 | 452 | } |
|
448 | 453 |
@@ -216,14 +216,24 b' macro_rules! py_shared_ref {' | |||
|
216 | 216 | .borrow_mut(py, unsafe { data.borrow_mut() }) |
|
217 | 217 | } |
|
218 | 218 | |
|
219 | /// Returns a leaked reference and its management object. | |
|
220 | /// | |
|
221 | /// # Safety | |
|
222 | /// | |
|
223 | /// It's up to you to make sure that the management object lives | |
|
224 | /// longer than the leaked reference. Otherwise, you'll get a | |
|
225 | /// dangling reference. | |
|
219 | 226 | fn leak_immutable<'a>( |
|
220 | 227 | &'a self, |
|
221 | 228 | py: Python<'a>, |
|
222 | ) -> PyResult<&'static $inner_struct> { | |
|
229 | ) -> PyResult<($leaked, &'static $inner_struct)> { | |
|
223 | 230 | // assert $data_member type |
|
224 | 231 | use crate::ref_sharing::PySharedRefCell; |
|
225 | 232 | let data: &PySharedRefCell<_> = self.$data_member(py); |
|
226 | self.py_shared_state(py).leak_immutable(py, data) | |
|
233 | let static_ref = | |
|
234 | self.py_shared_state(py).leak_immutable(py, data)?; | |
|
235 | let leak_handle = $leaked::new(py, self); | |
|
236 | Ok((leak_handle, static_ref)) | |
|
227 | 237 | } |
|
228 | 238 | } |
|
229 | 239 | |
@@ -336,10 +346,11 b' macro_rules! py_shared_iterator_impl {' | |||
|
336 | 346 | /// data py_shared_state: PySharedState; |
|
337 | 347 | /// |
|
338 | 348 | /// def __iter__(&self) -> PyResult<MyTypeItemsIterator> { |
|
349 | /// let (leak_handle, leaked_ref) = self.leak_immutable(py)?; | |
|
339 | 350 | /// MyTypeItemsIterator::create_instance( |
|
340 | 351 | /// py, |
|
341 |
/// RefCell::new(Some( |
|
|
342 |
/// RefCell::new( |
|
|
352 | /// RefCell::new(Some(leak_handle)), | |
|
353 | /// RefCell::new(leaked_ref.iter()), | |
|
343 | 354 | /// ) |
|
344 | 355 | /// } |
|
345 | 356 | /// }); |
General Comments 0
You need to be logged in to leave comments.
Login now