Ruby  2.1.10p492(2016-04-01revision54464)
cfunc.c
Go to the documentation of this file.
1 /* -*- C -*-
2  * $Id: cfunc.c 43598 2013-11-09 05:29:59Z zzak $
3  */
4 
5 #include <ruby/ruby.h>
6 #include <ruby/util.h>
7 #include <errno.h>
8 #include "dl.h"
9 
11 
13 
14 static VALUE
16 {
18 }
19 
20 static VALUE
22 {
24  return Qnil;
25 }
26 
27 #if defined(_WIN32)
28 #include <windows.h>
29 static ID id_win32_last_error;
30 
31 static VALUE
32 rb_dl_get_win32_last_error(VALUE self)
33 {
34  return rb_thread_local_aref(rb_thread_current(), id_win32_last_error);
35 }
36 
37 static VALUE
38 rb_dl_set_win32_last_error(VALUE self, VALUE val)
39 {
40  rb_thread_local_aset(rb_thread_current(), id_win32_last_error, val);
41  return Qnil;
42 }
43 #endif
44 
45 static void
46 dlcfunc_mark(void *ptr)
47 {
48  struct cfunc_data *data = ptr;
49  if (data->wrap) {
50  rb_gc_mark(data->wrap);
51  }
52 }
53 
54 static void
56 {
57  struct cfunc_data *data = ptr;
58  if( data->name ){
59  xfree(data->name);
60  }
61  xfree(data);
62 }
63 
64 static size_t
65 dlcfunc_memsize(const void *ptr)
66 {
67  const struct cfunc_data *data = ptr;
68  size_t size = 0;
69  if( data ){
70  size += sizeof(*data);
71  if( data->name ){
72  size += strlen(data->name) + 1;
73  }
74  }
75  return size;
76 }
77 
79  "dl/cfunc",
81 };
82 
83 VALUE
84 rb_dlcfunc_new(void (*func)(), int type, const char *name, ID calltype)
85 {
86  VALUE val;
87  struct cfunc_data *data;
88 
89  if( func ){
91  data->ptr = (void *)(VALUE)func;
92  data->name = name ? strdup(name) : NULL;
93  data->type = type;
94  data->calltype = calltype;
95  }
96  else{
97  val = Qnil;
98  }
99 
100  return val;
101 }
102 
103 void *
105 {
106  struct cfunc_data *data;
107  void * func;
108 
110  data = DATA_PTR(val);
111  func = data->ptr;
112  }
113  else if( val == Qnil ){
114  func = NULL;
115  }
116  else{
117  rb_raise(rb_eTypeError, "DL::CFunc was expected");
118  }
119 
120  return func;
121 }
122 
123 static VALUE
125 {
126  VALUE obj;
127  struct cfunc_data *data;
128 
129  obj = TypedData_Make_Struct(klass, struct cfunc_data, &dlcfunc_data_type, data);
130  data->ptr = 0;
131  data->name = 0;
132  data->type = 0;
133  data->calltype = CFUNC_CDECL;
134 
135  return obj;
136 }
137 
138 int
140 {
142 }
143 
144 /*
145  * call-seq:
146  * DL::CFunc.new(address, type=DL::TYPE_VOID, name=nil, calltype=:cdecl)
147  *
148  * Create a new function that points to +address+ with an optional return type
149  * of +type+, a name of +name+ and a calltype of +calltype+.
150  */
151 static VALUE
153 {
154  VALUE addr, name, type, calltype, addrnum;
155  struct cfunc_data *data;
156  void *saddr;
157  const char *sname;
158 
159  rb_scan_args(argc, argv, "13", &addr, &type, &name, &calltype);
160 
161  addrnum = rb_Integer(addr);
162  saddr = (void*)(NUM2PTR(addrnum));
163  sname = NIL_P(name) ? NULL : StringValuePtr(name);
164 
165  TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, data);
166  if( data->name ) xfree(data->name);
167  data->ptr = saddr;
168  data->name = sname ? strdup(sname) : 0;
169  data->type = NIL_P(type) ? DLTYPE_VOID : NUM2INT(type);
171  data->wrap = (addrnum == addr) ? 0 : addr;
172 
173  return Qnil;
174 }
175 
176 /*
177  * call-seq:
178  * name => str
179  *
180  * Get the name of this function
181  */
182 static VALUE
184 {
185  struct cfunc_data *cfunc;
186 
187  TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
188  return cfunc->name ? rb_tainted_str_new2(cfunc->name) : Qnil;
189 }
190 
191 /*
192  * call-seq:
193  * cfunc.ctype => num
194  *
195  * Get the C function return value type. See DL for a list of constants
196  * corresponding to this method's return value.
197  */
198 static VALUE
200 {
201  struct cfunc_data *cfunc;
202 
203  TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
204  return INT2NUM(cfunc->type);
205 }
206 
207 /*
208  * call-seq:
209  * cfunc.ctype = type
210  *
211  * Set the C function return value type to +type+.
212  */
213 static VALUE
215 {
216  struct cfunc_data *cfunc;
217 
218  TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
219  cfunc->type = NUM2INT(ctype);
220  return ctype;
221 }
222 
223 /*
224  * call-seq:
225  * cfunc.calltype => symbol
226  *
227  * Get the call type of this function.
228  */
229 static VALUE
231 {
232  struct cfunc_data *cfunc;
233 
234  TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
235  return ID2SYM(cfunc->calltype);
236 }
237 
238 /*
239  * call-seq:
240  * cfunc.calltype = symbol
241  *
242  * Set the call type for this function.
243  */
244 static VALUE
246 {
247  struct cfunc_data *cfunc;
248 
249  TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
250  cfunc->calltype = SYM2ID(sym);
251  return sym;
252 }
253 
254 /*
255  * call-seq:
256  * cfunc.ptr
257  *
258  * Get the underlying function pointer as a DL::CPtr object.
259  */
260 static VALUE
262 {
263  struct cfunc_data *cfunc;
264 
265  TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
266  return PTR2NUM(cfunc->ptr);
267 }
268 
269 /*
270  * call-seq:
271  * cfunc.ptr = pointer
272  *
273  * Set the underlying function pointer to a DL::CPtr named +pointer+.
274  */
275 static VALUE
277 {
278  struct cfunc_data *cfunc;
279 
280  TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
281  cfunc->ptr = NUM2PTR(addr);
282 
283  return Qnil;
284 }
285 
286 /*
287  * call-seq:
288  * inspect
289  * to_s
290  *
291  * Returns a string formatted with an easily readable representation of the
292  * internal state of the DL::CFunc
293  */
294 static VALUE
296 {
297  VALUE val;
298  struct cfunc_data *cfunc;
299 
300  TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
301 
302  val = rb_sprintf("#<DL::CFunc:%p ptr=%p type=%d name='%s'>",
303  cfunc,
304  cfunc->ptr,
305  cfunc->type,
306  cfunc->name ? cfunc->name : "");
307  OBJ_TAINT(val);
308  return val;
309 }
310 
311 
312 # define DECL_FUNC_CDECL(f,ret,args,val) \
313  ret (FUNC_CDECL(*(f)))(args) = (ret (FUNC_CDECL(*))(args))(VALUE)(val)
314 #ifdef FUNC_STDCALL
315 # define DECL_FUNC_STDCALL(f,ret,args,val) \
316  ret (FUNC_STDCALL(*(f)))(args) = (ret (FUNC_STDCALL(*))(args))(VALUE)(val)
317 #endif
318 
319 #define CALL_CASE switch( RARRAY_LEN(ary) ){ \
320  CASE(0); break; \
321  CASE(1); break; CASE(2); break; CASE(3); break; CASE(4); break; CASE(5); break; \
322  CASE(6); break; CASE(7); break; CASE(8); break; CASE(9); break; CASE(10);break; \
323  CASE(11);break; CASE(12);break; CASE(13);break; CASE(14);break; CASE(15);break; \
324  CASE(16);break; CASE(17);break; CASE(18);break; CASE(19);break; CASE(20);break; \
325  default: rb_raise(rb_eArgError, "too many arguments"); \
326 }
327 
328 
329 #if defined(_MSC_VER) && defined(_M_AMD64) && _MSC_VER >= 1400 && _MSC_VER < 1600
330 # pragma optimize("", off)
331 #endif
332 /*
333  * call-seq:
334  * dlcfunc.call(ary) => some_value
335  * dlcfunc[ary] => some_value
336  *
337  * Calls the function pointer passing in +ary+ as values to the underlying
338  * C function. The return value depends on the ctype.
339  */
340 static VALUE
342 {
343  struct cfunc_data *cfunc;
344  int i;
345  DLSTACK_TYPE stack[DLSTACK_SIZE];
346  VALUE result = Qnil;
347 
348  memset(stack, 0, sizeof(DLSTACK_TYPE) * DLSTACK_SIZE);
349  Check_Type(ary, T_ARRAY);
350 
351  TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
352 
353  if( cfunc->ptr == 0 ){
354  rb_raise(rb_eDLError, "can't call null-function");
355  return Qnil;
356  }
357 
358  for( i = 0; i < RARRAY_LEN(ary); i++ ){
359  VALUE arg;
360  if( i >= DLSTACK_SIZE ){
361  rb_raise(rb_eDLError, "too many arguments (stack overflow)");
362  }
363  arg = rb_to_int(RARRAY_PTR(ary)[i]);
364  rb_check_safe_obj(arg);
365  if (FIXNUM_P(arg)) {
366  stack[i] = (DLSTACK_TYPE)FIX2LONG(arg);
367  }
368  else if (RB_TYPE_P(arg, T_BIGNUM)) {
369  unsigned long ls[(sizeof(DLSTACK_TYPE) + sizeof(long) - 1)/sizeof(long)];
370  DLSTACK_TYPE d;
371  int j;
372  rb_big_pack(arg, ls, sizeof(ls)/sizeof(*ls));
373  d = 0;
374  for (j = 0; j < (int)(sizeof(ls)/sizeof(*ls)); j++)
375  d |= (DLSTACK_TYPE)ls[j] << (j * sizeof(long) * CHAR_BIT);
376  stack[i] = d;
377  }
378  else {
379  Check_Type(arg, T_FIXNUM);
380  }
381  }
382 
383  /* calltype == CFUNC_CDECL */
384  if( cfunc->calltype == CFUNC_CDECL
385 #ifndef FUNC_STDCALL
386  || cfunc->calltype == CFUNC_STDCALL
387 #endif
388  ){
389  switch( cfunc->type ){
390  case DLTYPE_VOID:
391 #define CASE(n) case n: { \
392  DECL_FUNC_CDECL(f,void,DLSTACK_PROTO##n,cfunc->ptr); \
393  f(DLSTACK_ARGS##n(stack)); \
394  result = Qnil; \
395 }
396  CALL_CASE;
397 #undef CASE
398  break;
399  case DLTYPE_VOIDP:
400 #define CASE(n) case n: { \
401  DECL_FUNC_CDECL(f,void*,DLSTACK_PROTO##n,cfunc->ptr); \
402  void * ret; \
403  ret = f(DLSTACK_ARGS##n(stack)); \
404  result = PTR2NUM(ret); \
405 }
406  CALL_CASE;
407 #undef CASE
408  break;
409  case DLTYPE_CHAR:
410 #define CASE(n) case n: { \
411  DECL_FUNC_CDECL(f,char,DLSTACK_PROTO##n,cfunc->ptr); \
412  char ret; \
413  ret = f(DLSTACK_ARGS##n(stack)); \
414  result = CHR2FIX(ret); \
415 }
416  CALL_CASE;
417 #undef CASE
418  break;
419  case DLTYPE_SHORT:
420 #define CASE(n) case n: { \
421  DECL_FUNC_CDECL(f,short,DLSTACK_PROTO##n,cfunc->ptr); \
422  short ret; \
423  ret = f(DLSTACK_ARGS##n(stack)); \
424  result = INT2NUM((int)ret); \
425 }
426  CALL_CASE;
427 #undef CASE
428  break;
429  case DLTYPE_INT:
430 #define CASE(n) case n: { \
431  DECL_FUNC_CDECL(f,int,DLSTACK_PROTO##n,cfunc->ptr); \
432  int ret; \
433  ret = f(DLSTACK_ARGS##n(stack)); \
434  result = INT2NUM(ret); \
435 }
436  CALL_CASE;
437 #undef CASE
438  break;
439  case DLTYPE_LONG:
440 #define CASE(n) case n: { \
441  DECL_FUNC_CDECL(f,long,DLSTACK_PROTO##n,cfunc->ptr); \
442  long ret; \
443  ret = f(DLSTACK_ARGS##n(stack)); \
444  result = LONG2NUM(ret); \
445 }
446  CALL_CASE;
447 #undef CASE
448  break;
449 #if HAVE_LONG_LONG /* used in ruby.h */
450  case DLTYPE_LONG_LONG:
451 #define CASE(n) case n: { \
452  DECL_FUNC_CDECL(f,LONG_LONG,DLSTACK_PROTO##n,cfunc->ptr); \
453  LONG_LONG ret; \
454  ret = f(DLSTACK_ARGS##n(stack)); \
455  result = LL2NUM(ret); \
456 }
457  CALL_CASE;
458 #undef CASE
459  break;
460 #endif
461  case DLTYPE_FLOAT:
462 #define CASE(n) case n: { \
463  DECL_FUNC_CDECL(f,float,DLSTACK_PROTO##n,cfunc->ptr); \
464  float ret; \
465  ret = f(DLSTACK_ARGS##n(stack)); \
466  result = rb_float_new(ret); \
467 }
468  CALL_CASE;
469 #undef CASE
470  break;
471  case DLTYPE_DOUBLE:
472 #define CASE(n) case n: { \
473  DECL_FUNC_CDECL(f,double,DLSTACK_PROTO##n,cfunc->ptr); \
474  double ret; \
475  ret = f(DLSTACK_ARGS##n(stack)); \
476  result = rb_float_new(ret); \
477 }
478  CALL_CASE;
479 #undef CASE
480  break;
481  default:
482  rb_raise(rb_eDLTypeError, "unknown type %d", cfunc->type);
483  }
484  }
485 #ifdef FUNC_STDCALL
486  else if( cfunc->calltype == CFUNC_STDCALL ){
487  /* calltype == CFUNC_STDCALL */
488  switch( cfunc->type ){
489  case DLTYPE_VOID:
490 #define CASE(n) case n: { \
491  DECL_FUNC_STDCALL(f,void,DLSTACK_PROTO##n##_,cfunc->ptr); \
492  f(DLSTACK_ARGS##n(stack)); \
493  result = Qnil; \
494 }
495  CALL_CASE;
496 #undef CASE
497  break;
498  case DLTYPE_VOIDP:
499 #define CASE(n) case n: { \
500  DECL_FUNC_STDCALL(f,void*,DLSTACK_PROTO##n##_,cfunc->ptr); \
501  void * ret; \
502  ret = f(DLSTACK_ARGS##n(stack)); \
503  result = PTR2NUM(ret); \
504 }
505  CALL_CASE;
506 #undef CASE
507  break;
508  case DLTYPE_CHAR:
509 #define CASE(n) case n: { \
510  DECL_FUNC_STDCALL(f,char,DLSTACK_PROTO##n##_,cfunc->ptr); \
511  char ret; \
512  ret = f(DLSTACK_ARGS##n(stack)); \
513  result = CHR2FIX(ret); \
514 }
515  CALL_CASE;
516 #undef CASE
517  break;
518  case DLTYPE_SHORT:
519 #define CASE(n) case n: { \
520  DECL_FUNC_STDCALL(f,short,DLSTACK_PROTO##n##_,cfunc->ptr); \
521  short ret; \
522  ret = f(DLSTACK_ARGS##n(stack)); \
523  result = INT2NUM((int)ret); \
524 }
525  CALL_CASE;
526 #undef CASE
527  break;
528  case DLTYPE_INT:
529 #define CASE(n) case n: { \
530  DECL_FUNC_STDCALL(f,int,DLSTACK_PROTO##n##_,cfunc->ptr); \
531  int ret; \
532  ret = f(DLSTACK_ARGS##n(stack)); \
533  result = INT2NUM(ret); \
534 }
535  CALL_CASE;
536 #undef CASE
537  break;
538  case DLTYPE_LONG:
539 #define CASE(n) case n: { \
540  DECL_FUNC_STDCALL(f,long,DLSTACK_PROTO##n##_,cfunc->ptr); \
541  long ret; \
542  ret = f(DLSTACK_ARGS##n(stack)); \
543  result = LONG2NUM(ret); \
544 }
545  CALL_CASE;
546 #undef CASE
547  break;
548 #if HAVE_LONG_LONG /* used in ruby.h */
549  case DLTYPE_LONG_LONG:
550 #define CASE(n) case n: { \
551  DECL_FUNC_STDCALL(f,LONG_LONG,DLSTACK_PROTO##n##_,cfunc->ptr); \
552  LONG_LONG ret; \
553  ret = f(DLSTACK_ARGS##n(stack)); \
554  result = LL2NUM(ret); \
555 }
556  CALL_CASE;
557 #undef CASE
558  break;
559 #endif
560  case DLTYPE_FLOAT:
561 #define CASE(n) case n: { \
562  DECL_FUNC_STDCALL(f,float,DLSTACK_PROTO##n##_,cfunc->ptr); \
563  float ret; \
564  ret = f(DLSTACK_ARGS##n(stack)); \
565  result = rb_float_new(ret); \
566 }
567  CALL_CASE;
568 #undef CASE
569  break;
570  case DLTYPE_DOUBLE:
571 #define CASE(n) case n: { \
572  DECL_FUNC_STDCALL(f,double,DLSTACK_PROTO##n##_,cfunc->ptr); \
573  double ret; \
574  ret = f(DLSTACK_ARGS##n(stack)); \
575  result = rb_float_new(ret); \
576 }
577  CALL_CASE;
578 #undef CASE
579  break;
580  default:
581  rb_raise(rb_eDLTypeError, "unknown type %d", cfunc->type);
582  }
583  }
584 #endif
585  else{
586  const char *name = rb_id2name(cfunc->calltype);
587  if( name ){
588  rb_raise(rb_eDLError, "unsupported call type: %s",
589  name);
590  }
591  else{
592  rb_raise(rb_eDLError, "unsupported call type: %"PRIxVALUE,
593  cfunc->calltype);
594  }
595  }
596 
598 #if defined(_WIN32)
599  rb_dl_set_win32_last_error(self, INT2NUM(GetLastError()));
600 #endif
601 
602  return result;
603 }
604 #if defined(_MSC_VER) && defined(_M_AMD64) && _MSC_VER >= 1400 && _MSC_VER < 1600
605 # pragma optimize("", on)
606 #endif
607 
608 /*
609  * call-seq:
610  * dlfunc.to_i => integer
611  *
612  * Returns the memory location of this function pointer as an integer.
613  */
614 static VALUE
616 {
617  struct cfunc_data *cfunc;
618 
619  TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
620  return PTR2NUM(cfunc->ptr);
621 }
622 
623 void
625 {
626  id_last_error = rb_intern("__DL2_LAST_ERROR__");
627 #if defined(_WIN32)
628  id_win32_last_error = rb_intern("__DL2_WIN32_LAST_ERROR__");
629 #endif
630 
631  /*
632  * Document-class: DL::CFunc
633  *
634  * A direct accessor to a function in a C library
635  *
636  * == Example
637  *
638  * libc_so = "/lib64/libc.so.6"
639  * => "/lib64/libc.so.6"
640  * libc = DL::dlopen(libc_so)
641  * => #<DL::Handle:0x00000000e05b00>
642  * @cfunc = DL::CFunc.new(libc['strcpy'], DL::TYPE_VOIDP, 'strcpy')
643  * => #<DL::CFunc:0x000000012daec0 ptr=0x007f62ca5a8300 type=1 name='strcpy'>
644  *
645  */
648 
649  /*
650  * Document-method: last_error
651  *
652  * Returns the last error for the current executing thread
653  */
655 #if defined(_WIN32)
656 
657  /*
658  * Document-method: win32_last_error
659  *
660  * Returns the last win32 error for the current executing thread
661  */
662  rb_define_module_function(rb_cDLCFunc, "win32_last_error", rb_dl_get_win32_last_error, 0);
663 #endif
677 }
int rb_dlcfunc_kind_p(VALUE func)
Definition: cfunc.c:139
VALUE rb_mDL
Definition: dl.c:13
#define RARRAY_LEN(a)
Definition: ruby.h:878
size_t strlen(const char *)
#define INT2NUM(x)
Definition: ruby.h:1296
#define T_FIXNUM
Definition: ruby.h:489
#define NUM2INT(x)
Definition: ruby.h:630
#define DLSTACK_TYPE
Definition: dl.h:35
static VALUE rb_dl_get_last_error(VALUE self)
Definition: cfunc.c:15
static VALUE rb_dlcfunc_set_calltype(VALUE self, VALUE sym)
Definition: cfunc.c:245
void rb_big_pack(VALUE val, unsigned long *buf, long num_longs)
Definition: bignum.c:3199
#define TypedData_Get_Struct(obj, type, data_type, sval)
Definition: ruby.h:1041
char * name
Definition: dl.h:190
#define DLTYPE_SHORT
Definition: dl.h:157
VALUE rb_eTypeError
Definition: error.c:548
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:113
#define SYM2ID(x)
Definition: ruby.h:356
#define NUM2PTR(x)
Definition: dl.h:169
#define PRIxVALUE
Definition: ruby.h:135
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:657
VALUE rb_to_int(VALUE)
Definition: object.c:2700
#define Check_Type(v, t)
Definition: ruby.h:532
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1857
static VALUE rb_dlcfunc_inspect(VALUE self)
Definition: cfunc.c:295
VALUE rb_eDLError
Definition: dl.c:14
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
#define CFUNC_STDCALL
Definition: dl.h:198
#define DLTYPE_VOID
Definition: dl.h:154
#define DATA_PTR(dta)
Definition: ruby.h:992
static void dlcfunc_free(void *ptr)
Definition: cfunc.c:55
void rb_gc_mark(VALUE ptr)
Definition: gc.c:3607
VALUE rb_eDLTypeError
Definition: dl.c:15
#define T_ARRAY
Definition: ruby.h:484
static VALUE rb_dlcfunc_set_ptr(VALUE self, VALUE addr)
Definition: cfunc.c:276
#define FIXNUM_P(f)
Definition: ruby.h:347
VALUE rb_thread_local_aref(VALUE, ID)
Definition: thread.c:2765
#define sym(x)
Definition: date_core.c:3695
static VALUE rb_dl_set_last_error(VALUE self, VALUE val)
Definition: cfunc.c:21
int type
Definition: dl.h:191
#define RB_TYPE_P(obj, type)
Definition: ruby.h:1672
static VALUE rb_dlcfunc_set_ctype(VALUE self, VALUE ctype)
Definition: cfunc.c:214
VALUE rb_dlcfunc_new(void(*func)(), int type, const char *name, ID calltype)
Definition: cfunc.c:84
#define CALL_CASE
Definition: cfunc.c:319
#define DLTYPE_DOUBLE
Definition: dl.h:164
#define val
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1561
static VALUE rb_dlcfunc_to_i(VALUE self)
Definition: cfunc.c:615
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
Definition: error.c:510
VALUE rb_thread_current(void)
Definition: thread.c:2405
#define NIL_P(v)
Definition: ruby.h:438
#define PTR2NUM(x)
Definition: dl.h:168
static VALUE rb_dlcfunc_s_allocate(VALUE klass)
Definition: cfunc.c:124
int argc
Definition: ruby.c:131
static void dlcfunc_mark(void *ptr)
Definition: cfunc.c:46
VALUE rb_Integer(VALUE)
Definition: object.c:2757
#define T_BIGNUM
Definition: ruby.h:487
static VALUE rb_dlcfunc_initialize(int argc, VALUE argv[], VALUE self)
Definition: cfunc.c:152
VALUE rb_thread_local_aset(VALUE, ID, VALUE)
Definition: thread.c:2858
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
Definition: class.c:1661
Definition: dl.h:188
int errno
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1250
#define strdup(s)
Definition: util.h:67
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1719
unsigned long ID
Definition: ruby.h:89
#define Qnil
Definition: ruby.h:427
int type
Definition: tcltklib.c:112
static size_t dlcfunc_memsize(const void *ptr)
Definition: cfunc.c:65
#define OBJ_TAINT(x)
Definition: ruby.h:1184
unsigned long VALUE
Definition: ruby.h:88
static VALUE result
Definition: nkf.c:40
#define rb_tainted_str_new2
Definition: intern.h:844
#define CHAR_BIT
Definition: ruby.h:198
static VALUE rb_dlcfunc_ctype(VALUE self)
Definition: cfunc.c:199
int size
Definition: encoding.c:49
static VALUE rb_dlcfunc_ptr(VALUE self)
Definition: cfunc.c:261
#define DLTYPE_INT
Definition: dl.h:158
void * ptr
Definition: dl.h:189
#define DLTYPE_FLOAT
Definition: dl.h:163
#define RARRAY_PTR(a)
Definition: ruby.h:907
void rb_check_safe_obj(VALUE)
Definition: safe.c:122
#define TypedData_Make_Struct(klass, type, data_type, sval)
Definition: ruby.h:1030
#define DLTYPE_VOIDP
Definition: dl.h:155
VALUE wrap
Definition: dl.h:193
static ID id_last_error
Definition: cfunc.c:12
const char * name
Definition: nkf.c:208
#define ID2SYM(x)
Definition: ruby.h:355
const char * rb_id2name(ID id)
Definition: ripper.c:17271
#define StringValuePtr(v)
Definition: ruby.h:540
#define DLTYPE_LONG
Definition: dl.h:159
#define DLTYPE_CHAR
Definition: dl.h:156
static VALUE rb_dlcfunc_name(VALUE self)
Definition: cfunc.c:183
const rb_data_type_t dlcfunc_data_type
Definition: cfunc.c:78
void void xfree(void *)
#define rb_intern(str)
VALUE rb_cDLCFunc
Definition: cfunc.c:10
#define NULL
Definition: _sdbm.c:102
#define FIX2LONG(x)
Definition: ruby.h:345
void * rb_dlcfunc2ptr(VALUE val)
Definition: cfunc.c:104
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1479
void Init_dlcfunc(void)
Definition: cfunc.c:624
static VALUE rb_dlcfunc_calltype(VALUE self)
Definition: cfunc.c:230
static VALUE rb_dlcfunc_call(VALUE self, VALUE ary)
Definition: cfunc.c:341
#define DLSTACK_SIZE
Definition: dl.h:36
char ** argv
Definition: ruby.c:132
#define CFUNC_CDECL
Definition: dl.h:197
ID calltype
Definition: dl.h:192