summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-03 20:28:20 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-03 20:28:20 +0000
commit02d55ac989bf29d6a87d63e93dc49941438f495b (patch)
tree4ce30bdfe91e4b2386a6e26daf31bcf8d2d20e88 /ext
parentb9e0294edaceecb177401902f3809a45af666d7e (diff)
* test/dl/test_cptr.rb (test_to_ptr*): testing DL::CPtr#to_ptr
* ext/dl/cptr.c (rb_dlptr_free_set, rb_dlptr_free_get, rb_dlptr_s_to_ptr): adding documentation, fixing indentation git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/dl/cptr.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/ext/dl/cptr.c b/ext/dl/cptr.c
index 94632e8240..cdcc23c727 100644
--- a/ext/dl/cptr.c
+++ b/ext/dl/cptr.c
@@ -254,7 +254,12 @@ rb_dlptr_null_p(VALUE self)
return data->ptr ? Qfalse : Qtrue;
}
-VALUE
+/*
+ * call-seq: free=(function)
+ *
+ * Set the free function for this pointer to the DL::CFunc in +function+.
+ */
+static VALUE
rb_dlptr_free_set(VALUE self, VALUE val)
{
struct ptr_data *data;
@@ -265,7 +270,12 @@ rb_dlptr_free_set(VALUE self, VALUE val)
return Qnil;
}
-VALUE
+/*
+ * call-seq: free
+ *
+ * Get the free function for this pointer. Returns DL::CFunc or nil.
+ */
+static VALUE
rb_dlptr_free_get(VALUE self)
{
struct ptr_data *pdata;
@@ -499,21 +509,29 @@ rb_dlptr_size_get(VALUE self)
return LONG2NUM(RPTR_DATA(self)->size);
}
-VALUE
+/*
+ * call-seq:
+ * DL::CPtr.to_ptr(val) => cptr
+ * DL::CPtr[val] => cptr
+ *
+ * Get the underlying pointer for ruby object +val+ and return it as a
+ * DL::CPtr object.
+ */
+static VALUE
rb_dlptr_s_to_ptr(VALUE self, VALUE val)
{
VALUE ptr;
- if (rb_obj_is_kind_of(val, rb_cIO) == Qtrue){
+ if (RTEST(rb_obj_is_kind_of(val, rb_cIO))){
rb_io_t *fptr;
FILE *fp;
GetOpenFile(val, fptr);
fp = rb_io_stdio_file(fptr);
ptr = rb_dlptr_new(fp, 0, NULL);
}
- else if (rb_obj_is_kind_of(val, rb_cString) == Qtrue){
- char *str = StringValuePtr(val);
- ptr = rb_dlptr_new(str, RSTRING_LEN(val), NULL);
+ else if (RTEST(rb_obj_is_kind_of(val, rb_cString))){
+ char *str = StringValuePtr(val);
+ ptr = rb_dlptr_new(str, RSTRING_LEN(val), NULL);
}
else if (rb_respond_to(val, id_to_ptr)){
VALUE vptr = rb_funcall(val, id_to_ptr, 0);