summaryrefslogtreecommitdiff
path: root/ext/fiddle/pointer.c
diff options
context:
space:
mode:
authorKenta Murata <mrkn@users.noreply.github.com>2021-07-14 11:26:52 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-07-14 18:43:32 +0900
commit818c74b7f4d5b88833af26226fc81e563b5d11b9 (patch)
tree8b5271350f2d3394e43e648ce3dd70fbaf2eed80 /ext/fiddle/pointer.c
parent57a743efa408f0c47fc18dd16758a1a1cd54d296 (diff)
[ruby/fiddle] Return the module handle value in Fiddle::Handle#to_i and add FIddle::Handle#to_ptr (https://github.com/ruby/fiddle/pull/87)
https://github.com/ruby/fiddle/commit/170111a0cb
Diffstat (limited to 'ext/fiddle/pointer.c')
-rw-r--r--ext/fiddle/pointer.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/ext/fiddle/pointer.c b/ext/fiddle/pointer.c
index ae9eb16..9d05c13 100644
--- a/ext/fiddle/pointer.c
+++ b/ext/fiddle/pointer.c
@@ -24,7 +24,7 @@
VALUE rb_cPointer;
-typedef void (*freefunc_t)(void*);
+typedef rb_fiddle_freefunc_t freefunc_t;
struct ptr_data {
void *ptr;
@@ -125,7 +125,7 @@ static const rb_memory_view_entry_t fiddle_ptr_memory_view_entry = {
#endif
static VALUE
-rb_fiddle_ptr_new2(VALUE klass, void *ptr, long size, freefunc_t func)
+rb_fiddle_ptr_new2(VALUE klass, void *ptr, long size, freefunc_t func, VALUE wrap0, VALUE wrap1)
{
struct ptr_data *data;
VALUE val;
@@ -135,14 +135,22 @@ rb_fiddle_ptr_new2(VALUE klass, void *ptr, long size, freefunc_t func)
data->free = func;
data->freed = false;
data->size = size;
+ data->wrap[0] = wrap0;
+ data->wrap[1] = wrap1;
return val;
}
+VALUE
+rb_fiddle_ptr_new_wrap(void *ptr, long size, freefunc_t func, VALUE wrap0, VALUE wrap1)
+{
+ return rb_fiddle_ptr_new2(rb_cPointer, ptr, size, func, wrap0, wrap1);
+}
+
static VALUE
rb_fiddle_ptr_new(void *ptr, long size, freefunc_t func)
{
- return rb_fiddle_ptr_new2(rb_cPointer, ptr, size, func);
+ return rb_fiddle_ptr_new2(rb_cPointer, ptr, size, func, 0, 0);
}
static VALUE
@@ -152,7 +160,7 @@ rb_fiddle_ptr_malloc(VALUE klass, long size, freefunc_t func)
ptr = ruby_xmalloc((size_t)size);
memset(ptr,0,(size_t)size);
- return rb_fiddle_ptr_new2(klass, ptr, size, func);
+ return rb_fiddle_ptr_new2(klass, ptr, size, func, 0, 0);
}
static void *