Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/capi/src/ceval.rs`:
- Around line 59-61: PyEval_GetBuiltins currently returns the interpreter-wide
vm.builtins unconditionally; change it to check vm.current_frame() and, if
Some(frame), return that frame's InterpreterFrame.builtins raw pointer,
otherwise fall back to vm.builtins. Update the implementation inside with_vm to
call vm.current_frame(), access frame.builtins (via as_object().as_raw() or
equivalent), and only use vm.builtins when no current frame is present so the
function honors per-frame __builtins__ overrides.
- Around line 11-22: The FFI functions (notably Py_CompileString and other C
entrypoints that call CStr::from_ptr or dereference raw pointers like &*co and
&*globals) must validate incoming pointers before dereferencing to avoid UB:
check that raw pointers (code, filename, co, globals) are non-null (use
NonNull::new or explicit null checks) and return an appropriate Python exception
via the VM when null or invalid UTF-8 occurs; then safely call CStr::from_ptr
and only dereference pointers after wrapping them in NonNull and converting to
references. Ensure you mirror the existing locals pattern (NonNull::new(locals))
for code, filename, co, globals and produce the VM error return path instead of
dereferencing null.
---
Nitpick comments:
In `@crates/capi/src/ceval.rs`:
- Around line 64-84: The disabled test module (mod tests) uses #[cfg(false)] and
exercises PyO3's Python::eval/run rather than the crate's exported C-API; either
remove this dead module or replace it with tests that call the real FFI surface
(e.g., tests that invoke the exported functions which wrap Py_CompileString and
PyEval_EvalCode) — update or add test functions (replace test_code_eval and
test_code_run_exception) to call the crate's C-API entrypoints, assert correct
return values and that exceptions from the FFI path produce PyException
instances, and remove #[cfg(false)] so the tests run.