Mercurial > hg
comparison rust/hg-cpython/src/dirstate/dirstate_map.rs @ 43284:ce6dd1cee4c8
rust-cpython: put leaked reference in PyLeakedRef
The next patch will make PyLeakedRef manage the lifetime of the underlying
object. leak_handle.data.take() will be removed soon.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 15 Sep 2019 22:06:19 +0900 |
parents | 478d0b1bf0c5 |
children | ffc1fbd7d1f5 |
comparison
equal
deleted
inserted
replaced
43283:96eb9ef777a8 | 43284:ce6dd1cee4c8 |
---|---|
302 )), | 302 )), |
303 } | 303 } |
304 } | 304 } |
305 | 305 |
306 def keys(&self) -> PyResult<DirstateMapKeysIterator> { | 306 def keys(&self) -> PyResult<DirstateMapKeysIterator> { |
307 let (leak_handle, leaked_ref) = | 307 let mut leak_handle = |
308 unsafe { self.inner_shared(py).leak_immutable()? }; | 308 unsafe { self.inner_shared(py).leak_immutable()? }; |
309 let leaked_ref = leak_handle.data.take().unwrap(); | |
309 DirstateMapKeysIterator::from_inner( | 310 DirstateMapKeysIterator::from_inner( |
310 py, | 311 py, |
311 leak_handle, | 312 leak_handle, |
312 leaked_ref.iter(), | 313 leaked_ref.iter(), |
313 ) | 314 ) |
314 } | 315 } |
315 | 316 |
316 def items(&self) -> PyResult<DirstateMapItemsIterator> { | 317 def items(&self) -> PyResult<DirstateMapItemsIterator> { |
317 let (leak_handle, leaked_ref) = | 318 let mut leak_handle = |
318 unsafe { self.inner_shared(py).leak_immutable()? }; | 319 unsafe { self.inner_shared(py).leak_immutable()? }; |
320 let leaked_ref = leak_handle.data.take().unwrap(); | |
319 DirstateMapItemsIterator::from_inner( | 321 DirstateMapItemsIterator::from_inner( |
320 py, | 322 py, |
321 leak_handle, | 323 leak_handle, |
322 leaked_ref.iter(), | 324 leaked_ref.iter(), |
323 ) | 325 ) |
324 } | 326 } |
325 | 327 |
326 def __iter__(&self) -> PyResult<DirstateMapKeysIterator> { | 328 def __iter__(&self) -> PyResult<DirstateMapKeysIterator> { |
327 let (leak_handle, leaked_ref) = | 329 let mut leak_handle = |
328 unsafe { self.inner_shared(py).leak_immutable()? }; | 330 unsafe { self.inner_shared(py).leak_immutable()? }; |
331 let leaked_ref = leak_handle.data.take().unwrap(); | |
329 DirstateMapKeysIterator::from_inner( | 332 DirstateMapKeysIterator::from_inner( |
330 py, | 333 py, |
331 leak_handle, | 334 leak_handle, |
332 leaked_ref.iter(), | 335 leaked_ref.iter(), |
333 ) | 336 ) |
441 None => Ok(default), | 444 None => Ok(default), |
442 } | 445 } |
443 } | 446 } |
444 | 447 |
445 def copymapiter(&self) -> PyResult<CopyMapKeysIterator> { | 448 def copymapiter(&self) -> PyResult<CopyMapKeysIterator> { |
446 let (leak_handle, leaked_ref) = | 449 let mut leak_handle = |
447 unsafe { self.inner_shared(py).leak_immutable()? }; | 450 unsafe { self.inner_shared(py).leak_immutable()? }; |
451 let leaked_ref = leak_handle.data.take().unwrap(); | |
448 CopyMapKeysIterator::from_inner( | 452 CopyMapKeysIterator::from_inner( |
449 py, | 453 py, |
450 leak_handle, | 454 leak_handle, |
451 leaked_ref.copy_map.iter(), | 455 leaked_ref.copy_map.iter(), |
452 ) | 456 ) |
453 } | 457 } |
454 | 458 |
455 def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> { | 459 def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> { |
456 let (leak_handle, leaked_ref) = | 460 let mut leak_handle = |
457 unsafe { self.inner_shared(py).leak_immutable()? }; | 461 unsafe { self.inner_shared(py).leak_immutable()? }; |
462 let leaked_ref = leak_handle.data.take().unwrap(); | |
458 CopyMapItemsIterator::from_inner( | 463 CopyMapItemsIterator::from_inner( |
459 py, | 464 py, |
460 leak_handle, | 465 leak_handle, |
461 leaked_ref.copy_map.iter(), | 466 leaked_ref.copy_map.iter(), |
462 ) | 467 ) |
491 | 496 |
492 py_shared_ref!(DirstateMap, RustDirstateMap, inner, inner_shared); | 497 py_shared_ref!(DirstateMap, RustDirstateMap, inner, inner_shared); |
493 | 498 |
494 py_shared_iterator!( | 499 py_shared_iterator!( |
495 DirstateMapKeysIterator, | 500 DirstateMapKeysIterator, |
496 PyLeakedRef, | 501 PyLeakedRef<&'static RustDirstateMap>, |
497 StateMapIter<'static>, | 502 StateMapIter<'static>, |
498 DirstateMap::translate_key, | 503 DirstateMap::translate_key, |
499 Option<PyBytes> | 504 Option<PyBytes> |
500 ); | 505 ); |
501 | 506 |
502 py_shared_iterator!( | 507 py_shared_iterator!( |
503 DirstateMapItemsIterator, | 508 DirstateMapItemsIterator, |
504 PyLeakedRef, | 509 PyLeakedRef<&'static RustDirstateMap>, |
505 StateMapIter<'static>, | 510 StateMapIter<'static>, |
506 DirstateMap::translate_key_value, | 511 DirstateMap::translate_key_value, |
507 Option<(PyBytes, PyObject)> | 512 Option<(PyBytes, PyObject)> |
508 ); | 513 ); |
509 | 514 |