2 * $Id: ptr.c 12039 2007-03-11 16:24:34Z knu $
7 #include <version.h> /* for ruby version code */
11 VALUE rb_mDLMemorySpace
;
12 static VALUE DLMemoryTable
;
15 # define T_SYMBOL T_FIXNUM
18 #if RUBY_VERSION_CODE < 171
20 rb_hash_delete(VALUE hash
, VALUE key
)
22 return rb_funcall(hash
, rb_intern("delete"), 1, key
);
27 rb_dlmem_delete(void *ptr
)
30 rb_hash_delete(DLMemoryTable
, DLLONG2NUM(ptr
));
34 rb_dlmem_aset(void *ptr
, VALUE obj
)
40 rb_hash_aset(DLMemoryTable
, DLLONG2NUM(ptr
), DLLONG2NUM(obj
));
45 rb_dlmem_aref(void *ptr
)
49 val
= rb_hash_aref(DLMemoryTable
, DLLONG2NUM(ptr
));
50 return val
== Qnil
? Qnil
: (VALUE
)DLNUM2LONG(val
);
54 dlptr_free(struct ptr_data
*data
)
58 printf("dlptr_free(): removing the pointer `0x%x' from the MemorySpace\n",
61 rb_dlmem_delete(data
->ptr
);
64 printf("dlptr_free(): 0x%x(data->ptr:0x%x)\n",data
->free
,data
->ptr
);
66 (*(data
->free
))(data
->ptr
);
69 if (data
->stype
) dlfree(data
->stype
);
70 if (data
->ssize
) dlfree(data
->ssize
);
71 if (data
->ids
) dlfree(data
->ids
);
77 struct ptr_data
*data
;
79 Data_Get_Struct(val
, struct ptr_data
, data
);
81 printf("dlptr_init(): add the pointer `0x%x' to the MemorySpace\n",
84 rb_dlmem_aset(data
->ptr
, val
);
89 rb_dlptr_new2(VALUE klass
, void *ptr
, long size
, freefunc_t func
)
91 struct ptr_data
*data
;
96 val
= rb_dlmem_aref(ptr
);
98 val
= Data_Make_Struct(klass
, struct ptr_data
,
102 data
->ctype
= DLPTR_CTYPE_UNKNOWN
;
113 Data_Get_Struct(val
, struct ptr_data
, data
);
126 rb_dlptr_new(void *ptr
, long size
, freefunc_t func
)
128 return rb_dlptr_new2(rb_cDLPtrData
, ptr
, size
, func
);
132 rb_dlptr_malloc(long size
, freefunc_t func
)
137 ptr
= dlmalloc((size_t)size
);
138 memset(ptr
,0,(size_t)size
);
139 return rb_dlptr_new(ptr
, size
, func
);
143 rb_dlptr2cptr(VALUE val
)
145 struct ptr_data
*data
;
148 if (rb_obj_is_kind_of(val
, rb_cDLPtrData
)) {
149 Data_Get_Struct(val
, struct ptr_data
, data
);
152 else if (val
== Qnil
) {
156 rb_raise(rb_eTypeError
, "DL::PtrData was expected");
163 rb_dlptr_s_allocate(VALUE klass
)
166 struct ptr_data
*data
;
169 obj
= Data_Make_Struct(klass
, struct ptr_data
, 0, dlptr_free
, data
);
172 data
->ctype
= DLPTR_CTYPE_UNKNOWN
;
184 rb_dlptr_initialize(int argc
, VALUE argv
[], VALUE self
)
186 VALUE ptr
, sym
, size
;
187 struct ptr_data
*data
;
192 switch (rb_scan_args(argc
, argv
, "12", &ptr
, &size
, &sym
)) {
194 p
= (void*)(DLNUM2LONG(rb_Integer(ptr
)));
197 p
= (void*)(DLNUM2LONG(rb_Integer(ptr
)));
198 s
= DLNUM2LONG(size
);
201 p
= (void*)(DLNUM2LONG(rb_Integer(ptr
)));
202 s
= DLNUM2LONG(size
);
203 f
= rb_dlsym2csym(sym
);
206 rb_bug("rb_dlptr_initialize");
210 Data_Get_Struct(self
, struct ptr_data
, data
);
211 if (data
->ptr
&& data
->free
) {
212 /* Free previous memory. Use of inappropriate initialize may cause SEGV. */
213 (*(data
->free
))(data
->ptr
);
224 rb_dlptr_s_malloc(int argc
, VALUE argv
[], VALUE klass
)
226 VALUE size
, sym
, obj
;
230 switch (rb_scan_args(argc
, argv
, "11", &size
, &sym
)) {
236 f
= rb_dlsym2csym(sym
);
239 rb_bug("rb_dlptr_s_malloc");
242 obj
= rb_dlptr_malloc(s
,f
);
248 rb_dlptr_to_i(VALUE self
)
250 struct ptr_data
*data
;
252 Data_Get_Struct(self
, struct ptr_data
, data
);
253 return DLLONG2NUM(data
->ptr
);
257 rb_dlptr_ptr(VALUE self
)
259 struct ptr_data
*data
;
261 Data_Get_Struct(self
, struct ptr_data
, data
);
262 return rb_dlptr_new(*((void**)(data
->ptr
)),0,0);
266 rb_dlptr_ref(VALUE self
)
268 struct ptr_data
*data
;
270 Data_Get_Struct(self
, struct ptr_data
, data
);
271 return rb_dlptr_new(&(data
->ptr
),0,0);
275 rb_dlptr_null_p(VALUE self
)
277 struct ptr_data
*data
;
279 Data_Get_Struct(self
, struct ptr_data
, data
);
280 return data
->ptr
? Qfalse
: Qtrue
;
284 rb_dlptr_free_set(VALUE self
, VALUE val
)
286 struct ptr_data
*data
;
288 Data_Get_Struct(self
, struct ptr_data
, data
);
290 data
->free
= DLFREEFUNC(rb_dlsym2csym(val
));
296 rb_dlptr_free_get(VALUE self
)
298 struct ptr_data
*pdata
;
300 Data_Get_Struct(self
, struct ptr_data
, pdata
);
302 return rb_dlsym_new(pdata
->free
,"(free)","0P");
306 rb_dlptr_to_array(int argc
, VALUE argv
[], VALUE self
)
308 struct ptr_data
*data
;
315 Data_Get_Struct(self
, struct ptr_data
, data
);
317 switch (rb_scan_args(argc
, argv
, "11", &type
, &size
)) {
319 t
= StringValuePtr(type
)[0];
323 t
= StringValuePtr(type
)[0];
329 n
= data
->size
/ sizeof(short);
332 n
= data
->size
/ sizeof(int);
335 n
= data
->size
/ sizeof(long);
338 n
= data
->size
/ sizeof(float);
341 n
= data
->size
/ sizeof(double);
344 n
= data
->size
/ sizeof(void*);
347 for (n
=0; ((void**)(data
->ptr
))[n
]; n
++) {};
354 rb_bug("rb_dlptr_to_array");
359 for (i
=0; i
< n
; i
++) {
362 rb_ary_push(ary
, INT2NUM(((char*)(data
->ptr
))[i
]));
365 rb_ary_push(ary
, INT2NUM(((short*)(data
->ptr
))[i
]));
368 rb_ary_push(ary
, INT2NUM(((int*)(data
->ptr
))[i
]));
371 rb_ary_push(ary
, DLLONG2NUM(((long*)(data
->ptr
))[i
]));
374 rb_ary_push(ary
, rb_float_new(((double*)(data
->ptr
))[i
]));
377 rb_ary_push(ary
, rb_float_new(((float*)(data
->ptr
))[i
]));
381 char *str
= ((char**)(data
->ptr
))[i
];
383 rb_ary_push(ary
, rb_tainted_str_new2(str
));
386 rb_ary_push(ary
, Qnil
);
392 char *str
= ((char**)(data
->ptr
))[i
];
394 rb_ary_push(ary
, rb_tainted_str_new2(str
));
398 rb_ary_push(ary
, Qnil
);
403 rb_ary_push(ary
, rb_dlptr_new(((void**)(data
->ptr
))[i
],0,0));
407 rb_dlptr_new(((void**)(data
->ptr
))[i
],0,dlfree
));
417 rb_dlptr_to_s(int argc
, VALUE argv
[], VALUE self
)
419 struct ptr_data
*data
;
423 Data_Get_Struct(self
, struct ptr_data
, data
);
424 switch (rb_scan_args(argc
, argv
, "01", &arg1
)) {
426 val
= rb_tainted_str_new2((char*)(data
->ptr
));
430 val
= rb_tainted_str_new((char*)(data
->ptr
), len
);
433 rb_bug("rb_dlptr_to_s");
440 rb_dlptr_to_str(int argc
, VALUE argv
[], VALUE self
)
442 struct ptr_data
*data
;
446 Data_Get_Struct(self
, struct ptr_data
, data
);
447 switch (rb_scan_args(argc
, argv
, "01", &arg1
)) {
449 val
= rb_tainted_str_new((char*)(data
->ptr
),data
->size
);
453 val
= rb_tainted_str_new((char*)(data
->ptr
), len
);
456 rb_bug("rb_dlptr_to_str");
463 rb_dlptr_inspect(VALUE self
)
465 struct ptr_data
*data
;
468 Data_Get_Struct(self
, struct ptr_data
, data
);
469 snprintf(str
, 1023, "#<%s:0x%x ptr=0x%x size=%ld free=0x%x>",
470 rb_class2name(CLASS_OF(self
)), data
, data
->ptr
, data
->size
, data
->free
);
471 return rb_str_new2(str
);
475 rb_dlptr_eql(VALUE self
, VALUE other
)
478 ptr1
= rb_dlptr2cptr(self
);
479 ptr2
= rb_dlptr2cptr(other
);
481 return ptr1
== ptr2
? Qtrue
: Qfalse
;
485 rb_dlptr_cmp(VALUE self
, VALUE other
)
488 ptr1
= rb_dlptr2cptr(self
);
489 ptr2
= rb_dlptr2cptr(other
);
490 return DLLONG2NUM((long)ptr1
- (long)ptr2
);
494 rb_dlptr_plus(VALUE self
, VALUE other
)
499 ptr
= rb_dlptr2cptr(self
);
500 size
= RDLPTR(self
)->size
;
501 num
= DLNUM2LONG(other
);
502 return rb_dlptr_new((char *)ptr
+ num
, size
- num
, 0);
506 rb_dlptr_minus(VALUE self
, VALUE other
)
511 ptr
= rb_dlptr2cptr(self
);
512 size
= RDLPTR(self
)->size
;
513 num
= DLNUM2LONG(other
);
514 return rb_dlptr_new((char *)ptr
- num
, size
+ num
, 0);
518 rb_dlptr_define_data_type(int argc
, VALUE argv
[], VALUE self
)
520 VALUE data_type
, type
, rest
, vid
;
521 struct ptr_data
*data
;
525 rb_scan_args(argc
, argv
, "11*", &data_type
, &type
, &rest
);
526 Data_Get_Struct(self
, struct ptr_data
, data
);
528 if (argc
== 1 || (argc
== 2 && type
== Qnil
)) {
529 if (NUM2INT(data_type
) == DLPTR_CTYPE_UNKNOWN
) {
530 data
->ctype
= DLPTR_CTYPE_UNKNOWN
;
544 rb_raise(rb_eArgError
, "wrong arguments");
548 t
= NUM2INT(data_type
);
550 Check_Type(rest
, T_ARRAY
);
551 num
= RARRAY(rest
)->len
;
552 for (i
=0; i
<num
; i
++) {
553 rb_to_id(rb_ary_entry(rest
,i
));
559 if (data
->stype
) dlfree(data
->stype
);
560 data
->stype
= (char*)dlmalloc(sizeof(char) * num
);
561 if (data
->ssize
) dlfree(data
->ssize
);
562 data
->ssize
= (int*)dlmalloc(sizeof(int) * num
);
563 if (data
->ids
) dlfree(data
->ids
);
564 data
->ids
= (ID
*)dlmalloc(sizeof(ID
) * data
->ids_num
);
566 ctype
= StringValuePtr(type
);
567 for (i
=0; i
<num
; i
++) {
568 vid
= rb_ary_entry(rest
,i
);
569 data
->ids
[i
] = rb_to_id(vid
);
570 data
->stype
[i
] = *ctype
;
572 if (isdigit(*ctype
)) {
574 for (p
=ctype
; isdigit(*p
); p
++) ;
575 d
= ALLOCA_N(char, p
- ctype
+ 1);
576 strncpy(d
, ctype
, p
- ctype
);
578 data
->ssize
[i
] = atoi(d
);
587 rb_raise(rb_eArgError
, "too few/many arguments");
591 data
->size
= dlsizeof(RSTRING(type
)->ptr
);
597 rb_dlptr_define_struct(int argc
, VALUE argv
[], VALUE self
)
602 pass_argc
= argc
+ 1;
603 pass_argv
= ALLOCA_N(VALUE
, pass_argc
);
604 pass_argv
[0] = INT2FIX(DLPTR_CTYPE_STRUCT
);
605 for (i
=1; i
<pass_argc
; i
++) {
606 pass_argv
[i
] = argv
[i
-1];
608 return rb_dlptr_define_data_type(pass_argc
, pass_argv
, self
);
612 rb_dlptr_define_union(int argc
, VALUE argv
[], VALUE self
)
617 pass_argc
= argc
+ 1;
618 pass_argv
= ALLOCA_N(VALUE
, pass_argc
);
619 pass_argv
[0] = INT2FIX(DLPTR_CTYPE_UNION
);
620 for (i
=1; i
<pass_argc
; i
++) {
621 pass_argv
[i
] = argv
[i
-1];
623 return rb_dlptr_define_data_type(pass_argc
, pass_argv
, self
);
627 rb_dlptr_get_data_type(VALUE self
)
629 struct ptr_data
*data
;
631 Data_Get_Struct(self
, struct ptr_data
, data
);
633 return rb_assoc_new(INT2FIX(data
->ctype
),
634 rb_tainted_str_new(data
->stype
, data
->slen
));
636 return rb_assoc_new(INT2FIX(data
->ctype
), Qnil
);
640 cary2ary(void *ptr
, char t
, int len
)
652 elem
= INT2NUM(*((int*)ptr
));
653 ptr
= (char *)ptr
+ sizeof(int);
656 elem
= DLLONG2NUM(*((long*)ptr
));
657 ptr
= (char *)ptr
+ sizeof(long);
661 elem
= rb_dlptr_new(*((void**)ptr
),0, 0);
662 ptr
= (char *)ptr
+ sizeof(void*);
665 elem
= rb_float_new(*((float*)ptr
));
666 ptr
= (char *)ptr
+ sizeof(float);
669 elem
= rb_float_new(*((double*)ptr
));
670 ptr
= (char *)ptr
+ sizeof(double);
673 elem
= INT2NUM(*((char*)ptr
));
674 ptr
= (char *)ptr
+ sizeof(char);
677 elem
= INT2NUM(*((short*)ptr
));
678 ptr
= (char *)ptr
+ sizeof(short);
681 rb_raise(rb_eDLTypeError
, "unsupported type '%c'", t
);
687 for (i
=0; i
< len
; i
++) {
690 elem
= INT2NUM(*((int*)ptr
));
691 ptr
= (char *)ptr
+ sizeof(int);
694 elem
= DLLONG2NUM(*((long*)ptr
));
695 ptr
= (char *)ptr
+ sizeof(long);
699 elem
= rb_dlptr_new(*((void**)ptr
), 0, 0);
700 ptr
= (char *)ptr
+ sizeof(void*);
703 elem
= rb_float_new(*((float*)ptr
));
704 ptr
= (char *)ptr
+ sizeof(float);
707 elem
= rb_float_new(*((float*)ptr
));
708 ptr
= (char *)ptr
+ sizeof(double);
711 elem
= INT2NUM(*((char*)ptr
));
712 ptr
= (char *)ptr
+ sizeof(char);
715 elem
= INT2NUM(*((short*)ptr
));
716 ptr
= (char *)ptr
+ sizeof(short);
719 rb_raise(rb_eDLTypeError
, "unsupported type '%c'", t
);
721 rb_ary_push(ary
, elem
);
728 rb_dlptr_aref(int argc
, VALUE argv
[], VALUE self
)
730 VALUE key
= Qnil
, num
= Qnil
;
732 struct ptr_data
*data
;
736 if (rb_scan_args(argc
, argv
, "11", &key
, &num
) == 1) {
740 if (TYPE(key
) == T_FIXNUM
|| TYPE(key
) == T_BIGNUM
) {
743 return rb_dlptr_to_str(1, pass
, rb_dlptr_plus(self
, key
));
746 if (! (TYPE(key
) == T_STRING
|| TYPE(key
) == T_SYMBOL
)) {
747 rb_raise(rb_eTypeError
, "the key must be a string or symbol");
751 Data_Get_Struct(self
, struct ptr_data
, data
);
753 switch (data
->ctype
) {
754 case DLPTR_CTYPE_STRUCT
:
755 for (i
=0; i
< data
->ids_num
; i
++) {
756 switch (data
->stype
[i
]) {
758 DLALIGN(data
->ptr
,offset
,INT_ALIGN
);
761 DLALIGN(data
->ptr
,offset
,LONG_ALIGN
);
765 DLALIGN(data
->ptr
,offset
,VOIDP_ALIGN
);
768 DLALIGN(data
->ptr
,offset
,FLOAT_ALIGN
);
771 DLALIGN(data
->ptr
,offset
,DOUBLE_ALIGN
);
776 DLALIGN(data
->ptr
,offset
,SHORT_ALIGN
);
779 rb_raise(rb_eDLTypeError
, "unsupported type '%c'", data
->stype
[i
]);
781 if (data
->ids
[i
] == id
) {
782 return cary2ary((char *)data
->ptr
+ offset
, data
->stype
[i
], data
->ssize
[i
]);
784 switch (data
->stype
[i
]) {
786 offset
+= sizeof(int) * data
->ssize
[i
];
789 offset
+= sizeof(long) * data
->ssize
[i
];
793 offset
+= sizeof(void*) * data
->ssize
[i
];
796 offset
+= sizeof(float) * data
->ssize
[i
];
799 offset
+= sizeof(double) * data
->ssize
[i
];
802 offset
+= sizeof(char) * data
->ssize
[i
];
805 offset
+= sizeof(short) * data
->ssize
[i
];
808 rb_raise(rb_eDLTypeError
, "unsupported type '%c'", data
->stype
[i
]);
812 case DLPTR_CTYPE_UNION
:
813 for (i
=0; i
< data
->ids_num
; i
++) {
814 if (data
->ids
[i
] == id
) {
815 return cary2ary((char *)data
->ptr
+ offset
, data
->stype
[i
], data
->ssize
[i
]);
819 } /* end of switch */
821 rb_raise(rb_eNameError
, "undefined key `%s' for %s",
822 rb_id2name(id
), rb_class2name(CLASS_OF(self
)));
828 ary2cary(char t
, VALUE val
, long *size
)
832 if (TYPE(val
) == T_ARRAY
) {
833 ptr
= rb_ary2cary(t
, val
, size
);
836 ptr
= rb_ary2cary(t
, rb_ary_new3(1, val
), size
);
842 rb_dlptr_aset(int argc
, VALUE argv
[], VALUE self
)
844 VALUE key
= Qnil
, num
= Qnil
, val
= Qnil
;
846 struct ptr_data
*data
;
853 switch (rb_scan_args(argc
, argv
, "21", &key
, &num
, &val
)) {
860 if (TYPE(key
) == T_FIXNUM
|| TYPE(key
) == T_BIGNUM
) {
865 Data_Get_Struct(self
, struct ptr_data
, data
);
866 dst
= (void*)((long)(data
->ptr
) + DLNUM2LONG(key
));
867 src
= RSTRING(val
)->ptr
;
868 len
= RSTRING(val
)->len
;
870 memcpy(dst
, src
, len
);
873 long n
= NUM2INT(num
);
874 memcpy(dst
, src
, n
< len
? n
: len
);
875 if (n
> len
) MEMZERO((char*)dst
+ len
, char, n
- len
);
881 Data_Get_Struct(self
, struct ptr_data
, data
);
882 switch (data
->ctype
) {
883 case DLPTR_CTYPE_STRUCT
:
885 for (i
=0; i
< data
->ids_num
; i
++) {
886 switch (data
->stype
[i
]) {
888 DLALIGN(data
->ptr
,offset
,INT_ALIGN
);
891 DLALIGN(data
->ptr
,offset
,LONG_ALIGN
);
895 DLALIGN(data
->ptr
,offset
,VOIDP_ALIGN
);
898 DLALIGN(data
->ptr
,offset
,DOUBLE_ALIGN
);
901 DLALIGN(data
->ptr
,offset
,FLOAT_ALIGN
);
906 DLALIGN(data
->ptr
,offset
,SHORT_ALIGN
);
909 rb_raise(rb_eDLTypeError
, "unsupported type '%c'", data
->stype
[i
]);
911 if (data
->ids
[i
] == id
) {
912 memimg
= ary2cary(data
->stype
[i
], val
, &memsize
);
913 memcpy((char *)data
->ptr
+ offset
, memimg
, memsize
);
917 switch (data
->stype
[i
]) {
920 offset
+= sizeof(int) * data
->ssize
[i
];
924 offset
+= sizeof(long) * data
->ssize
[i
];
930 offset
+= sizeof(void*) * data
->ssize
[i
];
934 offset
+= sizeof(double) * data
->ssize
[i
];
938 offset
+= sizeof(float) * data
->ssize
[i
];
942 offset
+= sizeof(char) * data
->ssize
[i
];
946 offset
+= sizeof(short) * data
->ssize
[i
];
949 rb_raise(rb_eDLTypeError
, "unsupported type '%c'", data
->stype
[i
]);
954 case DLPTR_CTYPE_UNION
:
955 for (i
=0; i
< data
->ids_num
; i
++) {
956 if (data
->ids
[i
] == id
) {
957 switch (data
->stype
[i
]) {
959 memsize
= sizeof(int) * data
->ssize
[i
];
962 memsize
= sizeof(long) * data
->ssize
[i
];
966 memsize
= sizeof(void*) * data
->ssize
[i
];
969 memsize
= sizeof(float) * data
->ssize
[i
];
972 memsize
= sizeof(double) * data
->ssize
[i
];
975 memsize
= sizeof(char) * data
->ssize
[i
];
978 memsize
= sizeof(short) * data
->ssize
[i
];
981 rb_raise(rb_eDLTypeError
, "unsupported type '%c'", data
->stype
[i
]);
983 memimg
= ary2cary(data
->stype
[i
], val
, NULL
);
984 memcpy(data
->ptr
, memimg
, memsize
);
992 rb_raise(rb_eNameError
, "undefined key `%s' for %s",
993 rb_id2name(id
), rb_class2name(CLASS_OF(self
)));
999 rb_dlptr_size(int argc
, VALUE argv
[], VALUE self
)
1003 if (rb_scan_args(argc
, argv
, "01", &size
) == 0){
1004 return DLLONG2NUM(RDLPTR(self
)->size
);
1007 RDLPTR(self
)->size
= DLNUM2LONG(size
);
1013 dlmem_each_i(VALUE assoc
, void *data
)
1016 key
= rb_ary_entry(assoc
, 0);
1017 val
= rb_ary_entry(assoc
, 1);
1018 rb_yield(rb_assoc_new(key
,(VALUE
)DLNUM2LONG(val
)));
1023 rb_dlmem_each(VALUE self
)
1025 rb_iterate(rb_each
, DLMemoryTable
, dlmem_each_i
, 0);
1032 rb_cDLPtrData
= rb_define_class_under(rb_mDL
, "PtrData", rb_cObject
);
1033 rb_define_alloc_func(rb_cDLPtrData
, rb_dlptr_s_allocate
);
1034 rb_define_singleton_method(rb_cDLPtrData
, "malloc", rb_dlptr_s_malloc
, -1);
1035 rb_define_method(rb_cDLPtrData
, "initialize", rb_dlptr_initialize
, -1);
1036 rb_define_method(rb_cDLPtrData
, "free=", rb_dlptr_free_set
, 1);
1037 rb_define_method(rb_cDLPtrData
, "free", rb_dlptr_free_get
, 0);
1038 rb_define_method(rb_cDLPtrData
, "to_i", rb_dlptr_to_i
, 0);
1039 rb_define_method(rb_cDLPtrData
, "ptr", rb_dlptr_ptr
, 0);
1040 rb_define_method(rb_cDLPtrData
, "+@", rb_dlptr_ptr
, 0);
1041 rb_define_method(rb_cDLPtrData
, "ref", rb_dlptr_ref
, 0);
1042 rb_define_method(rb_cDLPtrData
, "-@", rb_dlptr_ref
, 0);
1043 rb_define_method(rb_cDLPtrData
, "null?", rb_dlptr_null_p
, 0);
1044 rb_define_method(rb_cDLPtrData
, "to_a", rb_dlptr_to_array
, -1);
1045 rb_define_method(rb_cDLPtrData
, "to_s", rb_dlptr_to_s
, -1);
1046 rb_define_method(rb_cDLPtrData
, "to_str", rb_dlptr_to_str
, -1);
1047 rb_define_method(rb_cDLPtrData
, "inspect", rb_dlptr_inspect
, 0);
1048 rb_define_method(rb_cDLPtrData
, "<=>", rb_dlptr_cmp
, 1);
1049 rb_define_method(rb_cDLPtrData
, "==", rb_dlptr_eql
, 1);
1050 rb_define_method(rb_cDLPtrData
, "eql?", rb_dlptr_eql
, 1);
1051 rb_define_method(rb_cDLPtrData
, "+", rb_dlptr_plus
, 1);
1052 rb_define_method(rb_cDLPtrData
, "-", rb_dlptr_minus
, 1);
1053 rb_define_method(rb_cDLPtrData
, "define_data_type",
1054 rb_dlptr_define_data_type
, -1);
1055 rb_define_method(rb_cDLPtrData
, "struct!", rb_dlptr_define_struct
, -1);
1056 rb_define_method(rb_cDLPtrData
, "union!", rb_dlptr_define_union
, -1);
1057 rb_define_method(rb_cDLPtrData
, "data_type", rb_dlptr_get_data_type
, 0);
1058 rb_define_method(rb_cDLPtrData
, "[]", rb_dlptr_aref
, -1);
1059 rb_define_method(rb_cDLPtrData
, "[]=", rb_dlptr_aset
, -1);
1060 rb_define_method(rb_cDLPtrData
, "size", rb_dlptr_size
, -1);
1061 rb_define_method(rb_cDLPtrData
, "size=", rb_dlptr_size
, -1);
1063 rb_mDLMemorySpace
= rb_define_module_under(rb_mDL
, "MemorySpace");
1064 DLMemoryTable
= rb_hash_new();
1065 rb_define_const(rb_mDLMemorySpace
, "MemoryTable", DLMemoryTable
);
1066 rb_define_module_function(rb_mDLMemorySpace
, "each", rb_dlmem_each
, 0);