Ruby 2.0.0p353(2013-11-22revision43784)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

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