Forum: Ruby Two Lines of C in Ruby Source

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A0599814ceddc2e283792f4e47c57f5e?d=identicon&s=25 Brian Takita (Guest)
on 2006-01-23 08:23
(Received via mailing list)
Hello,

Can somebody tell me what these lines of code mean?

extern int snprintf __((char *, size_t n, char const *, ...));
extern int vsnprintf _((char *, size_t n, char const *, va_list));

I am confused over what _, __, and ... mean.

They are in missing.h lines 134 - 135
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 unknown (Guest)
on 2006-01-23 08:32
(Received via mailing list)
Hi,

At Mon, 23 Jan 2006 16:20:59 +0900,
Brian Takita wrote in [ruby-talk:176520]:
> I am confused over what _, __, and ... mean.

See defines.h for _ and __.  Look for a tutorial of C for ...

Ruby source and extensions are not good as a tutorial.
A0599814ceddc2e283792f4e47c57f5e?d=identicon&s=25 Brian Takita (Guest)
on 2006-01-24 09:53
(Received via mailing list)
> See defines.h for _ and __.
Thank you for the pointer. I found the defines.

#ifdef __cplusplus
# ifndef  HAVE_PROTOTYPES
#  define HAVE_PROTOTYPES 1
# endif
# ifndef  HAVE_STDARG_PROTOTYPES
#  define HAVE_STDARG_PROTOTYPES 1
# endif
#endif

#undef _
#ifdef HAVE_PROTOTYPES
# define _(args) args
#else
# define _(args) ()
#endif

#undef __
#ifdef HAVE_STDARG_PROTOTYPES
# define __(args) args
#else
# define __(args) ()
#endif

It looks like if __cplusplus is not defined, an empty argument field is
outputted. If __cplusplus is defined, the arguments are outputted by the
preprocessor.

... is a variable argument. stdarg.h is required for this.
More information can be found at
http://www.thinkage.ca/english/gcos/expl/c/incl/stdarg.html

> Ruby source and extensions are not good as a tutorial.
I'm trying to find out where the File name and line number of methods
are
stored. So far my search has lead me to look in the backtrace function
in
eval.c: line 6094.

If you have any pointers to lead me in the right direction, I would
appreciate it very much.

Of course, looking at the ruby c source requires me to learn some c. :)

Thank you,
Brian Takita
392450979e40b958c4bdad04579e74d5?d=identicon&s=25 Gioele Barabucci (Guest)
on 2006-01-24 13:41
(Received via mailing list)
On Tuesday 24 January 2006 09:53, Brian Takita wrote:
> #ifdef HAVE_PROTOTYPES
> # define _(args) args
> #else
> # define _(args) ()
> #endif
Are there still compilers that don't support function prototypes?
7264fb16beeea92b89bb42023738259d?d=identicon&s=25 Christian Neukirchen (Guest)
on 2006-01-24 19:18
(Received via mailing list)
Brian Takita <brian.takita@gmail.com> writes:

> I'm trying to find out where the File name and line number of methods are
> stored. So far my search has lead me to look in the backtrace function in
> eval.c: line 6094.

Spoiler warning:
http://ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/140058
A0599814ceddc2e283792f4e47c57f5e?d=identicon&s=25 Brian Takita (Guest)
on 2006-01-25 05:44
(Received via mailing list)
>
> Spoiler warning:
>
> http://ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/140058
>

Thank you for your help Christian.

Would there be a way to access the Node struct from a Ruby object?

My objective is to find all of the file and line numbers of the class,
module, and method definitions.
To me, it looks like it would require significant rewriting of the Ruby
core
to easily achieve this.

The reason is I'm looking at
#define NEW_METHOD(n,x) NEW_NODE(NODE_METHOD,x,n,0)
...
#define NEW_CLASS(n,b,s) NEW_NODE(NODE_CLASS
#define NEW_SCLASS(r,b)
NEW_NODE(NODE_SCLASS,r,NEW_SCOPE(b),0),n,NEW_SCOPE(b),(s))
#define NEW_MODULE(n,b) NEW_NODE(NODE_MODULE,n,NEW_SCOPE(b),0)

in node.h

They are all called in parse.y, parse.c, class.c, and eval.c
It looks like set_trace_func is the best way to achieve this goal.


Thank you,
Brian Takita
7264fb16beeea92b89bb42023738259d?d=identicon&s=25 Christian Neukirchen (Guest)
on 2006-01-25 17:02
(Received via mailing list)
Brian Takita <brian.takita@gmail.com> writes:

>>
>> Spoiler warning:
>>
>> http://ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/140058
>>
>
> Thank you for your help Christian.
>
> Would there be a way to access the Node struct from a Ruby object?

http://rubystuff.org/nodewrap/
A0599814ceddc2e283792f4e47c57f5e?d=identicon&s=25 Brian Takita (Guest)
on 2006-01-27 18:27
(Received via mailing list)
Thank you Christian. This is really neat.
This topic is locked and can not be replied to.