Anyone tried compiling Ruby with c++?

A

Asfand Yar Qazi

No, I didn't say "porting Ruby to C++", I said "compiling Ruby
with C++."

I think this would solve the problem of longjmping out of C++
functions (due to throwing Ruby exceptions) and not having
destructors of stack objects declared in those C++ functions. Or
am I wrong?

thanks,
Asfand Yar
 
P

Paul Brannan

No, I didn't say "porting Ruby to C++", I said "compiling Ruby
with C++."

I think this would solve the problem of longjmping out of C++
functions (due to throwing Ruby exceptions) and not having
destructors of stack objects declared in those C++ functions. Or
am I wrong?

Unless I misunderstand you: the longjmp function is part of the C++
standard (since the C++ standard library includes the C89 standard
library). Recompiling Ruby with a C++ compiler will not eliminate the
calls to longjmp. The C++ standard is very clear that any call to
longjmp that jumps over the desctruction of an automatic object will
result in undefined behavior, irrespective of whether that code was
compiled with a C or a C++ compiler.

It would be possible to modify Ruby to use C++ exceptions, but this
would not be a small change (Ruby wraps calls to longjmp in macros, but
it's not just a matter of changing the macros, since longjmp and
exceptions use a different syntax), and I don't know how well C++
exceptions would play with Ruby's threads.

Also, C++ has much stricter typing than C, and I suspect that much of
the Ruby source would fail to compiler under a C++ compiler without
modification.

Paul
 
A

Asfand Yar Qazi

Paul said:
Unless I misunderstand you: the longjmp function is part of the C++
standard (since the C++ standard library includes the C89 standard
library). Recompiling Ruby with a C++ compiler will not eliminate the
calls to longjmp. The C++ standard is very clear that any call to
longjmp that jumps over the desctruction of an automatic object will
result in undefined behavior, irrespective of whether that code was
compiled with a C or a C++ compiler.

Ahh... that's what I didn't know.
It would be possible to modify Ruby to use C++ exceptions, but this
would not be a small change (Ruby wraps calls to longjmp in macros, but
it's not just a matter of changing the macros, since longjmp and
exceptions use a different syntax), and I don't know how well C++
exceptions would play with Ruby's threads.

I wish there was a scripting language that did just that... I am
yearning for a scripting language that has support for C++
exceptions out-of-the-box...
Also, C++ has much stricter typing than C, and I suspect that much of
the Ruby source would fail to compiler under a C++ compiler without
modification.

I thought of that too.

thanks for the reply.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top