ruby-changes:13877
From: tenderlove <ko1@a...>
Date: Sat, 7 Nov 2009 03:29:41 +0900 (JST)
Subject: [ruby-changes:13877] Ruby:r25677 (trunk): * ext/dl/cptr.c (rb_dlptr_to_str, rb_dlptr_to_s) adding documentation
tenderlove 2009-11-07 03:29:31 +0900 (Sat, 07 Nov 2009) New Revision: 25677 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25677 Log: * ext/dl/cptr.c (rb_dlptr_to_str, rb_dlptr_to_s) adding documentation * test/dl/test_cptr.rb (test_to_str, test_to_s) testing the stringification of DL::Ptr Modified files: trunk/ext/dl/cptr.c trunk/test/dl/test_cptr.rb Index: ext/dl/cptr.c =================================================================== --- ext/dl/cptr.c (revision 25676) +++ ext/dl/cptr.c (revision 25677) @@ -188,7 +188,12 @@ return obj; } -VALUE +/* + * call-seq: to_i + * + * Returns the integer memory location of this DL::CPtr. + */ +static VALUE rb_dlptr_to_i(VALUE self) { struct ptr_data *data; @@ -202,7 +207,7 @@ * * Cast this CPtr to a ruby object. */ -VALUE +static VALUE rb_dlptr_to_value(VALUE self) { struct ptr_data *data; @@ -285,7 +290,17 @@ return rb_dlcfunc_new(pdata->free, DLTYPE_VOID, "free<anonymous>", CFUNC_CDECL); } -VALUE +/* + * call-seq: + * + * ptr.to_s => string + * ptr.to_s(len) => string + * + * Returns the pointer contents as a string. When called with no arguments, + * this method will return the contents until the first NULL byte. When + * called with +len+, a string of +len+ bytes will be returned. + */ +static VALUE rb_dlptr_to_s(int argc, VALUE argv[], VALUE self) { struct ptr_data *data; @@ -308,7 +323,17 @@ return val; } -VALUE +/* + * call-seq: + * + * ptr.to_str => string + * ptr.to_str(len) => string + * + * Returns the pointer contents as a string. When called with no arguments, + * this method will return the contents with the length of this pointer's + * +size+. When called with +len+, a string of +len+ bytes will be returned. + */ +static VALUE rb_dlptr_to_str(int argc, VALUE argv[], VALUE self) { struct ptr_data *data; Index: test/dl/test_cptr.rb =================================================================== --- test/dl/test_cptr.rb (revision 25676) +++ test/dl/test_cptr.rb (revision 25677) @@ -3,6 +3,28 @@ module DL class TestCPtr < TestBase + def test_to_str + str = "hello world" + ptr = CPtr[str] + + assert_equal 3, ptr.to_str(3).length + assert_equal str, ptr.to_str + + ptr[5] = 0 + assert_equal "hello\0world", ptr.to_str + end + + def test_to_s + str = "hello world" + ptr = CPtr[str] + + assert_equal 3, ptr.to_s(3).length + assert_equal str, ptr.to_s + + ptr[5] = 0 + assert_equal 'hello', ptr.to_s + end + def test_minus str = "hello world" ptr = CPtr[str] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/