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

arc: cpp exceptions don't work #13402

Closed
cooldome opened this issue Feb 12, 2020 · 7 comments
Closed

arc: cpp exceptions don't work #13402

cooldome opened this issue Feb 12, 2020 · 7 comments

Comments

@cooldome
Copy link
Member

cooldome commented Feb 12, 2020

Compile as nim cpp --gc:arc $1 to get a crash at runtime.

proc myproc = 
  raise newException(ValueError, "Error")

try:
  myproc()
except ValueError as ex:
  echo ex[]

Crashes with stacktrace:

Traceback (most recent call last)
C:\Nim\lib\system\excpt.nim(73) x2
C:\Nim\lib\system\refs_v2.nim(120) nimDestroyAndDispose
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Works with c backend but not with cpp.

@cooldome
Copy link
Member Author

cooldome commented Feb 12, 2020

@Araq,
As far as I got it PR #13065 is supposed to fix this problem.
But looks like the progress has stalled, any serious blockers found a long they way?

@Araq
Copy link
Member

Araq commented Feb 13, 2020

The only remaining problem is that tests/iter/tyieldintry.nim fails in my PR and I don't know why. Any help is welcome. Supporting C++ codegen well is more expensive than it looked a couple of years ago, I'm rethinking it. I wanted C++ for the better exception handling but my goto-based exceptions offer reasonable performance so my original motivation to compile to C++ is lost.

@andreaferretti
Copy link
Collaborator

my original motivation to compile to C++ is lost.

I guess an important motivation to compile to C++ is to be able to use C++ libraries without C bindings?

@Araq
Copy link
Member

Araq commented Feb 13, 2020

@cooldome As a compromise I could merge the PR now disabling the now failing test and later investigate so that gc:arc with nim cpp works better than before.

@cooldome
Copy link
Member Author

@Araq, that would be fantastic solution solution. Much appreciated.
Agree with Andrea Ferretti, major reason for using cpp backend for me is hard requirement to use cpp libraries. I have to import their templates and use their library specific smart pointers and catch their exceptions. Yack, but I have to do it, no choice or possible workarounds this for me.

@Araq
Copy link
Member

Araq commented Feb 14, 2020

Yack, but I have to do it, no choice or possible workarounds this for me.

I can imagine. In the long run I hope to have a much better "cpp2nim" tool that wraps the C++ code into DLLs that we then call from Nim, but how to deal with template instantiations is a huge problem. So there might no other way out but to support "nim cpp" for forever. Maybe with a rewrite of the backend things become easier.

@cooldome
Copy link
Member Author

PR #13065 is submitted closing

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

No branches or pull requests

3 participants