aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-01 01:47:08 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-01 01:47:08 +0000
commita9e662ac7aebe26c927dfdc1ef2a35eccffc470c (patch)
tree180b27b003760335f6a5176a031e5b9914a3e04f
parent4b76900a55b4159888dd2edc6a8828e2964318d2 (diff)
downloadruby-a9e662ac7aebe26c927dfdc1ef2a35eccffc470c.tar.gz
* ext/dl/cptr.c (rb_dlptr_ptr, rb_dlptr_ref) adding documentation
* test/dl/test_cptr.rb (test_ref_ptr) testing CPtr#ref and CPtr#ptr git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ext/dl/cptr.c12
-rw-r--r--test/dl/test_cptr.rb8
2 files changed, 20 insertions, 0 deletions
diff --git a/ext/dl/cptr.c b/ext/dl/cptr.c
index 555236f2ad..466905f69b 100644
--- a/ext/dl/cptr.c
+++ b/ext/dl/cptr.c
@@ -210,6 +210,12 @@ rb_dlptr_to_value(VALUE self)
return (VALUE)(data->ptr);
}
+/*
+ * call-seq: ptr
+ *
+ * Returns a DL::CPtr that is a dereferenced pointer for this DL::CPtr.
+ * Analogous to the star operator in C.
+ */
VALUE
rb_dlptr_ptr(VALUE self)
{
@@ -219,6 +225,12 @@ rb_dlptr_ptr(VALUE self)
return rb_dlptr_new(*((void**)(data->ptr)),0,0);
}
+/*
+ * call-seq: ref
+ *
+ * Returns a DL::CPtr that is a reference pointer for this DL::CPtr.
+ * Analogous to the ampersand operator in C.
+ */
VALUE
rb_dlptr_ref(VALUE self)
{
diff --git a/test/dl/test_cptr.rb b/test/dl/test_cptr.rb
index 461b7d27d4..2a55a07dee 100644
--- a/test/dl/test_cptr.rb
+++ b/test/dl/test_cptr.rb
@@ -3,6 +3,14 @@ require_relative '../ruby/envutil'
module DL
class TestCPtr < TestBase
+ def test_ref_ptr
+ ary = [0,1,2,4,5]
+ addr = CPtr.new(dlwrap(ary))
+ assert_equal addr.to_i, addr.ref.ptr.to_i
+
+ assert_equal addr.to_i, (+ (- addr)).to_i
+ end
+
def test_to_value
ary = [0,1,2,4,5]
addr = CPtr.new(dlwrap(ary))