[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

64-bit integers in Ruby/DL

Jamis Buck

12/14/2004 10:07:00 PM

Okay, you C gurus out there. Here's a stumper.

Is there any way, without modifying Ruby/DL itself, to specify
a function that returns a 64-bit integer using Ruby/DL? And to pass
a 64-bit integer to a function?

Consider:

require 'dl/import'
module Test64
dlload "foo.so"
extern "long long int get_64bit_value()"
extern "void set_64bit_value(long long int)"
end

The above results in an error, currently, because Ruby/DL does not
support 64-bit integers as immediate values.

I thought of using a double (which is 64 bits, on my platform anyway):

require 'dl/import'
module Test64
dlload "foo.so"
extern "double get_64bit_value()"
extern "void set_64bit_value(double)"
end

result = Test64.get_64bit_value
p [result].pack("D").unpack("LL")

But the value that comes back is nothing like what the function itself
is really returning...

Any clever tricks I can try? Anyone? Please?

- Jamis

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck...



4 Answers

Florian Gross

12/14/2004 11:45:00 PM

0

Jamis Buck wrote:

> Is there any way, without modifying Ruby/DL itself, to specify
> a function that returns a 64-bit integer using Ruby/DL? And to pass
> a 64-bit integer to a function?

As far as I know Ruby/DL does not yet work properly on 64 bit platforms.
The author plans to fix that, but didn't have the time to do it when I
last contacted him.

I think this would involve changes in lots of places because Ruby/DL
seems to be using one-byte type tokens and .pack() internally. However
if you want to use the native bit-width of the system you will need to
use "L_" instead of "L" and so on in the pack arguments. So I think this
would involve changing the semantics in quite a few code locations...

Jamis Buck

12/15/2004 12:04:00 AM

0

On 08:47 Wed 15 Dec , Florian Gross wrote:
> Jamis Buck wrote:
>
> >Is there any way, without modifying Ruby/DL itself, to specify
> >a function that returns a 64-bit integer using Ruby/DL? And to pass
> >a 64-bit integer to a function?
>
> As far as I know Ruby/DL does not yet work properly on 64 bit platforms.
> The author plans to fix that, but didn't have the time to do it when I
> last contacted him.
>
> I think this would involve changes in lots of places because Ruby/DL
> seems to be using one-byte type tokens and .pack() internally. However
> if you want to use the native bit-width of the system you will need to
> use "L_" instead of "L" and so on in the pack arguments. So I think this
> would involve changing the semantics in quite a few code locations...

Well, I'm actually on a 32-bit system. But gcc supports a 64-bit
integer (long long), as does MSVC++.

It's not critical, but it would certainly be nice. For now, I'm just
using unsigned longs, which will lose the most significant 32 bits of
each return value. :(

- Jamis

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck...



DaZoner

12/15/2004 3:51:00 PM

0


I don't know very much about Ruby/DL but can't you just define a struct that
has two 32-bit numbers in it, and manipulate and pass those?

"Jamis Buck" <jamis_buck@byu.edu> wrote in message
news:20041214220549.GA15605@serling.WorkGroup...
> Okay, you C gurus out there. Here's a stumper.
>
> Is there any way, without modifying Ruby/DL itself, to specify
> a function that returns a 64-bit integer using Ruby/DL? And to pass
> a 64-bit integer to a function?
>
> Consider:
>
> require 'dl/import'
> module Test64
> dlload "foo.so"
> extern "long long int get_64bit_value()"
> extern "void set_64bit_value(long long int)"
> end
>
> The above results in an error, currently, because Ruby/DL does not
> support 64-bit integers as immediate values.
>
> I thought of using a double (which is 64 bits, on my platform anyway):
>
> require 'dl/import'
> module Test64
> dlload "foo.so"
> extern "double get_64bit_value()"
> extern "void set_64bit_value(double)"
> end
>
> result = Test64.get_64bit_value
> p [result].pack("D").unpack("LL")
>
> But the value that comes back is nothing like what the function itself
> is really returning...
>
> Any clever tricks I can try? Anyone? Please?
>
> - Jamis
>
> --
> Jamis Buck
> jgb3@email.byu.edu
> http://www.jamisbuck...
>
>
>


Jamis Buck

12/15/2004 8:46:00 PM

0

On 01:17 Thu 16 Dec , DaZoner wrote:
>
> I don't know very much about Ruby/DL but can't you just define a struct that
> has two 32-bit numbers in it, and manipulate and pass those?

Well, structs in Ruby/DL are implemented as pointers to structs. You
can't create a "bare" structure in Ruby/DL (to my knowledge).

- Jamis

>
> "Jamis Buck" <jamis_buck@byu.edu> wrote in message
> news:20041214220549.GA15605@serling.WorkGroup...
> > Okay, you C gurus out there. Here's a stumper.
> >
> > Is there any way, without modifying Ruby/DL itself, to specify
> > a function that returns a 64-bit integer using Ruby/DL? And to pass
> > a 64-bit integer to a function?
> >
> > Consider:
> >
> > require 'dl/import'
> > module Test64
> > dlload "foo.so"
> > extern "long long int get_64bit_value()"
> > extern "void set_64bit_value(long long int)"
> > end
> >
> > The above results in an error, currently, because Ruby/DL does not
> > support 64-bit integers as immediate values.
> >
> > I thought of using a double (which is 64 bits, on my platform anyway):
> >
> > require 'dl/import'
> > module Test64
> > dlload "foo.so"
> > extern "double get_64bit_value()"
> > extern "void set_64bit_value(double)"
> > end
> >
> > result = Test64.get_64bit_value
> > p [result].pack("D").unpack("LL")
> >
> > But the value that comes back is nothing like what the function itself
> > is really returning...
> >
> > Any clever tricks I can try? Anyone? Please?
> >
> > - Jamis
> >
> > --
> > Jamis Buck
> > jgb3@email.byu.edu
> > http://www.jamisbuck...
> >
> >
> >
>
>
>
>

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck...