Some HTML error fixes

Long blockquote lines shortened


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6063 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2004-07-23 23:21:14 +00:00
commit 687cfbb625
17 changed files with 233 additions and 179 deletions

View file

@ -42,6 +42,7 @@
Scheme-to-C compiler supporting most of the language features as
defined in the <i>Revised^5 Report on Scheme</i>. Its main
attributes are that it
</p>
<ol>
<li>generates portable C code</li>
<li>includes a customizable interpreter</li>
@ -49,6 +50,7 @@
<li>supports full tail-recursion and first-class continuations</li>
</ol>
<p>
When confronted with a large C library, CHICKEN users can use
SWIG to generate CHICKEN wrappers for the C library. However,
the real advantages of using SWIG with CHICKEN are its
@ -68,7 +70,7 @@
present in releases of CHICKEN with version number
<strong>greater than or equal to <tt>1.40</tt></strong>.
<br></br> CHICKEN can be downloaded from <a
<br> CHICKEN can be downloaded from <a
href="http://www.call-with-current-continuation.org/">http://www.call-with-current-continuation.org/</a>
You may want to look at any of the examples in Examples/chicken/
@ -137,7 +139,7 @@
<tt>Foo-Bar->Foo-Baz</tt>. That is, an underscore is converted
to a dash and '_to_' is converted to an arrow.
<br></br>
<br>
Additionally, there is a <em>mixed</em> mode that can be
specified with the <tt>-mixed</tt> option on the SWIG command
@ -148,7 +150,7 @@
named <tt>someDeclaration_xyz</tt> will be available as the
CHICKEN identifier ending with <tt>some-declaration-xyz</tt>.
<br></br>
<br>
You may control what the CHICKEN identifier will be by using the
<tt>%rename</tt> SWIG directive in the SWIG interface file.
@ -162,6 +164,7 @@
(which has been deprecated); instead, it uses a prefix system.
Specifying the module name as 'example' in SWIG CHICKEN can be
done using either of:
</p>
<ul>
<li>Placing <tt>%module example</tt> in the SWIG interface
file.</li>
@ -169,10 +172,11 @@
line.</li>
</ul>
<p>
CHICKEN will be able to access the module using the <tt>(declare
(uses <i>modulename</i>))</tt> CHICKEN Scheme form.
<br></br>
<br>
Normally, for a C declaration <tt>Foo_Bar</tt> with a module
name of 'example', the corresponding CHICKEN identifier will be
@ -180,7 +184,7 @@
prefixed to the CHICKEN identifier</strong> (following normal
naming conventions).
<br></br>
<br>
You may explicitly override the prefix with the SWIG command
line option <tt>-prefix <i>whateverprefix</i></tt>, or you may
@ -194,6 +198,7 @@
<p>
Constants may be created using any of the four constructs in
the interface file:
</p>
<ol>
<li><code>#define MYCONSTANT1 ...</code></li>
<li><code>%constant int MYCONSTANT2 = ...</code></li>
@ -201,6 +206,7 @@
<li><code>enum { MYCONSTANT4 = ... };</code></li>
</ol>
<p>
In all cases, the constants may be accessed from with CHICKEN
using the form <tt>(MYCONSTANT1)</tt>; that is, the constants
may be accessed using the read-only parameter form.
@ -249,7 +255,7 @@
system. Please consult a Scheme book if you are unfamiliar
with the concept.
<br></br>
<br>
CHICKEN has a modified version of TinyCLOS, which SWIG CHICKEN
uses in C++ mode. SWIG CHICKEN generates a
@ -260,7 +266,7 @@
"xxx-clos")</tt> all the metaobject (class) macros your program
needs.
<br></br>
<br>
SWIG CHICKEN will call the destructor for all TinyCLOS objects
that are garbage-collected by CHICKEN. It also allows access to
@ -337,7 +343,7 @@
read from <code>Lib/chicken/typemaps.i</code> and
<code>Lib/chicken/chicken.swg</code>.
<br></br>
<br>
Two Chicken-specific typemaps are supported:
<code>clos_in</code> and <code>clos_out</code>. They are for
@ -373,7 +379,7 @@
are exposed in the SWIG interface file; it "fully knows" only
those classes that are not forward declarations.
<br></br>
<br>
A real-world example of the "fully knows" problem is found in
the VTK visualization library. All VTK classes are derived from

View file

@ -17,7 +17,7 @@ All Rights Reserved<br>
David M. Beazley<br>
Department of Computer Science <br>
University of Utah <br>
Salt Lake City, Utah 84112 </br>
Salt Lake City, Utah 84112 <br>
<tt>beazley@cs.utah.edu</tt>
<p>

View file

@ -361,8 +361,6 @@ $ <b>swig -c++ -python -dump_tags example.i</b>
. top . include . insert (/r0/beazley/Projects/lib/swig1.3/python/python.swg:7)
. top . include . insert (/r0/beazley/Projects/lib/swig1.3/python/python.swg:8)
. top . include . typemap (/r0/beazley/Projects/lib/swig1.3/python/python.swg:19)
. top . include . typemap . typemapitem (/r0/beazley/Projects/lib/swig1.3/python/python.swg:19)
. top . include . typemap . typemapitem (/r0/beazley/Projects/lib/swig1.3/python/python.swg:19)
...
. top . include (example.i:6)
. top . include . module (example.i:2)
@ -1312,7 +1310,7 @@ common to see small code fragments of code generated using code like this:
/* Print into a string */
String *s = NewString("");
Printf(s,"Hello\n");
for (i = 0; i < 10; i++) {
for (i = 0; i &lt; 10; i++) {
Printf(s,"%d\n", i);
}
...
@ -2155,7 +2153,7 @@ command line options, simply use code similar to this:
<blockquote>
<pre>
void Language::main(int argc, char *argv[]) {
for (int i = 1; i < argc; i++) {
for (int i = 1; i &lt; argc; i++) {
if (argv[i]) {
if(strcmp(argv[i],"-interface") == 0) {
if (argv[i+1]) {
@ -2293,8 +2291,8 @@ int Python::top(Node *n) {
return SWIG_OK;
}
</blockquote>
</pre>
</blockquote>
<a name="n37"></a><H3>26.10.6 Module I/O and wrapper skeleton</H3>
@ -2380,7 +2378,7 @@ might rely on it.<p>
Here is where you may also define an alias (but then you'll need to
kludge --- don't do this):<p>
<blockquote<tt>
<blockquote><tt>
skip-qux = $(skip-qux99)
</tt></blockquote><p>

View file

@ -48,8 +48,6 @@ This section details guile-specific support in SWIG.
<a name="n2"></a><H2>16.1 Meaning of "Module"</H2>
</a>
<p>
There are three different concepts of "module" involved, defined
separately for SWIG, Guile, and Libtool. To avoid horrible confusion,
@ -106,8 +104,6 @@ If that happens, there is A LOT less code duplication in the standard typemaps.<
<a name="n4"></a><H2>16.3 Linkage</H2>
</a>
<p>
Guile support is complicated by a lack of user community cohesiveness,
which manifests in multiple shared-library usage conventions. A set of
@ -307,8 +303,6 @@ module with code that is being wrapped. See the
<a name="n11"></a><H2>16.4 Underscore Folding</H2>
</a>
<p>
Underscores are converted to dashes in identifiers. Guile support may
grow an option to inhibit this folding in the future, but no one has
@ -321,8 +315,6 @@ functions and variables (see CHANGES).
<a name="n12"></a><H2>16.5 Typemaps</H2>
</a>
<p>
The Guile module handles all types via typemaps. This
information is read from <code>Lib/guile/typemaps.i</code>.
@ -455,8 +447,6 @@ the guile module replaces $owner with 0 or 1 depending on feature:new.</p>
<a name="n17"></a><H2>16.7 Exception Handling</H2>
</a>
<p>
SWIG code calls <code>scm_error</code> on exception, using the following
mapping:
@ -481,8 +471,6 @@ See Lib/exception.i for details.
<a name="n18"></a><H2>16.8 Procedure documentation</H2>
</a>
<p>If invoked with the command-line option <code>-procdoc
<var>file</var></code>, SWIG creates documentation strings for the
generated wrapper functions, describing the procedure signature and
@ -516,8 +504,6 @@ details.
<a name="n19"></a><H2>16.9 Procedures with setters</H2>
</a>
<p>For global variables, SWIG creates a single wrapper procedure
<code>(<var>variable</var> :optional value)</code>, which is used for
both getting and setting the value. For struct members, SWIG creates
@ -746,7 +732,8 @@ into the GOOPS guile-module. So if <i>Module-primitive.scm</i> is on the autolo
<code>%goops</code> directive can be empty. Otherwise, the <code>%goops</code> directive should contain
whatever code is needed to load the <i>Module-primitive.scm</i> file into guile.</li>
<blockquote><pre>%scheme %{ (load-extension "./foo.so" "scm_init_my_modules_foo_module") %}
// only include the following definition if (my modules foo) can not be loaded automatically
// only include the following definition if (my modules foo) cannot
// be loaded automatically
%goops %{
(primitive-load "/path/to/foo-primitive.scm")
(primitive-load "/path/to/Swig/common.scm")
@ -760,7 +747,8 @@ Produces the following code at the top of the generated GOOPS guile-module
(primitive-load "/path/to/Swig/common.scm")
(use-modules (oop goops) (Swig common))
(use-modules ((my modules foo-primitive) :renamer (symbol-prefix-proc 'primitive:)))
(use-modules ((my modules foo-primitive) :renamer (symbol-prefix-proc
'primitive:)))
</pre></blockquote>
@ -777,7 +765,8 @@ Produces the following code at the top of the generated GOOPS guile-module
(load-extension "./foo.so" "scm_init_my_modules_foo_module")
(use-modules (oop goops) (Swig common))
(use-modules ((my modules foo-primitive) :renamer (symbol-prefix-proc 'primitive:)))
(use-modules ((my modules foo-primitive) :renamer (symbol-prefix-proc
'primitive:)))
</pre></blockquote>
</ul>

View file

@ -364,7 +364,8 @@ The following exception is indicative of this:
<blockquote><pre>
$ java main
Exception in thread "main" java.lang.UnsatisfiedLinkError: libexample.so: undefined symbol: fact
Exception in thread "main" java.lang.UnsatisfiedLinkError: libexample.so: undefined
symbol: fact
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java, Compiled Code)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java, Compiled Code)
@ -398,7 +399,8 @@ compiler. For example:
<p>
<blockquote><pre>% swig -c++ -java example.i
% g++ -c -fpic example.cxx
% g++ -c -fpic example_wrap.cxx -I/usr/java/j2sdk1.4.1/include -I/usr/java/j2sdk1.4.1/include/linux
% g++ -c -fpic example_wrap.cxx -I/usr/java/j2sdk1.4.1/include -I/usr/java/
j2sdk1.4.1/include/linux
% g++ -shared example.o example_wrap.o -o libexample.so
</pre></blockquote>
@ -560,7 +562,7 @@ Details of all these generated classes will unfold as you read this section.
<p>
The JNI (C/C++) code is generated into a file which also contains the module name, for example <tt>example_wrap.cxx</tt>
or </tt>example_wrap.c</tt>. These C or C++ files complete the contents of the module.
or <tt>example_wrap.c</tt>. These C or C++ files complete the contents of the module.
<p>
The generated Java classes can be placed into a Java package by using the <tt>-package</tt> commandline option.
@ -1514,7 +1516,8 @@ If declarations such as these appear, you will get a warning message like this:
<blockquote>
<pre>
example.i:12: Warning(515): Overloaded method spam(unsigned short) ignored. Method spam(int) at example.i:11 used.
example.i:12: Warning(515): Overloaded method spam(unsigned short) ignored.
Method spam(int) at example.i:11 used.
</pre>
</blockquote>
@ -1774,10 +1777,14 @@ JNI functions. The JNI functions have to follow a particular naming convention s
<blockquote>
<pre>
JNIEXPORT jlong JNICALL Java_exampleJNI_new_1Foo(JNIEnv *jenv, jclass jcls);
JNIEXPORT void JNICALL Java_exampleJNI_delete_1Foo(JNIEnv *jenv, jclass jcls, jlong jarg1);
JNIEXPORT void JNICALL Java_exampleJNI_set_1Foo_1x(JNIEnv *jenv, jclass jcls, jlong jarg1, jint jarg2);
JNIEXPORT jint JNICALL Java_exampleJNI_get_1Foo_1x(JNIEnv *jenv, jclass jcls, jlong jarg1);
JNIEXPORT jint JNICALL Java_exampleJNI_Foo_1spam(JNIEnv *jenv, jclass jcls, jlong jarg1, jint jarg2, jlong jarg3);
JNIEXPORT void JNICALL Java_exampleJNI_delete_1Foo(JNIEnv *jenv, jclass jcls,
jlong jarg1);
JNIEXPORT void JNICALL Java_exampleJNI_set_1Foo_1x(JNIEnv *jenv, jclass jcls,
jlong jarg1, jint jarg2);
JNIEXPORT jint JNICALL Java_exampleJNI_get_1Foo_1x(JNIEnv *jenv, jclass jcls,
jlong jarg1);
JNIEXPORT jint JNICALL Java_exampleJNI_Foo_1spam(JNIEnv *jenv, jclass jcls,
jlong jarg1, jint jarg2, jlong jarg3);
JNIEXPORT void JNICALL Java_exampleJNI_egg(JNIEnv *jenv, jclass jcls, jlong jarg1);
</pre>
</blockquote>
@ -1857,7 +1864,8 @@ The pragma code appears in the generated intermediary JNI class where you would
<blockquote>
<pre>
[ jniclassimports pragma ]
[ jniclassmodifiers pragma ] jniclassname extends [ jniclassbase pragma ] implements [ jniclassinterfaces pragma ] {
[ jniclassmodifiers pragma ] jniclassname extends [ jniclassbase pragma ]
implements [ jniclassinterfaces pragma ] {
[ jniclasscode pragma ]
... SWIG generated native methods ...
}
@ -1955,7 +1963,8 @@ The pragma code appears in the generated module class like this:
<blockquote>
<pre>
[ moduleimports pragma ]
[ modulemodifiers pragma ] modulename extends [ modulebase pragma ] implements [ moduleinterfaces pragma ] {
[ modulemodifiers pragma ] modulename extends [ modulebase pragma ]
implements [ moduleinterfaces pragma ] {
[ modulecode pragma ]
... SWIG generated wrapper functions ...
}
@ -1992,7 +2001,7 @@ public class Foo {
}
public void delete() {
if(swigCPtr != 0 && swigCMemOwn) {
if(swigCPtr != 0 &amp;&amp; swigCMemOwn) {
exampleJNI.delete_Foo(swigCPtr);
swigCMemOwn = false;
}
@ -2173,7 +2182,7 @@ Obj obj = Factory.createObj(); // obj.swigCMemOwn = true;
<a name="n42"></a><H4>17.4.3.2 Inheritance</H4>
Java proxy classes will mirror C++ inheritance chains. For example, given the base class <tt>Base</tt> and its derived class </tt>Derived</tt>:
Java proxy classes will mirror C++ inheritance chains. For example, given the base class <tt>Base</tt> and its derived class <tt>Derived</tt>:
<blockquote><pre>
class Base {
@ -2208,7 +2217,7 @@ public class Base {
}
public void delete() {
if(swigCPtr != 0 && swigCMemOwn) {
if(swigCPtr != 0 &amp;&amp; swigCMemOwn) {
exampleJNI.delete_Base(swigCPtr);
swigCMemOwn = false;
}
@ -2245,7 +2254,7 @@ public class Derived extends Base {
}
public void delete() {
if(swigCPtr != 0 && swigCMemOwn) {
if(swigCPtr != 0 &amp;&amp; swigCMemOwn) {
exampleJNI.delete_Derived(swigCPtr);
swigCMemOwn = false;
}
@ -2399,7 +2408,9 @@ The Java function generated is:
<blockquote>
<pre>
public static void spam(SWIGTYPE_p_Snazzy x, SWIGTYPE_p_Snazzy y, SWIGTYPE_p_Snazzy z) { ... }
public static void spam(SWIGTYPE_p_Snazzy x, SWIGTYPE_p_Snazzy y, SWIGTYPE_p_Snazzy z) {
...
}
</pre>
</blockquote>
@ -2463,12 +2474,13 @@ public final class Beverage {
}
public static Beverage swigToEnum(int swigValue) {
if (swigValue < swigValues.length && swigValues[swigValue].swigValue == swigValue)
if (swigValue &lt; swigValues.length &amp;&amp; swigValues[swigValue].swigValue == swigValue)
return swigValues[swigValue];
for (int i = 0; i < swigValues.length; i++)
for (int i = 0; i &lt; swigValues.length; i++)
if (swigValues[i].swigValue == swigValue)
return swigValues[i];
throw new IllegalArgumentException("No enum " + Beverage.class + " with value " + swigValue);
throw new IllegalArgumentException("No enum " + Beverage.class + " with value " +
swigValue);
}
private Beverage(String swigName) {
@ -2528,12 +2540,13 @@ public enum Beverage {
public static Beverage swigToEnum(int swigValue) {
Beverage[] swigValues = Beverage.class.getEnumConstants();
if (swigValue < swigValues.length && swigValues[swigValue].swigValue == swigValue)
if (swigValue &lt; swigValues.length &amp;&amp; swigValues[swigValue].swigValue == swigValue)
return swigValues[swigValue];
for (Beverage swigEnum : swigValues)
if (swigEnum.swigValue == swigValue)
return swigEnum;
throw new IllegalArgumentException("No enum " + Beverage.class + " with value " + swigValue);
throw new IllegalArgumentException("No enum " + Beverage.class +
" with value " + swigValue);
}
private Beverage() {
@ -2741,7 +2754,6 @@ void callup(DirectorBase *director) {
The following <code>directorDerived</code> Java class is derived from the Java proxy class <code>DirectorBase</code> and overrides <code>upcall_method()</code>.
When C++ code invokes <code>upcall_method()</code>, the SWIG-generated C++ code redirects the call via JNI to the Java <code>directorDerived</code> subclass.
Naturally, the SWIG generated C++ code and the generated Java intermediate class marshall and convert arguments between C++ and Java when needed.
</p>
<blockquote>
<pre>
@ -3484,7 +3496,7 @@ The following table lists the default type mapping from Java to C/C++.<p>
</tr>
<tr>
<td>bool<br> const bool & </td>
<td>bool<br> const bool &amp; </td>
<td>boolean</td>
<td>jboolean</td>
</tr>
@ -3583,19 +3595,21 @@ Also note that all const references to primitive types are treated as if they ar
Given the following C function:
<blockquote> <pre>
void func(unsigned short a, char *b, const long &c, unsigned long long d);
</blockquote> </pre>
</pre> </blockquote>
The module class method would be:
<blockquote> <pre>
public static void func(int a, String b, int c, java.math.BigInteger d) {...}
</blockquote> </pre>
</pre> </blockquote>
The intermediary JNI class would use the same types:
<blockquote> <pre>
public final static native void func(int jarg1, String jarg2, int jarg3, java.math.BigInteger jarg4);
</blockquote> </pre>
public final static native void func(int jarg1, String jarg2, int jarg3,
java.math.BigInteger jarg4);
</pre> </blockquote>
and the JNI function would look like this:
<blockquote> <pre>
JNIEXPORT void JNICALL Java_exampleJNI_func(JNIEnv *jenv, jclass jcls, jint jarg1, jstring jarg2, jint jarg3, jobject jarg4) {...}
</blockquote> </pre>
JNIEXPORT void JNICALL Java_exampleJNI_func(JNIEnv *jenv, jclass jcls,
jint jarg1, jstring jarg2, jint jarg3, jobject jarg4) {...}
</pre> </blockquote>
<p>
The mappings for C <tt>int</tt> and C <tt>long</tt> are appropriate for 32 bit applications which are used in the 32 bit JVMs.
@ -3793,7 +3807,7 @@ The most important of these implement the mapping of C/C++ types to Java types:
<p>
If you are writing your own typemaps to handle a particular type, you will normally have to write a collection of them.
The default typemaps are in "<tt>java.swg</tt>" and so might be a good place for finding typemaps to base any new ones on.</li>
The default typemaps are in "<tt>java.swg</tt>" and so might be a good place for finding typemaps to base any new ones on.
<p>
The "jni", "jtype" and "jstype" typemaps are usually defined together to handle the Java to C/C++ type mapping.
@ -4158,7 +4172,8 @@ In summary the contents of the typemaps make up a proxy class like this:
<blockquote>
<pre>
[ javaimports typemap ]
[ javaclassmodifiers typemap ] javaclassname extends [ javabase typemap ] implements [ javainterfaces typemap ] {
[ javaclassmodifiers typemap ] javaclassname extends [ javabase typemap ]
implements [ javainterfaces typemap ] {
[ javabody or javabody_derived typemap ]
[ javafinalize typemap ]
public void <i>delete</i>() [ javadestruct OR javadestruct_derived typemap ]
@ -4176,7 +4191,8 @@ The type wrapper class is similar in construction:
<blockquote>
<pre>
[ javaimports typemap ]
[ javaclassmodifiers typemap ] javaclassname extends [ javabase typemap ] implements [ javainterfaces typemap ] {
[ javaclassmodifiers typemap ] javaclassname extends [ javabase typemap ]
implements [ javainterfaces typemap ] {
[ javabody typemap ]
[ javacode typemap ]
}
@ -4187,7 +4203,8 @@ The enum class is also similar in construction:
<blockquote>
<pre>
[ javaimports typemap ]
[ javaclassmodifiers typemap ] javaclassname extends [ javabase typemap ] implements [ javainterfaces typemap ] {
[ javaclassmodifiers typemap ] javaclassname extends [ javabase typemap ]
implements [ javainterfaces typemap ] {
... Enum values ...
[ javabody typemap ]
[ javacode typemap ]
@ -4391,7 +4408,8 @@ Practically speaking, you should create a separate SWIG interface file, which is
<blockquote>
<pre>
%typemap("javapackage") SWIGTYPE, SWIGTYPE *, SWIGTYPE &amp; "package.for.most.classes";
%typemap("javapackage") SWIGTYPE, SWIGTYPE *, SWIGTYPE &amp;
"package.for.most.classes";
%typemap("javapackage") Package_2_class_one "package.for.other.classes";
%typemap("javapackage") Package_3_class_two "package.for.another.set";
@ -4400,7 +4418,6 @@ Practically speaking, you should create a separate SWIG interface file, which is
</blockquote>
The basic strategy here is to provide a default package typemap for the majority of the classes, only providing "javapackage" typemaps for the exceptions.
</p>
</blockquote>
@ -4498,7 +4515,7 @@ Let's consider a simple file class <tt>SimpleFile</tt> and an exception class <t
class FileException {
std::string message;
public:
FileException(const std::string& msg) : message(msg) {}
FileException(const std::string&amp; msg) : message(msg) {}
std::string what() {
return message;
}
@ -4507,7 +4524,7 @@ public:
class SimpleFile {
std::string filename;
public:
SimpleFile(const std::string& filename) : filename(filename) {}
SimpleFile(const std::string&amp; filename) : filename(filename) {}
void open() throw(FileException) {
...
}
@ -4522,7 +4539,8 @@ The default generic "throws" typemap looks like this:
<blockquote>
<pre>
%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [ANY] %{
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "C++ $1_type exception thrown");
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException,
"C++ $1_type exception thrown");
return $null;
%}
</pre>
@ -4616,7 +4634,8 @@ To validate every <tt>float</tt> being passed to C++, we could preceed the code
%module example
%typemap(javain) float "$module.CheckForNaN($javainput)"
%pragma(java) modulecode=%{
/** Simply returns the input value unless it is not a number, whereupon an exception is thrown. */
/** Simply returns the input value unless it is not a number,
whereupon an exception is thrown. */
static protected float CheckForNaN(float num) {
if (Float.isNaN(num))
throw new RuntimeException("Not a number");
@ -4634,7 +4653,8 @@ The following shows the generated code of interest:
public class example {
...
/** Simply returns the input value unless it is not a number, whereupon an exception is thrown. */
/** Simply returns the input value unless it is not a number,
whereupon an exception is thrown. */
static protected float CheckForNaN(float num) {
if (Float.isNaN(num))
throw new RuntimeException("Not a number");
@ -4659,7 +4679,8 @@ Thus we can modify the pragma and the typemap for the throws clause:
<pre>
%typemap(javain, throws="java.lang.Exception") float "$module.CheckForNaN($javainput)"
%pragma(java) modulecode=%{
/** Simply returns the input value unless it is not a number, whereupon an exception is thrown. */
/** Simply returns the input value unless it is not a number,
whereupon an exception is thrown. */
static protected float CheckForNaN(float num) throws java.lang.Exception {
if (Float.isNaN(num))
throw new RuntimeException("Not a number");
@ -4677,7 +4698,8 @@ the throws clause contains a single instance of <tt>java.lang.Exception</tt>:
public class example {
...
/** Simply returns the input value unless it is not a number, whereupon an exception is thrown. */
/** Simply returns the input value unless it is not a number,
whereupon an exception is thrown. */
static protected float CheckForNaN(float num) throws java.lang.Exception {
if (Float.isNaN(num))
throw new RuntimeException("Not a number");
@ -4704,7 +4726,8 @@ The following SWIG interface file allows a Java String array to be used as a <tt
<blockquote><pre>
%module example
/* This tells SWIG to treat char ** as a special case when used as a parameter in a function call */
/* This tells SWIG to treat char ** as a special case when used as a parameter
in a function call */
%typemap(in) char ** (jint size) {
int i = 0;
size = (*jenv)-&gt;GetArrayLength(jenv, $input);
@ -4752,7 +4775,8 @@ The following SWIG interface file allows a Java String array to be used as a <tt
%typemap(jtype) char ** "String[]"
%typemap(jstype) char ** "String[]"
/* These 2 typemaps handle the conversion of the jtype to jstype typemap type and visa versa */
/* These 2 typemaps handle the conversion of the jtype to jstype typemap type
and visa versa */
%typemap(javain) char ** "$javainput"
%typemap(javaout) char ** {
return $jnicall;
@ -5025,10 +5049,10 @@ class Ambulance : public Vehicle {
public:
Ambulance(string volume) : vol(volume) {}
virtual void start() {
cout << "Ambulance started" << endl;
cout &lt;&lt; "Ambulance started" &lt;&lt; endl;
}
void sound_siren() {
cout << vol << " siren sounded!" << endl;
cout &lt;&lt; vol &lt;&lt; " siren sounded!" &lt;&lt; endl;
}
...
};
@ -5111,10 +5135,10 @@ class FireEngine : public Vehicle {
public:
FireEngine() {}
virtual void start() {
cout << "FireEngine started" << endl;
cout &lt;&lt; "FireEngine started" &lt;&lt; endl;
}
void roll_out_hose() {
cout << "Hose rolled out" << endl;
cout &lt;&lt; "Hose rolled out" &lt;&lt; endl;
}
...
};
@ -5173,11 +5197,11 @@ Note that in this case, the Java class is constructed using JNI code rather than
}
}
else {
cout << "Unexpected type " << endl;
cout &lt;&lt; "Unexpected type " &lt;&lt; endl;
}
if (!$result)
cout << "Failed to create new java object" << endl;
cout &lt;&lt; "Failed to create new java object" &lt;&lt; endl;
}
</pre></blockquote>
@ -5304,7 +5328,6 @@ This example contains some useful functionality which you may want in your code.
%template(VectorOfInt) std::vector<int>;
</pre>
</blockquote>
</p>
<li><i>When I pass class pointers or references through a C++ upcall and I
try to type cast them, Java complains with a ClassCastException. What am I
@ -5328,7 +5351,8 @@ public static void MyClass_method_upcall(MyClass self, long jarg1)
<blockquote>
<pre>
public static void MyClass_method_upcall(MyClass self, long jarg1, Foo jarg1_object)
public static void MyClass_method_upcall(MyClass self, long jarg1,
Foo jarg1_object)
{
Foo darg1 = (jarg1_object != null ? jarg1_object : new Foo(jarg1, false));
@ -5337,6 +5361,7 @@ public static void MyClass_method_upcall(MyClass self, long jarg1, Foo jarg1_obj
</pre>
</blockquote>
<p>
When you import a SWIG interface file containing class definitions, the classes you want to be director-enabled must be have the <code>feature("director")</code> enabled for type symmetry to work.
This applies even when the class being wrapped isn't a director-enabled class but takes parameters that are director-enabled classes.
</p>
@ -5362,7 +5387,8 @@ public static void MyClass_method_upcall(MyClass self, long jarg1, Foo jarg1_obj
public class MyClassDerived {
public void method_upcall(Foo foo_object)
{
FooDerived derived = (foo_object != null ? (FooDerived) Foo.downcastFoo(foo_object) : null);
FooDerived derived = (foo_object != null ?
(FooDerived) Foo.downcastFoo(foo_object) : null);
/* rest of your code here */
}
}
@ -5437,7 +5463,6 @@ public abstract class UserVisibleFoo extends Foo {
</pre>
</blockquote>
This doesn't prevent the user from creating subclasses derived from Foo, however, UserVisibleFoo provides the safety net that reminds the user to override the <code>method_upcall()</code> method.
</p>
</ol>
<a name="odds_ends"></a>
@ -5562,7 +5587,8 @@ For example:
<blockquote><pre>
%native (HandRolled) void HandRolled(int, char *);
%{
JNIEXPORT void JNICALL Java_packageName_moduleName_HandRolled(JNIEnv *, jclass, jlong, jstring);
JNIEXPORT void JNICALL Java_packageName_moduleName_HandRolled(JNIEnv *, jclass,
jlong, jstring);
%}
</pre></blockquote>

View file

@ -174,8 +174,9 @@ struct name {
~name(); // Delete pointer object
void assign(type value); // Assign value
type value(); // Get value
type *cast(); // Cast the pointer to original type.
static name *frompointer(type *); // Create class wrapper from existing pointer
type *cast(); // Cast the pointer to original type
static name *frompointer(type *); // Create class wrapper from existing
// pointer
};
</pre>
</blockquote>
@ -300,7 +301,7 @@ function like this:
<pre>
void print_array(double x[10]) {
int i;
for (i = 0; i < 10; i++) {
for (i = 0; i &lt; 10; i++) {
printf("[%d] = %g\n", i, x[i]);
}
}
@ -347,7 +348,8 @@ struct name {
type getitem(int index); // Return item
void setitem(index, type value); // Set item
type *cast(); // Cast to original type
static name *frompointer(type *); // Create class wrapper from existing pointer
static name *frompointer(type *); // Create class wrapper from
// existing pointer
};
</pre>
</blockquote>
@ -554,7 +556,8 @@ Python example:
... a[i] = i
>>> b = cdata(a,40)
>>> b
'\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\t'
'\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04
\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\t'
>>> c = intArray(10)
>>> memmove(c,b)
>>> print c[4]
@ -1184,14 +1187,14 @@ double average(std::vector&lt;int> v) {
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
}
std::vector&lt;double> half(const std::vector&lt;double>& v) {
std::vector&lt;double> half(const std::vector&lt;double>&amp; v) {
std::vector&lt;double> w(v);
for (unsigned int i=0; i&lt;w.size(); i++)
w[i] /= 2.0;
return w;
}
void halve_in_place(std::vector&lt;double>& v) {
void halve_in_place(std::vector&lt;double>&amp; v) {
std::transform(v.begin(),v.end(),v.begin(),
std::bind2nd(std::divides&lt;double>(),2.0));
}
@ -1332,7 +1335,7 @@ For example:
%exception std::vector::getitem {
try {
$action
} catch (std::out_of_range& e) {
} catch (std::out_of_range&amp; e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}

View file

@ -438,7 +438,6 @@ There's also no support for
<tt>%exception</tt></a>, yet.
</li>
</ul>
</p>
<p>
Be warned:
@ -602,6 +601,7 @@ i.e. functions that convert values between C and Modula-3
and call the corresponding C function.
Modula-3 wrapper functions generated by SWIG
consist of the following parts:
</p>
<ul>
<li>Generate <tt>PROCEDURE</tt> signature.</li>
<li>Declare local variables.</li>
@ -613,7 +613,6 @@ consist of the following parts:
<li>Free temporary storage.</li>
<li>Return values.</li>
</ul>
</p>
<table border>
<tr>
@ -799,12 +798,12 @@ for the typemap library
.
For a monolithic module you might be better off
if you add the imports directly:
</p>
<pre>
%insert(m3rawintf) %{
IMPORT M3toC;
%}
</pre>
</p>
<a name="exceptions"></a>

View file

@ -172,7 +172,7 @@ a '+= b</td>
<tr><th colspan=2>Note that because camlp4 always recognizes &lt;&lt;
and &gt;&gt;, they are replaced by lsl and lsr in operator names.
<tr><td>
<i>'unop</i> object as in</br>
<i>'unop</i> object as in<br>
'! a
</td><td>
(invoke a) "!" C_void</td></tr>
@ -474,7 +474,7 @@ into this type of function convenient.
void printfloats( float *tab, int len ) {
int i;
for( i = 0; i < len; i++ ) {
for( i = 0; i &lt; len; i++ ) {
printf( "%f ", tab[i] );
}
@ -487,7 +487,7 @@ void printfloats( float *tab, int len ) {
/* $*1_type */
$2 = caml_array_len($input);
$1 = ($*1_type *)malloc( $2 * sizeof( float ) );
for( i = 0; i < $2; i++ ) {
for( i = 0; i &lt; $2; i++ ) {
$1[i] = caml_double_val(caml_array_nth($input,i));
}
}

View file

@ -285,7 +285,9 @@ A common error received by first-time users is the following:
<blockquote>
<pre>
use example;
Can't locate example.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005 .) at - line 1.
Can't locate example.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-lin
ux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/pe
rl5/site_perl/5.005 .) at - line 1.
BEGIN failed--compilation aborted at - line 1.
</pre>
</blockquote>
@ -446,7 +448,8 @@ it needs to be. So you should compile the wrapper like:
</pre></blockquote>
So you could also compile the wrapper like
<blockquote><pre>
% g++ -c example_wrap.cxx -I/usr/lib/perl/5.8.0/CORE `perl -e 'use Config; print $Config{ccflags}'`
% g++ -c example_wrap.cxx -I/usr/lib/perl/5.8.0/CORE \
`perl -e 'use Config; print $Config{ccflags}'`
</pre></blockquote>
<p>
@ -1975,7 +1978,7 @@ To make the member writable, a "memberin" typemap can be used.
<p>
<blockquote><pre>%typemap(memberin) int [SIZE] {
int i;
for (i = 0; i < SIZE; i++) {
for (i = 0; i &lt; SIZE; i++) {
$1[i] = $input[i];
}
}
@ -1992,7 +1995,7 @@ For example:
<blockquote><pre>%typemap(memberin) int [ANY] {
int i;
for (i = 0; i < $1_dim0; i++) {
for (i = 0; i &lt; $1_dim0; i++) {
$1[i] = $input[i];
}
}
@ -2091,7 +2094,7 @@ void *SWIG_MakePtr(SV *obj, void *ptr, swig_type_info *ty, int flags)</tt>
<blockquote>
Creates a new Perl pointer object. <tt>obj</tt> is a Perl SV that has been initialized to hold the result,
<tt>ptr</tt is the pointer to convert, <tt>ty</tt> is the SWIG type descriptor structure that
<tt>ptr</tt> is the pointer to convert, <tt>ty</tt> is the SWIG type descriptor structure that
describes the type, and <tt>flags</tt> is a flag that controls properties of the conversion. <tt>flags</tt> is currently undefined
and reserved.
@ -2167,7 +2170,7 @@ you provided with the <tt>%module</tt> directive. Then, in place of the origina
SWIG creates a collection of high-level Perl wrappers. In your scripts, you will use these
high level wrappers. The wrappers, in turn, interact with the low-level procedural module.
<h3>Structure and class wrappers</h2>
<h3>Structure and class wrappers</h3>
Suppose you have the following SWIG interface file :<p>

View file

@ -194,7 +194,7 @@ dl("example.so");
print $seki;
$seki = $seki * 2; # Does not affect C variable, still equal to 2
example_func(); # Syncs C variable to PHP Variable, now both 4
<pre></blockquote>
</pre></blockquote>
SWIG supports global variables of all C datatypes including pointers and complex
objects.<p>
@ -334,8 +334,6 @@ So, in the example above, the TEST constant was declared first, and will be stor
they were declared non-case sensitive, the output would be 'Hello Hello', as
both point to the same value, without the case test taking place.
( Apologies, this paragraph needs rewritting to make some sense. )
</pre>
</blockquote>
<a name="n11"></a><H3>21.2.8 Shadow classes</H3>

View file

@ -1180,8 +1180,6 @@ they are accessed through <tt>cvar</tt> like this:
</pre>
</blockquote>
</pre></blockquote>
<a name="n21"></a><H3>22.3.8 C++ inheritance</H3>
@ -1342,7 +1340,8 @@ If declarations such as these appear, you will get a warning message like this:
<blockquote>
<pre>
example.i:12: Warning(509): Overloaded spam(short) is shadowed by spam(int) at example.i:11.
example.i:12: Warning(509): Overloaded spam(short) is shadowed by spam(int)
at example.i:11.
</pre>
</blockquote>
@ -2811,7 +2810,7 @@ Sometimes a C function expects an array to be passed as a pointer. For example,
<pre>
int sumitems(int *first, int nitems) {
int i, sum = 0;
for (i = 0; i < nitems; i++) {
for (i = 0; i &lt; nitems; i++) {
sum += first[i];
}
return sum;
@ -2977,7 +2976,7 @@ You can refine this by supplying an optional parameter name. For example:
%typemap(in) int nonnegative {
$1 = (int) PyLong_AsLong($input);
if ($1 < 0) {
if ($1 &lt; 0) {
PyErr_SetString(PyExc_ValueError,"Expected a nonnegative value.");
return NULL;
}
@ -3501,7 +3500,7 @@ arrays of different sizes. To do this, you might write a typemap as follows:
PyErr_SetString(PyExc_ValueError,"Expecting a sequence with $1_dim0 elements");
return NULL;
}
for (i =0; i < $1_dim0; i++) {
for (i =0; i &lt; $1_dim0; i++) {
PyObject *o = PySequence_GetItem($input,i);
if (!PyFloat_Check(o)) {
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of floats");
@ -3541,7 +3540,7 @@ static int convert_darray(PyObject *input, double *ptr, int size) {
PyErr_SetString(PyExc_ValueError,"Sequence size mismatch");
return 0;
}
for (i =0; i < size; i++) {
for (i =0; i &lt; size; i++) {
PyObject *o = PySequence_GetItem(input,i);
if (!PyFloat_Check(o)) {
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of floats");
@ -3604,7 +3603,8 @@ is usually accessed as follows:
<blockquote>
<pre>
Foo *f;
if (SWIG_ConvertPtr($input, (void **) &f, SWIGTYPE_p_Foo, SWIG_POINTER_EXCEPTION) == -1) return NULL;
if (SWIG_ConvertPtr($input, (void **) &f, SWIGTYPE_p_Foo, SWIG_POINTER_EXCEPTION) == -1)
return NULL;
PyObject *obj;
obj = SWIG_NewPointerObj(f, SWIGTYPE_p_Foo, 0);
@ -3617,7 +3617,8 @@ variable <tt>$1_descriptor</tt>. For example:
<blockquote>
<pre>
%typemap(in) Foo * {
if ((SWIG_ConvertPtr($input,(void **) &$1, $1_descriptor,SWIG_POINTER_EXCEPTION)) == -1) return NULL;
if ((SWIG_ConvertPtr($input,(void **) &$1, $1_descriptor,SWIG_POINTER_EXCEPTION)) == -1)
return NULL;
}
</pre>
</blockquote>
@ -3629,7 +3630,8 @@ For example:
<blockquote>
<pre>
%typemap(in) Foo * {
if ((SWIG_ConvertPtr($input,(void **) &$1, $descriptor(Foo *), SWIG_POINTER_EXCEPTION)) == -1) return NULL;
if ((SWIG_ConvertPtr($input,(void **) &$1, $descriptor(Foo *), SWIG_POINTER_EXCEPTION)) == -1)
return NULL;
}
</pre>
</blockquote>

View file

@ -767,7 +767,10 @@ the <em>is_a?</em> relationship would fail). When SWIG processes this
interface file,
you'll see a warning message like:
<blockquote>
<pre>example.i:5: Warning(802): Warning for Derived: Base Base2 ignored. Multiple inheritance is not supported in Ruby.<br></pre>
<pre>
example.i:5: Warning(802): Warning for Derived: Base Base2 ignored.
Multiple inheritance is not supported in Ruby.
</pre>
</blockquote>
Starting with SWIG 1.3.20, the Ruby module for SWIG provides limited
support
@ -854,7 +857,10 @@ or
If declarations such as these appear, you will get a warning message
like this:
<blockquote>
<pre>example.i:12: Warning(509): Overloaded spam(short) is shadowed by spam(int) at example.i:11.<br></pre>
<pre>
example.i:12: Warning(509): Overloaded spam(short) is shadowed by spam(int)
at example.i:11.
</pre>
</blockquote>
To fix this, you either need to ignore or rename one of the methods.
For example:
@ -1603,7 +1609,10 @@ somehow extracts the last three arguments (<i>nattributes</i>, <i>names</i>
and
<i>values</i>) needed by your C function. Let's start with the basics:
<blockquote>
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br>}<br></pre>
<pre>
%typemap(in) (int nattributes, const char **names, const int *values)
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br>}
</pre>
</blockquote>
This <tt>%typemap</tt> directive tells SWIG that we want to match any
function declaration that
@ -1622,7 +1631,9 @@ and <i>val</i>) define local variables that our typemap will need.
next add a check for that:
</p>
<blockquote>
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br> <b>Check_Type($input, T_HASH);</b>
<pre>
%typemap(in) (int nattributes, const char **names, const int *values)
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br> <b>Check_Type($input, T_HASH);</b>
}
</pre>
</blockquote>
@ -1640,7 +1651,9 @@ get around that by calling the hash's <i>size</i> method directly and
converting its result
to a C <tt>int</tt> value: </p>
<blockquote>
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> <b>$1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));</b>
<pre>
%typemap(in) (int nattributes, const char **names, const int *values)
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> <b>$1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));</b>
}
</pre>
</blockquote>
@ -1650,7 +1663,9 @@ third typemap arguments (i.e. the two C arrays) to <tt>NULL</tt> and
set the stage
for extracting the keys and values from the hash:
<blockquote>
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> <b>$2 = NULL;<br> $3 = NULL;<br> if ($1 &gt; 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> }</b>
<pre>
%typemap(in) (int nattributes, const char **names, const int *values)
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> <b>$2 = NULL;<br> $3 = NULL;<br> if ($1 &gt; 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> }</b>
}
</pre>
</blockquote>
@ -1662,7 +1677,9 @@ method
the elements
in that array:
<blockquote>
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 &gt; 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> <b>keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i &lt; $1; i++) {<br> }</b>
<pre>
%typemap(in) (int nattributes, const char **names, const int *values)
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 &gt; 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> <b>keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i &lt; $1; i++) {<br> }</b>
}
}
</pre>
@ -1672,7 +1689,9 @@ typemap. For each element in the <i>keys_arr</i>
array, we want to get the key itself, as well as the value
corresponding to that key in the hash:
<blockquote>
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 &gt; 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i &lt; $1; i++) {<br> <b>key = rb_ary_entry(keys_arr, i);<br> val = rb_hash_aref($input, key);</b>
<pre>
%typemap(in) (int nattributes, const char **names, const int *values)
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 &gt; 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i &lt; $1; i++) {<br> <b>key = rb_ary_entry(keys_arr, i);<br> val = rb_hash_aref($input, key);</b>
}
}
}
@ -1682,7 +1701,9 @@ To be safe, we should again use the <tt>Check_Type()</tt> macro to
confirm that the
key is a <tt>String</tt> and the value is a <tt>Fixnum</tt>:
<blockquote>
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 &gt; 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i &lt; $1; i++) {<br> key = rb_ary_entry(keys_arr, i);<br> val = rb_hash_aref($input, key);<br> <b>Check_Type(key, T_STRING);<br> Check_Type(val, T_FIXNUM);</b>
<pre>
%typemap(in) (int nattributes, const char **names, const int *values)
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 &gt; 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i &lt; $1; i++) {<br> key = rb_ary_entry(keys_arr, i);<br> val = rb_hash_aref($input, key);<br> <b>Check_Type(key, T_STRING);<br> Check_Type(val, T_FIXNUM);</b>
}
}
}
@ -1692,7 +1713,9 @@ Finally, we can convert these Ruby objects into their C equivalents and
store them
in our local C arrays:
<blockquote>
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 &gt; 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i &lt; $1; i++) {<br> key = rb_ary_entry(keys_arr, i);<br> val = rb_hash_aref($input, key);<br> Check_Type(key, T_STRING);<br> Check_Type(val, T_FIXNUM);<br> <b>$2[i] = STR2CSTR(key);<br> $3[i] = NUM2INT(val);</b>
<pre>
%typemap(in) (int nattributes, const char **names, const int *values)
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 &gt; 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i &lt; $1; i++) {<br> key = rb_ary_entry(keys_arr, i);<br> val = rb_hash_aref($input, key);<br> Check_Type(key, T_STRING);<br> Check_Type(val, T_FIXNUM);<br> <b>$2[i] = STR2CSTR(key);<br> $3[i] = NUM2INT(val);</b>
}
}
}

View file

@ -2310,7 +2310,7 @@ _wrap_Vector_x_get(ClientData clientData, Tcl_Interp *interp,
struct Vector *arg1 ;
double result ;
if (SWIG_GetArgs(interp, objc, objv,"p:Vector_x_get self ",&arg0,
if (SWIG_GetArgs(interp, objc, objv,"p:Vector_x_get self ",&amp;arg0,
SWIGTYPE_p_Vector) == TCL_ERROR)
return TCL_ERROR;
result = (double ) (arg1->x);

View file

@ -1378,7 +1378,8 @@ or for statically typed languages like Java:
<blockquote>
<pre>
example.i:4: Warning(516): Overloaded method foo(long) ignored. Method foo(int) at example.i:3 used.
example.i:4: Warning(516): Overloaded method foo(long) ignored. Method foo(int)
at example.i:3 used.
</pre>
</blockquote>
@ -1396,7 +1397,7 @@ Ambiguity problems are known to arise in the following situations:
<li>Floating point conversion. <tt>float</tt> and <tt>double</tt> can not be disambiguated in some languages.
<p>
<li>Pointers and references. For example, <tt>Foo *</tt> and <tt>Foo &</tt>.
<li>Pointers and references. For example, <tt>Foo *</tt> and <tt>Foo &amp;</tt>.
<p>
<li>Pointers and arrays. For example, <tt>Foo *</tt> and <tt>Foo [4]</tt>.
@ -1420,7 +1421,8 @@ When wrapping an overloaded function, there is a chance that you will get an err
<blockquote>
<pre>
example.i:3: Warning(467): Overloaded foo(int) not supported (no type checking rule for 'int').
example.i:3: Warning(467): Overloaded foo(int) not supported (no type checking
rule for 'int').
</pre>
</blockquote>
@ -2225,7 +2227,7 @@ template&lt;class T&gt; class Bar : public Foo&lt;T&gt; {
The order is important since SWIG uses the instantiation names to
properly set up the inheritance hierarchy in the resulting wrapper
code (and base classes need to be wrapped before derived classes).
Don't worry--if you get the order wrong, SWIG should generate an warning message.
Don't worry--if you get the order wrong, SWIG should generate a warning message.
<P>
Occassionally, you may need to tell SWIG about base classes that are defined by templates,
@ -2408,8 +2410,9 @@ template&lt;class T1, class T2&gt; struct pair {
T1 first;
T2 second;
pair() : first(T1()), second(T2()) { }
pair(const T1 &x, const T2 &y) : first(x), second(y) { }
template&lt;class U1, class U2&gt; pair(const pair&lt;U1,U2&gt; &x) : first(x.first),second(x.second) { }
pair(const T1 &amp;x, const T2 &amp;y) : first(x), second(y) { }
template&lt;class U1, class U2&gt; pair(const pair&lt;U1,U2&gt; &amp;x)
: first(x.first),second(x.second) { }
};
</pre>
</blockquote>

View file

@ -1284,7 +1284,8 @@ If declarations such as these appear, you will get a warning message like this:
<blockquote>
<pre>
example.i:12: Warning(509): Overloaded spam(short) is shadowed by spam(int) at example.i:11.
example.i:12: Warning(509): Overloaded spam(short) is shadowed by spam(int)
at example.i:11.
</pre>
</blockquote>
@ -2376,7 +2377,7 @@ used as a <tt>char **</tt> object.<p>
return TCL_ERROR;
}
$1 = (char **) malloc((nitems+1)*sizeof(char *));
for (i = 0; i < nitems; i++) {
for (i = 0; i &lt; nitems; i++) {
$1[i] = Tcl_GetStringFromObj(listobjv[i],0);
}
$1[i] = 0;
@ -2496,10 +2497,13 @@ void Tcl_AppendToObj(Tcl_Obj *obj, char *str, int len);
Tcl_Obj *Tcl_NewListObj(int objc, Tcl_Obj *objv);
int Tcl_ListObjAppendList(Tcl_Interp *, Tcl_Obj *listPtr, Tcl_Obj *elemListPtr);
int Tcl_ListObjAppendElement(Tcl_Interp *, Tcl_Obj *listPtr, Tcl_Obj *element);
int Tcl_ListObjGetElements(Tcl_Interp *, Tcl_Obj *listPtr, int *objcPtr, Tcl_Obj ***objvPtr);
int Tcl_ListObjGetElements(Tcl_Interp *, Tcl_Obj *listPtr, int *objcPtr,
Tcl_Obj ***objvPtr);
int Tcl_ListObjLength(Tcl_Interp *, Tcl_Obj *listPtr, int *intPtr);
int Tcl_ListObjIndex(Tcl_Interp *, Tcl_Obj *listPtr, int index, Tcl_Obj_Obj **objptr);
int Tcl_ListObjReplace(Tcl_Interp *, Tcl_Obj *listPtr, int first, int count, int objc, Tcl_Obj *objv);
int Tcl_ListObjIndex(Tcl_Interp *, Tcl_Obj *listPtr, int index,
Tcl_Obj_Obj **objptr);
int Tcl_ListObjReplace(Tcl_Interp *, Tcl_Obj *listPtr, int first, int count,
int objc, Tcl_Obj *objv);
</pre>
</blockquote>

View file

@ -133,7 +133,7 @@ PyObject *wrap_factorial(PyObject *self, PyObject *args) {
PyObject *obj1;
PyObject *resultobj;
if (!PyArg_ParseTuple("O:factorial", &obj1)) return NULL;
if (!PyArg_ParseTuple("O:factorial", &amp;obj1)) return NULL;
<b><font color="#0000ff">arg1 = PyInt_AsLong(obj1);</font></b>
result = factorial(arg1);
<b><font color="#0000ff">resultobj = PyInt_FromLong(result);</font></b>
@ -226,7 +226,7 @@ PyObject *wrap_gcd(PyObject *self, PyObject *args) {
PyObject *obj2;
PyObject *resultobj;
if (!PyArg_ParseTuple("OO:gcd", &obj1, &obj2)) return NULL;
if (!PyArg_ParseTuple("OO:gcd", &amp;obj1, &amp;obj2)) return NULL;
/* "in" typemap, argument 1 */<b><font color="#0000ff">
{
@ -314,7 +314,7 @@ example, you could write a typemap like this:
<pre>
%typemap(in) <b><font color="#ff0000">double nonnegative</font></b> {
$1 = PyFloat_AsDouble($input);
if ($1 < 0) {
if ($1 &lt; 0) {
PyErr_SetString(PyExc_ValueError,"argument must be nonnegative.");
return NULL;
}
@ -667,7 +667,7 @@ Here are some examples of valid typemap specifications:
%typemap(in, numinputs=0) int *output (int temp),
long *output (long temp)
{
$1 = &temp;
$1 = &amp;temp;
}
</pre>
</blockquote>
@ -817,7 +817,7 @@ namespace std {
class Bar {
public:
typedef const int & const_reference;
typedef const int &amp; const_reference;
%typemap(out) const_reference {
...
}
@ -1034,13 +1034,13 @@ Row4 [10]
Row4 rows[ANY]
Row4 [ANY]
# Reduce Row4 --> Integer[4]
# Reduce Row4 --&gt; Integer[4]
Integer rows[10][4]
Integer [10][4]
Integer rows[ANY][ANY]
Integer [ANY][ANY]
# Reduce Integer --> int
# Reduce Integer --&gt; int
int rows[10][4]
int [10][4]
int rows[ANY][ANY]
@ -1066,7 +1066,7 @@ In this case, the following typemap patterns are searched for the argument <tt>f
fooii *x
fooii *
# Reduce fooii --> foo&lt;Integer,Integer&gt;
# Reduce fooii --&gt; foo&lt;Integer,Integer&gt;
foo&lt;Integer,Integer&gt; *x
foo&lt;Integer,Integer&gt; *
@ -1111,7 +1111,7 @@ specifying rules for variations of the reserved <tt>SWIGTYPE</tt> type. For ex
<blockquote>
<pre>
%typemap(in) SWIGTYPE * { ... default pointer handling ... }
%typemap(in) SWIGTYPE & { ... default reference handling ... }
%typemap(in) SWIGTYPE &amp; { ... default reference handling ... }
%typemap(in) SWIGTYPE [] { ... default array handling ... }
%typemap(in) enum SWIGTYPE { ... default handling for enum values ... }
%typemap(in) SWIGTYPE (CLASS::*) { ... default pointer member handling ... }
@ -1180,8 +1180,8 @@ any typemaps specified for a single type. For example:
void foo(char *buffer, int len, int count); // (char *buffer, int len)
void bar(char *buffer, int blah); // char *buffer
</blockquote>
</pre>
</blockquote>
Multi-argument typemaps are also more restrictive in the way that they are matched.
Currently, the first argument follows the matching rules described in the previous section,
@ -1748,7 +1748,7 @@ converted. For example:
<blockquote>
<pre>
%typemap(check) int positive {
if ($1 <= 0) {
if ($1 &lt;= 0) {
SWIG_exception(SWIG_ValueError,"Expected positive value.");
}
}
@ -2243,7 +2243,7 @@ maps perform the conversion described for the above example:
}
$1 = PyList_Size($input);
$2 = (char **) malloc(($1+1)*sizeof(char *));
for (i = 0; i < $1; i++) {
for (i = 0; i &lt; $1; i++) {
PyObject *s = PyList_GetItem($input,i);
if (!PyString_Check(s)) {
free($2);
@ -2258,8 +2258,8 @@ maps perform the conversion described for the above example:
%typemap(freearg) (int argc, char *argv[]) {
if ($2) free($2);
}
</blockquote>
</pre>
</blockquote>
A multi-argument map is always specified by surrounding the arguments with parentheses as shown.
For example:
@ -2354,7 +2354,7 @@ might write typemaps like this:
return NULL;
}
$2 = PyInt_AsLong($input);
if ($2 < 0) {
if ($2 &lt; 0) {
PyErr_SetString(PyExc_ValueError, "Positive integer expected");
return NULL;
}
@ -2364,7 +2364,7 @@ might write typemaps like this:
// Return the buffer. Discarding any previous return result
%typemap(argout) (void *rbuffer, size_t len) {
Py_XDECREF($result); /* Blow away any previous result */
if (result < 0) { /* Check for I/O error */
if (result &lt; 0) { /* Check for I/O error */
free($1);
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
@ -2483,9 +2483,9 @@ of the classes <tt>Foo</tt> and <tt>Bar</tt> as well as its own data members. F
<blockquote>
<pre>
FooBar --> | -----------| <-- Foo
FooBar --&gt; | -----------| &lt;-- Foo
| int x |
|------------| <-- Bar
|------------| &lt;-- Bar
| int y |
|------------|
| int z |
@ -2507,7 +2507,7 @@ if you look at the wrapper code for Python, you will see code like this:
<blockquote>
<pre>
if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_Foo,1)) == -1) return NULL;
if ((SWIG_ConvertPtr(obj0,(void **) &amp;arg1, SWIGTYPE_p_Foo,1)) == -1) return NULL;
</pre>
</blockquote>
@ -2529,7 +2529,7 @@ similar to this:
<blockquote>
<pre>
%typemap(in) Foo * {
if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor)) == -1) return NULL;
if ((SWIG_ConvertPtr($input, (void **) &amp;$1, $1_descriptor)) == -1) return NULL;
}
</pre>
</blockquote>
@ -2558,9 +2558,9 @@ descriptor name for any C datatype. For example:
<blockquote>
<pre>
%typemap(in) Foo * {
if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor)) == -1) {
if ((SWIG_ConvertPtr($input, (void **) &amp;$1, $1_descriptor)) == -1) {
Bar *temp;
if ((SWIG_ConvertPtr($input), (void **) &temp, <b>$descriptor(Bar *)</b>) == -1) {
if ((SWIG_ConvertPtr($input), (void **) &amp;temp, <b>$descriptor(Bar *)</b>) == -1) {
return NULL;
}
$1 = (Foo *) temp;
@ -2618,7 +2618,7 @@ void foo(PyObject *o) {
descr = SWIG_TypeQuery("Foo *"); /* Get the type descriptor structure for Foo */
assert(descr);
}
if ((SWIG_ConvertPtr(o,(void **) &f, descr) == -1)) {
if ((SWIG_ConvertPtr(o,(void **) &amp;f, descr) == -1)) {
abort();
}
...
@ -2715,7 +2715,7 @@ _wrap_foo(argc, args[]) {
}
}
if (argc == 2) {
if (IsString(args[0]) && IsInteger(args[1])) {
if (IsString(args[0]) &amp;&amp; IsInteger(args[1])) {
return _wrap_foo_2(argc,args);
}
}
@ -2796,33 +2796,33 @@ The follow excerpt from the Python module illustrates this:
unsigned int, unsigned short, unsigned long,
signed char, unsigned char,
long long, unsigned long long,
const int &, const short &, const long &,
const unsigned int &, const unsigned short &, const unsigned long &,
const long long &, const unsigned long long &,
const int &amp;, const short &amp;, const long &amp;,
const unsigned int &amp;, const unsigned short &amp;, const unsigned long &amp;,
const long long &amp;, const unsigned long long &amp;,
enum SWIGTYPE,
bool, const bool &
bool, const bool &amp;
{
$1 = (PyInt_Check($input) || PyLong_Check($input)) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_DOUBLE)
float, double,
const float &, const double &
const float &amp;, const double &amp;
{
$1 = (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input)) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_CHAR) char {
$1 = (PyString_Check($input) && (PyString_Size($input) == 1)) ? 1 : 0;
$1 = (PyString_Check($input) &amp;&amp; (PyString_Size($input) == 1)) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_STRING) char * {
$1 = PyString_Check($input) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &amp;, SWIGTYPE [] {
void *ptr;
if (SWIG_ConvertPtr($input, (void **) &ptr, $1_descriptor, 0) == -1) {
if (SWIG_ConvertPtr($input, (void **) &amp;ptr, $1_descriptor, 0) == -1) {
$1 = 0;
PyErr_Clear();
} else {
@ -2832,7 +2832,7 @@ The follow excerpt from the Python module illustrates this:
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
void *ptr;
if (SWIG_ConvertPtr($input, (void **) &ptr, $&1_descriptor, 0) == -1) {
if (SWIG_ConvertPtr($input, (void **) &amp;ptr, $&amp;1_descriptor, 0) == -1) {
$1 = 0;
PyErr_Clear();
} else {
@ -2842,7 +2842,7 @@ The follow excerpt from the Python module illustrates this:
%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
void *ptr;
if (SWIG_ConvertPtr($input, (void **) &ptr, 0, 0) == -1) {
if (SWIG_ConvertPtr($input, (void **) &amp;ptr, 0, 0) == -1) {
$1 = 0;
PyErr_Clear();
} else {
@ -2927,7 +2927,7 @@ a set of typemaps like this:
<blockquote>
<pre>
%typemap(in,numinputs=0) int *OUTPUT (int temp) {
$1 = &temp;
$1 = &amp;temp;
}
%typemap(argout) int *OUTPUT {
// return value somehow
@ -2964,11 +2964,11 @@ For example:
<pre>
%typemap(in) int *INPUT (int temp) {
temp = ... get value from $input ...;
$1 = &temp;
$1 = &amp;temp;
}
%typemap(check) int *POSITIVE {
if (*$1 <= 0) {
if (*$1 &lt;= 0) {
SWIG_exception(SWIG_ValueError,"Expected a positive number!\n");
return NULL;
}

View file

@ -170,8 +170,8 @@ int wrap_printf(const char *fmt, ...) {
...
va_end(ap);
};
</blockquote>
</pre>
</blockquote>
Athough this code might compile, it won't do what you expect. This is
because the call to <tt>printf()</tt> is compiled as a procedure call