1.9 Ruby C Extension ???

A

Alex Katebi

[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);
}
 
T

Tim Hunter

Alex said:
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.
 
J

Jason Roelofs

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/ruby/pickaxe/, the chapter called
Extending Ruby

Jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top