diff options
author | Kenta Murata <[email protected]> | 2021-07-14 11:26:52 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2021-07-14 18:43:32 +0900 |
commit | 818c74b7f4d5b88833af26226fc81e563b5d11b9 (patch) | |
tree | 8b5271350f2d3394e43e648ce3dd70fbaf2eed80 /ext/fiddle/handle.c | |
parent | 57a743efa408f0c47fc18dd16758a1a1cd54d296 (diff) |
[ruby/fiddle] Return the module handle value in Fiddle::Handle#to_i and add FIddle::Handle#to_ptr (https://github.com/ruby/fiddle/pull/87)
https://github.com/ruby/fiddle/commit/170111a0cb
Diffstat (limited to 'ext/fiddle/handle.c')
-rw-r--r-- | ext/fiddle/handle.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/ext/fiddle/handle.c b/ext/fiddle/handle.c index c1b2db557a..a4a32f1ecb 100644 --- a/ext/fiddle/handle.c +++ b/ext/fiddle/handle.c @@ -259,7 +259,21 @@ rb_fiddle_handle_to_i(VALUE self) struct dl_handle *fiddle_handle; TypedData_Get_Struct(self, struct dl_handle, &fiddle_handle_data_type, fiddle_handle); - return PTR2NUM(fiddle_handle); + return PTR2NUM(fiddle_handle->ptr); +} + +/* + * call-seq: to_ptr + * + * Returns the Fiddle::Pointer of this handle. + */ +static VALUE +rb_fiddle_handle_to_ptr(VALUE self) +{ + struct dl_handle *fiddle_handle; + + TypedData_Get_Struct(self, struct dl_handle, &fiddle_handle_data_type, fiddle_handle); + return rb_fiddle_ptr_new_wrap(fiddle_handle->ptr, 0, 0, self, 0); } static VALUE fiddle_handle_sym(void *handle, VALUE symbol); @@ -466,6 +480,7 @@ Init_fiddle_handle(void) rb_define_method(rb_cHandle, "initialize", rb_fiddle_handle_initialize, -1); rb_define_method(rb_cHandle, "to_i", rb_fiddle_handle_to_i, 0); + rb_define_method(rb_cHandle, "to_ptr", rb_fiddle_handle_to_ptr, 0); rb_define_method(rb_cHandle, "close", rb_fiddle_handle_close, 0); rb_define_method(rb_cHandle, "sym", rb_fiddle_handle_sym, 1); rb_define_method(rb_cHandle, "[]", rb_fiddle_handle_sym, 1); |