ruby-changes:13884
From: tenderlove <ko1@a...>
Date: Sun, 8 Nov 2009 09:21:50 +0900 (JST)
Subject: [ruby-changes:13884] Ruby:r25686 (trunk): * ext/dl/cfunc.c (**) updating documentation
tenderlove 2009-11-08 09:21:41 +0900 (Sun, 08 Nov 2009) New Revision: 25686 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25686 Log: * ext/dl/cfunc.c (**) updating documentation * test/dl/test_cfunc.rb (test_ptr=, test_ptr) testing the pointer accessor methods on CFunc Modified files: trunk/ext/dl/cfunc.c trunk/test/dl/test_cfunc.rb Index: ext/dl/cfunc.c =================================================================== --- ext/dl/cfunc.c (revision 25685) +++ ext/dl/cfunc.c (revision 25686) @@ -112,7 +112,7 @@ return func; } -VALUE +static VALUE rb_dlcfunc_s_allocate(VALUE klass) { VALUE obj; @@ -241,8 +241,13 @@ return sym; } - -VALUE +/* + * call-seq: + * cfunc.ptr + * + * Get the underlying function pointer as a DL::CPtr object. + */ +static VALUE rb_dlcfunc_ptr(VALUE self) { struct cfunc_data *cfunc; @@ -251,7 +256,13 @@ return PTR2NUM(cfunc->ptr); } -VALUE +/* + * call-seq: + * cfunc.ptr = pointer + * + * Set the underlying function pointer to a DL::CPtr named +pointer+. + */ +static VALUE rb_dlcfunc_set_ptr(VALUE self, VALUE addr) { struct cfunc_data *cfunc; @@ -262,7 +273,13 @@ return Qnil; } -VALUE +/* + * call-seq: inspect + * + * Returns a string formatted with an easily readable representation of the + * internal state of the DL::CFunc + */ +static VALUE rb_dlcfunc_inspect(VALUE self) { VALUE val; @@ -302,6 +319,14 @@ } +/* + * call-seq: + * dlcfunc.call(ary) => some_value + * dlcfunc[ary] => some_value + * + * Calls the function pointer passing in +ary+ as values to the underlying + * C function. The return value depends on the ctype. + */ static VALUE rb_dlcfunc_call(VALUE self, VALUE ary) { @@ -550,7 +575,13 @@ return result; } -VALUE +/* + * call-seq: + * dlfunc.to_i => integer + * + * Returns the memory location of this function pointer as an integer. + */ +static VALUE rb_dlcfunc_to_i(VALUE self) { struct cfunc_data *cfunc; Index: test/dl/test_cfunc.rb =================================================================== --- test/dl/test_cfunc.rb (revision 25685) +++ test/dl/test_cfunc.rb (revision 25686) @@ -9,6 +9,15 @@ @cf = CFunc.new(@libc[@name], TYPE_VOIDP, @name) end + def test_ptr= + @cf.ptr = @libc['malloc'] + assert_equal @cf.ptr, @libc['malloc'] + end + + def test_ptr + assert_equal @cf.ptr, @libc[@name] + end + def test_set_calltype @cf.calltype = :foo assert_equal :foo, @cf.calltype -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/