Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGSEGV: Illegal storage access error when trying to echo py.exec("invalid python") #262

Open
M-MAD-Official opened this issue Apr 10, 2022 · 1 comment

Comments

@M-MAD-Official
Copy link

import
  rdstdin,
  nimpy

let py = pyBuiltinsModule()

proc repl*(prompt: string = "$ ", welcome_message: string = "") =
  if welcome_message != "": echo welcome_message
  while true:
    try:
      let input: auto = readLineFromStdin(prompt)
      var output: PyObject
      try:
        output = py.exec(input)
      except Exception:
        echo "Exception! ", repr(getCurrentException()[])
      echo type(output)
      echo output
    except IOError:
      quit 0

This code compiles; but when I type invalid python in repl, this happens:

...
/home/user/Documents/Nim/repl.nim(82) repl (It's the `echo $output` line)
/home/user/.nimble/pkgs/nimpy-0.2.0/nimpy.nim(435) $
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Why it is happening? And how can I fix it?
Also, I wanted to be able to catch different python exceptions like I was doing it in Python, but nimpy only raise one type of Exception for all cases, is there anything I can do about it?

@M-MAD-Official M-MAD-Official changed the title SIGSEGV: Illegal storage access error when trying to echo py.exec("invalid python") SIGSEGV: Illegal storage access error when trying to echo py.exec("invalid python") Apr 11, 2022
@M-MAD-Official
Copy link
Author

M-MAD-Official commented Apr 11, 2022

I think I figured it out; I needed to assign output to py.None when initializing.
But I think it is necessary to do something in nimpy so we won't need to initialize PyObject variables.
And I still could not figure out how to catch different Python Exceptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant