11 # define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj) 12 # define RB_OBJ_STRING(obj) (obj) 14 # define PRIsVALUE "s" 15 # define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj) 16 # define RB_OBJ_STRING(obj) StringValueCStr(obj) 30 #define RPTR_DATA(obj) ((struct ptr_data *)(DATA_PTR(obj))) 41 *wrap = (addrnum != func) ? func : 0;
48 fiddle_ptr_mark(
void *
ptr)
60 fiddle_ptr_free(
void *
ptr)
72 fiddle_ptr_memsize(
const void *
ptr)
75 return sizeof(*data) + data->
size;
80 {fiddle_ptr_mark, fiddle_ptr_free, fiddle_ptr_memsize,},
110 memset(ptr,0,(
size_t)size);
111 return rb_fiddle_ptr_new(ptr, size, func);
124 else if (val ==
Qnil) {
135 rb_fiddle_ptr_s_allocate(
VALUE klass)
169 if (addrnum != ptr) wrap =
ptr;
176 f = get_freefunc(sym, &funcwrap);
186 data->
wrap[1] = funcwrap;
220 f = get_freefunc(sym, &wrap);
223 rb_bug(
"rb_fiddle_ptr_s_malloc");
226 obj = rb_fiddle_ptr_malloc(s,f);
238 rb_fiddle_ptr_to_i(
VALUE self)
252 rb_fiddle_ptr_to_value(
VALUE self)
268 rb_fiddle_ptr_ptr(
VALUE self)
273 return rb_fiddle_ptr_new(*((
void**)(data->
ptr)),0,0);
285 rb_fiddle_ptr_ref(
VALUE self)
290 return rb_fiddle_ptr_new(&(data->
ptr),0,0);
299 rb_fiddle_ptr_null_p(
VALUE self)
319 data->
free = get_freefunc(val, &data->
wrap[1]);
334 rb_fiddle_ptr_free_get(
VALUE self)
386 rb_bug(
"rb_fiddle_ptr_to_s");
424 rb_bug(
"rb_fiddle_ptr_to_str");
437 rb_fiddle_ptr_inspect(
VALUE self)
461 ptr1 = rb_fiddle_ptr2cptr(
self);
462 ptr2 = rb_fiddle_ptr2cptr(other);
483 ptr1 = rb_fiddle_ptr2cptr(
self);
484 ptr2 = rb_fiddle_ptr2cptr(other);
502 ptr = rb_fiddle_ptr2cptr(
self);
505 return rb_fiddle_ptr_new((
char *)ptr + num, size - num, 0);
520 ptr = rb_fiddle_ptr2cptr(
self);
523 return rb_fiddle_ptr_new((
char *)ptr - num, size + num, 0);
549 retval =
INT2NUM(*((
char *)data->
ptr + offset));
557 rb_bug(
"rb_fiddle_ptr_aref()");
576 VALUE arg0, arg1, arg2;
597 mem = rb_fiddle_ptr2cptr(arg2);
602 memcpy((
char *)data->
ptr + offset, mem, len);
606 rb_bug(
"rb_fiddle_ptr_aset()");
629 rb_fiddle_ptr_size_get(
VALUE self)
652 ptr = rb_fiddle_ptr_new(fp, 0,
NULL);
669 if (num == val) wrap = 0;
RUBY_EXTERN VALUE rb_cString
void rb_bug(const char *fmt,...)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
void rb_raise(VALUE exc, const char *fmt,...)
#define TypedData_Get_Struct(obj, type, data_type, sval)
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE rb_Integer(VALUE)
Equivalent to Kernel#Integer in Ruby.
void rb_gc_mark(VALUE ptr)
#define GetOpenFile(obj, fp)
#define RB_TYPE_P(obj, type)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
call-seq: obj.is_a?(class) -> true or false obj.kind_of?(class) -> true or false
RUBY_EXTERN VALUE rb_cObject
void rb_define_const(VALUE, const char *, VALUE)
void(* freefunc_t)(void *)
#define RB_OBJ_CLASSNAME(obj)
VALUE rb_sprintf(const char *format,...)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
#define rb_tainted_str_new2
register unsigned int len
void * ruby_xmalloc(size_t size)
VALUE rb_fiddle_new_function(VALUE address, VALUE arg_types, VALUE ret_type)
#define TypedData_Make_Struct(klass, type, data_type, sval)
FILE * rb_io_stdio_file(rb_io_t *fptr)
#define StringValuePtr(v)
void Init_fiddle_pointer(void)
VALUE rb_tainted_str_new(const char *, long)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)