Skip to content

Commit

Permalink
fix(python): take references to Python objects to prevent them being …
Browse files Browse the repository at this point in the history
…freed early (#54)

By taking references to the Python objects, we prevent the backing Rust object
from being freed too early.
  • Loading branch information
notmgsk authored Nov 7, 2023
1 parent 1dc84a2 commit ec7c239
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions python/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ impl PyCompilationResult {

#[pyfunction]
pub fn compile(
program: crate::program::PyProgram,
chip: crate::chip::PyChip,
options: Option<PyCompileOptions>,
program: &crate::program::PyProgram,
chip: &crate::chip::PyChip,
options: Option<&PyCompileOptions>,
) -> PyResult<PyCompilationResult> {
let protoquil = options.and_then(|e| e.into_inner().protoquil);
let protoquil = options.and_then(|e| e.as_inner().protoquil);

let compilation_result = if let Some(true) = protoquil {
libquil_sys::quilc::compile_protoquil(&program.into_inner().0, &chip.into_inner().0)
libquil_sys::quilc::compile_protoquil(&program.as_inner().0, &chip.as_inner().0)
.map_err(|e| crate::RustLibquilQuilcError::from(e).to_py_err())?
} else {
libquil_sys::quilc::compile_program(&program.into_inner().0, &chip.into_inner().0)
libquil_sys::quilc::compile_program(&program.as_inner().0, &chip.as_inner().0)
.map_err(|e| crate::RustLibquilQuilcError::from(e).to_py_err())?
};

Expand Down

0 comments on commit ec7c239

Please sign in to comment.