Show More
@@ -92,7 +92,7 b' py_class!(pub class Dirs |py| {' | |||
|
92 | 92 | }) |
|
93 | 93 | } |
|
94 | 94 | def __iter__(&self) -> PyResult<DirsMultisetKeysIterator> { |
|
95 |
let leaked_ref = self.inner_shared(py).leak_immutable() |
|
|
95 | let leaked_ref = self.inner_shared(py).leak_immutable(); | |
|
96 | 96 | DirsMultisetKeysIterator::from_inner( |
|
97 | 97 | py, |
|
98 | 98 | unsafe { leaked_ref.map(py, |o| o.iter()) }, |
@@ -304,7 +304,7 b' py_class!(pub class DirstateMap |py| {' | |||
|
304 | 304 | } |
|
305 | 305 | |
|
306 | 306 | def keys(&self) -> PyResult<DirstateMapKeysIterator> { |
|
307 |
let leaked_ref = self.inner_shared(py).leak_immutable() |
|
|
307 | let leaked_ref = self.inner_shared(py).leak_immutable(); | |
|
308 | 308 | DirstateMapKeysIterator::from_inner( |
|
309 | 309 | py, |
|
310 | 310 | unsafe { leaked_ref.map(py, |o| o.iter()) }, |
@@ -312,7 +312,7 b' py_class!(pub class DirstateMap |py| {' | |||
|
312 | 312 | } |
|
313 | 313 | |
|
314 | 314 | def items(&self) -> PyResult<DirstateMapItemsIterator> { |
|
315 |
let leaked_ref = self.inner_shared(py).leak_immutable() |
|
|
315 | let leaked_ref = self.inner_shared(py).leak_immutable(); | |
|
316 | 316 | DirstateMapItemsIterator::from_inner( |
|
317 | 317 | py, |
|
318 | 318 | unsafe { leaked_ref.map(py, |o| o.iter()) }, |
@@ -320,7 +320,7 b' py_class!(pub class DirstateMap |py| {' | |||
|
320 | 320 | } |
|
321 | 321 | |
|
322 | 322 | def __iter__(&self) -> PyResult<DirstateMapKeysIterator> { |
|
323 |
let leaked_ref = self.inner_shared(py).leak_immutable() |
|
|
323 | let leaked_ref = self.inner_shared(py).leak_immutable(); | |
|
324 | 324 | DirstateMapKeysIterator::from_inner( |
|
325 | 325 | py, |
|
326 | 326 | unsafe { leaked_ref.map(py, |o| o.iter()) }, |
@@ -437,7 +437,7 b' py_class!(pub class DirstateMap |py| {' | |||
|
437 | 437 | } |
|
438 | 438 | |
|
439 | 439 | def copymapiter(&self) -> PyResult<CopyMapKeysIterator> { |
|
440 |
let leaked_ref = self.inner_shared(py).leak_immutable() |
|
|
440 | let leaked_ref = self.inner_shared(py).leak_immutable(); | |
|
441 | 441 | CopyMapKeysIterator::from_inner( |
|
442 | 442 | py, |
|
443 | 443 | unsafe { leaked_ref.map(py, |o| o.copy_map.iter()) }, |
@@ -445,7 +445,7 b' py_class!(pub class DirstateMap |py| {' | |||
|
445 | 445 | } |
|
446 | 446 | |
|
447 | 447 | def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> { |
|
448 |
let leaked_ref = self.inner_shared(py).leak_immutable() |
|
|
448 | let leaked_ref = self.inner_shared(py).leak_immutable(); | |
|
449 | 449 | CopyMapItemsIterator::from_inner( |
|
450 | 450 | py, |
|
451 | 451 | unsafe { leaked_ref.map(py, |o| o.copy_map.iter()) }, |
@@ -89,10 +89,10 b' impl PySharedState {' | |||
|
89 | 89 | &self, |
|
90 | 90 | _py: Python, |
|
91 | 91 | data: Ref<T>, |
|
92 |
) -> |
|
|
92 | ) -> (&'static T, &'static PySharedState) { | |
|
93 | 93 | let ptr: *const T = &*data; |
|
94 | 94 | let state_ptr: *const PySharedState = self; |
|
95 |
|
|
|
95 | (&*ptr, &*state_ptr) | |
|
96 | 96 | } |
|
97 | 97 | |
|
98 | 98 | fn current_borrow_count(&self, _py: Python) -> usize { |
@@ -208,20 +208,15 b" impl<'a, T> PySharedRef<'a, T> {" | |||
|
208 | 208 | /// # Panics |
|
209 | 209 | /// |
|
210 | 210 | /// Panics if this is mutably borrowed. |
|
211 |
pub fn leak_immutable(&self) -> |
|
|
211 | pub fn leak_immutable(&self) -> PyLeaked<&'static T> { | |
|
212 | 212 | let state = &self.data.py_shared_state; |
|
213 | 213 | // make sure self.data isn't mutably borrowed; otherwise the |
|
214 | 214 | // generation number can't be trusted. |
|
215 | 215 | let data_ref = self.borrow(); |
|
216 | 216 | unsafe { |
|
217 | 217 | let (static_ref, static_state_ref) = |
|
218 |
state.leak_immutable(self.py, data_ref) |
|
|
219 | Ok(PyLeaked::new( | |
|
220 | self.py, | |
|
221 | self.owner, | |
|
222 | static_ref, | |
|
223 | static_state_ref, | |
|
224 | )) | |
|
218 | state.leak_immutable(self.py, data_ref); | |
|
219 | PyLeaked::new(self.py, self.owner, static_ref, static_state_ref) | |
|
225 | 220 | } |
|
226 | 221 | } |
|
227 | 222 | } |
@@ -459,7 +454,7 b" impl<T> DerefMut for PyLeakedRefMut<'_, " | |||
|
459 | 454 | /// data inner: PySharedRefCell<MyStruct>; |
|
460 | 455 | /// |
|
461 | 456 | /// def __iter__(&self) -> PyResult<MyTypeItemsIterator> { |
|
462 |
/// let leaked_ref = self.inner_shared(py).leak_immutable() |
|
|
457 | /// let leaked_ref = self.inner_shared(py).leak_immutable(); | |
|
463 | 458 | /// MyTypeItemsIterator::from_inner( |
|
464 | 459 | /// py, |
|
465 | 460 | /// unsafe { leaked_ref.map(py, |o| o.iter()) }, |
@@ -551,7 +546,7 b' mod test {' | |||
|
551 | 546 | fn test_leaked_borrow() { |
|
552 | 547 | let (gil, owner) = prepare_env(); |
|
553 | 548 | let py = gil.python(); |
|
554 |
let leaked = owner.string_shared(py).leak_immutable() |
|
|
549 | let leaked = owner.string_shared(py).leak_immutable(); | |
|
555 | 550 | let leaked_ref = leaked.try_borrow(py).unwrap(); |
|
556 | 551 | assert_eq!(*leaked_ref, "new"); |
|
557 | 552 | } |
@@ -560,7 +555,7 b' mod test {' | |||
|
560 | 555 | fn test_leaked_borrow_mut() { |
|
561 | 556 | let (gil, owner) = prepare_env(); |
|
562 | 557 | let py = gil.python(); |
|
563 |
let leaked = owner.string_shared(py).leak_immutable() |
|
|
558 | let leaked = owner.string_shared(py).leak_immutable(); | |
|
564 | 559 | let mut leaked_iter = unsafe { leaked.map(py, |s| s.chars()) }; |
|
565 | 560 | let mut leaked_ref = leaked_iter.try_borrow_mut(py).unwrap(); |
|
566 | 561 | assert_eq!(leaked_ref.next(), Some('n')); |
@@ -573,7 +568,7 b' mod test {' | |||
|
573 | 568 | fn test_leaked_borrow_after_mut() { |
|
574 | 569 | let (gil, owner) = prepare_env(); |
|
575 | 570 | let py = gil.python(); |
|
576 |
let leaked = owner.string_shared(py).leak_immutable() |
|
|
571 | let leaked = owner.string_shared(py).leak_immutable(); | |
|
577 | 572 | owner.string_shared(py).borrow_mut().unwrap().clear(); |
|
578 | 573 | assert!(leaked.try_borrow(py).is_err()); |
|
579 | 574 | } |
@@ -582,7 +577,7 b' mod test {' | |||
|
582 | 577 | fn test_leaked_borrow_mut_after_mut() { |
|
583 | 578 | let (gil, owner) = prepare_env(); |
|
584 | 579 | let py = gil.python(); |
|
585 |
let leaked = owner.string_shared(py).leak_immutable() |
|
|
580 | let leaked = owner.string_shared(py).leak_immutable(); | |
|
586 | 581 | let mut leaked_iter = unsafe { leaked.map(py, |s| s.chars()) }; |
|
587 | 582 | owner.string_shared(py).borrow_mut().unwrap().clear(); |
|
588 | 583 | assert!(leaked_iter.try_borrow_mut(py).is_err()); |
@@ -593,7 +588,7 b' mod test {' | |||
|
593 | 588 | fn test_leaked_map_after_mut() { |
|
594 | 589 | let (gil, owner) = prepare_env(); |
|
595 | 590 | let py = gil.python(); |
|
596 |
let leaked = owner.string_shared(py).leak_immutable() |
|
|
591 | let leaked = owner.string_shared(py).leak_immutable(); | |
|
597 | 592 | owner.string_shared(py).borrow_mut().unwrap().clear(); |
|
598 | 593 | let _leaked_iter = unsafe { leaked.map(py, |s| s.chars()) }; |
|
599 | 594 | } |
@@ -603,7 +598,7 b' mod test {' | |||
|
603 | 598 | let (gil, owner) = prepare_env(); |
|
604 | 599 | let py = gil.python(); |
|
605 | 600 | assert!(owner.string_shared(py).borrow_mut().is_ok()); |
|
606 |
let leaked = owner.string_shared(py).leak_immutable() |
|
|
601 | let leaked = owner.string_shared(py).leak_immutable(); | |
|
607 | 602 | { |
|
608 | 603 | let _leaked_ref = leaked.try_borrow(py).unwrap(); |
|
609 | 604 | assert!(owner.string_shared(py).borrow_mut().is_err()); |
@@ -621,7 +616,7 b' mod test {' | |||
|
621 | 616 | let (gil, owner) = prepare_env(); |
|
622 | 617 | let py = gil.python(); |
|
623 | 618 | assert!(owner.string_shared(py).borrow_mut().is_ok()); |
|
624 |
let leaked = owner.string_shared(py).leak_immutable() |
|
|
619 | let leaked = owner.string_shared(py).leak_immutable(); | |
|
625 | 620 | let mut leaked_iter = unsafe { leaked.map(py, |s| s.chars()) }; |
|
626 | 621 | { |
|
627 | 622 | let _leaked_ref = leaked_iter.try_borrow_mut(py).unwrap(); |
@@ -636,6 +631,6 b' mod test {' | |||
|
636 | 631 | let (gil, owner) = prepare_env(); |
|
637 | 632 | let py = gil.python(); |
|
638 | 633 | let _mut_ref = owner.string_shared(py).borrow_mut(); |
|
639 |
|
|
|
634 | owner.string_shared(py).leak_immutable(); | |
|
640 | 635 | } |
|
641 | 636 | } |
General Comments 0
You need to be logged in to leave comments.
Login now