[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

1.9 Ruby C Extension ???

Alex Katebi

8/7/2008 5:44:00 PM

[Note: parts of this message were removed to make it a legal post.]

Hi All,

When writing ruby extensions in C, how can I save C pointers into ruby
variables Bignum or Fixnum?
The only Macros available are INT2FIX, INT2NUM & FIX2INT and NUM2INT. I can
not save a pinter value that is 32 bits long.

example:

static VALUE round_trip(VALUE self, VALUE vptr)
{
void* ptr = NUM2INT(vptr);
return INT2NUM(ptr);
}

2 Answers

Tim Hunter

8/7/2008 6:04:00 PM

0

Alex Katebi wrote:
> Hi All,
>
> When writing ruby extensions in C, how can I save C pointers into
> ruby
> variables Bignum or Fixnum?
> The only Macros available are INT2FIX, INT2NUM & FIX2INT and NUM2INT. I
> can
> not save a pinter value that is 32 bits long.
>
> example:
>
> static VALUE round_trip(VALUE self, VALUE vptr)
> {
> void* ptr = NUM2INT(vptr);
> return INT2NUM(ptr);
> }

I don't think I'd do that. My inclination would be to create a structure
to hold the pointer and wrap the structure into a Ruby object.
--
Posted via http://www.ruby-....

Jason Roelofs

8/7/2008 6:10:00 PM

0

On Thu, Aug 7, 2008 at 1:44 PM, Alex Katebi <alex.katebi@gmail.com> wrote:
> Hi All,
>
> When writing ruby extensions in C, how can I save C pointers into ruby
> variables Bignum or Fixnum?
> The only Macros available are INT2FIX, INT2NUM & FIX2INT and NUM2INT. I can
> not save a pinter value that is 32 bits long.
>
> example:
>
> static VALUE round_trip(VALUE self, VALUE vptr)
> {
> void* ptr = NUM2INT(vptr);
> return INT2NUM(ptr);
> }
>

Um, yeah, that, that's just wrong. What exactly are you trying to
accomplish with this extension?

In case you haven't read it, please go read:
http://whytheluckystiff.net/rub..., the chapter called
Extending Ruby

Jason