Ruby 2.0.0p353(2013-11-22revision43784)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Data Structures | Macros | Typedefs | Functions | Variables
pointer.c File Reference
`#include <ruby/ruby.h>`
`#include <ruby/io.h>`
`#include <ctype.h>`
`#include <fiddle.h>`
Include dependency graph for pointer.c:

Go to the source code of this file.

## Data Structures
struct | ptr_data

## Macros
#define | RPTR_DATA(obj) ((struct ptr_data *)(DATA_PTR(obj)))

## Typedefs
typedef void(* | freefunc_t )(void *)

## Functions
static freefunc_t | get_freefunc (VALUE func, volatile VALUE *wrap)
static void | fiddle_ptr_mark (void *ptr)
static void | fiddle_ptr_free (void *ptr)
static size_t | fiddle_ptr_memsize (const void *ptr)
static VALUE | rb_fiddle_ptr_new2 (VALUE klass, void *ptr, long size, freefunc_t func)
static VALUE | rb_fiddle_ptr_new (void *ptr, long size, freefunc_t func)
static VALUE | rb_fiddle_ptr_malloc (long size, freefunc_t func)
static void * | rb_fiddle_ptr2cptr (VALUE val)
static VALUE | rb_fiddle_ptr_s_allocate (VALUE klass)
static VALUE | rb_fiddle_ptr_initialize (int argc, VALUE argv[], VALUE self)
static VALUE | rb_fiddle_ptr_s_malloc (int argc, VALUE argv[], VALUE klass)
static VALUE | rb_fiddle_ptr_to_i (VALUE self)
static VALUE | rb_fiddle_ptr_to_value (VALUE self)
static VALUE | rb_fiddle_ptr_ptr (VALUE self)
static VALUE | rb_fiddle_ptr_ref (VALUE self)
static VALUE | rb_fiddle_ptr_null_p (VALUE self)
static VALUE | rb_fiddle_ptr_free_set (VALUE self, VALUE val)
static VALUE | rb_fiddle_ptr_free_get (VALUE self)
static VALUE | rb_fiddle_ptr_to_s (int argc, VALUE argv[], VALUE self)
static VALUE | rb_fiddle_ptr_to_str (int argc, VALUE argv[], VALUE self)
static VALUE | rb_fiddle_ptr_inspect (VALUE self)
static VALUE | rb_fiddle_ptr_eql (VALUE self, VALUE other)
static VALUE | rb_fiddle_ptr_cmp (VALUE self, VALUE other)
static VALUE | rb_fiddle_ptr_plus (VALUE self, VALUE other)
static VALUE | rb_fiddle_ptr_minus (VALUE self, VALUE other)
static VALUE | rb_fiddle_ptr_aref (int argc, VALUE argv[], VALUE self)
static VALUE | rb_fiddle_ptr_aset (int argc, VALUE argv[], VALUE self)
static VALUE | rb_fiddle_ptr_size_set (VALUE self, VALUE size)
static VALUE | rb_fiddle_ptr_size_get (VALUE self)
static VALUE | rb_fiddle_ptr_s_to_ptr (VALUE self, VALUE val)
void | Init_fiddle_pointer (void)

## Variables
VALUE | rb_cPointer
static ID | id_to_ptr
static const rb_data_type_t | fiddle_ptr_data_type

## Macro Definition Documentation

#define RPTR_DATA | ( |  | obj | ) | ((struct ptr_data *)(DATA_PTR(obj)))

Definition at line 21 of file pointer.c.

Referenced by rb_fiddle_ptr_minus(), rb_fiddle_ptr_plus(), rb_fiddle_ptr_s_malloc(), rb_fiddle_ptr_s_to_ptr(), rb_fiddle_ptr_size_get(), and rb_fiddle_ptr_size_set().

## Typedef Documentation

typedef void(* freefunc_t)(void *)

Definition at line 12 of file pointer.c.

## Function Documentation

static void fiddle_ptr_free | ( | void * | ptr | ) |
| static

Definition at line 51 of file pointer.c.

References data, ptr_data::free, ptr_data::ptr, and ptr.

static void fiddle_ptr_mark | ( | void * | ptr | ) |
| static

Definition at line 39 of file pointer.c.

References data, ptr, rb_gc_mark(), and ptr_data::wrap.

static size_t fiddle_ptr_memsize | ( | const void * | ptr | ) |
| static

Definition at line 62 of file pointer.c.

References data, ptr, and ptr_data::size.

static freefunc_t get_freefunc | ( | VALUE | func,
|  | volatile VALUE * | wrap
| ) |  |
| inline static

Definition at line 24 of file pointer.c.

References func, NIL_P(), NULL, NUM2PTR, and rb_Integer().

Referenced by rb_fiddle_ptr_free_set(), rb_fiddle_ptr_initialize(), and rb_fiddle_ptr_s_malloc().

void Init_fiddle_pointer | ( | void |  | ) |

Definition at line 673 of file pointer.c.

References id_to_ptr, mFiddle, rb_cObject, rb_cPointer, rb_define_alloc_func(), rb_define_class_under(), rb_define_const(), rb_define_method(), rb_define_singleton_method(), rb_fiddle_ptr_aref(), rb_fiddle_ptr_aset(), rb_fiddle_ptr_cmp(), rb_fiddle_ptr_eql(), rb_fiddle_ptr_free_get(), rb_fiddle_ptr_free_set(), rb_fiddle_ptr_initialize(), rb_fiddle_ptr_inspect(), rb_fiddle_ptr_minus(), rb_fiddle_ptr_new(), rb_fiddle_ptr_null_p(), rb_fiddle_ptr_plus(), rb_fiddle_ptr_ptr(), rb_fiddle_ptr_ref(), rb_fiddle_ptr_s_allocate(), rb_fiddle_ptr_s_malloc(), rb_fiddle_ptr_s_to_ptr(), rb_fiddle_ptr_size_get(), rb_fiddle_ptr_size_set(), rb_fiddle_ptr_to_i(), rb_fiddle_ptr_to_s(), rb_fiddle_ptr_to_str(), rb_fiddle_ptr_to_value(), and rb_intern.

Referenced by Init_fiddle().

static void* rb_fiddle_ptr2cptr | ( | VALUE | val | ) |
| static

Definition at line 107 of file pointer.c.

References data, NULL, ptr_data::ptr, ptr, Qnil, rb_cPointer, rb_eTypeError, rb_obj_is_kind_of(), rb_raise(), and TypedData_Get_Struct.

Referenced by rb_fiddle_ptr_aset(), rb_fiddle_ptr_cmp(), rb_fiddle_ptr_eql(), rb_fiddle_ptr_minus(), and rb_fiddle_ptr_plus().

static VALUE rb_fiddle_ptr_aref | ( | int | argc,
|  | VALUE | argv[],
|  | VALUE | self
| ) |  |
| static

Definition at line 532 of file pointer.c.

References data, INT2NUM, len, NUM2ULONG, ptr_data::ptr, Qnil, rb_bug(), rb_eFiddleError, rb_raise(), rb_scan_args(), rb_tainted_str_new(), retval, and TypedData_Get_Struct.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_aset | ( | int | argc,
|  | VALUE | argv[],
|  | VALUE | self
| ) |  |
| static

Definition at line 569 of file pointer.c.

References data, len, memcpy(), NUM2PTR, NUM2UINT, NUM2ULONG, ptr_data::ptr, Qnil, rb_bug(), rb_cPointer, rb_eFiddleError, rb_fiddle_ptr2cptr(), rb_obj_is_kind_of(), rb_raise(), rb_scan_args(), RB_TYPE_P, retval, StringValuePtr, T_STRING, and TypedData_Get_Struct.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_cmp | ( | VALUE | self,
|  | VALUE | other
| ) |  |
| static

Definition at line 471 of file pointer.c.

References diff(), INT2FIX, INT2NUM, Qnil, rb_cPointer, rb_fiddle_ptr2cptr(), rb_obj_is_kind_of(), and SIGNED_VALUE.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_eql | ( | VALUE | self,
|  | VALUE | other
| ) |  |
| static

Definition at line 450 of file pointer.c.

References Qfalse, Qtrue, rb_cPointer, rb_fiddle_ptr2cptr(), and rb_obj_is_kind_of().

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_free_get | ( | VALUE | self | ) |
| static

Definition at line 327 of file pointer.c.

References ptr_data::free, INT2NUM, PTR2NUM, Qnil, rb_ary_new(), rb_ary_push(), rb_fiddle_new_function(), TYPE_VOID, TYPE_VOIDP, and TypedData_Get_Struct.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_free_set | ( | VALUE | self,
|  | VALUE | val
| ) |  |
| static

Definition at line 307 of file pointer.c.

References data, ptr_data::free, get_freefunc(), Qnil, TypedData_Get_Struct, and ptr_data::wrap.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_initialize | ( | int | argc,
|  | VALUE | argv[],
|  | VALUE | self
| ) |  |
| static

Definition at line 152 of file pointer.c.

References data, f, ptr_data::free, get_freefunc(), NULL, NUM2LONG, NUM2PTR, p, ptr_data::ptr, ptr, Qnil, rb_Integer(), rb_scan_args(), s, size, ptr_data::size, sym, TypedData_Get_Struct, and ptr_data::wrap.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_inspect | ( | VALUE | self | ) |
| static

Definition at line 430 of file pointer.c.

References CLASS_OF, data, ptr_data::free, ptr_data::ptr, rb_class2name(), rb_str_new2, ptr_data::size, snprintf, str, and TypedData_Get_Struct.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_malloc | ( | long | size,
|  | freefunc_t | func
| ) |  |
| static

Definition at line 96 of file pointer.c.

References memset(), ptr, rb_fiddle_ptr_new(), rb_secure(), and ruby_xmalloc().

Referenced by rb_fiddle_ptr_s_malloc().

static VALUE rb_fiddle_ptr_minus | ( | VALUE | self,
|  | VALUE | other
| ) |  |
| static

Definition at line 510 of file pointer.c.

References NUM2LONG, ptr, rb_fiddle_ptr2cptr(), rb_fiddle_ptr_new(), RPTR_DATA, and size.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_new | ( | void * | ptr,
|  | long | size,
|  | freefunc_t | func
| ) |  |
| static

Definition at line 90 of file pointer.c.

References rb_cPointer, and rb_fiddle_ptr_new2().

Referenced by Init_fiddle_pointer(), rb_fiddle_ptr_malloc(), rb_fiddle_ptr_minus(), rb_fiddle_ptr_plus(), rb_fiddle_ptr_ptr(), rb_fiddle_ptr_ref(), and rb_fiddle_ptr_s_to_ptr().

static VALUE rb_fiddle_ptr_new2 | ( | VALUE | klass,
|  | void * | ptr,
|  | long | size,
|  | freefunc_t | func
| ) |  |
| static

Definition at line 74 of file pointer.c.

References data, ptr_data::free, func, OBJ_TAINT, ptr_data::ptr, ptr, rb_secure(), size, ptr_data::size, TypedData_Make_Struct, and val.

Referenced by rb_fiddle_ptr_new().

static VALUE rb_fiddle_ptr_null_p | ( | VALUE | self | ) |
| static

Definition at line 292 of file pointer.c.

References data, ptr_data::ptr, Qfalse, Qtrue, and TypedData_Get_Struct.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_plus | ( | VALUE | self,
|  | VALUE | other
| ) |  |
| static

Definition at line 492 of file pointer.c.

References NUM2LONG, ptr, rb_fiddle_ptr2cptr(), rb_fiddle_ptr_new(), RPTR_DATA, and size.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_ptr | ( | VALUE | self | ) |
| static

Definition at line 261 of file pointer.c.

References data, ptr_data::ptr, rb_fiddle_ptr_new(), and TypedData_Get_Struct.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_ref | ( | VALUE | self | ) |
| static

Definition at line 278 of file pointer.c.

References data, ptr_data::ptr, rb_fiddle_ptr_new(), and TypedData_Get_Struct.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_s_allocate | ( | VALUE | klass | ) |
| static

Definition at line 127 of file pointer.c.

References data, ptr_data::free, obj, ptr_data::ptr, rb_secure(), ptr_data::size, and TypedData_Make_Struct.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_s_malloc | ( | int | argc,
|  | VALUE | argv[],
|  | VALUE | klass
| ) |  |
| static

Definition at line 200 of file pointer.c.

References f, get_freefunc(), NULL, NUM2LONG, obj, rb_bug(), rb_fiddle_ptr_malloc(), rb_scan_args(), RPTR_DATA, s, size, sym, and ptr_data::wrap.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_s_to_ptr | ( | VALUE | self,
|  | VALUE | val
| ) |  |
| static

Definition at line 638 of file pointer.c.

References GetOpenFile, id_to_ptr, NULL, NUM2PTR, OBJ_INFECT, ptr, Qundef, rb_check_funcall(), rb_cIO, rb_cPointer, rb_cString, rb_eFiddleError, rb_fiddle_ptr_new(), rb_Integer(), rb_io_stdio_file(), rb_obj_is_kind_of(), rb_raise(), RPTR_DATA, RSTRING_LEN, RTEST, str, StringValuePtr, val, and ptr_data::wrap.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_size_get | ( | VALUE | self | ) |
| static

Definition at line 624 of file pointer.c.

References LONG2NUM, RPTR_DATA, and size.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_size_set | ( | VALUE | self,
|  | VALUE | size
| ) |  |
| static

Definition at line 612 of file pointer.c.

References NUM2LONG, RPTR_DATA, and size.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_to_i | ( | VALUE | self | ) |
| static

Definition at line 231 of file pointer.c.

References data, ptr_data::ptr, PTR2NUM, and TypedData_Get_Struct.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_to_s | ( | int | argc,
|  | VALUE | argv[],
|  | VALUE | self
| ) |  |
| static

Definition at line 363 of file pointer.c.

References data, len, NUM2INT, ptr_data::ptr, rb_bug(), rb_scan_args(), rb_tainted_str_new(), rb_tainted_str_new2, TypedData_Get_Struct, and val.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_to_str | ( | int | argc,
|  | VALUE | argv[],
|  | VALUE | self
| ) |  |
| static

Definition at line 401 of file pointer.c.

References data, len, NUM2INT, ptr_data::ptr, rb_bug(), rb_scan_args(), rb_tainted_str_new(), ptr_data::size, TypedData_Get_Struct, and val.

Referenced by Init_fiddle_pointer().

static VALUE rb_fiddle_ptr_to_value | ( | VALUE | self | ) |
| static

Definition at line 245 of file pointer.c.

References data, ptr_data::ptr, and TypedData_Get_Struct.

Referenced by Init_fiddle_pointer().

## Variable Documentation

const rb_data_type_t fiddle_ptr_data_type
| static

Initial value:
= {
"fiddle/pointer",
{fiddle_ptr_mark, fiddle_ptr_free, fiddle_ptr_memsize,},
}
fiddle_ptr_mark
static void fiddle_ptr_mark(void *ptr)
Definition: pointer.c:39
fiddle_ptr_memsize
static size_t fiddle_ptr_memsize(const void *ptr)
Definition: pointer.c:62
fiddle_ptr_free
static void fiddle_ptr_free(void *ptr)
Definition: pointer.c:51

Definition at line 68 of file pointer.c.

ID id_to_ptr
| static

Definition at line 36 of file pointer.c.

Referenced by Init_fiddle_pointer(), and rb_fiddle_ptr_s_to_ptr().

VALUE rb_cPointer

Definition at line 10 of file pointer.c.

Referenced by Init_fiddle_pointer(), rb_fiddle_ptr2cptr(), rb_fiddle_ptr_aset(), rb_fiddle_ptr_cmp(), rb_fiddle_ptr_eql(), rb_fiddle_ptr_new(), and rb_fiddle_ptr_s_to_ptr().