[ruby/fiddle] Update documentation

(https://github.com/ruby/fiddle/pull/119)

The documentation for `Fiddle.dlwrap` and `Fiddle.dlunwrap` were not
very accurate and pretty confusing. This commit updates the
documentation so it's easier to understand what the methods do.
This commit is contained in:
Aaron Patterson 2022-12-27 11:19:25 -08:00 committed by Hiroshi SHIBATA
parent 967dec5d61
commit 1df7f359d1
No known key found for this signature in database
GPG Key ID: F9CF13417264FAC2

View File

@ -58,18 +58,16 @@ rb_fiddle_free(VALUE self, VALUE addr)
/* /*
* call-seq: Fiddle.dlunwrap(addr) * call-seq: Fiddle.dlunwrap(addr)
* *
* Returns the hexadecimal representation of a memory pointer address +addr+ * Returns the Ruby object stored at the memory address +addr+
* *
* Example: * Example:
* *
* lib = Fiddle.dlopen('/lib64/libc-2.15.so') * >> x = Object.new
* => #<Fiddle::Handle:0x00000001342460> * => #<Object:0x0000000107c7d870>
* * >> Fiddle.dlwrap(x)
* lib['strcpy'].to_s(16) * => 4425504880
* => "7f59de6dd240" * >> Fiddle.dlunwrap(_)
* * => #<Object:0x0000000107c7d870>
* Fiddle.dlunwrap(Fiddle.dlwrap(lib['strcpy'].to_s(16)))
* => "7f59de6dd240"
*/ */
VALUE VALUE
rb_fiddle_ptr2value(VALUE self, VALUE addr) rb_fiddle_ptr2value(VALUE self, VALUE addr)
@ -80,15 +78,22 @@ rb_fiddle_ptr2value(VALUE self, VALUE addr)
/* /*
* call-seq: Fiddle.dlwrap(val) * call-seq: Fiddle.dlwrap(val)
* *
* Returns a memory pointer of a function's hexadecimal address location +val+ * Returns the memory address of the Ruby object stored at +val+
* *
* Example: * Example:
* *
* lib = Fiddle.dlopen('/lib64/libc-2.15.so') * >> x = Object.new
* => #<Fiddle::Handle:0x00000001342460> * => #<Object:0x0000000107c7d870>
* >> Fiddle.dlwrap(x)
* => 4425504880
* *
* Fiddle.dlwrap(lib['strcpy'].to_s(16)) * In the case +val+ is not a heap allocated object, this method will return
* => 25522520 * the tagged pointer value.
*
* Example:
*
* >> Fiddle.dlwrap(123)
* => 247
*/ */
static VALUE static VALUE
rb_fiddle_value2ptr(VALUE self, VALUE val) rb_fiddle_value2ptr(VALUE self, VALUE val)