Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

pointer.c
Go to the documentation of this file.
1 /* -*- C -*-
2 * $Id$
3 */
4
5 #include <ruby/ruby.h>
6 #include <ruby/io.h>
7 #include <ctype.h>
8 #include <fiddle.h>
9
10 #ifdef PRIsVALUE
11 # define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj)
12 # define RB_OBJ_STRING(obj) (obj)
13 #else
14 # define PRIsVALUE "s"
15 # define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj)
16 # define RB_OBJ_STRING(obj) StringValueCStr(obj)
17 #endif
18
19 VALUE rb_cPointer;
20
21 typedef void (*freefunc_t)(void*);
22
23 struct ptr_data {
24 void *ptr;
25 long size;
26 freefunc_t free;
27 VALUE wrap[2];
28 };
29
30 #define RPTR_DATA(obj) ((struct ptr_data *)(DATA_PTR(obj)))
31
32 static inline freefunc_t
33 get_freefunc(VALUE func, volatile VALUE *wrap)
34 {
35 VALUE addrnum;
36 if (NIL_P(func)) {
37 *wrap = 0;
38 return NULL;
39 }
40 addrnum = rb_Integer(func);
41 *wrap = (addrnum != func) ? func : 0;
42 return (freefunc_t)(VALUE)NUM2PTR(addrnum);
43 }
44
45 static ID id_to_ptr;
46
47 static void
48 fiddle_ptr_mark(void *ptr)
49 {
50 struct ptr_data *data = ptr;
51 if (data->wrap[0]) {
52 rb_gc_mark(data->wrap[0]);
53 }
54 if (data->wrap[1]) {
55 rb_gc_mark(data->wrap[1]);
56 }
57 }
58
59 static void
60 fiddle_ptr_free(void *ptr)
61 {
62 struct ptr_data *data = ptr;
63 if (data->ptr) {
64 if (data->free) {
65 (*(data->free))(data->ptr);
66 }
67 }
68 xfree(ptr);
69 }
70
71 static size_t
72 fiddle_ptr_memsize(const void *ptr)
73 {
74 const struct ptr_data *data = ptr;
75 return sizeof(*data) + data->size;
76 }
77
78 static const rb_data_type_t fiddle_ptr_data_type = {
79 "fiddle/pointer",
80 {fiddle_ptr_mark, fiddle_ptr_free, fiddle_ptr_memsize,},
81 };
82
83 static VALUE
84 rb_fiddle_ptr_new2(VALUE klass, void *ptr, long size, freefunc_t func)
85 {
86 struct ptr_data *data;
87 VALUE val;
88
89 val = TypedData_Make_Struct(klass, struct ptr_data, &fiddle_ptr_data_type, data);
90 data->ptr = ptr;
91 data->free = func;
92 data->size = size;
93
94 return val;
95 }
96
97 static VALUE
98 rb_fiddle_ptr_new(void *ptr, long size, freefunc_t func)
99 {
100 return rb_fiddle_ptr_new2(rb_cPointer, ptr, size, func);
101 }
102
103 static VALUE
104 rb_fiddle_ptr_malloc(long size, freefunc_t func)
105 {
106 void *ptr;
107
108 ptr = ruby_xmalloc((size_t)size);
109 memset(ptr,0,(size_t)size);
110 return rb_fiddle_ptr_new(ptr, size, func);
111 }
112
113 static void *
114 rb_fiddle_ptr2cptr(VALUE val)
115 {
116 struct ptr_data *data;
117 void *ptr;
118
119 if (rb_obj_is_kind_of(val, rb_cPointer)) {
120 TypedData_Get_Struct(val, struct ptr_data, &fiddle_ptr_data_type, data);
121 ptr = data->ptr;
122 }
123 else if (val == Qnil) {
124 ptr = NULL;
125 }
126 else{
127 rb_raise(rb_eTypeError, "Fiddle::Pointer was expected");
128 }
129
130 return ptr;
131 }
132
133 static VALUE
134 rb_fiddle_ptr_s_allocate(VALUE klass)
135 {
136 VALUE obj;
137 struct ptr_data *data;
138
139 obj = TypedData_Make_Struct(klass, struct ptr_data, &fiddle_ptr_data_type, data);
140 data->ptr = 0;
141 data->size = 0;
142 data->free = 0;
143
144 return obj;
145 }
146
147 /*
148 * call-seq:
149 * Fiddle::Pointer.new(address) => fiddle_cptr
150 * new(address, size) => fiddle_cptr
151 * new(address, size, freefunc) => fiddle_cptr
152 *
153 * Create a new pointer to +address+ with an optional +size+ and +freefunc+.
154 *
155 * +freefunc+ will be called when the instance is garbage collected.
156 */
157 static VALUE
158 rb_fiddle_ptr_initialize(int argc, VALUE argv[], VALUE self)
159 {
160 VALUE ptr, sym, size, wrap = 0, funcwrap = 0;
161 struct ptr_data *data;
162 void *p = NULL;
163 freefunc_t f = NULL;
164 long s = 0;
165
166 if (rb_scan_args(argc, argv, "12", &ptr, &size, &sym) >= 1) {
167 VALUE addrnum = rb_Integer(ptr);
168 if (addrnum != ptr) wrap = ptr;
169 p = NUM2PTR(addrnum);
170 }
171 if (argc >= 2) {
172 s = NUM2LONG(size);
173 }
174 if (argc >= 3) {
175 f = get_freefunc(sym, &funcwrap);
176 }
177
178 if (p) {
179 TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
180 if (data->ptr && data->free) {
181 /* Free previous memory. Use of inappropriate initialize may cause SEGV. */
182 (*(data->free))(data->ptr);
183 }
184 data->wrap[0] = wrap;
185 data->wrap[1] = funcwrap;
186 data->ptr = p;
187 data->size = s;
188 data->free = f;
189 }
190
191 return Qnil;
192 }
193
194 /*
195 * call-seq:
196 *
197 * Fiddle::Pointer.malloc(size, freefunc = nil) => fiddle pointer instance
198 *
199 * Allocate +size+ bytes of memory and associate it with an optional
200 * +freefunc+ that will be called when the pointer is garbage collected.
201 *
202 * +freefunc+ must be an address pointing to a function or an instance of
203 * Fiddle::Function
204 */
205 static VALUE
206 rb_fiddle_ptr_s_malloc(int argc, VALUE argv[], VALUE klass)
207 {
208 VALUE size, sym, obj, wrap = 0;
209 long s;
210 freefunc_t f;
211
212 switch (rb_scan_args(argc, argv, "11", &size, &sym)) {
213 case 1:
214 s = NUM2LONG(size);
215 f = NULL;
216 break;
217 case 2:
218 s = NUM2LONG(size);
219 f = get_freefunc(sym, &wrap);
220 break;
221 default:
222 rb_bug("rb_fiddle_ptr_s_malloc");
223 }
224
225 obj = rb_fiddle_ptr_malloc(s,f);
226 if (wrap) RPTR_DATA(obj)->wrap[1] = wrap;
227
228 return obj;
229 }
230
231 /*
232 * call-seq: to_i
233 *
234 * Returns the integer memory location of this pointer.
235 */
236 static VALUE
237 rb_fiddle_ptr_to_i(VALUE self)
238 {
239 struct ptr_data *data;
240
241 TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
242 return PTR2NUM(data->ptr);
243 }
244
245 /*
246 * call-seq: to_value
247 *
248 * Cast this pointer to a ruby object.
249 */
250 static VALUE
251 rb_fiddle_ptr_to_value(VALUE self)
252 {
253 struct ptr_data *data;
254 TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
255 return (VALUE)(data->ptr);
256 }
257
258 /*
259 * call-seq: ptr
260 *
261 * Returns a new Fiddle::Pointer instance that is a dereferenced pointer for
262 * this pointer.
263 *
264 * Analogous to the star operator in C.
265 */
266 static VALUE
267 rb_fiddle_ptr_ptr(VALUE self)
268 {
269 struct ptr_data *data;
270
271 TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
272 return rb_fiddle_ptr_new(*((void**)(data->ptr)),0,0);
273 }
274
275 /*
276 * call-seq: ref
277 *
278 * Returns a new Fiddle::Pointer instance that is a reference pointer for this
279 * pointer.
280 *
281 * Analogous to the ampersand operator in C.
282 */
283 static VALUE
284 rb_fiddle_ptr_ref(VALUE self)
285 {
286 struct ptr_data *data;
287
288 TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
289 return rb_fiddle_ptr_new(&(data->ptr),0,0);
290 }
291
292 /*
293 * call-seq: null?
294 *
295 * Returns +true+ if this is a null pointer.
296 */
297 static VALUE
298 rb_fiddle_ptr_null_p(VALUE self)
299 {
300 struct ptr_data *data;
301
302 TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
303 return data->ptr ? Qfalse : Qtrue;
304 }
305
306 /*
307 * call-seq: free=(function)
308 *
309 * Set the free function for this pointer to +function+ in the given
310 * Fiddle::Function.
311 */
312 static VALUE
313 rb_fiddle_ptr_free_set(VALUE self, VALUE val)
314 {
315 struct ptr_data *data;
316
317 TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
318 data->free = get_freefunc(val, &data->wrap[1]);
319
320 return Qnil;
321 }
322
323 /*
324 * call-seq: free => Fiddle::Function
325 *
326 * Get the free function for this pointer.
327 *
328 * Returns a new instance of Fiddle::Function.
329 *
330 * See Fiddle::Function.new
331 */
332 static VALUE
333 rb_fiddle_ptr_free_get(VALUE self)
334 {
335 struct ptr_data *pdata;
336 VALUE address;
337 VALUE arg_types;
338 VALUE ret_type;
339
340 TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, pdata);
341
342 if (!pdata->free)
343 return Qnil;
344
345 address = PTR2NUM(pdata->free);
346 ret_type = INT2NUM(TYPE_VOID);
347 arg_types = rb_ary_new();
348 rb_ary_push(arg_types, INT2NUM(TYPE_VOIDP));
349
350 return rb_fiddle_new_function(address, arg_types, ret_type);
351 }
352
353 /*
354 * call-seq:
355 *
356 * ptr.to_s => string
357 * ptr.to_s(len) => string
358 *
359 * Returns the pointer contents as a string.
360 *
361 * When called with no arguments, this method will return the contents until
362 * the first NULL byte.
363 *
364 * When called with +len+, a string of +len+ bytes will be returned.
365 *
366 * See to_str
367 */
368 static VALUE
369 rb_fiddle_ptr_to_s(int argc, VALUE argv[], VALUE self)
370 {
371 struct ptr_data *data;
372 VALUE arg1, val;
373 int len;
374
375 TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
376 switch (rb_scan_args(argc, argv, "01", &arg1)) {
377 case 0:
378 val = rb_str_new2((char*)(data->ptr));
379 break;
380 case 1:
381 len = NUM2INT(arg1);
382 val = rb_str_new((char*)(data->ptr), len);
383 break;
384 default:
385 rb_bug("rb_fiddle_ptr_to_s");
386 }
387
388 return val;
389 }
390
391 /*
392 * call-seq:
393 *
394 * ptr.to_str => string
395 * ptr.to_str(len) => string
396 *
397 * Returns the pointer contents as a string.
398 *
399 * When called with no arguments, this method will return the contents with the
400 * length of this pointer's +size+.
401 *
402 * When called with +len+, a string of +len+ bytes will be returned.
403 *
404 * See to_s
405 */
406 static VALUE
407 rb_fiddle_ptr_to_str(int argc, VALUE argv[], VALUE self)
408 {
409 struct ptr_data *data;
410 VALUE arg1, val;
411 int len;
412
413 TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
414 switch (rb_scan_args(argc, argv, "01", &arg1)) {
415 case 0:
416 val = rb_str_new((char*)(data->ptr),data->size);
417 break;
418 case 1:
419 len = NUM2INT(arg1);
420 val = rb_str_new((char*)(data->ptr), len);
421 break;
422 default:
423 rb_bug("rb_fiddle_ptr_to_str");
424 }
425
426 return val;
427 }
428
429 /*
430 * call-seq: inspect
431 *
432 * Returns a string formatted with an easily readable representation of the
433 * internal state of the pointer.
434 */
435 static VALUE
436 rb_fiddle_ptr_inspect(VALUE self)
437 {
438 struct ptr_data *data;
439
440 TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
441 return rb_sprintf("#<%"PRIsVALUE":%p ptr=%p size=%ld free=%p>",
442 RB_OBJ_CLASSNAME(self), (void *)data, data->ptr, data->size, (void *)data->free);
443 }
444
445 /*
446 * call-seq:
447 * ptr == other => true or false
448 * ptr.eql?(other) => true or false
449 *
450 * Returns true if +other+ wraps the same pointer, otherwise returns
451 * false.
452 */
453 static VALUE
454 rb_fiddle_ptr_eql(VALUE self, VALUE other)
455 {
456 void *ptr1, *ptr2;
457
458 if(!rb_obj_is_kind_of(other, rb_cPointer)) return Qfalse;
459
460 ptr1 = rb_fiddle_ptr2cptr(self);
461 ptr2 = rb_fiddle_ptr2cptr(other);
462
463 return ptr1 == ptr2 ? Qtrue : Qfalse;
464 }
465
466 /*
467 * call-seq:
468 * ptr <=> other => -1, 0, 1, or nil
469 *
470 * Returns -1 if less than, 0 if equal to, 1 if greater than +other+.
471 *
472 * Returns nil if +ptr+ cannot be compared to +other+.
473 */
474 static VALUE
475 rb_fiddle_ptr_cmp(VALUE self, VALUE other)
476 {
477 void *ptr1, *ptr2;
478 SIGNED_VALUE diff;
479
480 if(!rb_obj_is_kind_of(other, rb_cPointer)) return Qnil;
481
482 ptr1 = rb_fiddle_ptr2cptr(self);
483 ptr2 = rb_fiddle_ptr2cptr(other);
484 diff = (SIGNED_VALUE)ptr1 - (SIGNED_VALUE)ptr2;
485 if (!diff) return INT2FIX(0);
486 return diff > 0 ? INT2NUM(1) : INT2NUM(-1);
487 }
488
489 /*
490 * call-seq:
491 * ptr + n => new cptr
492 *
493 * Returns a new pointer instance that has been advanced +n+ bytes.
494 */
495 static VALUE
496 rb_fiddle_ptr_plus(VALUE self, VALUE other)
497 {
498 void *ptr;
499 long num, size;
500
501 ptr = rb_fiddle_ptr2cptr(self);
502 size = RPTR_DATA(self)->size;
503 num = NUM2LONG(other);
504 return rb_fiddle_ptr_new((char *)ptr + num, size - num, 0);
505 }
506
507 /*
508 * call-seq:
509 * ptr - n => new cptr
510 *
511 * Returns a new pointer instance that has been moved back +n+ bytes.
512 */
513 static VALUE
514 rb_fiddle_ptr_minus(VALUE self, VALUE other)
515 {
516 void *ptr;
517 long num, size;
518
519 ptr = rb_fiddle_ptr2cptr(self);
520 size = RPTR_DATA(self)->size;
521 num = NUM2LONG(other);
522 return rb_fiddle_ptr_new((char *)ptr - num, size + num, 0);
523 }
524
525 /*
526 * call-seq:
527 * ptr[index] -> an_integer
528 * ptr[start, length] -> a_string
529 *
530 * Returns integer stored at _index_.
531 *
532 * If _start_ and _length_ are given, a string containing the bytes from
533 * _start_ of _length_ will be returned.
534 */
535 static VALUE
536 rb_fiddle_ptr_aref(int argc, VALUE argv[], VALUE self)
537 {
538 VALUE arg0, arg1;
539 VALUE retval = Qnil;
540 size_t offset, len;
541 struct ptr_data *data;
542
543 TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
544 if (!data->ptr) rb_raise(rb_eFiddleError, "NULL pointer dereference");
545 switch( rb_scan_args(argc, argv, "11", &arg0, &arg1) ){
546 case 1:
547 offset = NUM2ULONG(arg0);
548 retval = INT2NUM(*((char *)data->ptr + offset));
549 break;
550 case 2:
551 offset = NUM2ULONG(arg0);
552 len = NUM2ULONG(arg1);
553 retval = rb_str_new((char *)data->ptr + offset, len);
554 break;
555 default:
556 rb_bug("rb_fiddle_ptr_aref()");
557 }
558 return retval;
559 }
560
561 /*
562 * call-seq:
563 * ptr[index] = int -> int
564 * ptr[start, length] = string or cptr or addr -> string or dl_cptr or addr
565 *
566 * Set the value at +index+ to +int+.
567 *
568 * Or, set the memory at +start+ until +length+ with the contents of +string+,
569 * the memory from +dl_cptr+, or the memory pointed at by the memory address
570 * +addr+.
571 */
572 static VALUE
573 rb_fiddle_ptr_aset(int argc, VALUE argv[], VALUE self)
574 {
575 VALUE arg0, arg1, arg2;
576 VALUE retval = Qnil;
577 size_t offset, len;
578 void *mem;
579 struct ptr_data *data;
580
581 TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
582 if (!data->ptr) rb_raise(rb_eFiddleError, "NULL pointer dereference");
583 switch( rb_scan_args(argc, argv, "21", &arg0, &arg1, &arg2) ){
584 case 2:
585 offset = NUM2ULONG(arg0);
586 ((char*)data->ptr)[offset] = NUM2UINT(arg1);
587 retval = arg1;
588 break;
589 case 3:
590 offset = NUM2ULONG(arg0);
591 len = NUM2ULONG(arg1);
592 if (RB_TYPE_P(arg2, T_STRING)) {
593 mem = StringValuePtr(arg2);
594 }
595 else if( rb_obj_is_kind_of(arg2, rb_cPointer) ){
596 mem = rb_fiddle_ptr2cptr(arg2);
597 }
598 else{
599 mem = NUM2PTR(arg2);
600 }
601 memcpy((char *)data->ptr + offset, mem, len);
602 retval = arg2;
603 break;
604 default:
605 rb_bug("rb_fiddle_ptr_aset()");
606 }
607 return retval;
608 }
609
610 /*
611 * call-seq: size=(size)
612 *
613 * Set the size of this pointer to +size+
614 */
615 static VALUE
616 rb_fiddle_ptr_size_set(VALUE self, VALUE size)
617 {
618 RPTR_DATA(self)->size = NUM2LONG(size);
619 return size;
620 }
621
622 /*
623 * call-seq: size
624 *
625 * Get the size of this pointer.
626 */
627 static VALUE
628 rb_fiddle_ptr_size_get(VALUE self)
629 {
630 return LONG2NUM(RPTR_DATA(self)->size);
631 }
632
633 /*
634 * call-seq:
635 * Fiddle::Pointer[val] => cptr
636 * to_ptr(val) => cptr
637 *
638 * Get the underlying pointer for ruby object +val+ and return it as a
639 * Fiddle::Pointer object.
640 */
641 static VALUE
642 rb_fiddle_ptr_s_to_ptr(VALUE self, VALUE val)
643 {
644 VALUE ptr, wrap = val, vptr;
645
646 if (RTEST(rb_obj_is_kind_of(val, rb_cIO))){
647 rb_io_t *fptr;
648 FILE *fp;
649 GetOpenFile(val, fptr);
650 fp = rb_io_stdio_file(fptr);
651 ptr = rb_fiddle_ptr_new(fp, 0, NULL);
652 }
653 else if (RTEST(rb_obj_is_kind_of(val, rb_cString))){
654 char *str = StringValuePtr(val);
655 ptr = rb_fiddle_ptr_new(str, RSTRING_LEN(val), NULL);
656 }
657 else if ((vptr = rb_check_funcall(val, id_to_ptr, 0, 0)) != Qundef){
658 if (rb_obj_is_kind_of(vptr, rb_cPointer)){
659 ptr = vptr;
660 wrap = 0;
661 }
662 else{
663 rb_raise(rb_eFiddleError, "to_ptr should return a Fiddle::Pointer object");
664 }
665 }
666 else{
667 VALUE num = rb_Integer(val);
668 if (num == val) wrap = 0;
669 ptr = rb_fiddle_ptr_new(NUM2PTR(num), 0, NULL);
670 }
671 if (wrap) RPTR_DATA(ptr)->wrap[0] = wrap;
672 return ptr;
673 }
674
675 void
676 Init_fiddle_pointer(void)
677 {
678 #undef rb_intern
679 id_to_ptr = rb_intern("to_ptr");
680
681 /* Document-class: Fiddle::Pointer
682 *
683 * Fiddle::Pointer is a class to handle C pointers
684 *
685 */
686 rb_cPointer = rb_define_class_under(mFiddle, "Pointer", rb_cObject);
687 rb_define_alloc_func(rb_cPointer, rb_fiddle_ptr_s_allocate);
688 rb_define_singleton_method(rb_cPointer, "malloc", rb_fiddle_ptr_s_malloc, -1);
689 rb_define_singleton_method(rb_cPointer, "to_ptr", rb_fiddle_ptr_s_to_ptr, 1);
690 rb_define_singleton_method(rb_cPointer, "[]", rb_fiddle_ptr_s_to_ptr, 1);
691 rb_define_method(rb_cPointer, "initialize", rb_fiddle_ptr_initialize, -1);
692 rb_define_method(rb_cPointer, "free=", rb_fiddle_ptr_free_set, 1);
693 rb_define_method(rb_cPointer, "free", rb_fiddle_ptr_free_get, 0);
694 rb_define_method(rb_cPointer, "to_i", rb_fiddle_ptr_to_i, 0);
695 rb_define_method(rb_cPointer, "to_int", rb_fiddle_ptr_to_i, 0);
696 rb_define_method(rb_cPointer, "to_value", rb_fiddle_ptr_to_value, 0);
697 rb_define_method(rb_cPointer, "ptr", rb_fiddle_ptr_ptr, 0);
698 rb_define_method(rb_cPointer, "+@", rb_fiddle_ptr_ptr, 0);
699 rb_define_method(rb_cPointer, "ref", rb_fiddle_ptr_ref, 0);
700 rb_define_method(rb_cPointer, "-@", rb_fiddle_ptr_ref, 0);
701 rb_define_method(rb_cPointer, "null?", rb_fiddle_ptr_null_p, 0);
702 rb_define_method(rb_cPointer, "to_s", rb_fiddle_ptr_to_s, -1);
703 rb_define_method(rb_cPointer, "to_str", rb_fiddle_ptr_to_str, -1);
704 rb_define_method(rb_cPointer, "inspect", rb_fiddle_ptr_inspect, 0);
705 rb_define_method(rb_cPointer, "<=>", rb_fiddle_ptr_cmp, 1);
706 rb_define_method(rb_cPointer, "==", rb_fiddle_ptr_eql, 1);
707 rb_define_method(rb_cPointer, "eql?", rb_fiddle_ptr_eql, 1);
708 rb_define_method(rb_cPointer, "+", rb_fiddle_ptr_plus, 1);
709 rb_define_method(rb_cPointer, "-", rb_fiddle_ptr_minus, 1);
710 rb_define_method(rb_cPointer, "[]", rb_fiddle_ptr_aref, -1);
711 rb_define_method(rb_cPointer, "[]=", rb_fiddle_ptr_aset, -1);
712 rb_define_method(rb_cPointer, "size", rb_fiddle_ptr_size_get, 0);
713 rb_define_method(rb_cPointer, "size=", rb_fiddle_ptr_size_set, 1);
714
715 /* Document-const: NULL
716 *
717 * A NULL pointer
718 */
719 rb_define_const(mFiddle, "NULL", rb_fiddle_ptr_new(0, 0, 0));
720 }
ID
unsigned long ID
Definition: ruby.h:103
TYPE_VOIDP
#define TYPE_VOIDP
Definition: fiddle.h:108
rb_check_funcall
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
Definition: vm_eval.c:505
void
void
Definition: rb_mjit_min_header-2.7.0.h:13273
TypedData_Make_Struct
#define TypedData_Make_Struct(klass, type, data_type, sval)
Definition: ruby.h:1244
RPTR_DATA
#define RPTR_DATA(obj)
Definition: pointer.c:30
rb_str_new2
#define rb_str_new2
Definition: intern.h:903
mFiddle
VALUE mFiddle
Definition: fiddle.c:3
memset
void * memset(void *, int, size_t)
rb_scan_args
#define rb_scan_args(argc, argvp, fmt,...)
Definition: rb_mjit_min_header-2.7.0.h:6372
INT2FIX
#define INT2FIX(i)
Definition: ruby.h:263
ruby_xmalloc
void * ruby_xmalloc(size_t size)
Definition: gc.c:11950
NUM2LONG
#define NUM2LONG(x)
Definition: ruby.h:679
NUM2ULONG
#define NUM2ULONG(x)
Definition: ruby.h:689
fiddle.h
VALUE
unsigned long VALUE
Definition: ruby.h:102
rb_intern
#define rb_intern(str)
RB_TYPE_P
#define RB_TYPE_P(obj, type)
Definition: ruby.h:560
SIGNED_VALUE
#define SIGNED_VALUE
Definition: ruby.h:104
Qundef
#define Qundef
Definition: ruby.h:470
rb_define_singleton_method
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1755
rb_define_method
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1551
INT2NUM
#define INT2NUM(x)
Definition: ruby.h:1609
ptr
struct RIMemo * ptr
Definition: debug.c:74
rb_Integer
VALUE rb_Integer(VALUE)
Equivalent to Kernel#Integer in Ruby.
Definition: object.c:3106
Qfalse
#define Qfalse
Definition: ruby.h:467
NULL
#define NULL
Definition: _sdbm.c:101
PRIsVALUE
#define PRIsVALUE
Definition: ruby.h:166
ruby.h
ptr_data::wrap
VALUE wrap[2]
Definition: pointer.c:27
rb_io_stdio_file
FILE * rb_io_stdio_file(rb_io_t *fptr)
Definition: io.c:8032
rb_raise
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2669
NUM2UINT
#define NUM2UINT(x)
Definition: ruby.h:716
LONG2NUM
#define LONG2NUM(x)
Definition: ruby.h:1644
obj
const VALUE VALUE obj
Definition: rb_mjit_min_header-2.7.0.h:5742
memcpy
void * memcpy(void *__restrict, const void *__restrict, size_t)
freefunc_t
void(* freefunc_t)(void *)
Definition: pointer.c:21
rb_eFiddleError
VALUE rb_eFiddleError
Definition: fiddle.c:4
sym
#define sym(x)
Definition: date_core.c:3716
rb_ary_push
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:1195
rb_eTypeError
VALUE rb_eTypeError
Definition: error.c:922
NUM2PTR
#define NUM2PTR(x)
Definition: conversions.h:37
StringValuePtr
#define StringValuePtr(v)
Definition: ruby.h:603
size
int size
Definition: encoding.c:58
RB_OBJ_CLASSNAME
#define RB_OBJ_CLASSNAME(obj)
Definition: pointer.c:11
TYPE_VOID
#define TYPE_VOID
Definition: fiddle.h:107
ptr_data::ptr
void * ptr
Definition: pointer.c:24
rb_cObject
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:2010
TypedData_Get_Struct
#define TypedData_Get_Struct(obj, type, data_type, sval)
Definition: ruby.h:1252
rb_bug
void rb_bug(const char *fmt,...)
Definition: error.c:634
argv
char ** argv
Definition: ruby.c:223
f
#define f
rb_sprintf
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1197
klass
VALUE klass
Definition: rb_mjit_min_header-2.7.0.h:13254
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
rb_cString
RUBY_EXTERN VALUE rb_cString
Definition: ruby.h:2044
rb_fiddle_new_function
VALUE rb_fiddle_new_function(VALUE address, VALUE arg_types, VALUE ret_type)
Definition: function.c:67
NIL_P
#define NIL_P(v)
Definition: ruby.h:482
io.h
argc
int argc
Definition: ruby.c:222
PTR2NUM
#define PTR2NUM(x)
Definition: conversions.h:36
rb_define_const
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2880
ptr_data::size
long size
Definition: pointer.c:25
rb_data_type_struct
Definition: ruby.h:1148
xfree
#define xfree
Definition: defines.h:216
GetOpenFile
#define GetOpenFile(obj, fp)
Definition: io.h:127
rb_str_new
#define rb_str_new(str, len)
Definition: rb_mjit_min_header-2.7.0.h:6116
rb_gc_mark
void rb_gc_mark(VALUE ptr)
Definition: gc.c:5212
Qtrue
#define Qtrue
Definition: ruby.h:468
ptr_data
Definition: pointer.c:23
len
uint8_t len
Definition: escape.c:17
T_STRING
#define T_STRING
Definition: ruby.h:528
rb_define_class_under
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:698
rb_cPointer
VALUE rb_cPointer
Definition: pointer.c:19
rb_ary_new
VALUE rb_ary_new(void)
Definition: array.c:723
NUM2INT
#define NUM2INT(x)
Definition: ruby.h:715
Qnil
#define Qnil
Definition: ruby.h:469
rb_io_t
Definition: io.h:66
RSTRING_LEN
#define RSTRING_LEN(str)
Definition: ruby.h:1005
Init_fiddle_pointer
void Init_fiddle_pointer(void)
Definition: pointer.c:676
rb_obj_is_kind_of
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
Definition: object.c:692
rb_define_alloc_func
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
RTEST
#define RTEST(v)
Definition: ruby.h:481
ptr_data::free
freefunc_t free
Definition: pointer.c:26
rb_cIO
RUBY_EXTERN VALUE rb_cIO
Definition: ruby.h:2030
__sFILE
Definition: vsnprintf.c:169