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

Method hash

crates/vm/src/builtins/weakref.rs:95–116  ·  view source on GitHub ↗
(zelf: &Py<Self>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

93
94impl Hashable for PyWeak {
95 fn hash(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyHash> {
96 let hash = match zelf.hash.load(Ordering::Relaxed) {
97 hash::SENTINEL => {
98 let obj = zelf
99 .upgrade()
100 .ok_or_else(|| vm.new_type_error("weak object has gone away"))?;
101 let hash = obj.hash(vm)?;
102 match Radium::compare_exchange(
103 &zelf.hash,
104 hash::SENTINEL,
105 hash::fix_sentinel(hash),
106 Ordering::Relaxed,
107 Ordering::Relaxed,
108 ) {
109 Ok(_) => hash,
110 Err(prev_stored) => prev_stored,
111 }
112 }
113 hash => hash,
114 };
115 Ok(hash)
116 }
117}
118
119impl Comparable for PyWeak {

Callers

nothing calls this directly

Calls 4

fix_sentinelFunction · 0.85
ok_or_elseMethod · 0.80
loadMethod · 0.45
upgradeMethod · 0.45

Tested by

no test coverage detected