Bug in RubyInline 1.0.5

The following code fragment does not compile, using ruby 1.7.2 (2002-07-02)
[i386-mswin32]

···

#----------------------------------------------------------------------
require "inline"
include Inline

def showstr(*args)
inline args, <<END1
#include <stdio.h>
printf("%s\n",STR2CSTR(argv[0]));
return 0;
END
end

showstr(‘Hello RubyInline’)
#-----------------------------------------------------------------------

The work-around is to rewrite the printf( ) as follows:

printf("%s\n",STR2CSTR(argv[0]));
^^^
Notice the double back slash after %s.

Hoping that this is not a “feature” :wink:

Thanks,

– Shanko

Hi,

#----------------------------------------------------------------------
require "inline"
include Inline

def showstr(*args)
inline args, <<‘END1’
#include <stdio.h>
printf("%s\n",STR2CSTR(argv[0]));
return 0;
END
end

showstr(‘Hello RubyInline’)
#-----------------------------------------------------------------------

Use single-quoted here-document to get rid of escape chars.

···

At Sun, 15 Sep 2002 06:25:58 +0900, Shashank Date wrote:


Nobu Nakada

Sorry for the unneccesary noise.
But there is a bug in my bug-report :wink:

def showstr(*args)
inline args, <<END1
#include <stdio.h>
printf("%s\n",STR2CSTR(argv[0]));
return 0;
END
^
1 is missing here. So it should be :

def showstr(*args)
inline args, <<END1
#include <stdio.h>
printf("%s\n",STR2CSTR(argv[0]));
return 0;
END1
end

But my original claim is still true: that it will not work.
Unless, of course, you use single-quoted here-document as suggested by Nobu.

– shanko

nobu.nokada@softhome.net wrote in message

Use single-quoted here-document to get rid of escape chars.
Nobu Nakada

Yes, that took care of it ! Thanks nobu.

Is it true for “here documents” in general or is it due to the way
RubyInline gets implemented ?

Thanks,
– Shanko

Single quoting a here document is just like single quoting any string.
Interpolation and backslash translation does not occur. What you found
is not a bug in RubyInline at all, it’s doing exactly what you told it
to do. But C doesn’t like strings that span more than one line, so you
are generating bad C code. It has nothing to do with the way RubyInline
is implemented.

···

On Saturday, Sep 14, 2002, at 22:46 US/Pacific, Shashank Date wrote:

Is it true for “here documents” in general or is it due to the way
RubyInline gets implemented ?

“Ryan Davis” ryand-ruby@zenspider.com wrote in message

Single quoting a here document is just like single quoting any string.
Interpolation and backslash translation does not occur.

Did not know this fact about here-document.

What you found is not a bug in RubyInline at all,
it’s doing exactly what you told it to do.

Sorry Ryan … should have done more research before posting.

Anyway, I am looking forward to your next version which will handle the
includes.
Keep up the good work.

Thanks,
– shanko