(
pyc_bytes: &[u8],
name: Option<&str>,
bytecode_path: Option<&str>,
source_path: Option<&str>,
vm: &VirtualMachine,
)
| 442 | ) |
| 443 | } |
| 444 | pub fn from_pyc( |
| 445 | pyc_bytes: &[u8], |
| 446 | name: Option<&str>, |
| 447 | bytecode_path: Option<&str>, |
| 448 | source_path: Option<&str>, |
| 449 | vm: &VirtualMachine, |
| 450 | ) -> PyResult<PyRef<Self>> { |
| 451 | if !crate::import::check_pyc_magic_number_bytes(pyc_bytes) { |
| 452 | return Err(vm.new_value_error("pyc bytes has wrong MAGIC")); |
| 453 | } |
| 454 | let bootstrap_external = vm.import("_frozen_importlib_external", 0)?; |
| 455 | let compile_bytecode = bootstrap_external.get_attr("_compile_bytecode", vm)?; |
| 456 | // 16 is the pyc header length |
| 457 | let Some((_, code_bytes)) = pyc_bytes.split_at_checked(16) else { |
| 458 | return Err(vm.new_value_error(format!( |
| 459 | "pyc_bytes header is broken. 16 bytes expected but {} bytes given.", |
| 460 | pyc_bytes.len() |
| 461 | ))); |
| 462 | }; |
| 463 | let code_bytes_obj = vm.ctx.new_bytes(code_bytes.to_vec()); |
| 464 | let compiled = |
| 465 | compile_bytecode.call((code_bytes_obj, name, bytecode_path, source_path), vm)?; |
| 466 | compiled.try_downcast(vm) |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | impl fmt::Debug for PyCode { |
nothing calls this directly
no test coverage detected