MCPcopy Index your code
hub / github.com/RustPython/RustPython / upgrade

Method upgrade

crates/vm/src/object/core.rs:829–849  ·  view source on GitHub ↗

_PyWeakref_GET_REF: attempt to upgrade the weakref to a strong reference.

(&self)

Source from the content-addressed store, hash-verified

827impl PyWeak {
828 /// _PyWeakref_GET_REF: attempt to upgrade the weakref to a strong reference.
829 pub(crate) fn upgrade(&self) -> Option<PyObjectRef> {
830 let obj_ptr = self.wr_object.load(Ordering::Acquire);
831 if obj_ptr.is_null() {
832 return None;
833 }
834
835 let _lock = weakref_lock::lock(obj_ptr as usize);
836
837 // Double-check under lock (clear may have run between our check and lock)
838 let obj_ptr = self.wr_object.load(Ordering::Relaxed);
839 if obj_ptr.is_null() {
840 return None;
841 }
842
843 unsafe {
844 if !(*obj_ptr).0.ref_count.safe_inc() {
845 return None;
846 }
847 Some(PyObjectRef::from_raw(NonNull::new_unchecked(obj_ptr)))
848 }
849 }
850
851 pub(crate) fn is_dead(&self) -> bool {
852 self.wr_object.load(Ordering::Acquire).is_null()

Callers 15

newMethod · 0.45
thenMethod · 0.45
py_to_jsFunction · 0.45
request_animation_frameFunction · 0.45
load_moduleFunction · 0.45
_servername_callbackFunction · 0.45
_msg_callbackFunction · 0.45
ownerMethod · 0.45
update_subclassesMethod · 0.45
is_currentMethod · 0.45
_shutdownFunction · 0.45

Calls 5

lockFunction · 0.85
safe_incMethod · 0.80
SomeClass · 0.50
loadMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected