From: Aston Date: 2009-05-07T03:04:36+09:00 Subject: [ruby-core:23371] Re: Ruby/DL Documentation --0-744217757-1241633070=:65549 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable thanks a lot tad.bochan@bnpparibas.com and sh@sheepman.sakura.ne.jp=0A=0Ata= d seems to be using 1.8.x, i am using ruby19 on FreeBSD7.2=0A=0A[diesalunix= @raptor ~]$ uname -a=0AFreeBSD raptor 7.2-PRERELEASE FreeBSD 7.2-PRERELEASE= #1: Sun Mar 29=0A19:18:27 UTC 2009 root@raptor:/usr/obj/usr/src/sys/AR= GON18 amd64=0A[diesalunix@raptor ~]$ ruby19 -v=0Aruby 1.9.2dev (2009-05-02= trunk 23326) [x86_64-freebsd7.2]=0A=0Aas suggested by sh@ test/dl/test_*.r= b are good (not gr8!) source for learning, but given the fact there exists = no other code using dl elsewhere I am very happy I found them. thanks sh@= =0A=0AWhile googling around I discovered ruby-ffi (http://kenai.com/project= s/ruby-ffi/pages/Home), and it seems to be much more clean and complete sol= ution. It is supported by other VMs as well. I would have prefered to be wi= th dl since it is part of standard ruby C implementation but it is very dif= ficult to use(u got to have lot of time and little black magic), code using= it is almost non-existent and /dev/null documentation=0A=0Awhen reading ab= out ruby-ffi elsewhere it appears very promising, what is its future in reg= ard to ruby's C implementation ? will it ever be part of stdlib ? it appear= s it is still taking shape but by and large stable=0A=0AAston=0A=0A=0A=0A= =0A________________________________=0AFrom: "sh@sheepman.sakura.ne.jp" =0ATo: ruby-core@ruby-lang.org=0ASent: Tuesday, 5 May= , 2009 2:06:09 PM=0ASubject: [ruby-core:23359] Re: Ruby/DL Documentation=0A= =0AHi,=0A=0AIt is helpful to read test/dl/test_*.rb in ruby-1.9.tar.gz.=0AY= ou have to master pack and unpack anyway.=0AThe following is an example.=0A= =0A$ cat sum.c=0Adouble sum(double *arry, int len)=0A{=0A double ret =3D 0= ;=0A int i;=0A for(i =3D 0; i < len; i++){=0A ret =3D ret + arry[i];= =0A }=0A return ret;=0A}=0A=0A$ gcc -shared sum.c -o libsum.so=0A=0A$ cat= d.rb=0Arequire 'dl/import'=0Amodule M=0A extend DL::Importer=0A dlload '= ./libsum.so'=0A extern 'double sum(double*, int)'=0Aend=0Ap M.sum([2.0, 3.= 0, 4.0].pack("d*"), 3)=0A=0A$ ruby-1.9 -v d.rb=0Aruby 1.9.2dev (2009-05-02 = trunk 23326) [i686-linux]=0A9.0=0A=0A=0A2009/5/4 Aston :=0A> Hello,=0A>=0A> recently i have been trying to learn and = use dl library. while searching i=0A> found this excellent link=0A> http://= www.jbrowse.com/text/rdl_en.html=0A>=0A> unfortunately it is specific to 1.= 8.x=0A>=0A> i wonder how people here use DL, since it is very scarcely docu= mented. i=0A> have been trying to=0A> hack around ./ext/dl/*.c files but i = have gained very little usable=0A> information.=0A>=0A> ok, my question is = about passing an array from ruby to some native libraries=0A> (IPP(http://s= oftware.intel.com/en-us/intel-ipp/) to be specific)=0A> on windows. yes i a= bout other alternatives, i could embed ruby in my app and=0A> do whatever, = there is gr8 support there=0A> but this is about quickly loading and using = native libraries via dynamic=0A> loader.=0A>=0A> consider code below=0A> so= me_fast_math_function( float* array, int len);=0A>=0A> then how to pass 'ar= ray' argument from ruby ?=0A> i tried this=0A>=0A> require 'dl'=0A>=0A> mod= ule NativeLibs=0A> # do the job for accessing some_fast_math_function=0A> e= nd=0A>=0A> array =3D DL.malloc(size)=0A> NativeLibs.some_fast_math_function= ( array, size) # crashes :(=0A>=0A> some how sucess is elusive for me, this= crashes(core dumps) for me, i am=0A> sure this is due to my inexperienced = stunts with DL=0A>=0A> Aston=0A>=0A>=0A> ________________________________= =0A> Now surf faster and smarter ! Check out the new Firefox 3 - Yahoo! Edi= tion *=0A> Click here!=0A=0A=0A Bollywood news, movie reviews, film tr= ailers and more! Go to http://in.movies.yahoo.com/ --0-744217757-1241633070=:65549 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
thanks a lot tad.bochan@bnpparibas= .com and sh@sheepman.sakura.ne.jp
tad seems to be using 1.8.x, i am using ruby19 on FreeBSD7.2

<= /font>[diesalunix@raptor ~]$ uname -a
= =0AFreeBSD raptor 7.2-PRERELEASE FreeBSD 7.2-PRERELEASE #1: Sun Mar 29=0A19= :18:27 UTC 2009     root@raptor:/usr/obj/usr/src/sys/AR= GON18  amd64
[diesalunix@ra= ptor ~]$ ruby19 -v
ruby 1.9.2dev (2009-05-02 trunk 23326) [x86_64-freebs= d7.2]

as suggested by sh@ test/dl/test_*.rb are good (not gr8!) sour= ce for learning, but given the fact there exists no other code using dl els= ewhere I am very happy I found them. thanks sh@

While googling= around I discovered ruby-ffi (http://kenai.com/projects/ruby-ffi/pages/Ho= me), and it seems to be much more clean and complete solution. It is su= pported by other VMs as well. I would have prefered to be with dl since it = is part of standard ruby C implementation but it is very difficult to use(u= got to have lot of time and little black magic), code using it is almost n= on-existent and /dev/null documentation

when reading about ruby-ffi elsewhere it appears very promising, what is its future in regard= to ruby's C implementation ? will it ever be part of stdlib ? it appears i= t is still taking shape but by and large stable

Aston
=

From: "sh@sheepman.sakura.ne.jp" <sh@sheepman.sa= kura.ne.jp>
To: ruby= -core@ruby-lang.org
Sent: Tuesday, 5 May, 2009 2:06:09 PM
Subject: [ruby-core:23359] Re: Ruby/DL Documentation
=
Hi,

It is helpful to read test/dl/test_*.rb in ruby-1.9.tar.gz.<= br>You have to master pack and unpack anyway.
The following is an exampl= e.

$ cat sum.c
double sum(double *arry, int len)
{
  double ret = =3D 0;
  int i;
  for(i =3D 0; i < len; i++){
  =   ret =3D ret + arry[i];
  }
  return ret;
}
$ gcc -shared sum.c -o libsum.so

$ cat d.rb
require 'dl/import'<= br>module M
  extend DL::Importer
  dlload './libsum.so'  extern 'double sum(double*, int)'
end
p M.sum([2.0, 3.0, 4.0]= .pack("d*"), 3)

$ ruby-1.9 -v d.rb
ruby 1.9.2dev (2009-05-02 trun= k 23326) [i686-linux]
9.0


2009/5/4 Aston <blackapache512-ticket@yahoo.com>:
> Hello,
><= br>> recently i have been trying to learn and use dl library. while sear= ching i
> found this excellent link
> http://www.jbrowse.com/text/rdl_en.html
>
&= gt; unfortunately it is specific to 1.8.x
>
> i wonder how peop= le here use DL, since it is very scarcely documented. i
> have been t= rying to
> hack around ./ext/dl/*.c files but i have gained very litt= le usable
> information.
>
> ok, my question is about pas= sing an array from ruby to some native libraries
> (IPP(http://software= .intel.com/en-us/intel-ipp/) to be specific)
> on windows. yes i = about other alternatives, i could embed ruby in my app and
> do whate= ver, there is gr8 support there
> but this is about quickly loading a= nd using native libraries via dynamic
> loader.
>
> consi= der code below
> some_fast_math_function( float* array, int len);
= >
> then how to pass 'array' argument from ruby ?
> i tried this
>
> require 'dl'
>
> module NativeLibs
>= ; # do the job for accessing some_fast_math_function
> end
>> array =3D DL.malloc(size)
> NativeLibs.some_fast_math_function(= array, size) # crashes :(
>
> some how sucess is elusive for m= e, this crashes(core dumps) for me, i am
> sure this is due to my ine= xperienced stunts with DL
>
> Aston
>
>
> ___= _____________________________
> Now surf faster and smarter ! Check o= ut the new Firefox 3 - Yahoo! Edition *
> Click here!


=0A=0A=0A
Explore your hobbie= s and interests. Click here to begin. --0-744217757-1241633070=:65549--