From: Aston Date: 2009-05-07T18:35:48+09:00 Subject: Fw: [ruby-core:23371] Re: Ruby/DL Documentation --0-600190453-1241688540=:26635 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable I think this thread makes more sense here instead of polluting core ML=0A= =0A=0A=0A----- Forwarded Message ----=0AFrom: Aston =0ATo: ruby-core@ruby-lang.org=0ASent: Wednesday, 6 May, 2009 11:= 34:36 PM=0ASubject: [ruby-core:23371] Re: Ruby/DL Documentation=0A=0A=0Atha= nks a lot tad.bochan@bnpparibas.com and sh@sheepman.sakura.ne.jp=0A=0Atad s= eems to be using 1.8.x, i am using ruby19 on FreeBSD7.2=0A=0A[diesalunix@ra= ptor ~]$ uname -a=0AFreeBSD raptor 7.2-PRERELEASE FreeBSD 7.2-PRERELEASE #1= : Sun Mar 29 19:18:27 UTC 2009=A0=A0=A0=A0 root@raptor:/usr/obj/usr/src/sys= /ARGON18=A0 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/tes= t_*.rb are good (not gr8!) source for learning, but given the fact there ex= ists 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/proj= ects/ruby-ffi/pages/Home), and it seems to be much more clean and complete = solution. It is supported 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 us= ing it is almost non-existent and /dev/null documentation=0A=0Awhen 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 app= ears it is still taking shape but by and large stable=0A=0AAston=0A=0A=0A= =0A=0A________________________________=0AFrom: "sh@sheepman.sakura.ne.jp" <= 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.= =0AYou 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=A0 double ret= =3D 0;=0A=A0 int i;=0A=A0 for(i =3D 0; i < len; i++){=0A=A0 =A0 ret =3D re= t + arry[i];=0A=A0 }=0A=A0 return ret;=0A}=0A=0A$ gcc -shared sum.c -o libs= um.so=0A=0A$ cat d.rb=0Arequire 'dl/import'=0Amodule M=0A=A0 extend DL::Imp= orter=0A=A0 dlload './libsum.so'=0A=A0 extern 'double sum(double*, int)'=0A= end=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 Asto= n :=0A> Hello,=0A>=0A> recently i have bee= n trying to learn and use dl library. while searching i=0A> found this exce= llent link=0A> http://www.jbrowse.com/text/rdl_en.html=0A>=0A> unfortunatel= y it is specific to 1.8.x=0A>=0A> i wonder how people here use DL, since it= is very scarcely documented. i=0A> have been trying to=0A> hack around ./e= xt/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 lib= raries=0A> (IPP(http://software.intel.com/en-us/intel-ipp/) to be specific)= =0A> on windows. yes i about other alternatives, i could embed ruby in my a= pp and=0A> do whatever, there is gr8 support there=0A> but this is about qu= ickly loading and using native libraries via dynamic=0A> loader.=0A>=0A> co= nsider code below=0A> some_fast_math_function( float* array, int len);=0A>= =0A> then how to pass 'array' argument from ruby ?=0A> i tried this=0A>=0A>= require 'dl'=0A>=0A> module NativeLibs=0A> # do the job for accessing some= _fast_math_function=0A> end=0A>=0A> array =3D DL.malloc(size)=0A> NativeLib= s.some_fast_math_function( array, size) # crashes :(=0A>=0A> some how suces= s 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! Edition *=0A> Click here!=0A=0A=0A_____________________= ___________=0AExplore your hobbies and interests. Click here to begin.=0A= =0A=0A Cricket on your mind? Visit the ultimate cricket website. Enter= http://beta.cricket.yahoo.com --0-600190453-1241688540=:26635--