[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Smoking out C extension mistakes

Berger, Daniel

1/10/2006 4:18:00 PM

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


2 Answers

Paul Brannan

1/10/2006 5:07:00 PM

0

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




ts

1/10/2006 5:10:00 PM

0

>>>>> "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