File: C:/Ruby27-x64/share/doc/ruby/html/Fiddle/Pointer.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>class Fiddle::Pointer - RDoc Documentation</title>
<script type="text/javascript">
var rdoc_rel_prefix = "../";
var index_rel_prefix = "../";
</script>
<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>
<link href="../css/fonts.css" rel="stylesheet">
<link href="../css/rdoc.css" rel="stylesheet">
<body id="top" role="document" class="class">
<nav role="navigation">
<div id="project-navigation">
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
<h2>
<a href="../index.html" rel="home">Home</a>
</h2>
<div id="table-of-contents-navigation">
<a href="../table_of_contents.html#pages">Pages</a>
<a href="../table_of_contents.html#classes">Classes</a>
<a href="../table_of_contents.html#methods">Methods</a>
</div>
</div>
<div id="search-section" role="search" class="project-section initially-hidden">
<form action="#" method="get" accept-charset="utf-8">
<div id="search-field-wrapper">
<input id="search-field" role="combobox" aria-label="Search"
aria-autocomplete="list" aria-controls="search-results"
type="text" name="search" placeholder="Search" spellcheck="false"
title="Type to search, Up and Down to navigate, Enter to load">
</div>
<ul id="search-results" aria-label="Search Results"
aria-busy="false" aria-expanded="false"
aria-atomic="false" class="initially-hidden"></ul>
</form>
</div>
</div>
<div id="class-metadata">
<div id="parent-class-section" class="nav-section">
<h3>Parent</h3>
<p class="link"><a href="../Object.html">Object</a>
</div>
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
<h3>Methods</h3>
<ul class="link-list" role="directory">
<li ><a href="#method-c-5B-5D">::[]</a>
<li ><a href="#method-c-malloc">::malloc</a>
<li ><a href="#method-c-new">::new</a>
<li ><a href="#method-c-to_ptr">::to_ptr</a>
<li ><a href="#method-i-2B">#+</a>
<li ><a href="#method-i-2B-40">#+@</a>
<li ><a href="#method-i-2D">#-</a>
<li ><a href="#method-i-2D-40">#-@</a>
<li ><a href="#method-i-3C-3D-3E">#<=></a>
<li ><a href="#method-i-3D-3D">#==</a>
<li ><a href="#method-i-5B-5D">#[]</a>
<li ><a href="#method-i-5B-5D-3D">#[]=</a>
<li ><a href="#method-i-eql-3F">#eql?</a>
<li ><a href="#method-i-free">#free</a>
<li ><a href="#method-i-free-3D">#free=</a>
<li ><a href="#method-i-inspect">#inspect</a>
<li ><a href="#method-i-null-3F">#null?</a>
<li ><a href="#method-i-ptr">#ptr</a>
<li ><a href="#method-i-ref">#ref</a>
<li ><a href="#method-i-size">#size</a>
<li ><a href="#method-i-size-3D">#size=</a>
<li ><a href="#method-i-to_i">#to_i</a>
<li ><a href="#method-i-to_int">#to_int</a>
<li ><a href="#method-i-to_s">#to_s</a>
<li ><a href="#method-i-to_str">#to_str</a>
<li ><a href="#method-i-to_value">#to_value</a>
</ul>
</div>
</div>
</nav>
<main role="main" aria-labelledby="class-Fiddle::Pointer">
<h1 id="class-Fiddle::Pointer" class="class">
class Fiddle::Pointer
</h1>
<section class="description">
<p><a href="Pointer.html"><code>Fiddle::Pointer</code></a> is a class to handle C pointers</p>
</section>
<section id="5Buntitled-5D" class="documentation-section">
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
<header>
<h3>Public Class Methods</h3>
</header>
<div id="method-c-5B-5D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
Fiddle::Pointer[val] → cptr
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
to_ptr(val) → cptr
</span>
</div>
<div class="method-description">
<p>Get the underlying pointer for ruby object <code>val</code> and return it as a <a href="Pointer.html"><code>Fiddle::Pointer</code></a> object.</p>
<div class="method-source-code" id="5B-5D-source">
<pre>static VALUE
rb_fiddle_ptr_s_to_ptr(VALUE self, VALUE val)
{
VALUE ptr, wrap = val, vptr;
if (RTEST(rb_obj_is_kind_of(val, rb_cIO))){
rb_io_t *fptr;
FILE *fp;
GetOpenFile(val, fptr);
fp = rb_io_stdio_file(fptr);
ptr = rb_fiddle_ptr_new(fp, 0, NULL);
}
else if (RTEST(rb_obj_is_kind_of(val, rb_cString))){
char *str = StringValuePtr(val);
ptr = rb_fiddle_ptr_new(str, RSTRING_LEN(val), NULL);
}
else if ((vptr = rb_check_funcall(val, id_to_ptr, 0, 0)) != Qundef){
if (rb_obj_is_kind_of(vptr, rb_cPointer)){
ptr = vptr;
wrap = 0;
}
else{
rb_raise(rb_eFiddleError, "to_ptr should return a Fiddle::Pointer object");
}
}
else{
VALUE num = rb_Integer(val);
if (num == val) wrap = 0;
ptr = rb_fiddle_ptr_new(NUM2PTR(num), 0, NULL);
}
if (wrap) RPTR_DATA(ptr)->wrap[0] = wrap;
return ptr;
}</pre>
</div>
</div>
</div>
<div id="method-c-malloc" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
Fiddle::Pointer.malloc(size, freefunc = nil) → fiddle pointer instance
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Allocate <code>size</code> bytes of memory and associate it with an optional <code>freefunc</code> that will be called when the pointer is garbage collected.</p>
<p><code>freefunc</code> must be an address pointing to a function or an instance of <a href="Function.html"><code>Fiddle::Function</code></a></p>
<div class="method-source-code" id="malloc-source">
<pre>static VALUE
rb_fiddle_ptr_s_malloc(int argc, VALUE argv[], VALUE klass)
{
VALUE size, sym, obj, wrap = 0;
long s;
freefunc_t f;
switch (rb_scan_args(argc, argv, "11", &size, &sym)) {
case 1:
s = NUM2LONG(size);
f = NULL;
break;
case 2:
s = NUM2LONG(size);
f = get_freefunc(sym, &wrap);
break;
default:
rb_bug("rb_fiddle_ptr_s_malloc");
}
obj = rb_fiddle_ptr_malloc(s,f);
if (wrap) RPTR_DATA(obj)->wrap[1] = wrap;
return obj;
}</pre>
</div>
</div>
</div>
<div id="method-c-new" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
Fiddle::Pointer.new(address) → fiddle_cptr
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
new(address, size) → fiddle_cptr
</span>
</div>
<div class="method-heading">
<span class="method-callseq">
new(address, size, freefunc) → fiddle_cptr
</span>
</div>
<div class="method-description">
<p>Create a new pointer to <code>address</code> with an optional <code>size</code> and <code>freefunc</code>.</p>
<p><code>freefunc</code> will be called when the instance is garbage collected.</p>
<div class="method-source-code" id="new-source">
<pre>static VALUE
rb_fiddle_ptr_initialize(int argc, VALUE argv[], VALUE self)
{
VALUE ptr, sym, size, wrap = 0, funcwrap = 0;
struct ptr_data *data;
void *p = NULL;
freefunc_t f = NULL;
long s = 0;
if (rb_scan_args(argc, argv, "12", &ptr, &size, &sym) >= 1) {
VALUE addrnum = rb_Integer(ptr);
if (addrnum != ptr) wrap = ptr;
p = NUM2PTR(addrnum);
}
if (argc >= 2) {
s = NUM2LONG(size);
}
if (argc >= 3) {
f = get_freefunc(sym, &funcwrap);
}
if (p) {
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
if (data->ptr && data->free) {
/* Free previous memory. Use of inappropriate initialize may cause SEGV. */
(*(data->free))(data->ptr);
}
data->wrap[0] = wrap;
data->wrap[1] = funcwrap;
data->ptr = p;
data->size = s;
data->free = f;
}
return Qnil;
}</pre>
</div>
</div>
</div>
<div id="method-c-to_ptr" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
to_ptr(val) → cptr
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Get the underlying pointer for ruby object <code>val</code> and return it as a <a href="Pointer.html"><code>Fiddle::Pointer</code></a> object.</p>
<div class="method-source-code" id="to_ptr-source">
<pre>static VALUE
rb_fiddle_ptr_s_to_ptr(VALUE self, VALUE val)
{
VALUE ptr, wrap = val, vptr;
if (RTEST(rb_obj_is_kind_of(val, rb_cIO))){
rb_io_t *fptr;
FILE *fp;
GetOpenFile(val, fptr);
fp = rb_io_stdio_file(fptr);
ptr = rb_fiddle_ptr_new(fp, 0, NULL);
}
else if (RTEST(rb_obj_is_kind_of(val, rb_cString))){
char *str = StringValuePtr(val);
ptr = rb_fiddle_ptr_new(str, RSTRING_LEN(val), NULL);
}
else if ((vptr = rb_check_funcall(val, id_to_ptr, 0, 0)) != Qundef){
if (rb_obj_is_kind_of(vptr, rb_cPointer)){
ptr = vptr;
wrap = 0;
}
else{
rb_raise(rb_eFiddleError, "to_ptr should return a Fiddle::Pointer object");
}
}
else{
VALUE num = rb_Integer(val);
if (num == val) wrap = 0;
ptr = rb_fiddle_ptr_new(NUM2PTR(num), 0, NULL);
}
if (wrap) RPTR_DATA(ptr)->wrap[0] = wrap;
return ptr;
}</pre>
</div>
</div>
</div>
</section>
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
<header>
<h3>Public Instance Methods</h3>
</header>
<div id="method-i-2B" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ptr + n → new cptr
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a new pointer instance that has been advanced <code>n</code> bytes.</p>
<div class="method-source-code" id="2B-source">
<pre>static VALUE
rb_fiddle_ptr_plus(VALUE self, VALUE other)
{
void *ptr;
long num, size;
ptr = rb_fiddle_ptr2cptr(self);
size = RPTR_DATA(self)->size;
num = NUM2LONG(other);
return rb_fiddle_ptr_new((char *)ptr + num, size - num, 0);
}</pre>
</div>
</div>
</div>
<div id="method-i-2B-40" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ptr
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a new <a href="Pointer.html"><code>Fiddle::Pointer</code></a> instance that is a dereferenced pointer for this pointer.</p>
<p>Analogous to the star operator in C.</p>
<div class="method-source-code" id="2B-40-source">
<pre>static VALUE
rb_fiddle_ptr_ptr(VALUE self)
{
struct ptr_data *data;
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
return rb_fiddle_ptr_new(*((void**)(data->ptr)),0,0);
}</pre>
</div>
</div>
</div>
<div id="method-i-2D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ptr - n → new cptr
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a new pointer instance that has been moved back <code>n</code> bytes.</p>
<div class="method-source-code" id="2D-source">
<pre>static VALUE
rb_fiddle_ptr_minus(VALUE self, VALUE other)
{
void *ptr;
long num, size;
ptr = rb_fiddle_ptr2cptr(self);
size = RPTR_DATA(self)->size;
num = NUM2LONG(other);
return rb_fiddle_ptr_new((char *)ptr - num, size + num, 0);
}</pre>
</div>
</div>
</div>
<div id="method-i-2D-40" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ref
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a new <a href="Pointer.html"><code>Fiddle::Pointer</code></a> instance that is a reference pointer for this pointer.</p>
<p>Analogous to the ampersand operator in C.</p>
<div class="method-source-code" id="2D-40-source">
<pre>static VALUE
rb_fiddle_ptr_ref(VALUE self)
{
struct ptr_data *data;
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
return rb_fiddle_ptr_new(&(data->ptr),0,0);
}</pre>
</div>
</div>
</div>
<div id="method-i-3C-3D-3E" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ptr <=> other → -1, 0, 1, or nil
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns -1 if less than, 0 if equal to, 1 if greater than <code>other</code>.</p>
<p>Returns nil if <code>ptr</code> cannot be compared to <code>other</code>.</p>
<div class="method-source-code" id="3C-3D-3E-source">
<pre>static VALUE
rb_fiddle_ptr_cmp(VALUE self, VALUE other)
{
void *ptr1, *ptr2;
SIGNED_VALUE diff;
if(!rb_obj_is_kind_of(other, rb_cPointer)) return Qnil;
ptr1 = rb_fiddle_ptr2cptr(self);
ptr2 = rb_fiddle_ptr2cptr(other);
diff = (SIGNED_VALUE)ptr1 - (SIGNED_VALUE)ptr2;
if (!diff) return INT2FIX(0);
return diff > 0 ? INT2NUM(1) : INT2NUM(-1);
}</pre>
</div>
</div>
</div>
<div id="method-i-3D-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ptr == other → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if <code>other</code> wraps the same pointer, otherwise returns false.</p>
<div class="method-source-code" id="3D-3D-source">
<pre>static VALUE
rb_fiddle_ptr_eql(VALUE self, VALUE other)
{
void *ptr1, *ptr2;
if(!rb_obj_is_kind_of(other, rb_cPointer)) return Qfalse;
ptr1 = rb_fiddle_ptr2cptr(self);
ptr2 = rb_fiddle_ptr2cptr(other);
return ptr1 == ptr2 ? Qtrue : Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-i-5B-5D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ptr[index] → an_integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
ptr[start, length] → a_string
</span>
</div>
<div class="method-description">
<p>Returns integer stored at <em>index</em>.</p>
<p>If <em>start</em> and <em>length</em> are given, a string containing the bytes from <em>start</em> of <em>length</em> will be returned.</p>
<div class="method-source-code" id="5B-5D-source">
<pre>static VALUE
rb_fiddle_ptr_aref(int argc, VALUE argv[], VALUE self)
{
VALUE arg0, arg1;
VALUE retval = Qnil;
size_t offset, len;
struct ptr_data *data;
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
if (!data->ptr) rb_raise(rb_eFiddleError, "NULL pointer dereference");
switch( rb_scan_args(argc, argv, "11", &arg0, &arg1) ){
case 1:
offset = NUM2ULONG(arg0);
retval = INT2NUM(*((char *)data->ptr + offset));
break;
case 2:
offset = NUM2ULONG(arg0);
len = NUM2ULONG(arg1);
retval = rb_str_new((char *)data->ptr + offset, len);
break;
default:
rb_bug("rb_fiddle_ptr_aref()");
}
return retval;
}</pre>
</div>
</div>
</div>
<div id="method-i-5B-5D-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ptr[index] = int → int
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
ptr[start, length] = string or cptr or addr → string or dl_cptr or addr
</span>
</div>
<div class="method-description">
<p><a href="../Set.html"><code>Set</code></a> the value at <code>index</code> to <code>int</code>.</p>
<p>Or, set the memory at <code>start</code> until <code>length</code> with the contents of <code>string</code>, the memory from <code>dl_cptr</code>, or the memory pointed at by the memory address <code>addr</code>.</p>
<div class="method-source-code" id="5B-5D-3D-source">
<pre>static VALUE
rb_fiddle_ptr_aset(int argc, VALUE argv[], VALUE self)
{
VALUE arg0, arg1, arg2;
VALUE retval = Qnil;
size_t offset, len;
void *mem;
struct ptr_data *data;
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
if (!data->ptr) rb_raise(rb_eFiddleError, "NULL pointer dereference");
switch( rb_scan_args(argc, argv, "21", &arg0, &arg1, &arg2) ){
case 2:
offset = NUM2ULONG(arg0);
((char*)data->ptr)[offset] = NUM2UINT(arg1);
retval = arg1;
break;
case 3:
offset = NUM2ULONG(arg0);
len = NUM2ULONG(arg1);
if (RB_TYPE_P(arg2, T_STRING)) {
mem = StringValuePtr(arg2);
}
else if( rb_obj_is_kind_of(arg2, rb_cPointer) ){
mem = rb_fiddle_ptr2cptr(arg2);
}
else{
mem = NUM2PTR(arg2);
}
memcpy((char *)data->ptr + offset, mem, len);
retval = arg2;
break;
default:
rb_bug("rb_fiddle_ptr_aset()");
}
return retval;
}</pre>
</div>
</div>
</div>
<div id="method-i-eql-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
eql?(other) → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if <code>other</code> wraps the same pointer, otherwise returns false.</p>
<div class="method-source-code" id="eql-3F-source">
<pre>static VALUE
rb_fiddle_ptr_eql(VALUE self, VALUE other)
{
void *ptr1, *ptr2;
if(!rb_obj_is_kind_of(other, rb_cPointer)) return Qfalse;
ptr1 = rb_fiddle_ptr2cptr(self);
ptr2 = rb_fiddle_ptr2cptr(other);
return ptr1 == ptr2 ? Qtrue : Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-i-free" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
free → Fiddle::Function
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Get the free function for this pointer.</p>
<p>Returns a new instance of <a href="Function.html"><code>Fiddle::Function</code></a>.</p>
<p>See <a href="Function.html#method-c-new"><code>Fiddle::Function.new</code></a></p>
<div class="method-source-code" id="free-source">
<pre>static VALUE
rb_fiddle_ptr_free_get(VALUE self)
{
struct ptr_data *pdata;
VALUE address;
VALUE arg_types;
VALUE ret_type;
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, pdata);
if (!pdata->free)
return Qnil;
address = PTR2NUM(pdata->free);
ret_type = INT2NUM(TYPE_VOID);
arg_types = rb_ary_new();
rb_ary_push(arg_types, INT2NUM(TYPE_VOIDP));
return rb_fiddle_new_function(address, arg_types, ret_type);
}</pre>
</div>
</div>
</div>
<div id="method-i-free-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
free=(function)
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p><a href="../Set.html"><code>Set</code></a> the free function for this pointer to <code>function</code> in the given <a href="Function.html"><code>Fiddle::Function</code></a>.</p>
<div class="method-source-code" id="free-3D-source">
<pre>static VALUE
rb_fiddle_ptr_free_set(VALUE self, VALUE val)
{
struct ptr_data *data;
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
data->free = get_freefunc(val, &data->wrap[1]);
return Qnil;
}</pre>
</div>
</div>
</div>
<div id="method-i-inspect" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
inspect
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a string formatted with an easily readable representation of the internal state of the pointer.</p>
<div class="method-source-code" id="inspect-source">
<pre>static VALUE
rb_fiddle_ptr_inspect(VALUE self)
{
struct ptr_data *data;
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
return rb_sprintf("#<%"PRIsVALUE":%p ptr=%p size=%ld free=%p>",
RB_OBJ_CLASSNAME(self), (void *)data, data->ptr, data->size, (void *)data->free);
}</pre>
</div>
</div>
</div>
<div id="method-i-null-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
null?
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if this is a null pointer.</p>
<div class="method-source-code" id="null-3F-source">
<pre>static VALUE
rb_fiddle_ptr_null_p(VALUE self)
{
struct ptr_data *data;
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
return data->ptr ? Qfalse : Qtrue;
}</pre>
</div>
</div>
</div>
<div id="method-i-ptr" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ptr
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a new <a href="Pointer.html"><code>Fiddle::Pointer</code></a> instance that is a dereferenced pointer for this pointer.</p>
<p>Analogous to the star operator in C.</p>
<div class="method-source-code" id="ptr-source">
<pre>static VALUE
rb_fiddle_ptr_ptr(VALUE self)
{
struct ptr_data *data;
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
return rb_fiddle_ptr_new(*((void**)(data->ptr)),0,0);
}</pre>
</div>
</div>
</div>
<div id="method-i-ref" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ref
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a new <a href="Pointer.html"><code>Fiddle::Pointer</code></a> instance that is a reference pointer for this pointer.</p>
<p>Analogous to the ampersand operator in C.</p>
<div class="method-source-code" id="ref-source">
<pre>static VALUE
rb_fiddle_ptr_ref(VALUE self)
{
struct ptr_data *data;
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
return rb_fiddle_ptr_new(&(data->ptr),0,0);
}</pre>
</div>
</div>
</div>
<div id="method-i-size" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
size
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Get the size of this pointer.</p>
<div class="method-source-code" id="size-source">
<pre>static VALUE
rb_fiddle_ptr_size_get(VALUE self)
{
return LONG2NUM(RPTR_DATA(self)->size);
}</pre>
</div>
</div>
</div>
<div id="method-i-size-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
size=(size)
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p><a href="../Set.html"><code>Set</code></a> the size of this pointer to <code>size</code></p>
<div class="method-source-code" id="size-3D-source">
<pre>static VALUE
rb_fiddle_ptr_size_set(VALUE self, VALUE size)
{
RPTR_DATA(self)->size = NUM2LONG(size);
return size;
}</pre>
</div>
</div>
</div>
<div id="method-i-to_i" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
to_i
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the integer memory location of this pointer.</p>
<div class="method-source-code" id="to_i-source">
<pre>static VALUE
rb_fiddle_ptr_to_i(VALUE self)
{
struct ptr_data *data;
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
return PTR2NUM(data->ptr);
}</pre>
</div>
</div>
</div>
<div id="method-i-to_int" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
to_i
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the integer memory location of this pointer.</p>
<div class="method-source-code" id="to_int-source">
<pre>static VALUE
rb_fiddle_ptr_to_i(VALUE self)
{
struct ptr_data *data;
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
return PTR2NUM(data->ptr);
}</pre>
</div>
</div>
</div>
<div id="method-i-to_s" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
to_s → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
to_s(len) → string
</span>
</div>
<div class="method-description">
<p>Returns the pointer contents as a string.</p>
<p>When called with no arguments, this method will return the contents until the first NULL byte.</p>
<p>When called with <code>len</code>, a string of <code>len</code> bytes will be returned.</p>
<p>See <a href="Pointer.html#method-i-to_str"><code>to_str</code></a></p>
<div class="method-source-code" id="to_s-source">
<pre>static VALUE
rb_fiddle_ptr_to_s(int argc, VALUE argv[], VALUE self)
{
struct ptr_data *data;
VALUE arg1, val;
int len;
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
switch (rb_scan_args(argc, argv, "01", &arg1)) {
case 0:
val = rb_str_new2((char*)(data->ptr));
break;
case 1:
len = NUM2INT(arg1);
val = rb_str_new((char*)(data->ptr), len);
break;
default:
rb_bug("rb_fiddle_ptr_to_s");
}
return val;
}</pre>
</div>
</div>
</div>
<div id="method-i-to_str" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
to_str → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
to_str(len) → string
</span>
</div>
<div class="method-description">
<p>Returns the pointer contents as a string.</p>
<p>When called with no arguments, this method will return the contents with the length of this pointer's <code>size</code>.</p>
<p>When called with <code>len</code>, a string of <code>len</code> bytes will be returned.</p>
<p>See <a href="Pointer.html#method-i-to_s"><code>to_s</code></a></p>
<div class="method-source-code" id="to_str-source">
<pre>static VALUE
rb_fiddle_ptr_to_str(int argc, VALUE argv[], VALUE self)
{
struct ptr_data *data;
VALUE arg1, val;
int len;
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
switch (rb_scan_args(argc, argv, "01", &arg1)) {
case 0:
val = rb_str_new((char*)(data->ptr),data->size);
break;
case 1:
len = NUM2INT(arg1);
val = rb_str_new((char*)(data->ptr), len);
break;
default:
rb_bug("rb_fiddle_ptr_to_str");
}
return val;
}</pre>
</div>
</div>
</div>
<div id="method-i-to_value" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
to_value
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Cast this pointer to a ruby object.</p>
<div class="method-source-code" id="to_value-source">
<pre>static VALUE
rb_fiddle_ptr_to_value(VALUE self)
{
struct ptr_data *data;
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
return (VALUE)(data->ptr);
}</pre>
</div>
</div>
</div>
</section>
</section>
</main>
<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.1.1.
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>