Skip to content

Commit a2a18f2

Browse files
committed
Fix make_frozen to return PyRef<PyCode>
1 parent 75f606a commit a2a18f2

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

vm/src/import.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[cfg(feature = "rustpython-compiler")]
55
use crate::compile;
66
use crate::{
7-
builtins::{code, code::CodeObject, list, traceback::PyTraceback, PyBaseExceptionRef},
7+
builtins::{list, traceback::PyTraceback, PyBaseExceptionRef, PyCode},
88
scope::Scope,
99
version::get_git_revision,
1010
vm::{thread, VirtualMachine},
@@ -85,12 +85,11 @@ pub(crate) fn init_importlib_package(
8585
})
8686
}
8787

88-
pub fn make_frozen(vm: &VirtualMachine, name: &str) -> PyResult<code::CodeObject> {
89-
vm.state
90-
.frozen
91-
.get(name)
92-
.map(|frozen| vm.ctx.new_code_object(frozen.code.clone()))
93-
.ok_or_else(|| vm.new_import_error(format!("No such frozen object named {}", name), name))
88+
pub fn make_frozen(vm: &VirtualMachine, name: &str) -> PyResult<PyRef<PyCode>> {
89+
let frozen = vm.state.frozen.get(name).ok_or_else(|| {
90+
vm.new_import_error(format!("No such frozen object named {}", name), name)
91+
})?;
92+
Ok(vm.ctx.new_code(frozen.code.clone()))
9493
}
9594

9695
pub fn import_frozen(vm: &VirtualMachine, module_name: &str) -> PyResult {
@@ -122,15 +121,16 @@ pub fn import_file(
122121
file_path: String,
123122
content: String,
124123
) -> PyResult {
125-
let code = compile::compile(&content, compile::Mode::Exec, file_path, vm.compile_opts())
124+
let code = vm
125+
.compile_with_opts(&content, compile::Mode::Exec, file_path, vm.compile_opts())
126126
.map_err(|err| vm.new_syntax_error(&err))?;
127-
import_codeobj(vm, module_name, vm.ctx.new_code_object(code), true)
127+
import_codeobj(vm, module_name, code, true)
128128
}
129129

130130
pub fn import_codeobj(
131131
vm: &VirtualMachine,
132132
module_name: &str,
133-
code_obj: CodeObject,
133+
code_obj: PyRef<PyCode>,
134134
set_file_attr: bool,
135135
) -> PyResult {
136136
let attrs = vm.ctx.new_dict();
@@ -145,10 +145,7 @@ pub fn import_codeobj(
145145
sys_modules.set_item(module_name, module.clone(), vm)?;
146146

147147
// Execute main code in module:
148-
vm.run_code_obj(
149-
code::PyCode::new(code_obj).into_ref(vm),
150-
Scope::with_builtins(None, attrs, vm),
151-
)?;
148+
vm.run_code_obj(code_obj, Scope::with_builtins(None, attrs, vm))?;
152149
Ok(module)
153150
}
154151

vm/src/stdlib/imp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ mod _imp {
9393

9494
#[pyfunction]
9595
fn get_frozen_object(name: PyStrRef, vm: &VirtualMachine) -> PyResult<PyRef<PyCode>> {
96-
import::make_frozen(vm, name.as_str()).map(|code| vm.ctx.new_code(code))
96+
import::make_frozen(vm, name.as_str())
9797
}
9898

9999
#[pyfunction]

0 commit comments

Comments
 (0)