[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

how to handle 64 bit variables on 32 bit machines ?

Alexander Neundorf

10/27/2003 4:08:00 PM

Hi,

I'd like to use the ruby/dl library to access function in a C library from
ruby.
Now these functions take 64 bit parameters und my machine (x86) is a 32 bit
machine.
As I saw in lib/ruby/1.8/dl/types.rb this is the place where the types are
listed
which ruby/dl supports.
Now if I could add a type uint64 or something and an appropriate pack/unpack

method, I guess everything would work.

I tried pack("LL"), but this doesn't work.

My C functions look like:

void doSomething(uint64_t foo);

and I need to access them:

module Test
...
extern "void doSomething(uint64)"
end

# call it
Test.doSomething(7)

when I insert the lines

["uint64", "LL",
proc{|v| [v].pack("LL").unpack("ll")[0]},
proc{|v| [v].pack("ll").unpack("LL")[0]},
proc{|v| [v].pack("LL").unpack("ll")[0]},
proc{|v| [v].pack("ll").unpack("LL")[0]}],

into types.rb, it recognizes the type and imports the functions, but then
says
when calling the function:

/usr/local/lib/ruby/1.8/dl/types.rb:76:in `pack': too few arguments
(ArgumentError)
from /usr/local/lib/ruby/1.8/dl/types.rb:76
from /usr/local/lib/ruby/1.8/dl/types.rb:76:in `call'
from /usr/local/lib/ruby/1.8/dl/import.rb:200:in `encode_types'
from /usr/local/lib/ruby/1.8/dl/import.rb:200:in `call'
from (eval):3:in `sLMS_Sqr3'
from test.rb:17

I'm still quite new to ruby, any help would be very much appreciated.

Bye
Alex





--
NEU FÜR ALLE - GMX MediaCenter - für Fotos, Musik, Dateien...
Fotoalbum, File Sharing, MMS, Multimedia-Gruß, GMX FotoService

Jetzt kostenlos anmelden unter http://w...

+++ GMX - die erste Adresse für Mail, Message, More! +++


2 Answers

mike

10/27/2003 4:25:00 PM

0

In article <25451.1067270894@www59.gmx.net>,
Alexander Neundorf <a.neundorf-work@gmx.net> wrote:
>Hi,
>
>I'd like to use the ruby/dl library to access function in a C library from
>ruby.
>Now these functions take 64 bit parameters und my machine (x86) is a 32 bit
>machine.
>As I saw in lib/ruby/1.8/dl/types.rb this is the place where the types are
>listed
>which ruby/dl supports.
>Now if I could add a type uint64 or something and an appropriate pack/unpack
>
>method, I guess everything would work.
>
>I tried pack("LL"), but this doesn't work.

Does the 'Q' format help?

e.g.

[mike@ratdog mike]$ irb --simple-prompt
>> [1234567890123].pack('Q')
=> "\313\004\373q\037\001\000\000"
>> "\313\004\373q\037\001\000\000".unpack('Q')
=> [1234567890123]

Hope this helps,

Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co... | GPG PGP Key 1024D/059913DA
mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60
http://www.exe... | 75D2 9EC4 C1C0 0599 13DA

Laurence J. Lane

10/28/2003 1:07:00 AM

0

On Tue, Oct 28, 2003 at 01:08:17AM +0900, Alexander Neundorf wrote:

> Now if I could add a type uint64 or something and an appropriate pack/unpack

Perhaps this from faiermud's ruby 1.8.0 changes list:

Array#pack, String#unpack
New templates 'q' and 'Q' for 64bit integer (signed and
unsigned respectively).