[ruby-talk:444502] Accessing error.c symbols from the ruby C library

I have compiled ruby 3.2.2 vm using gcc with the following command:

gcc -std=c23 -o test test.c -g -Wall -Wextra -Woverflow -Og -pedantic -Wno-unused-parameter -I/home/user/.rbenv/versions/3.2.2/include/ruby-3.2.0 -I/home/user/.rbenv/versions/3.2.2/include/ruby-3.2.0/x86_64-linux -L/home/user/.rbenv/versions/3.2.2/lib -Wl,-rpath,/home/user/.rbenv/versions/3.2.2/lib -lruby

This works for the most part (I can successfully init the vm and run ruby code).
Though, when I tried to handle ruby exceptions within my C code I find out that
the exc_message(VALUE exc) is a static symbol inside error.c. I can not
see it being exported anywhere.

Is there something more then ruby.h header that I need to include to access
this function from C?

Daniel Sierpiński

Let me redefine my question please. I get that `exc_message` is static as it's
defined only to by visible to `rb_define_method` in the same file. I suppose
then accessing this function from anywhere else is not possible without
modifying ruby's source code, and that's not what I want. In stead I took a
look at how `exc_message` is implemented.

return rb_funcallv(exc, idTo_s, 0, 0);

Now, what is `idTo_s`? It's not accessible from my code and I can't find the
[definition][1] of it.

[1]: Code search results · GitHub

Daniel Sierpiński

···

Sent: Saturday, June 08, 2024 at 7:04 PM
From: "Daniel Sierpinski via ruby-talk" <ruby-talk@ml.ruby-lang.org>
To: ruby-talk@ml.ruby-lang.org
Cc: "Daniel Sierpinski" <siery@comic.com>
Subject: [ruby-talk:444502] Accessing error.c symbols from the ruby C library

I have compiled ruby 3.2.2 vm using gcc with the following command:

gcc -std=c23 -o test test.c -g -Wall -Wextra -Woverflow -Og -pedantic -Wno-unused-parameter -I/home/user/.rbenv/versions/3.2.2/include/ruby-3.2.0 -I/home/user/.rbenv/versions/3.2.2/include/ruby-3.2.0/x86_64-linux -L/home/user/.rbenv/versions/3.2.2/lib -Wl,-rpath,/home/user/.rbenv/versions/3.2.2/lib -lruby

This works for the most part (I can successfully init the vm and run ruby code).
Though, when I tried to handle ruby exceptions within my C code I find out that
the `exc_message(VALUE exc)` is a static symbol inside [error.c][1]. I can not
see it being exported anywhere.

Is there something more then ruby.h header that I need to include to access
this function from C?

[1]: ruby/error.c at 69c0b1438a45938e79e63407035f116de4634dcb · ruby/ruby · GitHub

Daniel Sierpiński

Maybe configure pulls it out or something?

···

On Sat, Jun 8, 2024 at 2:07 PM Daniel Sierpinski via ruby-talk <ruby-talk@ml.ruby-lang.org> wrote:

Let me redefine my question please. I get that `exc_message` is static as it's
defined only to by visible to `rb_define_method` in the same file. I suppose
then accessing this function from anywhere else is not possible without
modifying ruby's source code, and that's not what I want. In stead I took a
look at how `exc_message` is implemented.

return rb_funcallv(exc, idTo_s, 0, 0);

Now, what is `idTo_s`? It's not accessible from my code and I can't find the
[definition][1] of it.

[1]: Code search results · GitHub

Daniel Sierpiński

> Sent: Saturday, June 08, 2024 at 7:04 PM
> From: "Daniel Sierpinski via ruby-talk" <ruby-talk@ml.ruby-lang.org>
> To: ruby-talk@ml.ruby-lang.org
> Cc: "Daniel Sierpinski" <siery@comic.com>
> Subject: [ruby-talk:444502] Accessing error.c symbols from the ruby C library
>
> I have compiled ruby 3.2.2 vm using gcc with the following command:
>
> ```
> gcc -std=c23 -o test test.c -g -Wall -Wextra -Woverflow -Og -pedantic -Wno-unused-parameter -I/home/user/.rbenv/versions/3.2.2/include/ruby-3.2.0 -I/home/user/.rbenv/versions/3.2.2/include/ruby-3.2.0/x86_64-linux -L/home/user/.rbenv/versions/3.2.2/lib -Wl,-rpath,/home/user/.rbenv/versions/3.2.2/lib -lruby
> ```
>
> This works for the most part (I can successfully init the vm and run ruby code).
> Though, when I tried to handle ruby exceptions within my C code I find out that
> the `exc_message(VALUE exc)` is a static symbol inside [error.c][1]. I can not
> see it being exported anywhere.
>
> Is there something more then ruby.h header that I need to include to access
> this function from C?
>
> [1]: ruby/error.c at 69c0b1438a45938e79e63407035f116de4634dcb · ruby/ruby · GitHub
>
> Daniel Sierpiński

______________________________________________
ruby-talk mailing list -- ruby-talk@ml.ruby-lang.org
To unsubscribe send an email to ruby-talk-leave@ml.ruby-lang.org
ruby-talk info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-talk.ml.ruby-lang.org/