Correct documentation for SWIG_ConvertPtr() in the Ruby section of the

SWIG Manual.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4339 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Logan Johnson 2003-02-18 18:27:04 +00:00
commit 41d8ef047a

View file

@ -2156,13 +2156,16 @@ ways in which pointers can be represented, the following two functions are used
to safely perform this conversion: to safely perform this conversion:
<p> <p>
<tt>void * SWIG_ConvertPtr(VALUE obj, swig_type_info *ty)</tt> <tt>int SWIG_ConvertPtr(VALUE obj, void **ptr, swig_type_info *ty, int flags)</tt>
<blockquote> <blockquote>
Converts a Ruby object <i>obj</i> to a C pointer and returns the result. Converts a Ruby object <i>obj</i> to a C pointer whose address is <i>ptr</i>
The second argument, <i>ty</i>, is a pointer to a SWIG type descriptor structure. (i.e. <i>ptr</i> is a pointer to a pointer).
The third argument, <i>ty</i>, is a pointer to a SWIG type descriptor structure.
If <i>ty</i> is not <tt>NULL</tt>, that type information is used to validate If <i>ty</i> is not <tt>NULL</tt>, that type information is used to validate
type compatibility and other aspects of the type conversion, and any type type compatibility and other aspects of the type conversion. If <i>flags</i> is
errors result in a Ruby <tt>TypeError</tt> being raised. non-zero, any type errors encountered during this validation result in a Ruby
<tt>TypeError</tt> exception being raised; if <i>flags</i> is zero, such type errors will
cause <tt>SWIG_ConvertPtr()</tt> to return -1 but not raise an exception.
If <i>ty</i> is <tt>NULL</tt>, no type-checking is performed. If <i>ty</i> is <tt>NULL</tt>, no type-checking is performed.
</blockquote> </blockquote>
@ -2184,8 +2187,8 @@ descriptor structure is usually accessed as follows:
<blockquote> <blockquote>
<pre> <pre>
Foo *f; Foo *foo;
f = SWIG_ConvertPtr($input, SWIGTYPE_p_Foo); SWIG_ConvertPtr($input, (void **) &foo, SWIGTYPE_p_Foo, 1);
VALUE obj; VALUE obj;
obj = SWIG_NewPointerObj(f, SWIGTYPE_p_Foo, 0); obj = SWIG_NewPointerObj(f, SWIGTYPE_p_Foo, 0);
@ -2198,7 +2201,7 @@ typemap variable <tt>$1_descriptor</tt>. For example:
<blockquote> <blockquote>
<pre> <pre>
%typemap(in) Foo * { %typemap(in) Foo * {
$1 = SWIG_ConvertPtr($input, $1_descriptor); SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 1);
} }
</pre> </pre>
</blockquote> </blockquote>
@ -2209,18 +2212,18 @@ typemap variable <tt>$1_descriptor</tt>. For example:
<p> <p>
<tt>VALUE Data_Wrap_Struct(VALUE class, void (*mark)(void *), void (*free)(void *), void *ptr)</tt> <tt>VALUE Data_Wrap_Struct(VALUE class, void (*mark)(void *), void (*free)(void *), void *ptr)</tt>
<blockquote> <blockquote>
Given a pointer <i>ptr</i> to some C data, and the two garbage collection routines for this Given a pointer <i>ptr</i> to some C data, and the two garbage collection routines for this
data (<i>mark</i> and <i>free</i>), return a <tt>VALUE</tt> for the Ruby object. data (<i>mark</i> and <i>free</i>), return a <tt>VALUE</tt> for the Ruby object.
</blockquote> </blockquote>
<tt>VALUE Data_Make_Struct(VALUE class, <i>c-type</i>, void (*mark)(void *), void (*free)(void *), <i>c-type</i> *ptr)</tt> <tt>VALUE Data_Make_Struct(VALUE class, <i>c-type</i>, void (*mark)(void *), void (*free)(void *), <i>c-type</i> *ptr)</tt>
<blockquote> <blockquote>
Allocates a new instance of a C data type <i>c-type</i>, assigns it to the pointer <i>ptr</i>, then Allocates a new instance of a C data type <i>c-type</i>, assigns it to the pointer <i>ptr</i>, then
wraps that pointer with <tt>Data_Wrap_Struct()</tt> as above. wraps that pointer with <tt>Data_Wrap_Struct()</tt> as above.
</blockquote> </blockquote>
<tt>Data_Get_Struct(VALUE obj, <i>c-type</i>, <i>c-type</i> *ptr)</tt> <tt>Data_Get_Struct(VALUE obj, <i>c-type</i>, <i>c-type</i> *ptr)</tt>
<blockquote> <blockquote>
Retrieves the original C pointer of type <i>c-type</i> from the data object Retrieves the original C pointer of type <i>c-type</i> from the data object
<i>obj</i> and assigns that pointer to <i>ptr</i>. <i>obj</i> and assigns that pointer to <i>ptr</i>.
</blockquote> </blockquote>
<hr> <hr>