Ruby 2.0.0p247(2013-06-27revision41674)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Macros | Functions | Variables
cfunc.c File Reference
`#include <ruby/ruby.h>`
`#include <ruby/util.h>`
`#include <errno.h>`
`#include "dl.h"`
Include dependency graph for cfunc.c:

Go to the source code of this file.

## Macros
#define | DECL_FUNC_CDECL(f, ret, args, val) ret (FUNC_CDECL(*(f)))(args) = (ret (FUNC_CDECL(*))(args))(VALUE)(val)
#define | CALL_CASE
#define | CASE(n)

## Functions
static VALUE | rb_dl_get_last_error (VALUE self)
static VALUE | rb_dl_set_last_error (VALUE self, VALUE val)
static void | dlcfunc_mark (void *ptr)
static void | dlcfunc_free (void *ptr)
static size_t | dlcfunc_memsize (const void *ptr)
VALUE | rb_dlcfunc_new (void(*func)(), int type, const char *name, ID calltype)
void * | rb_dlcfunc2ptr (VALUE val)
static VALUE | rb_dlcfunc_s_allocate (VALUE klass)
int | rb_dlcfunc_kind_p (VALUE func)
static VALUE | rb_dlcfunc_initialize (int argc, VALUE argv[], VALUE self)
static VALUE | rb_dlcfunc_name (VALUE self)
static VALUE | rb_dlcfunc_ctype (VALUE self)
static VALUE | rb_dlcfunc_set_ctype (VALUE self, VALUE ctype)
static VALUE | rb_dlcfunc_calltype (VALUE self)
static VALUE | rb_dlcfunc_set_calltype (VALUE self, VALUE sym)
static VALUE | rb_dlcfunc_ptr (VALUE self)
static VALUE | rb_dlcfunc_set_ptr (VALUE self, VALUE addr)
static VALUE | rb_dlcfunc_inspect (VALUE self)
static VALUE | rb_dlcfunc_call (VALUE self, VALUE ary)
static VALUE | rb_dlcfunc_to_i (VALUE self)
void | Init_dlcfunc (void)

## Variables
VALUE | rb_cDLCFunc
static ID | id_last_error
const rb_data_type_t | dlcfunc_data_type

## Macro Definition Documentation

#define CALL_CASE

Value:
switch( RARRAY_LEN(ary) ){ \
CASE(0); break; \
CASE(1); break; CASE(2); break; CASE(3); break; CASE(4); break; CASE(5); break; \
CASE(6); break; CASE(7); break; CASE(8); break; CASE(9); break; CASE(10);break; \
CASE(11);break; CASE(12);break; CASE(13);break; CASE(14);break; CASE(15);break; \
CASE(16);break; CASE(17);break; CASE(18);break; CASE(19);break; CASE(20);break; \
default: rb_raise(rb_eArgError, "too many arguments"); \
}

Definition at line 318 of file cfunc.c.

Referenced by rb_dlcfunc_call().

#define CASE | ( |  | n) |  |

Value:
case n: { \
DECL_FUNC_CDECL(f,void,DLSTACK_PROTO##n,cfunc->ptr); \
f(DLSTACK_ARGS##n(stack)); \
result = Qnil; \
}

#define CASE | ( |  | n) |  |

Value:
case n: { \
DECL_FUNC_CDECL(f,void*,DLSTACK_PROTO##n,cfunc->ptr); \
void * ret; \
ret = f(DLSTACK_ARGS##n(stack)); \
result = PTR2NUM(ret); \
}

#define CASE | ( |  | n) |  |

Value:
case n: { \
DECL_FUNC_CDECL(f,char,DLSTACK_PROTO##n,cfunc->ptr); \
char ret; \
ret = f(DLSTACK_ARGS##n(stack)); \
result = CHR2FIX(ret); \
}

#define CASE | ( |  | n) |  |

Value:
case n: { \
DECL_FUNC_CDECL(f,short,DLSTACK_PROTO##n,cfunc->ptr); \
short ret; \
ret = f(DLSTACK_ARGS##n(stack)); \
result = INT2NUM((int)ret); \
}

#define CASE | ( |  | n) |  |

Value:
case n: { \
DECL_FUNC_CDECL(f,int,DLSTACK_PROTO##n,cfunc->ptr); \
int ret; \
ret = f(DLSTACK_ARGS##n(stack)); \
result = INT2NUM(ret); \
}

#define CASE | ( |  | n) |  |

Value:
case n: { \
DECL_FUNC_CDECL(f,long,DLSTACK_PROTO##n,cfunc->ptr); \
long ret; \
ret = f(DLSTACK_ARGS##n(stack)); \
result = LONG2NUM(ret); \
}

#define CASE | ( |  | n) |  |

Value:
case n: { \
DECL_FUNC_CDECL(f,float,DLSTACK_PROTO##n,cfunc->ptr); \
float ret; \
ret = f(DLSTACK_ARGS##n(stack)); \
result = rb_float_new(ret); \
}

#define CASE | ( |  | n) |  |

Value:
case n: { \
DECL_FUNC_CDECL(f,double,DLSTACK_PROTO##n,cfunc->ptr); \
double ret; \
ret = f(DLSTACK_ARGS##n(stack)); \
result = rb_float_new(ret); \
}

#define DECL_FUNC_CDECL | ( |  | f,
|  |  | ret,
|  |  | args,
|  |  | val
| ) |  | ret (FUNC_CDECL(*(f)))(args) = (ret (FUNC_CDECL(*))(args))(VALUE)(val)

Definition at line 311 of file cfunc.c.

## Function Documentation

static void dlcfunc_free | ( | void * | ptr) |  |
| static

Definition at line 55 of file cfunc.c.

References cfunc_data::name, cfunc_data::ptr, and xfree.

static void dlcfunc_mark | ( | void * | ptr) |  |
| static

Definition at line 46 of file cfunc.c.

References cfunc_data::ptr, rb_gc_mark(), and cfunc_data::wrap.

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

Definition at line 65 of file cfunc.c.

References cfunc_data::name, cfunc_data::ptr, size, and strlen().

void Init_dlcfunc | ( | void | ) |  |

Definition at line 622 of file cfunc.c.

References id_last_error, rb_cDLCFunc, rb_cObject, rb_define_alloc_func(), rb_define_class_under(), rb_define_method(), rb_define_module_function(), rb_dl_get_last_error(), rb_dlcfunc_call(), rb_dlcfunc_calltype(), rb_dlcfunc_ctype(), rb_dlcfunc_initialize(), rb_dlcfunc_inspect(), rb_dlcfunc_name(), rb_dlcfunc_ptr(), rb_dlcfunc_s_allocate(), rb_dlcfunc_set_calltype(), rb_dlcfunc_set_ctype(), rb_dlcfunc_set_ptr(), rb_dlcfunc_to_i(), rb_intern, and rb_mDL.

Referenced by Init_dl().

static VALUE rb_dl_get_last_error | ( | VALUE | self) |  |
| static

Definition at line 15 of file cfunc.c.

References id_last_error, rb_thread_current(), and rb_thread_local_aref().

Referenced by Init_dlcfunc().

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

Definition at line 21 of file cfunc.c.

References id_last_error, Qnil, rb_thread_current(), and rb_thread_local_aset().

Referenced by rb_dlcfunc_call().

void* rb_dlcfunc2ptr | ( | VALUE | val) |  |

Definition at line 105 of file cfunc.c.

References DATA_PTR, func, NULL, cfunc_data::ptr, Qnil, rb_eTypeError, rb_raise(), and rb_typeddata_is_kind_of().

static VALUE rb_dlcfunc_call | ( | VALUE | self,
|  | VALUE | ary
| ) |  |
| static

Definition at line 340 of file cfunc.c.

References arg, CALL_CASE, cfunc_data::calltype, CFUNC_CDECL, CFUNC_STDCALL, Check_Type, DLSTACK_SIZE, DLSTACK_TYPE, DLTYPE_CHAR, DLTYPE_DOUBLE, DLTYPE_FLOAT, DLTYPE_INT, DLTYPE_LONG, DLTYPE_SHORT, DLTYPE_VOID, DLTYPE_VOIDP, errno, FIX2LONG, FIXNUM_P, i, INT2NUM, name, PRIxVALUE, cfunc_data::ptr, Qnil, RARRAY_LEN, RARRAY_PTR, rb_big2ulong_pack(), rb_check_safe_obj(), rb_dl_set_last_error(), rb_eDLError, rb_eDLTypeError, rb_id2name(), rb_raise(), rb_secure_update(), rb_to_int(), RB_TYPE_P, result, T_ARRAY, T_BIGNUM, T_FIXNUM, cfunc_data::type, and TypedData_Get_Struct.

Referenced by Init_dlcfunc().

static VALUE rb_dlcfunc_calltype | ( | VALUE | self) |  |
| static

Definition at line 231 of file cfunc.c.

References cfunc_data::calltype, ID2SYM, and TypedData_Get_Struct.

Referenced by Init_dlcfunc().

static VALUE rb_dlcfunc_ctype | ( | VALUE | self) |  |
| static

Definition at line 200 of file cfunc.c.

References INT2NUM, cfunc_data::type, and TypedData_Get_Struct.

Referenced by Init_dlcfunc().

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

Definition at line 153 of file cfunc.c.

References cfunc_data::calltype, CFUNC_CDECL, DLTYPE_VOID, cfunc_data::name, name, NIL_P, NULL, NUM2INT, NUM2PTR, cfunc_data::ptr, Qnil, rb_Integer(), rb_scan_args(), strdup, StringValuePtr, SYM2ID, type, cfunc_data::type, TypedData_Get_Struct, cfunc_data::wrap, and xfree.

Referenced by Init_dlcfunc().

static VALUE rb_dlcfunc_inspect | ( | VALUE | self) |  |
| static

Definition at line 294 of file cfunc.c.

References cfunc_data::name, OBJ_TAINT, cfunc_data::ptr, rb_sprintf(), cfunc_data::type, and TypedData_Get_Struct.

Referenced by Init_dlcfunc().

int rb_dlcfunc_kind_p | ( | VALUE | func) |  |

Definition at line 140 of file cfunc.c.

References rb_typeddata_is_kind_of().

Referenced by get_freefunc().

static VALUE rb_dlcfunc_name | ( | VALUE | self) |  |
| static

Definition at line 184 of file cfunc.c.

References cfunc_data::name, Qnil, rb_tainted_str_new2, and TypedData_Get_Struct.

Referenced by Init_dlcfunc().

VALUE rb_dlcfunc_new | ( | void(*)() | func,
|  | int | type,
|  | const char * | name,
|  | ID | calltype
| ) |  |

Definition at line 84 of file cfunc.c.

References cfunc_data::calltype, func, cfunc_data::name, NULL, cfunc_data::ptr, Qnil, rb_cDLCFunc, rb_secure(), strdup, type, cfunc_data::type, and TypedData_Make_Struct.

Referenced by rb_dlptr_free_get().

static VALUE rb_dlcfunc_ptr | ( | VALUE | self) |  |
| static

Definition at line 262 of file cfunc.c.

References cfunc_data::ptr, PTR2NUM, and TypedData_Get_Struct.

Referenced by Init_dlcfunc().

static VALUE rb_dlcfunc_s_allocate | ( | VALUE | klass) |  |
| static

Definition at line 125 of file cfunc.c.

References cfunc_data::calltype, CFUNC_CDECL, cfunc_data::name, cfunc_data::ptr, cfunc_data::type, and TypedData_Make_Struct.

Referenced by Init_dlcfunc().

static VALUE rb_dlcfunc_set_calltype | ( | VALUE | self,
|  | VALUE | sym
| ) |  |
| static

Definition at line 246 of file cfunc.c.

References cfunc_data::calltype, sym, SYM2ID, and TypedData_Get_Struct.

Referenced by Init_dlcfunc().

static VALUE rb_dlcfunc_set_ctype | ( | VALUE | self,
|  | VALUE | ctype
| ) |  |
| static

Definition at line 215 of file cfunc.c.

References NUM2INT, cfunc_data::type, and TypedData_Get_Struct.

Referenced by Init_dlcfunc().

static VALUE rb_dlcfunc_set_ptr | ( | VALUE | self,
|  | VALUE | addr
| ) |  |
| static

Definition at line 277 of file cfunc.c.

References NUM2PTR, cfunc_data::ptr, Qnil, and TypedData_Get_Struct.

Referenced by Init_dlcfunc().

static VALUE rb_dlcfunc_to_i | ( | VALUE | self) |  |
| static

Definition at line 613 of file cfunc.c.

References cfunc_data::ptr, PTR2NUM, and TypedData_Get_Struct.

Referenced by Init_dlcfunc().

## Variable Documentation

const rb_data_type_t dlcfunc_data_type

Initial value:
= {
"dl/cfunc",
{dlcfunc_mark, dlcfunc_free, dlcfunc_memsize,},
}

Definition at line 78 of file cfunc.c.

ID id_last_error
| static

Definition at line 12 of file cfunc.c.

Referenced by Init_dlcfunc(), rb_dl_get_last_error(), and rb_dl_set_last_error().

VALUE rb_cDLCFunc

Definition at line 10 of file cfunc.c.

Referenced by Init_dlcfunc(), and rb_dlcfunc_new().