From 97dde18d45b4fd9c4bbe8af9192fafc225e9856e Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 9 Sep 2020 08:25:40 -0400 Subject: [PATCH] Use limited APIs for Py::run_code --- src/python.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/python.rs b/src/python.rs index db4abfe6b1a..9b71ebf0cd4 100644 --- a/src/python.rs +++ b/src/python.rs @@ -280,13 +280,11 @@ impl<'p> Python<'p> { .unwrap_or_else(|| ffi::PyModule_GetDict(mptr)); let locals = locals.map(AsPyPointer::as_ptr).unwrap_or(globals); - let res_ptr = ffi::PyRun_StringFlags( - code.as_ptr(), - start, - globals, - locals, - ::std::ptr::null_mut(), - ); + let code_obj = ffi::Py_CompileString(code.as_ptr(), "\0".as_ptr() as _, start); + if code_obj.is_null() { + return Err(PyErr::fetch(self)); + } + let res_ptr = ffi::PyEval_EvalCode(code_obj, globals, locals); self.from_owned_ptr_or_err(res_ptr) }