lib/pycall/eval.rb in pycall-0.1.0.alpha.20170224 vs lib/pycall/eval.rb in pycall-0.1.0.alpha.20170226
- old
+ new
@@ -5,18 +5,23 @@
def self.eval(str, filename: "pycall")
globals_ptr = maindict_ptr
locals_ptr = maindict_ptr
defer_sigint do
py_code_ptr = LibPython.Py_CompileString(str, filename, Py_eval_input)
+ raise PyError.fetch if py_code_ptr.null?
LibPython.PyEval_EvalCode(py_code_ptr, globals_ptr, locals_ptr)
end
end
class << self
private
+ def main_module
+ @main_module ||= PyCall.import_module("__main__")
+ end
+
def maindict_ptr
- LibPython.PyModule_GetDict(PyCall.import_module("__main__"))
+ @maindict_ptr ||= LibPython.PyModule_GetDict(main_module)
end
def defer_sigint
# TODO: should be implemented
yield