(
name: PyUtf8StrRef,
data: OptionalArg<PyObjectRef>,
vm: &VirtualMachine,
)
| 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 { |
nothing calls this directly
no test coverage detected