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

Function get_frozen_object

crates/vm/src/stdlib/_imp.rs:246–271  ·  view source on GitHub ↗
(
        name: PyUtf8StrRef,
        data: OptionalArg<PyObjectRef>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

244
245 #[pyfunction]
246 fn get_frozen_object(
247 name: PyUtf8StrRef,
248 data: OptionalArg<PyObjectRef>,
249 vm: &VirtualMachine,
250 ) -> PyResult<PyRef<PyCode>> {
251 if let OptionalArg::Present(data) = data
252 && !vm.is_none(&data)
253 {
254 let buf = crate::protocol::PyBuffer::try_from_borrowed_object(vm, &data)?;
255 let contiguous = buf.as_contiguous().ok_or_else(|| {
256 vm.new_buffer_error("get_frozen_object() requires a contiguous buffer")
257 })?;
258 let invalid_err = || {
259 vm.new_import_error(
260 format!("Frozen object named '{}' is invalid", name.as_str()),
261 name.clone().into_wtf8(),
262 )
263 };
264 let bag = crate::builtins::code::PyObjBag(&vm.ctx);
265 let code =
266 rustpython_compiler_core::marshal::deserialize_code(&mut &contiguous[..], bag)
267 .map_err(|_| invalid_err())?;
268 return Ok(vm.ctx.new_code(code));
269 }
270 import::make_frozen(vm, name.as_str())
271 }
272
273 #[pyfunction]
274 fn init_frozen(name: PyUtf8StrRef, vm: &VirtualMachine) -> PyResult {

Callers

nothing calls this directly

Calls 11

PyObjBagClass · 0.85
deserialize_codeFunction · 0.85
make_frozenFunction · 0.85
ok_or_elseMethod · 0.80
new_import_errorMethod · 0.80
into_wtf8Method · 0.80
is_noneMethod · 0.45
as_contiguousMethod · 0.45
cloneMethod · 0.45
new_codeMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected