Forum: Ruby Smoking out C extension mistakes

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.
F3b7b8756d0c7f71cc7460cc33aefaee?d=identicon&s=25 Daniel Berger (Guest)
on 2006-01-10 17:20
(Received via mailing list)
Hi all,

Every once in a while I'll hit a segfault that turns out to be caused by
accidentally passing a C datatype to a macro like NIL_P (which,
naturally, I
can't duplicate with a simple example, but recently occurred in
win32-eventlog).

Anyhoo, say I have something like this:

char* foo = "hello";
if(NIL_P(foo)) /* whoops */
    ...

I noticed that even compiling with gcc using -Wall -W I still don't see
a
warning.  Is this because it's a macro?  Is there a gcc option I can use
to
help me smoke these sorts of mistakes out?

Thanks,

Dan
Fe6a008c1e3065327d1f1b007d8f1362?d=identicon&s=25 Paul Brannan (Guest)
on 2006-01-10 18:08
(Received via mailing list)
On Wed, Jan 11, 2006 at 01:18:19AM +0900, Daniel Berger wrote:
> char* foo = "hello";
> if(NIL_P(foo)) /* whoops */
>    ...
>
> I noticed that even compiling with gcc using -Wall -W I still don't see a
> warning.  Is this because it's a macro?  Is there a gcc option I can use to
> help me smoke these sorts of mistakes out?

You could use:

  if(foo == Qnil)

instead of using the NIL_P macro.

Paul
956f185be9eac1760a2a54e287c4c844?d=identicon&s=25 ts (Guest)
on 2006-01-10 18:11
(Received via mailing list)
>>>>> "P" == Paul Brannan <pbrannan@atdesk.com> writes:

P> You could use:
P>   if(foo == Qnil)
P> instead of using the NIL_P macro.

  #define NIL_P(v) ((VALUE)(v) == Qnil)

 :-)


Guy Decoux
This topic is locked and can not be replied to.