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

Method to_pyobj

crates/vm/src/object/core.rs:1929–1938  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1927 /// * If **owned** → reconstructs `PyObjectRef` from the raw pointer, forgets self.
1928 #[inline(always)]
1929 pub fn to_pyobj(self) -> PyObjectRef {
1930 let obj = if self.is_borrowed() {
1931 self.as_object().to_owned() // inc refcount
1932 } else {
1933 let ptr = unsafe { NonNull::new_unchecked(self.bits.get() as *mut PyObject) };
1934 unsafe { PyObjectRef::from_raw(ptr) }
1935 };
1936 core::mem::forget(self); // don't run Drop
1937 obj
1938 }
1939
1940 /// Promote a borrowed ref to owned **in place** (increments refcount,
1941 /// clears the borrow tag). No-op if already owned.

Callers 7

execute_instructionMethod · 0.80
pop_value_optMethod · 0.80
pop_valueMethod · 0.80
pop_multipleMethod · 0.80
replace_topMethod · 0.80

Calls 5

forgetFunction · 0.85
is_borrowedMethod · 0.45
to_ownedMethod · 0.45
as_objectMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected