ext/fiddle/pointer.c in fiddle-1.0.9 vs ext/fiddle/pointer.c in fiddle-1.1.0
- old
+ new
@@ -4,17 +4,17 @@
#include <stdbool.h>
#include <ruby/ruby.h>
#include <ruby/io.h>
+#include <ctype.h>
+#include <fiddle.h>
+
#ifdef HAVE_RUBY_MEMORY_VIEW_H
# include <ruby/memory_view.h>
#endif
-#include <ctype.h>
-#include <fiddle.h>
-
#ifdef PRIsVALUE
# define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj)
# define RB_OBJ_STRING(obj) (obj)
#else
# define PRIsVALUE "s"
@@ -22,11 +22,11 @@
# define RB_OBJ_STRING(obj) StringValueCStr(obj)
#endif
VALUE rb_cPointer;
-typedef void (*freefunc_t)(void*);
+typedef rb_fiddle_freefunc_t freefunc_t;
struct ptr_data {
void *ptr;
long size;
freefunc_t free;
@@ -90,11 +90,11 @@
static const rb_data_type_t fiddle_ptr_data_type = {
"fiddle/pointer",
{fiddle_ptr_mark, fiddle_ptr_free, fiddle_ptr_memsize,},
};
-#ifdef FIDDLE_MEMORY_VIEW
+#ifdef HAVE_RUBY_MEMORY_VIEW_H
static struct ptr_data *
fiddle_ptr_check_memory_view(VALUE obj)
{
struct ptr_data *data;
TypedData_Get_Struct(obj, struct ptr_data, &fiddle_ptr_data_type, data);
@@ -123,38 +123,46 @@
fiddle_ptr_memory_view_available_p
};
#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;
val = TypedData_Make_Struct(klass, struct ptr_data, &fiddle_ptr_data_type, data);
data->ptr = ptr;
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
rb_fiddle_ptr_malloc(VALUE klass, long size, freefunc_t func)
{
void *ptr;
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 *
rb_fiddle_ptr2cptr(VALUE val)
{
@@ -831,10 +839,10 @@
rb_define_method(rb_cPointer, "[]", rb_fiddle_ptr_aref, -1);
rb_define_method(rb_cPointer, "[]=", rb_fiddle_ptr_aset, -1);
rb_define_method(rb_cPointer, "size", rb_fiddle_ptr_size_get, 0);
rb_define_method(rb_cPointer, "size=", rb_fiddle_ptr_size_set, 1);
-#ifdef FIDDLE_MEMORY_VIEW
+#ifdef HAVE_RUBY_MEMORY_VIEW_H
rb_memory_view_register(rb_cPointer, &fiddle_ptr_memory_view_entry);
#endif
/* Document-const: NULL
*