Visitar URL original
Write bytecode by palaviv · Pull Request #1166 · RustPython/RustPython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use git hash as pyc magic number
  • Loading branch information
palaviv committed Jul 24, 2019
commit 054bc72062c9e5e054a673f4cc9d90e66554c9a4
7 changes: 7 additions & 0 deletions vm/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::bytecode::CodeObject;
use crate::obj::{objcode, objsequence, objstr, objtype};
use crate::pyobject::{ItemProtocol, PyObjectRef, PyResult, PyValue};
use crate::scope::Scope;
use crate::version::get_git_revision;
use crate::vm::VirtualMachine;
#[cfg(feature = "rustpython-compiler")]
use rustpython_compiler::compile;
Expand All @@ -23,6 +24,12 @@ pub fn init_importlib(vm: &VirtualMachine, external: bool) -> PyResult {
let install_external =
vm.get_attribute(importlib.clone(), "_install_external_importers")?;
vm.invoke(install_external, vec![])?;
// Set pyc magic number to commit hash. Should be changed when bytecode will be more stable.
let sys_modules = vm.get_attribute(vm.sys_module.clone(), "modules")?;
Comment thread
palaviv marked this conversation as resolved.
Outdated
let importlib_external = sys_modules.get_item("_frozen_importlib_external", vm)?;
let mut magic = get_git_revision().into_bytes();
magic.truncate(4);
vm.set_attr(&importlib_external, "MAGIC_NUMBER", vm.ctx.new_bytes(magic))?;
}
Ok(vm.get_none())
}
Expand Down