Compare commits

..

No commits in common. "C" and "master" have entirely different histories.

103 changed files with 23 additions and 7180 deletions

View file

@ -49,8 +49,6 @@ jobs:
os: ubuntu-22.04
- SWIGLANG: ""
compiler: clang
- SWIGLANG: c
CPPSTD: c++11
- SWIGLANG: csharp
# D support can't be enabled because dmd 2.066 fails to build anything
# under Ubuntu 18.04 due to its standard library (libphobos2.a) not

View file

@ -1,7 +1,7 @@
SWIG Copyright and Authors
--------------------------
Copyright (c) 1995-2012 The SWIG Developers
Copyright (c) 1995-2011 The SWIG Developers
Copyright (c) 2005-2006 Arizona Board of Regents (University of Arizona).
Copyright (c) 1998-2005 University of Chicago.
Copyright (c) 1995-1998 The University of Utah and the Regents of the University of California
@ -16,7 +16,6 @@ Active SWIG Developers:
Joseph Wang (joequant@gmail.com) (R)
Xavier Delacour (xavier.delacour@gmail.com) (Octave)
David Nadlinger (code@klickverbot.at) (D)
Leif Middelschulte (leif.middelschulte@gmail.com) (C)
Oliver Buchtala (oliver.buchtala@gmail.com) (Javascript)
Neha Narang (narangneha03@gmail.com) (Javascript)
Simon Marchetto (simon.marchetto@scilab-enterprises.com) (Scilab)

View file

@ -1,762 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SWIG and C as the target language</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body bgcolor="#FFFFFF">
<H1><a name="C"></a>36 SWIG and C as the target language</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
<li><a href="#C_overview">Overview</a>
<li><a href="#C_preliminaries">Preliminaries</a>
<ul>
<li><a href="#C_running_swig">Running SWIG</a>
<li><a href="#C_commandline">Command line options</a>
<li><a href="#C_dynamic">Compiling dynamic module</a>
<li><a href="#C_using_module">Using generated module</a>
</ul>
<li><a href="#C_basic_c_wrapping">Basic C wrapping</a>
<ul>
<li><a href="#C_functions">Functions</a>
<li><a href="#C_variables">Variables</a>
<li><a href="#C_enums">Enums</a>
</ul>
<li><a href="#C_basic_cpp_wrapping">Basic C++ wrapping</a>
<ul>
<li><a href="#C_classes">Classes</a>
</ul>
<li><a href="#C_exceptions">Exception handling</a>
<li><a href="#C_cxx_wrappers">C++ wrappers</a>
</ul>
</div>
<!-- INDEX -->
<p>
This chapter describes SWIG's support for creating ANSI C wrappers. This module has a special purpose and thus is different from most other modules.
</p>
<p>
<b>NOTE:</b> this module is still under development.
</p>
<H2><a name="C_overview"></a>36.1 Overview</H2>
<p>
SWIG is normally used to provide access to C or C++ libraries from target languages such as scripting languages or languages running on a virtual machine.
SWIG performs analysis of the input C/C++ library header files from which it generates further code. For most target languages this code consists of two layers; namely an intermediary C code layer and a set of language specific proxy classes and functions on top of the C code layer.
We could also think of C as just another target language supported by SWIG.
The aim then is to generate a pure ANSI C interface to the input C or C++ library and hence the C target language module.
</p>
<p>
With wrapper interfaces generated by SWIG, it is easy to use the functionality of C++ libraries inside application code written in C. This module may also be useful to generate custom APIs for a library, to suit particular needs, e.g. to supply function calls with error checking or to implement a "design by contract".
</p>
<p>
Flattening C++ language constructs into a set of C-style functions obviously comes with many limitations and inconveniences, but this module is actually also capable of generating C++ wrappers defined completely inline using the C functions, thus wrapping the original C++ library API in another, similar C++ API. Contrary to the natural initial reaction, this is far from being completely pointless, as wrapping C++ API in this way avoids all problems due to C++ ABI issues, e.g. it is now possible to use the original C++ API using a different C++ compiler, or a different version of the same compiler, or even the same compiler, but with different compilation options affecting the ABI. The C++ wrapper API is not identical to the original one, but strives to be as close to it as possible.
</p>
<H3>Known C++ Shortcomings in Generated C API:</H3>
<ul>
<li>Enums with a context like class or namespace are broken</li>
<li>Global variables are not supported</li>
<li>Qualifiers are stripped</li>
<li>Vararg functions are not supported.</li>
</ul>
<H2><a name="C_preliminaries"></a>36.2 Preliminaries</H2>
<H3><a name="C_running_swig"></a>36.2.1 Running SWIG</H3>
<p>
Consider the following simple example. Suppose we have an interface file like:
</p>
<div class="code">
<pre>
/* File: example.i */
%module test
%{
#include "stuff.h"
%}
int fact(int n);
</pre>
</div>
<p>
To build a C module (C as the target language), run SWIG using the <tt>-c</tt> option :</p>
<div class="shell"><pre>
$ swig -c example.i
</pre></div>
<p>
The above assumes C as the input language. If the input language is C++ add the <tt>-c++</tt> option:
</p>
<div class="shell"><pre>
$ swig -c++ -c example.i
</pre></div>
<p>
Note that <tt>-c</tt> is the option specifying the <b>target</b> language and <tt>-c++</tt> controls what the <b>input</b> language is.
<p>
<p>
This will generate an <tt>example_wrap.c</tt> file or, in the latter case, <tt>example_wrap.cxx</tt> file, along with <tt>example_wrap.h</tt> (the same extension is used in both C and C++ cases for the last one). The names of the files are derived from the name of the input file by default, but can be changed using the <tt>-o</tt> and <tt>-oh</tt> options common to all language modules.
</p>
<p>
The <tt>xxx_wrap.c</tt> file contains the wrapper functions, which perform the main functionality of SWIG: each of the wrappers translates the input arguments from C to C++, makes calls to the original functions and marshals C++ output back to C data. The <tt>xxx_wrap.h</tt> header file contains the declarations of these functions as well as global variables.
</p>
<H3><a name="C_commandline"></a>36.2.2 Command line options</H3>
<p>
The following table list the additional command line options available for the C module. They can also be seen by using:
</p>
<div class="shell"><pre>
$ swig -c -help
</pre></div>
<table summary="C specific options">
<tr>
<th>C specific options</th>
</tr>
<tr>
<td>-namespace &lt;nspace&gt;</td>
<td>Generate wrappers with the prefix based on the provided namespace, e.g. if the option value is <tt>outer::inner</tt>, the prefix <tt>outer_inner_</tt> will be used. Notice that this is different from using SWIG <tt>nspace</tt> feature, as it applies the the prefix to all the symbols, regardless of the namespace they were actually declared in. Notably, this allows to export instantiations of templates defined in the <tt>std</tt> namespace, such as <tt>std::vector</tt>, using a custom prefix rather than <tt>std_</tt>.</td>
</tr>
<tr>
<td>-nocxx</td>
<td>Don't generate C++ wrappers, even when <tt>-c++</tt> option is used. See <a href="#C_cxx_wrappers">C++ Wrappers</a> section for more details.</td>
</tr>
<tr>
<td>-noexcept</td>
<td>generate wrappers with no support of exception handling; see <a href="#C_exceptions">Exceptions</a> chapter for more details </td>
</tr>
</table>
<H3><a name="C_dynamic"></a>36.2.3 Compiling a dynamic module</H3>
<p>
The next step is to build a dynamically loadable module, which we can link to our application. This can be done easily, for example using the <tt>gcc</tt> compiler (Linux, MinGW, etc.):
</p>
<div class="shell"><pre>
$ swig -c example.i
$ gcc -c example_wrap.c
$ gcc -shared example_wrap.o -o libexample.so
</pre></div>
<p>
Or, for C++ input:
</p>
<div class="shell"><pre>
$ swig -c++ -c example.i
$ g++ -c example_wrap.cxx
$ g++ -shared example_wrap.o -o libexample.so
</pre></div>
<p>
Now the shared library module is ready to use. Note that the name of the generated module is important: is should be prefixed with <tt>lib</tt> on Unix, and have the specific extension, like <tt>.dll</tt> for Windows or <tt>.so</tt> for Unix systems.
</p>
<H3><a name="C_using_module"></a>36.2.4 Using the generated module</H3>
<p>
The simplest way to use the generated shared module is to link it to the application code during the compilation stage. The process is usually similar to this:
</p>
<div class="shell"><pre>
$ gcc runme.c -L. -lexample -o runme
</pre></div>
<p>
This will compile the application code (<tt>runme.c</tt>) and link it against the generated shared module. Following the <tt>-L</tt> option is the path to the directory containing the shared module. The output executable is ready to use. The last thing to do is to supply to the operating system the information of location of our module. This is system dependant, for instance Unix systems look for shared modules in certain directories, like <tt>/usr/lib</tt>, and additionally we can set the environment variable <tt>LD_LIBRARY_PATH</tt> (Unix) or <tt>PATH</tt> (Windows) for other directories.
</p>
<H2><a name="C_basic_c_wrapping"></a>36.3 Basic C wrapping</H2>
<p>
Wrapping C functions and variables is obviously performed in a straightforward way. There is no need to perform type conversions, and all language constructs can be preserved in their original form. However, SWIG allows you to enhance the code with some additional elements, for instance using <tt>check</tt> typemap or <tt>%extend</tt> directive.
</p>
<p>
It is also possible to output arbitrary additional code into the generated header by using <tt>%insert</tt> directive with <tt>cheader</tt> section, e.g.
<div class="code"><pre>
%insert("cheader") %{
#include "another.h"
%}
</pre></div>
</p>
<H3><a name="C_functions"></a>36.3.1 Functions</H3>
<p>
For each C function declared in the interface file a wrapper function with a prefix, required to make its name different from the original one, is created. The prefix for the global functions is <tt>module_</tt>, i.e. the name of the SWIG module followed by underscore, by default. If <tt>-namespace</tt> option is used, the prefix corresponding to the given fixed namespace is used instead. If <tt>nspace</tt> feature is used, the prefix corresponding to the namespace in which the function is defined is used -- note that, unlike with <tt>-namespace</tt> option, this prefix can be different for different functions. The wrapper function performs a call to the original function, and returns its result.
</p>
<p>
For example, for function declaration in the module <tt>mymath</tt>:
</p>
<div class="targetlang"><pre>
int gcd(int x, int y);
</pre></div>
<p>
The output is simply:
</p>
<div class="targetlang"><pre>
int mymath_gcd(int arg1, int arg2) {
int result;
result = gcd(arg1,arg2);
return result;
}
</pre></div>
<p>
Now one might think, what's the use of creating such functions in C? The answer is, you can apply special rules to the generated code. Take for example constraint checking. You can write a "check" typemap in your interface file:
</p>
<div class="code"><pre>
%typemap(check) int POSITIVE {
if ($1 <= 0)
fprintf(stderr, "Expected positive value in $name.\n");
}
int gcd(int POSITIVE, int POSITIVE);
</pre></div>
<p>
And now the generated result looks like:
</p>
<div class="targetlang"><pre>
int _wrap_gcd(int arg1, int arg2) {
{
if (arg1 <= 0)
fprintf(stderr, "Expected positive value in gcd.\n");
}
{
if (arg1 <= 0)
fprintf(stderr, "Expected positive value in gcd.\n");
}
int result;
result = gcd(arg1,arg2);
return result;
}
</pre></div>
<p>
This time calling <tt>gcd</tt> with negative value argument will trigger an error message. This can save you time writing all the constraint checking code by hand.
</p>
<H3><a name="C_variables"></a>36.3.2 Variables</H3>
<p>
Wrapping variables comes also without any special issues. All global variables are directly accessible from application code. There is a difference in the semantics of <tt>struct</tt> definition in C and C++. When handling C <tt>struct</tt>, SWIG simply rewrites its declaration. In C++ <tt>struct</tt> is handled as class declaration.
</p>
<p>
You can still apply some of the SWIG features when handling structs, e.g. <tt>%extend</tt> directive. Suppose, you have a C struct declaration:
</p>
<div class="targetlang"><pre>
typedef struct {
int x;
char *str;
} my_struct;
</pre></div>
<p>
You can redefine it to have an additional fields, like:
</p>
<div class="code"><pre>
%extend my_struct {
double d;
};
</pre></div>
<p>
In application code:
</p>
<div class="targetlang"><pre>
struct my_struct ms;
ms.x = 123;
ms.d = 123.123;
</pre></div>
<H2><a name="C_basic_cpp_wrapping"></a>36.4 Basic C++ wrapping</H2>
<p>
The main reason of having the C module in SWIG is to be able to access C++ from C. In this chapter we will take a look at the rules of wrapping elements of the C++ language.
</p>
<p>
By default, SWIG attempts to build a natural C interface to your C/C++ code.
<table BORDER summary="Generated C representation of C++">
<tr>
<th>C++ Type</th>
<th>SWIG C Translation</th>
</tr>
<tr>
<td>Class <tt>Example</tt></td>
<td>Empty structure <tt>Example</tt></td>
</tr>
<tr>
<td>Public, mutable member variable <tt><tt>Foo Example::foo</tt></td>
<td><tt>
Example_foo_get(Example *e);</br>
Example_foo_set(Example *e, Foo *f);
</tt></td>
</tr>
<tr>
<td>Public, immutable member variable <tt><tt>Foo Example::bar</tt></td>
<td><tt>
Example_foo_get(Example *e);</br>
</tt></td>
</tr>
</table>
This section briefly covers the essential aspects of this wrapping.
</p>
<H3><a name="C_enums"></a>36.3.3 Enums</H3>
<p>
C enums and unscoped C++ enums are simply copied to the generated code and both the enum itself and its elements keep the same name as in the original code unless <tt>-namespace</tt> option is used or <tt>nspace</tt> feature is enabled, in which case the prefix corresponding to the specified namespace is used.
</p>
<p>
For scoped C++11 enums, the enum name itself is used as an additional prefix.
</p>
<H3><a name="C_classes"></a>36.4.1 Classes</H3>
<p>
Consider the following example. We have a C++ class, and want to use it from C code.
</p>
<div class="targetlang"><pre>
class Circle {
public:
double radius;
Circle(double r) : radius(r) { };
double area(void);
};
</pre></div>
<p>
What we need to do is to create an object of the class, manipulate it, and finally, destroy it. SWIG generates C functions for this purpose each time a class declaration is encountered in the interface file.
</p>
<p>
The first two generated functions are used to create and destroy instances of class <tt>Circle</tt>. Such instances are represented on the C side as pointers to special structs, called <tt>SwigObj</tt>. They are all "renamed" (via typedef) to the original class names, so that you can use the object instances on the C side using pointers like:
</p>
<div class="targetlang"><pre>
Circle *circle;
</pre></div>
<p>
The generated functions make calls to class' constructors and destructors, respectively. They also do all the necessary things required by the SWIG object management system in C.
</p>
<div class="targetlang"><pre>
Circle * Circle_new(double r);
void Circle_delete(Circle * self);
</pre></div>
<p>
The class <tt>Circle</tt> has a public variable called <tt>radius</tt>. SWIG generates a pair of setters and getters for each such variable:
</p>
<div class="targetlang"><pre>
void Circle_radius_set(Circle * self, double radius);
double Circle_radius_get(Circle * self);
</pre></div>
<p>
For each public method, an appropriate function is generated:
</p>
<div class="targetlang"><pre>
double Circle_area(Circle * self);
</pre></div>
<p>
You can see that in order to use the generated object we need to provide a pointer to the object instance (struct <tt>Circle</tt> in this case) as the first function argument. In fact, this struct is basically wrapping pointer to the "real" C++ object.
</p>
<p>
Our application code could look like this:
</p>
<div class="targetlang"><pre>
Circle *c = Circle_new(1.5);
printf("radius: %f\narea: %f\n", Circle_radius_get(c), Circle_area(c));
Circle_delete(c);
</pre></div>
<p>
After running this we'll get:
</p>
<div class="shell"><pre>
radius: 1.500000
area: 7.068583
</pre></div>
<H2><a name="C_developer"></a>Backend Developer Documentation</H2>
<H2><a name="C_typemaps"></a>Typemaps</H2>
<table BORDER summary="C Backend Typemaps">
<tr>
<th>Typemap</th>
<th>Used for</th>
</tr>
<tr>
<td><tt>ctype</tt></td>
<td>Provides types used for the C API and</br>
Typecasts wrapper functions return values in proxy functions</br>
<code>
MyClass *MyClass_new(void) {</br>
&nbsp;return (MyClass *)MyClass_new();</br>
}
</code>
</td>
</tr>
<tr>
<td><tt>in</tt></td>
<td>Mapping of wrapper functions parameters to local C++ variables</br>
</br>
<code>
SwigObj* MyClass_do(SwigObj *carg1) {</br>
&nbsp;SomeCPPClass *arg1 = 0;</br>
&nbsp;if (carg1)</br>
&nbsp;&nbsp;arg1 = (SomeCPPClass*)carg1->obj</br>
&nbsp;else</br>
&nbsp;&nbsp;arg1 = 0;</br>
}
</code></td>
</tr>
<tr>
<td><tt>out</tt></td>
<td>Assigns wrapped function's return value to a dedicated return variable, packaging it into SwigObj if necessary</td>
</tr>
<tr>
<td><tt>cppouttype</tt></td>
<td>Type of the result variable used for the return value if the wrapped function is a C++ function
</td>
</tr>
<tr>
<td><tt>cxxintype</tt></td>
<td>Defines the type for the parameters of C++ wrapper functions corresponding to this type. By default is the same as <tt>ctype</tt>, but may sometimes be different to make the functions more convenient to use. For example, <tt>ctype</tt> for <tt>std::string</tt> is <tt>const char*</tt>, but <tt>cxxintype</tt> typemap for it is <tt>std::string const&amp;</tt>, i.e. even though the C++ string passed as a raw pointer via C API, the C++ wrapper still accepts a C++ string. If this typemap is defined, <tt>cxxin</tt> should normally be defined as well. If it is not defined, <tt>ctype</tt> is used.
</td>
</tr>
<tr>
<td><tt>cxxouttype</tt></td>
<td>Similar to <tt>cxxintype</tt>, but is used for the function return values and together with <tt>cxxout</tt> typemap. Also defaults to <tt>ctype</tt> if not defined.
</td>
</tr>
<tr>
<td><tt>cxxin</tt></td>
<td>Defines how to transform <tt>cxxintype</tt> value to <tt>ctype</tt>
</td>
</tr>
<tr>
<td><tt>cxxout</tt></td>
<td>Defines how to transform <tt>ctype</tt> value returned by a function to <tt>cxxouttype</tt>
</td>
</tr>
<tr>
<td><tt>cxxcode</tt></td>
<td>May contain arbitrary code that will be injected in the declaration of the C++ wrapper class corresponding to the given type. Ignored for non-class types. The special variable <tt>$cxxclassname</tt> is replaced with the name of the class inside this typemap expansion and <tt>$cclassptrname</tt> is replaced with the name of the pointer type used to represent the class in C wrapper functions.
</td>
</tr>
</table>
<H3>C Typemaps, a Code Generation Walkthrough</H3>
To get a better idea of which typemap is used for which generated code, have a look at the following 'walk through'.</br>
Let's assume we have the following C++ interface file, we'd like to generate code for:
<H4>The Interface</H4>
<div class="code"><pre>
%module example
%inline
%{
class SomeClass{};
template &lt;typename T&gt; class SomeTemplateClass{};
SomeClass someFunction(SomeTemplateClass&lt;int&gt; &someParameter, int simpleInt);
%}
%template (SomeIntTemplateClass) SomeTemplateClass&lt;int&gt;;
</pre></div>
What we would like to generate as a C interface of this function would be something like this:
<div class="targetlang"><pre>
// wrapper header file
typedef struct SwigObj_SomeClass SomeClass;
SomeClass * SomeClass_new();
void SomeClass_delete(SomeClass * carg1);
SomeClass* someFunction(SomeIntTemplateClass* carg1, int carg2);
typedef struct SwigObj_SomeIntTemplateClass SomeIntTemplateClass;
SomeIntTemplateClass * SomeIntTemplateClass_new();
void SomeIntTemplateClass_delete(SomeIntTemplateClass * carg1);
</pre></div>
<H4>The Wrapper</H4>
We'll examine the generation of the wrapper function first.
<div class="targetlang"><pre>
SWIGEXPORTC SwigObj * module_someFunction(SwigObj * carg1, int carg2) {
SomeClass * cppresult;
SomeTemplateClass< int > *arg1 = 0 ;
int arg2 ;
SwigObj * result;
{
if (carg1)
arg1 = (SomeTemplateClass< int > *) carg1->obj;
else
arg1 = (SomeTemplateClass< int > *) 0;
}
arg2 = (int) carg2;
{
const SomeClass &_result_ref = someFunction(*arg1,arg2);cppresult = (SomeClass*) &_result_ref;
}
{
result = SWIG_create_object(cppresult, SWIG_STR(SomeClass));
}
return result;
}
</pre></div>
It might be helpful to think of the way function calls are generated as a composition of building blocks.</br>
A typical wrapper will be composited with these [optional] blocks:
<ol>
<li>Prototype</li>
<li>C return value variable</li>
<li>Local variables equal to the called C++ function's parameters</li>
<li>[C++ return value variable]</li>
<li>Assignment (extraction) of wrapper parameters to local parameter copies</li>
<li>[Contract (e.g. constraints) checking]</li>
<li> C++ function call</li>
<li>[Exception handling]</li>
<li>[Assignment to C++ return value]</li>
<li>Assignment to C return value</li>
</ol>
Let's go through it step by step and start with the wrapper prototype
<div class="targetlang"><pre>
ctype ctype ctype
--------- --------- ---
SwigObj * module_someFunction(SwigObj * carg1, int carg2);
</pre></div>
As first unit of the wrapper code, a variable to hold the return value of the function is emitted to the wrapper's body
<div class="targetlang"><pre>
ctype
---------
SwigObj * result;
</pre></div>
Now for each of the C++ function's arguments, a local variable with the very same type is emitted to the wrapper's body.
<div class="targetlang"><pre>
SomeTemplateClass< int > *arg1 = 0 ;
int arg2 ;
</pre></div>
If it's a C++ function that is wrapped (in this case it is), another variable is emitted for the 'original' return value of the C++ function.</br>
At this point, we simply 'inject' behavior if it's a C++ function that is wrapped (in this case it obviously is).
<div class="targetlang"><pre>
cppouttype
-----------
SomeClass * cppresult;
</pre></div>
Next, the values of the input parameters are assigned to the local variables using the 'in' typemap.
<div class="targetlang"><pre>
{
if (carg1)
arg1 = (SomeTemplateClass< int > *) carg1->obj;
else
arg1 = (SomeTemplateClass< int > *) 0;
}
arg2 = (int) carg2;
</pre></div>
A reasonable question would be: "Why aren't the parameters assigned in the declaration of their local counterparts?"</br>
As seen above, for complex types pointers have to be verified before extracting and </br>
casting the actual data pointer from the provided SwigObj pointer.</br>
This could easily become messy if it was done in the same line with the local variable declaration.</br>
<p>
At this point we are ready to call the C++ function with our parameters.</br>
</p>
<div class="targetlang"><pre>
{
const SomeClass &_result_ref = someFunction(*arg1,arg2);cppresult = (SomeClass*) &_result_ref;
}
</pre></div>
Subsequently, the return value is assigned to the dedicated return value variable using the 'out' typemap
<div class="targetlang"><pre>
{
result = SWIG_create_object(cppresult, SWIG_STR(SomeClass));
}
</pre></div>
Finally, the return value variable is returned.
<div class="targetlang"><pre>
return result;
</pre></div>
Note that typemaps may use <tt>$null</tt> special variable which will be
replaced with either <tt>0</tt> or nothing, depending on whether the function
has a non-void return value or not.
<H4>The Proxy</H4>
Compared to the wrapper code generation, the header code is very simple.</br>
Basically it contains just the declarations corresponding to the definitions
above.
<div class="targetlang"><pre>
// wrapper header file
typedef struct SwigObj_SomeClass SomeClass;
SomeClass * SomeClass_new();
void SomeClass_delete(SomeClass * carg1);
SomeClass* someFunction(SomeIntTemplateClass* carg1, int carg2);
typedef struct SwigObj_SomeIntTemplateClass SomeIntTemplateClass;
SomeIntTemplateClass * SomeIntTemplateClass_new();
void SomeIntTemplateClass_delete(SomeIntTemplateClass * carg1);
</pre></div>
<H2><a name="C_exceptions"></a>36.5 Exception handling</H2>
<p>
Any call to a C++ function may throw an exception, which cannot be caught by C code. Instead, the special <tt>SWIG_CException_get_pending()</tt> function must be called to check for this. If it returns a non-null pointer, <tt>SWIG_CException_msg_get()</tt> can be called to retrieve the error message associated with the exception. Finally, <tt>SWIG_CException_reset_pending()</tt> must be called to free the exception object and reset the current pending exception. Note that exception handling is much simpler when using C++, rather than C, wrappers, see sections 36.6.2.
</p>
<H2><a name="C_cxx_wrappers"></a>36.6 C++ Wrappers</H2>
<p>
When <tt>-c++</tt> command line option is used (and <tt>-nocxx</tt> one is not), the header file generated by SWIG will also contain the declarations of C++ wrapper functions and classes mirroring the original API. All C++ wrappers are fully inline, i.e. don't need to be compiled separately, and are always defined inside the namespace (or nested namespaces) specified by <tt>-namespace</tt> command-line option or the namespace with the same name as the SWIG module name if this option is not specified.
</p>
<p>
C++ wrappers try to provide a similar API to the original C++ API being wrapped, notably any class <tt>Foo</tt> in the original API appears as a class with the same name in the wrappers namespace, and has the same, or similar, public methods. A class <tt>Bar</tt> deriving from <tt>Foo</tt> also derives from it in the wrappers and so on. There are some differences with the original API, however. Some of them are due to fundamental limitations of the approach used, e.g.:
<ul>
<li>Only template instantiations are present in the wrappers, not the templates themselves.</li>
</ul>
Other ones are due to things that could be supported but haven't been implemented yet:
<ul>
<li>Only single, not multiple, inheritance is currently supported.</li>
<li>Only enums using <tt>int</tt> (or smaller type) as underlying type are supported.</li>
</ul>
</p>
<H3>36.6.1 Additional customization possibilities</H3>
Generated C++ code can be customized by inserting custom code in the following sections:
<ul>
<li><tt>cxxheader</tt> for including additional headers and other declarations in the global scope.</li>
<li><tt>cxxcode</tt> for additional code to appear after the declarations of all wrapper classes, inside the module-specific namespace.</li>
</ul>
The following features are taken into account when generating C++ wrappers:
<ul>
<li><tt>cxxignore</tt> May be set to skip generation of C++ wrappers for the given function or class, while still generating C wrappers for them.</li>
</ul>
<H3>36.6.2 Exception handling</H3>
<p>
Exception handling in C++ is more natural, as the exceptions are re-thrown when using C++ wrappers and so can be caught, as objects of the special <tt>SWIG_CException</tt> type, using the usual <tt>try/catch</tt> statement. The objects of <tt>SWIG_CException</tt> class have <tt>code()</tt> and <tt>msg()</tt> methods, with the latter returning the error message associated with the exception.
</p>
<p>
If necessary, a custom exception type may be used instead of <tt>SWIG_CException</tt>. To do this, a custom implementation of <tt>swig_check()</tt> function, called to check for the pending exception and throw the corresponding C++ exception if necessary, must be provided and <tt>SWIG_swig_check_DEFINED</tt> preprocessor symbol must be defined to prevent the default implementation of this function from being compiled:
</p>
<div class="code"><pre>
%insert(cxxheader) %{
#ifndef SWIG_swig_check_DEFINED
#define SWIG_swig_check_DEFINED 1
#include <stdexcept>
class Exception : public std::runtime_error {
public:
explicit Exception(const char* msg) : std::runtime_error{msg} {}
};
inline void swig_check() {
if (auto* swig_ex = SWIG_CException_get_pending()) {
Exception const e{SWIG_CException_msg_get(swig_ex)};
SWIG_CException_reset_pending();
throw e;
}
}
template <typename T> T swig_check(T x) {
swig_check();
return x;
}
#endif // SWIG_swig_check_DEFINED
%}
</pre></div>
</body>
</html>

View file

@ -20,7 +20,6 @@ Warnings.html
Modules.html
CCache.html
Android.html
C.html
CSharp.html
D.html
Go.html

View file

@ -1472,377 +1472,6 @@ ruby_clean:
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *$(RUBY_SO)
##################################################################
##### PHP ######
##################################################################
PHP = @PHP@
PHP_INCLUDE = @PHPINC@
PHP_SO = @PHP_SO@
PHP_SCRIPT = $(SRCDIR)$(RUNME).php
PHP_EXTENSION = example$(PHP_SO)
# -------------------------------------------------------------------
# Build a PHP dynamically loadable module (C)
# -------------------------------------------------------------------
php: $(SRCDIR_SRCS)
$(SWIG) -php $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(PHP_INCLUDE)
$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO)
# --------------------------------------------------------------------
# Build a PHP dynamically loadable module (C++)
# --------------------------------------------------------------------
php_cpp: $(SRCDIR_SRCS)
$(SWIG) -php -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PHP_INCLUDE)
$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO)
# -----------------------------------------------------------------
# Running a PHP example
# -----------------------------------------------------------------
php_run:
$(RUNTOOL) $(PHP) -n -d extension_dir=. -d extension=$(PHP_EXTENSION) -d display_errors=stderr -r 'set_error_handler(function($$n,$$s,$$f,$$l){if($$f!==Null){print$$f;if($$l!==Null)print":$$l";print": ";}print"$$s\n";exit(1);});if(strlen($$argv[1]))include($$argv[1]);' '$(PHP_SCRIPT)' $(RUNPIPE)
# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------
php_version:
$(PHP) -v | head -n 1
# -----------------------------------------------------------------
# Cleaning the PHP examples
# -----------------------------------------------------------------
php_clean:
rm -f *_wrap* *~ .~* example.php php_example.h
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *$(PHP_SO)
##################################################################
##### CSHARP ######
##################################################################
# Extra CSharp specific dynamic linking options
CSHARP_DLNK = @CSHARPDYNAMICLINKING@
CSHARP_LIBPREFIX = @CSHARPLIBRARYPREFIX@
CSHARPCOMPILER = @CSHARPCOMPILER@
CSHARPCILINTERPRETER = @CSHARPCILINTERPRETER@
CSHARPCILINTERPRETER_FLAGS = @CSHARPCILINTERPRETER_FLAGS@
CSHARPCFLAGS = @CSHARPCFLAGS@
CSHARPFLAGS =
CSHARPOPTIONS =
CSHARPSO = @CSHARPSO@
CSHARP_RUNME = ./$(RUNME).exe
# ----------------------------------------------------------------
# Build a CSharp dynamically loadable module (C)
# ----------------------------------------------------------------
csharp: $(SRCDIR_SRCS)
$(SWIG) -csharp $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(CSHARPCFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES)
$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(CSHARP_DLNK) $(LIBS) -o $(CSHARP_LIBPREFIX)$(TARGET)$(CSHARPSO)
# ----------------------------------------------------------------
# Build a CSharp dynamically loadable module (C++)
# ----------------------------------------------------------------
csharp_cpp: $(SRCDIR_SRCS)
$(SWIG) -csharp -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(CSHARPCFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES)
$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(CSHARP_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(CSHARP_LIBPREFIX)$(TARGET)$(CSHARPSO)
# ----------------------------------------------------------------
# Compile CSharp files
# ----------------------------------------------------------------
ifneq (,$(SRCDIR))
SRCDIR_CSHARPSRCS = $(addprefix $(SRCDIR),$(CSHARPSRCS))
else
SRCDIR_CSHARPSRCS =
endif
csharp_compile: $(SRCDIR_SRCS)
$(COMPILETOOL) $(CSHARPCOMPILER) $(CSHARPFLAGS) $(CSHARPOPTIONS) $(CSHARPSRCS) $(SRCDIR_CSHARPSRCS)
# -----------------------------------------------------------------
# Run CSharp example
# -----------------------------------------------------------------
csharp_run:
env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(CSHARPCILINTERPRETER) $(CSHARPCILINTERPRETER_FLAGS) $(CSHARP_RUNME) $(RUNPIPE)
# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------
# Version check below also works with MS csc.exe which does not understand --version
csharp_version:
$(CSHARPCOMPILER) --version | head -n 1
if test -n "$(CSHARPCILINTERPRETER)" ; then "$(CSHARPCILINTERPRETER)" --version ; fi
# -----------------------------------------------------------------
# Cleaning the CSharp examples
# -----------------------------------------------------------------
csharp_clean:
rm -f *_wrap* *~ .~* $(RUNME) $(RUNME).exe *.exe.mdb gc.log `find . -name \*.cs | grep -v $(RUNME).cs`
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@CSHARPSO@
##################################################################
##### LUA ######
##################################################################
# lua flags
LUA_INCLUDE= @LUAFLAGS@
LUA_LIB = @LUALINK@
# Extra specific dynamic linking options
LUA_DLNK = @LUADYNAMICLINKING@
LUA_SO = @LUA_SO@
LUA = @LUABIN@
LUA_SCRIPT = $(SRCDIR)$(RUNME).lua
# Extra code for lua static link
LUA_INTERP = ../lua.c
# ----------------------------------------------------------------
# Build a C dynamically loadable module
# ----------------------------------------------------------------
lua: $(SRCDIR_SRCS)
$(SWIG) -lua $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(LUA_INCLUDE)
$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(LUA_LIB) -o $(LIBPREFIX)$(TARGET)$(LUA_SO)
# -----------------------------------------------------------------
# Build a C++ dynamically loadable module
# -----------------------------------------------------------------
lua_cpp: $(SRCDIR_SRCS) $(GENCXXSRCS)
$(SWIG) -c++ -lua $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(GENCXXSRCS) $(INCLUDES) $(LUA_INCLUDE)
$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(LUA_LIB) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(LUA_SO)
lua_externalhdr:
$(SWIG) -lua -external-runtime $(TARGET)
lua_swig_cpp:
$(SWIG) -c++ -lua $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
# -----------------------------------------------------------------
# Build statically linked Lua interpreter
# -----------------------------------------------------------------
lua_static: $(SRCDIR_SRCS)
$(SWIG) -lua -module example $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(SRCDIR)$(LUA_INTERP) $(INCLUDES) \
$(LUA_INCLUDE) $(LIBS) $(LUA_LIB) -o $(TARGET)
lua_static_cpp: $(SRCDIR_SRCS) $(GENCXXSRCS)
$(SWIG) -c++ -lua -module example $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(GENCXXSRCS) $(SRCDIR)$(LUA_INTERP) $(INCLUDES) \
$(LUA_INCLUDE) $(LIBS) $(LUA_LIB) -o $(TARGET)
# -----------------------------------------------------------------
# Run Lua example
# -----------------------------------------------------------------
lua_run:
$(RUNTOOL) $(LUA) $(LUA_SCRIPT) $(RUNPIPE)
lua_embed_run:
$(RUNTOOL) ./$(TARGET) $(LUA_SCRIPT) $(RUNPIPE)
# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------
lua_version:
$(LUA) -v | head -n 1
# -----------------------------------------------------------------
# Cleaning the lua examples
# -----------------------------------------------------------------
lua_clean:
rm -f *_wrap* *~ .~* mylua@EXEEXT@
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *$(LUA_SO)
##################################################################
##### CFFI ######
##################################################################
CFFI = @CFFIBIN@
CFFI_SCRIPT=$(RUNME).lisp
cffi: $(SRCDIR_SRCS)
$(SWIG) -cffi $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
# $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCDIR_SRCS)
# $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
cffi_cpp: $(SRCDIR_SRCS)
$(SWIG) -c++ -cffi $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES)
$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
# -----------------------------------------------------------------
# Run CFFI example
# -----------------------------------------------------------------
cffi_run:
$(RUNTOOL) $(CFFI) -batch -s $(CFFI_SCRIPT) $(RUNPIPE)
# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------
cffi_version:
$(CFFI) --version
# -----------------------------------------------------------------
# Cleaning the CFFI examples
# -----------------------------------------------------------------
cffi_clean:
rm -f *_wrap* *~ .~*
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@SO@
##################################################################
##### R ######
##################################################################
R = R
RCXXSRCS = $(INTERFACE:.i=_wrap.cpp) #Need to use _wrap.cpp for R build system as it does not understand _wrap.cxx
RRSRC = $(INTERFACE:.i=.R)
R_CFLAGS=-fPIC
R_OPT = --slave --quiet --no-save --no-restore
R_SCRIPT=$(SRCDIR)$(RUNME).R
# need to compile .cxx files outside of R build system to make sure that
# we get -fPIC
# CMD SHLIB stdout is piped to /dev/null to prevent echo of compiler command
# ----------------------------------------------------------------
# Build a R dynamically loadable module (C)
# ----------------------------------------------------------------
r: $(SRCDIR_SRCS)
$(SWIG) -r $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
ifneq ($(SRCDIR_SRCS),)
$(CC) -g -c $(CPPFLAGS) $(CFLAGS) $(R_CFLAGS) $(SRCDIR_SRCS) $(INCLUDES)
endif
+( PKG_CPPFLAGS="$(CPPFLAGS) $(INCLUDES)" PKG_CFLAGS="$(CFLAGS)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(OBJS) > /dev/null )
# ----------------------------------------------------------------
# Build a R dynamically loadable module (C++)
# ----------------------------------------------------------------
r_cpp: $(SRCDIR_CXXSRCS)
$(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH)
ifneq ($(SRCDIR_CXXSRCS),)
$(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) $(R_CFLAGS) $(SRCDIR_CXXSRCS) $(INCLUDES)
endif
+( PKG_CPPFLAGS="$(CPPFLAGS) $(INCLUDES)" PKG_CXXFLAGS="$(CXXFLAGS)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null )
# -----------------------------------------------------------------
# Run R example
# -----------------------------------------------------------------
r_run:
$(RUNTOOL) $(R) $(R_OPT) -f $(R_SCRIPT) $(RUNPIPE)
# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------
r_version:
$(R) --version | head -n 1
# -----------------------------------------------------------------
# Cleaning the R examples
# -----------------------------------------------------------------
r_clean:
rm -f *_wrap* *~ .~*
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@SO@ NAMESPACE
rm -f $(RRSRC) $(RUNME).Rout .RData
##################################################################
##### C ######
##################################################################
# ----------------------------------------------------------------
# Build a C dynamically loadable module
# ----------------------------------------------------------------
CLIBPREFIX = lib
C_LDSHARED = @C_LDSHARED@
CXX_LDSHARED = @CXX_LDSHARED@
C_SO = @C_SO@
c: $(SRCDIR_SRCS)
$(SWIG) -c $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
$(CC) -c $(CCSHARED) -I$(SRCDIR) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES)
$(COMPILETOOL) $(C_LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(CLIBPREFIX)$(TARGET)$(C_SO)
c_cpp: $(SRCDIR_SRCS)
$(SWIG) -c++ -c $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
$(CXX) -c $(CCSHARED) -I$(SRCDIR) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_CXXSRCS) $(INCLUDES)
$(COMPILETOOL) $(CXX_LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(CLIBPREFIX)$(TARGET)$(C_SO)
c_compile_c: $(SRCDIR)$(RUNME).c
$(COMPILETOOL) $(CC) $(CFLAGS) -o $(RUNME)_$(RUNME_EXT) -I. -I.. $< -L. -l$(TARGET)
c_compile_cxx: $(SRCDIR)$(RUNME).cxx
$(COMPILETOOL) $(CXX) $(CXXFLAGS) -o $(RUNME)_$(RUNME_EXT) -I. -I.. $< -L. -l$(TARGET)
$(eval c_compile: c_compile_$(RUNME_EXT))
# This target is used for the unit tests: if we don't have any test code to
# run, we at least can check that the generated header can be included without
# giving any syntax errors, both when compiling it as C and C++ code.
c_syntax_check: c_syntax_check_c c_syntax_check_cxx
c_syntax_check_c:
$(CC) -fsyntax-only -x c -I$(SRCDIR)$(INTERFACEDIR) $(C_HEADER)
c_syntax_check_cxx:
$(CXX) -fsyntax-only -x c++ -I$(SRCDIR)$(INTERFACEDIR) $(C_HEADER)
# -----------------------------------------------------------------
# Run C example
# -----------------------------------------------------------------
c_run: c_compile
env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) ./$(RUNME)_$(RUNME_EXT) $(RUNPIPE)
# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------
c_version:
$(CC) --version | head -n 1
# -----------------------------------------------------------------
# Cleaning the C examples
# -----------------------------------------------------------------
c_clean:
rm -f *_wrap.[ch] *_wrap.cxx
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@SO@
rm -f $(RUNME)_c $(RUNME)_cxx
##################################################################
##### SCILAB ######
##################################################################

View file

@ -1,5 +0,0 @@
# see top-level Makefile.in
simple
class
std_vector
exception

View file

@ -1,24 +0,0 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
check_c: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=c c_run
check_cxx: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=cxx c_run
check: check_c check_cxx
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c_cpp
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' c_clean

View file

@ -1,28 +0,0 @@
/* File : example.cxx */
#include "example.h"
#define M_PI 3.14159265358979323846
/* Move the shape to a new location */
void Shape::move(double dx, double dy) {
x += dx;
y += dy;
}
int Shape::nshapes = 0;
double Circle::area() {
return M_PI*radius*radius;
}
double Circle::perimeter() {
return 2*M_PI*radius;
}
double Square::area() {
return width*width;
}
double Square::perimeter() {
return 4*width;
}

View file

@ -1,34 +0,0 @@
/* File : example.h */
class Shape {
public:
Shape() {
nshapes++;
}
virtual ~Shape() {
nshapes--;
}
double x, y;
void move(double dx, double dy);
virtual double area() = 0;
virtual double perimeter() = 0;
static int nshapes;
};
class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { }
virtual double area();
virtual double perimeter();
};
class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { }
virtual double area();
virtual double perimeter();
};

View file

@ -1,9 +0,0 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
/* Let's just grab the original header file here */
%include "example.h"

View file

@ -1,44 +0,0 @@
#include <stdio.h>
#include "example_wrap.h"
int main(int argc, char **argv) {
printf("Creating some objects from C:\n");
Circle* c = Circle_new(10);
printf(" Created circle\n");
Square* s = Square_new(10);
printf(" Created square\n");
printf("\nA total of %d shapes were created\n", Shape_nshapes_get());
Circle_x_set(c, 20);
Circle_y_set(c, 30);
Shape* shape = (Shape*) s;
Shape_x_set(shape, -10);
Shape_y_set(shape, 5);
printf("\nHere is their current positions:\n");
printf(" Circle = (%f %f)\n", Circle_x_get(c), Circle_y_get(c));
printf(" Square = (%f %f)\n", Square_x_get(s), Square_y_get(s));
printf("\nHere are some properties of the shapes:\n");
Shape* shapes[] = {(Shape*) c, (Shape*) s};
int i;
for (i = 0; i < 2; i++) {
printf(" %s\n", i ? "Square" : "Circle");
printf(" area = %f\n", Shape_area(shapes[i]));
printf(" perimeter = %f\n", Shape_perimeter(shapes[i]));
}
printf("\nGuess I'll clean up now\n");
Square_delete(s);
Circle_delete(c);
printf("%d shapes remain\n", Shape_nshapes_get());
printf("Goodbye from C\n");
return 0;
}

View file

@ -1,41 +0,0 @@
#include <iostream>
#include "example_wrap.h"
int main(int argc, char **argv) {
{ // Block containing the Circle and Square objects.
std::cout << "Creating some objects from C++:\n";
example::Circle c(10);
std::cout << " Created circle\n";
example::Square s(10);
std::cout << " Created square\n";
std::cout << "\nA total of " << example::Shape::nshapes() << " shapes were created\n";
c.x(20);
c.y(30);
example::Shape& shape = s;
shape.x(-10);
shape.y(5);
std::cout << "\nHere is their current positions:\n";
std::cout << " Circle = (" << c.x() << " " << c.y() << ")\n";
std::cout << " Square = (" << s.x() << " " << s.y() << ")\n";
std::cout << "\nHere are some properties of the shapes:\n";
example::Shape* shapes[] = {&c, &s};
for (int i = 0; i < 2; i++) {
std::cout << " " << (i ? "Square" : "Circle") << "\n";
std::cout << " area = " << shapes[i]->area() << "\n";
std::cout << " perimeter = " << shapes[i]->perimeter() << "\n";
}
std::cout << "\nGuess I'll clean up now\n";
}
std::cout << example::Shape::nshapes() << " shapes remain\n";
std::cout << "Goodbye from C++\n";
return 0;
}

View file

@ -1,24 +0,0 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
check_c: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=c c_run
check_cxx: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=cxx c_run
check: check_c check_cxx
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c_cpp
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' c_clean

View file

@ -1,45 +0,0 @@
/* File : example.h */
#include <string.h>
#ifndef SWIG
struct A {
};
#define SWIG_THROW(...)
#endif
class Exc {
public:
Exc(int c, const char *m) {
code = c;
strncpy(msg,m,255);
}
int code;
char msg[256];
};
class Test {
public:
int simple() SWIG_THROW(int&) {
throw(37);
return 1;
}
int message() SWIG_THROW(const char *) {
throw("I died.");
return 1;
}
int hosed() SWIG_THROW(Exc) {
throw(Exc(42,"Hosed"));
return 1;
}
int unknown() SWIG_THROW(A*) {
static A a;
throw &a;
return 1;
}
int multi(int x) SWIG_THROW(int, const char *, Exc) {
if (x == 1) throw(37);
if (x == 2) throw("Bleah!");
if (x == 3) throw(Exc(42,"No-go-diggy-die"));
return 1;
}
};

View file

@ -1,17 +0,0 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
%typemap(throws, noblock="1") Exc {
SWIG_exception(SWIG_RuntimeError, $1.msg);
}
/* This needs to be defined for SWIG, even though it can't be used in C++ any more. */
#define SWIG_THROW(...) throw(__VA_ARGS__)
/* Let's just grab the original header file here */
%include "example.h"

View file

@ -1,47 +0,0 @@
/*
* NOTE: this won't run with -noexcept flag
*/
#include <stdio.h>
#include <assert.h>
#include "example_wrap.h"
static void show_exception(const char* prefix) {
SWIG_CException* ex = SWIG_CException_get_pending();
assert(ex);
printf("%s exception: %s (%d)\n", prefix, SWIG_CException_msg_get(ex), SWIG_CException_code_get(ex));
SWIG_CException_reset_pending();
}
int main() {
Test *t = Test_new();
Test_unknown(t);
show_exception("Unknown");
Test_simple(t);
show_exception("Int");
Test_message(t);
show_exception("String");
Test_hosed(t);
show_exception("Custom");
int i;
for (i = 0; i < 4; ++i) {
Test_multi(t, i);
if (!SWIG_CException_get_pending()) {
printf("Success for i=%d\n", i);
} else {
printf("For i=%d", i);
show_exception("");
}
}
Test_delete(t);
return 0;
}

View file

@ -1,69 +0,0 @@
/*
* NOTE: this won't run with -noexcept flag
*/
#include <stdio.h>
#include <assert.h>
#include "example_wrap.h"
using Exception = example::SWIG_CException;
static int exit_code = 0;
static void show_exception(const char* prefix, Exception const& ex) {
printf("%s exception: %s (%d)\n", prefix, ex.msg(), ex.code());
}
static void missing_exception(const char* prefix) {
printf("*** ERROR: %s: expected exception not thrown.\n", prefix);
exit_code++;
}
int main() {
example::Test t;
try {
t.unknown();
missing_exception("Unknown");
} catch (Exception const& e) {
show_exception("Unknown", e);
}
try {
t.simple();
missing_exception("Int");
} catch (Exception const& e) {
show_exception("Int", e);
}
try {
t.message();
missing_exception("String");
} catch (Exception const& e) {
show_exception("String", e);
}
try {
t.hosed();
missing_exception("Custom");
} catch (Exception const& e) {
show_exception("Custom", e);
}
for (int i = 0; i < 4; ++i) {
try {
t.multi(i);
if (i == 0) {
printf("Success for i=%d\n", i);
} else {
missing_exception("Multi");
}
} catch (Exception const& e) {
printf("For i=%d", i);
show_exception("", e);
}
}
return exit_code;
}

View file

@ -1,18 +0,0 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
SRCS = example.c
TARGET = example
INTERFACE = example.i
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=c c_run
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' c_clean

View file

@ -1,18 +0,0 @@
/* File : example.c */
/* A global variable */
double Foo = 3.0;
/* Compute the greatest common divisor of positive integers */
int gcd(int x, int y) {
int g;
g = y;
while (x > 0) {
g = x;
x = y % x;
y = g;
}
return g;
}

View file

@ -1,7 +0,0 @@
/* File : example.i */
%module example
%inline %{
extern int gcd(int x, int y);
extern double Foo;
%}

View file

@ -1,15 +0,0 @@
#include <stdio.h>
#include "example_wrap.h"
int main(int argc, char **argv) {
int a = 42;
int b = 105;
int g = example_gcd(a, b);
printf("The gcd of %d and %d is %d\n", a, b, g);
printf("Foo = %f\n", Foo);
Foo = 3.1415926;
printf("Foo = %f\n", Foo);
return 0;
}

View file

@ -1,18 +0,0 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=c c_run
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c_cpp
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' c_clean

View file

@ -1,2 +0,0 @@
/* File : example.c */

View file

@ -1,18 +0,0 @@
/* File : example.h */
#include <string>
#include <vector>
class A {
public:
A() : name(""), value(0) {}
A(std::string str, int i) : name(str), value(i) {}
std::string name;
int value;
};
class Klass {
public:
std::vector<int> vi;
std::vector<A> va;
};

View file

@ -1,14 +0,0 @@
/* File : example.i */
%module example
%include <std_string.i>
%include <std_vector.i>
%{
#include "example.h"
%}
/* Let's just grab the original header file here */
%include "example.h"
%template(Vint) std::vector<int>;
%template(VA) std::vector<A>;

View file

@ -1,42 +0,0 @@
#include <stdio.h>
#include "example_wrap.h"
int main() {
Klass *klass = Klass_new();
Vint *vint = Klass_vi_get(klass);
VA *va = Klass_va_get(klass);
printf("Vector of ints:\n");
printf("size=%zd\ncapacity=%zd\n\n", Vint_size(vint), Vint_capacity(vint));
int i;
for (i = 0; i < 10; i++)
Vint_push_back(vint, i*i);
printf("size=%zd\ncapacity=%zd\n\n", Vint_size(vint), Vint_capacity(vint));
for (i = 0; i < Vint_size(vint); i++)
printf("%d%c", Vint_get(vint, i), i+1 == Vint_size(vint) ? '\n' : ',');
Vint_clear(vint);
Vint_reserve(vint, 100);
printf("\nsize=%zd\ncapacity=%zd\n", Vint_size(vint), Vint_capacity(vint));
printf("\nVector of objects:\n");
for (i = 0; i < 10; i++) {
A *a = A_new_std_string_i("hello", i);
VA_push_back(va, a);
A_delete(a);
}
for (i = 0; i < VA_size(va); i++) {
A *a = VA_get(va, i);
printf("%s %d\n", A_name_get(a), A_value_get(a));
}
Klass_delete(klass);
return 0;
}

View file

@ -1,6 +1,6 @@
%module argcargvtest
#if !defined(SWIGC) && !defined(SWIGCSHARP) && !defined(SWIGD) && !defined(SWIGGO) && !defined(SWIGGUILE) && !defined(SWIGJAVA) && !defined(SWIGJAVASCRIPT) && !defined(SWIGMZSCHEME) && !defined(SWIGOCAML) && !defined(SWIGR) && !defined(SWIGSCILAB)
#if !defined(SWIGCSHARP) && !defined(SWIGD) && !defined(SWIGGO) && !defined(SWIGGUILE) && !defined(SWIGJAVA) && !defined(SWIGJAVASCRIPT) && !defined(SWIGMZSCHEME) && !defined(SWIGOCAML) && !defined(SWIGR) && !defined(SWIGSCILAB)
%include <argcargv.i>
%apply (int ARGC, char **ARGV) { (size_t argc, const char **argv) }

View file

@ -1,239 +0,0 @@
#######################################################################
# Makefile for C test-suite
#######################################################################
LANGUAGE = c
C = gcc
CXX = g++
RUNMESUFFIX = _runme
srcdir = @srcdir@
top_srcdir = ../@top_srcdir@
top_builddir = ../@top_builddir@
# This can be set to ":" to avoid progress messages.
ECHO_PROGRESS := echo
CPP_TEST_CASES := \
c_backend_cpp_natural_std_string \
c_backend_cpp_exception
CPP11_TEST_CASES := \
cpp11_shared_ptr_const \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_upcast \
# The following tests are currently broken and need to be fixed.
FAILING_C_TESTS := \
arrays \
funcptr \
function_typedef \
lextype \
li_carrays \
nested \
nested_extend_c \
nested_structs \
typedef_struct \
union_parameter \
unions \
FAILING_CPP_TESTS := \
apply_signed_char \
array_member \
array_typedef_memberin \
arrayref \
arrays_dimensionless \
arrays_global \
arrays_global_twodim \
constant_pointers \
enum_thorough \
extend \
extend_default \
extern_c \
extern_template_method \
funcptr_cpp \
global_scope_types \
grouping \
import_nomodule \
li_attribute \
li_attribute_template \
li_boost_shared_ptr_attribute \
li_std_auto_ptr \
li_std_deque \
li_std_wstring \
li_windows \
member_funcptr_galore \
member_pointer \
member_pointer_const \
mixed_types \
nested_class \
template_basic \
template_default \
template_enum \
template_explicit \
template_typedef_fnc \
typedef_array_member \
typedef_funcptr \
typedef_struct_cpp \
typemap_namespace \
typemap_various \
using_extend \
varargs \
varargs_overload \
virtual_poly \
cpp11_ref_qualifiers \
cpp11_ref_qualifiers_typemaps \
cpp11_result_of \
cpp11_rvalue_reference \
cpp11_rvalue_reference2 \
cpp11_rvalue_reference3 \
cpp11_type_aliasing \
# Ignore warnings about failing to apply typemaps because none are defined:
# usually there is no need for special typemaps in C.
char_binary.cpptest director_binary_string.cpptest li_typemaps.cpptest li_typemaps_apply.cpptest long_long_apply.cpptest: SWIGOPT += -w453
include $(srcdir)/../common.mk
# Overridden variables here
# Suppress warnings about experimental status and unsupported features -- there are just too many of those for now for these warnings to be useful.
SWIGOPT += -w524 -w779
%.ctest: SWIGOPT += -nocxx
# Tests for which C++ wrappers currently don't compile.
contract.cpptest: SWIG_NOCXX = -nocxx # Class derived from a base class with multiple base classes and hence ignored.
conversion.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type not handled specially.
conversion_namespace.cpptest: SWIG_NOCXX = -nocxx # Conversion operator name not handled correctly.
conversion_ns_template.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return not handled specially.
cpp11_default_delete.cpptest: SWIG_NOCXX = -nocxx # Assignment operator and r-value references not handled.
cpp11_explicit_conversion_operators.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type.
cpp11_noexcept.cpptest: SWIG_NOCXX = -nocxx # Assignment operator.
default_constructor.cpptest: SWIG_NOCXX = -nocxx # Something weird with OSRSpatialReferenceShadow.
director_conversion_operators.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type.
director_frob.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type.
extend_template_method.cpptest: SWIG_NOCXX = -nocxx # Wrong form of template function name.
features.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type not handled specially.
global_namespace.cpptest: SWIG_NOCXX = -nocxx # Const const reference type.
li_carrays_cpp.cpptest: SWIG_NOCXX = -nocxx # Arrays not really supported currently.
li_cdata_cpp.cpptest: SWIG_NOCXX = -nocxx # No support for multiarg typemaps required here.
member_template.cpptest: SWIG_NOCXX = -nocxx # Wrong form of template function name.
multiple_inheritance_abstract.cpptest: SWIG_NOCXX = -nocxx # Multiple inheritance not supported.
multiple_inheritance_interfaces.cpptest: SWIG_NOCXX = -nocxx
multiple_inheritance_nspace.cpptest: SWIG_NOCXX = -nocxx
multiple_inheritance_shared_ptr.cpptest: SWIG_NOCXX = -nocxx
namespace_class.cpptest: SWIG_NOCXX = -nocxx # Many broken type names.
operator_pointer_ref.cpptest: SWIG_NOCXX = -nocxx
operbool.cpptest: SWIG_NOCXX = -nocxx
overload_null.cpptest: SWIG_NOCXX = -nocxx
overload_template.cpptest: SWIG_NOCXX = -nocxx
overload_template_fast.cpptest: SWIG_NOCXX = -nocxx
pure_virtual.cpptest: SWIG_NOCXX = -nocxx
rename1.cpptest: SWIG_NOCXX = -nocxx
rename2.cpptest: SWIG_NOCXX = -nocxx
rename3.cpptest: SWIG_NOCXX = -nocxx
rename4.cpptest: SWIG_NOCXX = -nocxx
rename_wildcard.cpptest: SWIG_NOCXX = -nocxx
return_const_value.cpptest: SWIG_NOCXX = -nocxx
smart_pointer_member.cpptest: SWIG_NOCXX = -nocxx
smart_pointer_template_const_overload.cpptest: SWIG_NOCXX = -nocxx
smart_pointer_templatemethods.cpptest: SWIG_NOCXX = -nocxx # Wrong form of template function name.
struct_initialization_cpp.cpptest: SWIG_NOCXX = -nocxx # Arrays in initialization not supported.
template_const_ref.cpptest: SWIG_NOCXX = -nocxx
template_default_arg_overloaded.cpptest: SWIG_NOCXX = -nocxx
template_inherit_abstract.cpptest: SWIG_NOCXX = -nocxx
template_methods.cpptest: SWIG_NOCXX = -nocxx
template_nested.cpptest: SWIG_NOCXX = -nocxx
template_nested_flat.cpptest: SWIG_NOCXX = -nocxx
template_qualifier.cpptest: SWIG_NOCXX = -nocxx
template_static.cpptest: SWIG_NOCXX = -nocxx
typemap_array_qualifiers.cpptest: SWIG_NOCXX = -nocxx # Arrays not supported.
valuewrapper_const.cpptest: SWIG_NOCXX = -nocxx # Misplaced const.
# Avoid conflict with the C++ keyword for some tests.
SWIG_NS = $*
dynamic_cast.cpptest: SWIG_NS = dyn_cast
typename.cpptest: SWIG_NS = type_name
%.multicpptest: SWIGOPT += -namespace $*
%.cpptest: SWIGOPT += -namespace $(SWIG_NS) $(SWIG_NOCXX)
SRCDIR = ../$(srcdir)/
# Make function to check if we have an executable test for the given test base name.
define has_runme
-f $(srcdir)/$1$(RUNMESUFFIX).c -o -f $(srcdir)/$1$(RUNMESUFFIX).cxx
endef
# Rules for the different types of tests
%.cpptest:
$(setup)
+(cd $* && $(swig_and_compile_cpp))
+if [ $(call has_runme,$*) ]; then \
$(do_run_testcase); \
else \
cd $* && $(call syntax_check_testcase,$*); \
fi
%.ctest:
$(setup)
+(cd $* && $(swig_and_compile_c))
+if [ $(call has_runme,$*) ]; then \
$(do_run_testcase); \
else \
cd $* && $(call syntax_check_testcase,$*,_c); \
fi
%.multicpptest:
$(setup)
+(cd $* && $(swig_and_compile_multi_cpp))
+if [ $(call has_runme,$*) ]; then \
$(do_run_testcase); \
else \
cd $* && for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list`; do \
$(call syntax_check_testcase,$${f}) || exit 1; \
done; \
fi
# Makes a directory for the testcase if it does not exist
setup = \
if [ $(call has_runme,$*) ]; then \
$(ECHO_PROGRESS) "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \
else \
$(ECHO_PROGRESS) "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \
fi; \
if [ ! -d $* ]; then \
mkdir $*; \
fi;
# Checks the header syntax if there is no runnable testcase for it.
#
# The optional second argument can be "_c" to check syntax using C compiler only
# (by default both C and C++ compilers are used).
syntax_check_testcase = \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \
SRCDIR='$(SRCDIR)' \
INTERFACEDIR='$(INTERFACEDIR)' \
C_HEADER=$1_wrap.h \
c_syntax_check$2
# Compiles C files then runs the testcase unconditionally.
do_run_testcase = \
cd $* && $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \
SRCDIR='$(SRCDIR)' \
RUNME=$*$(RUNMESUFFIX) \
RUNME_EXT=$(patsubst .%,%,$(suffix $(wildcard $(srcdir)/$*$(RUNMESUFFIX).c*))) \
TARGET='$*' \
c_run
# Clean: remove testcase directories
%.clean:
@if [ -d $* ]; then \
rm -rf $*; \
fi;
clean:
@rm -f *_wrap.* *~ *.exe *.dll *.so *.out *runme

View file

@ -1,12 +0,0 @@
#include "abstract_access/abstract_access_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
abstract_access_D *d = abstract_access_D_new();
assert(abstract_access_D_do_x(d) == 1);
abstract_access_D_delete(d);
return 0;
}

View file

@ -1,12 +0,0 @@
#include "abstract_inherit_ok_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
abstract_inherit_ok_Foo* const spam = (abstract_inherit_ok_Foo*)abstract_inherit_ok_Spam_new();
assert(abstract_inherit_ok_Foo_blah(spam) == 0);
abstract_inherit_ok_Foo_delete(spam);
return 0;
}

View file

@ -1,15 +0,0 @@
#include "abstract_typedef/abstract_typedef_wrap.h"
#include <stdbool.h>
#include <assert.h>
int main(int argc, const char *argv[]) {
abstract_typedef_Engine *e = abstract_typedef_Engine_new();
abstract_typedef_A *a = abstract_typedef_A_new();
assert(abstract_typedef_AbstractBaseClass_write((abstract_typedef_AbstractBaseClass*)a, e) == true);
abstract_typedef_A_delete(a);
abstract_typedef_Engine_delete(e);
return 0;
}

View file

@ -1,18 +0,0 @@
#include "abstract_virtual/abstract_virtual_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
abstract_virtual_B *b = abstract_virtual_B_new();
abstract_virtual_D *d = abstract_virtual_D_new();
abstract_virtual_E *e = abstract_virtual_E_new();
assert(abstract_virtual_B_foo(b) == 0);
assert(abstract_virtual_D_foo(d) == 0);
assert(abstract_virtual_E_foo(e) == 0);
abstract_virtual_B_delete(b);
abstract_virtual_D_delete(d);
abstract_virtual_E_delete(e);
return 0;
}

View file

@ -1,34 +0,0 @@
#include "access_change_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
access_change_BaseInt *ba = access_change_BaseInt_new();
access_change_DerivedInt *d = access_change_DerivedInt_new();
access_change_BottomInt *bo = access_change_BottomInt_new();
assert(access_change_BaseInt_PublicProtectedPublic1(ba) == 0);
assert(access_change_BaseInt_PublicProtectedPublic2(ba) == 0);
assert(access_change_BaseInt_PublicProtectedPublic3(ba) == 0);
assert(access_change_BaseInt_PublicProtectedPublic4(ba) == 0);
assert(access_change_DerivedInt_WasProtected1((access_change_DerivedInt*)ba) == 0);
assert(access_change_DerivedInt_WasProtected2((access_change_DerivedInt*)ba) == 0);
assert(access_change_DerivedInt_WasProtected3((access_change_DerivedInt*)ba) == 0);
assert(access_change_DerivedInt_WasProtected4((access_change_DerivedInt*)ba) == 0);
assert(access_change_BottomInt_PublicProtectedPublic1((access_change_BottomInt*)ba) == 0);
assert(access_change_BottomInt_PublicProtectedPublic2((access_change_BottomInt*)ba) == 0);
assert(access_change_BottomInt_PublicProtectedPublic3((access_change_BottomInt*)ba) == 0);
assert(access_change_BottomInt_PublicProtectedPublic4((access_change_BottomInt*)ba) == 0);
assert(access_change_BottomInt_WasProtected1((access_change_BottomInt*)ba) == 0);
assert(access_change_BottomInt_WasProtected2((access_change_BottomInt*)ba) == 0);
assert(access_change_BottomInt_WasProtected3((access_change_BottomInt*)ba) == 0);
assert(access_change_BottomInt_WasProtected4((access_change_BottomInt*)ba) == 0);
access_change_BaseInt_delete(ba);
access_change_DerivedInt_delete(d);
access_change_BottomInt_delete(bo);
return 0;
}

View file

@ -1,14 +0,0 @@
#include "add_link/add_link_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
add_link_Foo *f = add_link_Foo_new();
add_link_Foo *f2 = add_link_Foo_blah(f);
assert(f2 != 0);
add_link_Foo_delete(f);
add_link_Foo_delete(f2);
return 0;
}

View file

@ -1,29 +0,0 @@
#include "anonymous_bitfield/anonymous_bitfield_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
anonymous_bitfield_Foo *f = anonymous_bitfield_Foo_new();
assert(f != 0);
anonymous_bitfield_Foo_x_set(f, 1);
assert(anonymous_bitfield_Foo_x_get(f) == 1);
assert(anonymous_bitfield_Foo_y_get(f) == 0);
anonymous_bitfield_Foo_y_set(f, 0);
assert(anonymous_bitfield_Foo_x_get(f) == 1);
assert(anonymous_bitfield_Foo_y_get(f) == 0);
anonymous_bitfield_Foo_f_set(f, 1);
assert(anonymous_bitfield_Foo_f_get(f) == 1);
anonymous_bitfield_Foo_z_set(f, 1);
assert(anonymous_bitfield_Foo_z_get(f) == 1);
anonymous_bitfield_Foo_seq_set(f, 1);
assert(anonymous_bitfield_Foo_seq_get(f) == 1);
anonymous_bitfield_Foo_delete(f);
return 0;
}

View file

@ -1,14 +0,0 @@
#include <assert.h>
#include "c_backend_cpp_exception/c_backend_cpp_exception_wrap.h"
int main()
{
assert(c_backend_cpp_exception_checkVal_get() == 0);
c_backend_cpp_exception_throwSomeKnownException();
assert(c_backend_cpp_exception_checkVal_get() == 1);
c_backend_cpp_exception_throwSomeUnknownException();
assert(c_backend_cpp_exception_checkVal_get() == 2);
return 0;
}

View file

@ -1,18 +0,0 @@
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "c_backend_cpp_natural_std_string/c_backend_cpp_natural_std_string_wrap.h"
int main()
{
char buf[] = "World, ";
char *myComposedString = c_backend_cpp_natural_std_string_myStringAppend(buf, "Hello!");
assert(myComposedString);
assert(strcmp(myComposedString, "World, Hello!") == 0);
free(myComposedString);
return 0;
}

View file

@ -1,14 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cast_operator/cast_operator_wrap.h"
int main() {
cast_operator_A *a = cast_operator_A_new();
if (strcmp(cast_operator_A_tochar(a), "hi"))
fprintf(stderr, "cast failed\n");
cast_operator_A_delete(a);
exit(0);
}

View file

@ -1,200 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "char_strings/char_strings_wrap.h"
int main() {
char *CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible.";
char *OTHERLAND_MSG = "Little message from the safe world.";
int count = 10000;
int i = 0;
// get functions
for (i=0; i<count; i++) {
char *str = char_strings_GetCharHeapString();
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char get 1 failed, iteration %d\n", i);
exit(1);
}
char_strings_DeleteCharHeapString();
}
for (i=0; i<count; i++) {
const char *str = char_strings_GetConstCharProgramCodeString();
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char get 2 failed, iteration %d\n", i);
exit(1);
}
char_strings_DeleteCharHeapString();
}
for (i=0; i<count; i++) {
char *str = char_strings_GetCharStaticString();
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char get 3 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char *str = char_strings_GetCharStaticStringFixed();
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char get 4 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
const char *str = char_strings_GetConstCharStaticStringFixed();
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char get 5 failed, iteration %d\n", i);
exit(1);
}
}
// set functions
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetCharHeapString(str, i)) {
fprintf(stderr, "Test char set 1 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetCharStaticString(str, i)) {
fprintf(stderr, "Test char set 2 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetCharArrayStaticString(str, i)) {
fprintf(stderr, "Test char set 3 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetConstCharHeapString(str, i)) {
fprintf(stderr, "Test char set 4 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetConstCharStaticString(str, i)) {
fprintf(stderr, "Test char set 5 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetConstCharArrayStaticString(str, i)) {
fprintf(stderr, "Test char set 6 failed, iteration %d\n", i);
exit(1);
}
}
// get set function
for (i=0; i<count; i++) {
char ping[256];
sprintf(ping, "%s%d", OTHERLAND_MSG, i);
char *pong = char_strings_CharPingPong(ping);
if (strcmp(ping, pong) != 0) {
fprintf(stderr, "Test PingPong 1 failed.\nExpected:%s\nReceived:%s\n", ping, pong);
exit(1);
}
}
// variables
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
char_strings_global_char_set(str);
if (strcmp(char_strings_global_char_get(), str) != 0) {
fprintf(stderr, "Test variables 1 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
sprintf(char_strings_global_char_array1_get(), "%s%d", OTHERLAND_MSG, i);
if (strcmp(char_strings_global_char_array1_get(), str) != 0) {
fprintf(stderr, "Test variables 2 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
sprintf(char_strings_global_char_array2_get(), "%s%d", OTHERLAND_MSG, i);
if (strcmp(char_strings_global_char_array2_get(), str) != 0) {
fprintf(stderr, "Test variables 3 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
if (strcmp(char_strings_global_const_char_get(), CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test variables 3 failed, iteration %d\n", i);
exit(1);
}
}
/*
for (i=0; i<count; i++) {
if (strcmp(global_const_char_array1, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test variables 5 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
if (strcmp(global_const_char_array2, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test variables 6 failed, iteration %d\n", i);
exit(1);
}
}
*/
// char *& tests
for (i=0; i<count; i++) {
const char **str = char_strings_GetConstCharPointerRef();
if (strcmp(*str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char pointer ref get failed, iteration %d\n",i);
exit(1);
}
}
for (i=0; i<count; i++) {
char *str = (char*) malloc(sizeof(char) * 256);
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetConstCharPointerRef((const char **)&str, i)) {
fprintf(stderr, "Test char pointer ref set failed, iteration %d\n", i);
exit(1);
}
}
exit(0);
}

View file

@ -1,16 +0,0 @@
#include "cpp11_shared_ptr_const_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
cpp11_shared_ptr_const_Foo* f;
cpp11_shared_ptr_const_Foo* f2;
f = cpp11_shared_ptr_const_Foo_new(17);
assert(cpp11_shared_ptr_const_Foo_get_m(f) == 17);
f2 = cpp11_shared_ptr_const_foo(f);
assert(cpp11_shared_ptr_const_Foo_get_m(f2) == 17);
cpp11_shared_ptr_const_Foo_delete(f2);
cpp11_shared_ptr_const_Foo_delete(f);
return 0;
}

View file

@ -1,26 +0,0 @@
#include "cpp11_shared_ptr_upcast_wrap.h"
#include <assert.h>
int main(int argc, const char *argv[]) {
{
cpp11_shared_ptr_upcast_Derived* d;
d = cpp11_shared_ptr_upcast_Derived_new_i(17);
assert( cpp11_shared_ptr_upcast_base_num1((cpp11_shared_ptr_upcast_Base *)d) == -1 );
assert( cpp11_shared_ptr_upcast_derived_num1(d) == 17 );
cpp11_shared_ptr_upcast_Derived_delete(d);
}
{
cpp11_shared_ptr_upcast_Derived2* d2;
d2 = cpp11_shared_ptr_upcast_Derived2_new_i(289);
assert( cpp11_shared_ptr_upcast_base2_num1((cpp11_shared_ptr_upcast_Base2 *)d2) == -1 );
assert( cpp11_shared_ptr_upcast_derived2_num1(d2) == 289 );
cpp11_shared_ptr_upcast_Derived2_delete(d2);
}
return 0;
}

View file

@ -1,109 +0,0 @@
#include "cpp_basic/cpp_basic_wrap.h"
#include <assert.h>
#include <stdio.h>
int main(int argc, const char *argv[]) {
cpp_basic_Foo *f = cpp_basic_Foo_new(5);
// test global static variables
// TODO: Implement or document as not available
/*
assert(init_ref != 0);
global_fptr_set(f);
assert(cpp_basic_Foo_num_get(global_fptr_get()) == 5);
assert(cpp_basic_Foo_num_get(global_fref_get()) == -4);
cpp_basic_Foo_num_set(f, 6);
global_fref_set(f);
assert(cpp_basic_Foo_num_get(global_fref_get()) == 6);
cpp_basic_Foo_num_set(f, 7);
global_fval_set(f);
assert(cpp_basic_Foo_num_get(global_fval_get()) == 7);
*/
cpp_basic_Foo_num_set(f, 5);
assert(cpp_basic_Foo_num_get(f) == 5);
assert(cpp_basic_Foo_func1(f, 2) == 20);
assert(cpp_basic_Foo_func2(f, 2) == -10);
// function pointer set/get tests are missing
// because of unclear implementation details
//foo_func_ptr_set(f, &cpp_basic_Foo_func1);
// test of global static variable is missing
// because of unclear implementation details
//assert(c_init_ref != 0);
cpp_basic_Bar *b = cpp_basic_Bar_new();
// check default value set by constructor
assert(cpp_basic_Bar_cint_get(b) == 3);
// check default value set by cpp_basic_Bar initializer
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fval_get(b)) == 15);
// change, recheck
cpp_basic_Foo_num_set(cpp_basic_Bar_fval_get(b), 2);
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fval_get(b)) == 2);
// check references
assert(cpp_basic_Bar_fref_get(b) != 0);
// check global static value and references
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fref_get(b)) == -4);
cpp_basic_Foo_num_set(cpp_basic_Bar_fref_get(b), 1);
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fref_get(b)) == 1);
// create new cpp_basic_Bar instance and check static member value
cpp_basic_Bar *b2 = cpp_basic_Bar_new();
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fref_get(b2)) == 1);
cpp_basic_Bar_delete(b2);
b2 = 0;
// Try to set a pointer
cpp_basic_Bar_fptr_set(b, f);
assert(cpp_basic_Bar_test(b, 2, f) == 9);
assert(cpp_basic_Bar_test(b, 2, 0) == 4);
cpp_basic_Foo *f2 = cpp_basic_Bar_testFoo(b, 2, f);
assert(cpp_basic_Foo_num_get(f2) == 11);
cpp_basic_Foo_delete(f2);
f2 = 0;
// test static variables
cpp_basic_Bar_global_fptr_set(f);
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_global_fptr_get()) == 5);
cpp_basic_Foo_num_set(f, 6);
cpp_basic_Bar_global_fref_set(f);
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_global_fref_get()) == 6);
cpp_basic_Foo_num_set(f, 7);
cpp_basic_Bar_global_fval_set(f);
assert(cpp_basic_Foo_num_get(cpp_basic_Bar_global_fval_get()) == 7);
// getting, setting and calling function pointers isn't supported yet
#if 0
SomeTypeForMemFnPtr func1 = get_func1_ptr();
cpp_basic_Foo_func_ptr_set(f, func1);
assert(test_func_ptr(f, 2) == 28);
SomeTypeForMemFnPtr func2 = get_func2_ptr();
cpp_basic_Foo_func_ptr_set(f, func2);
assert(test_func_ptr(f, 2) == -14);
#endif
cpp_basic_Bar_delete(b);
cpp_basic_Foo_delete(f);
cpp_basic_Fl_Window *w = cpp_basic_Fl_Window_new();
// Test whether macro worked for code extension
// and test optional function parameters
cpp_basic_Fl_Window_show(w);
cpp_basic_Fl_Window_show_pv(w, 0);
cpp_basic_Fl_Window_show_pv_pv(w, 0, 0);
cpp_basic_Fl_Window_delete(w);
w = 0;
return 0;
}

View file

@ -1,71 +0,0 @@
#include "cpp_enum/cpp_enum_wrap.h"
#include <assert.h>
#include <stdio.h>
int main(int argc, const char *argv[]) {
enum cpp_enum_SOME_ENUM e = cpp_enum_ENUM_ONE, *p;
// check the constructor's default value
cpp_enum_StructWithEnums *s = cpp_enum_StructWithEnums_new();
assert(cpp_enum_StructWithEnums_some_enum_get(s) == cpp_enum_ENUM_ONE);
// check setter
cpp_enum_StructWithEnums_some_enum_set(s, cpp_enum_ENUM_TWO);
assert(cpp_enum_StructWithEnums_some_enum_get(s) == cpp_enum_ENUM_TWO);
// check function call
cpp_enum_StructWithEnums_enum_test1(s, e, &e, &e);
// check function call
cpp_enum_StructWithEnums_enum_test2(s, e, &e, &e);
// check function call
assert(cpp_enum_StructWithEnums_enum_test3(s) == cpp_enum_ENUM_ONE);
// check function call
assert(cpp_enum_StructWithEnums_enum_test4(s) == cpp_enum_ENUM_TWO);
// check function call
p = cpp_enum_StructWithEnums_enum_test5(s);
assert(*p == cpp_enum_ENUM_TWO);
// check function call
p = cpp_enum_StructWithEnums_enum_test6(s);
assert(*p == cpp_enum_ENUM_TWO);
// check function call
p = cpp_enum_StructWithEnums_enum_test7(s);
assert(*p == cpp_enum_ENUM_TWO);
// check function call
p = cpp_enum_StructWithEnums_enum_test8(s);
assert(*p == cpp_enum_ENUM_TWO);
cpp_enum_StructWithEnums_delete(s);
cpp_enum_Foo *f = cpp_enum_Foo_new();
// check the constructor's default value
assert(cpp_enum_Foo_hola_get(f) == cpp_enum_Foo_Hello);
cpp_enum_Foo_hola_set(f, cpp_enum_Foo_Hi);
assert(cpp_enum_Foo_hola_get(f) == cpp_enum_Foo_Hi);
cpp_enum_Foo_delete(f);
//check C enum
cpp_enum_hi_set(cpp_enum_Hi);
cpp_enum_hi_set(cpp_enum_Hello);
// check typedef enum
cpp_enum_play_state t;
t = cpp_enum_PLAY;
assert(t == 1);
t = cpp_enum_STOP;
assert(t == 0);
return 0;
}

View file

@ -1,12 +0,0 @@
#include <assert.h>
#include "enum_rename/enum_rename_wrap.h"
int main() {
assert(enum_rename_M_Jan == 0);
assert(enum_rename_May == 1);
assert(enum_rename_M_Dec == 2);
assert(enum_rename_S_Can == 1);
assert(enum_rename_S_Must == 2);
}

View file

@ -1,14 +0,0 @@
#include <assert.h>
#include <stdlib.h>
#include "enums/enums_wrap.h"
int main() {
assert(GlobalInstance == globalinstance1);
assert(iFoo_Char == 'a');
enums_bar2(1);
enums_bar3(1);
enums_bar1(1);
exit(0);
}

View file

@ -1,46 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "exception_order/exception_order_wrap.h"
int main() {
exception_order_A* a = exception_order_A_new();
exception_order_A_foo(a);
if (!exception_order_SWIG_CException_get_pending()) {
fprintf(stderr, "foo: bad exception order\n");
} else {
exception_order_SWIG_CException_reset_pending();
}
exception_order_A_bar(a);
if (!exception_order_SWIG_CException_get_pending()) {
fprintf(stderr, "bar: bad exception order\n");
} else {
exception_order_SWIG_CException_reset_pending();
}
exception_order_A_foobar(a);
if (!exception_order_SWIG_CException_get_pending()) {
fprintf(stderr, "foobar: bad exception order\n");
} else {
exception_order_SWIG_CException_reset_pending();
}
exception_order_A_barfoo(a, 1);
if (!exception_order_SWIG_CException_get_pending()) {
fprintf(stderr, "barfoo(1): bad exception order\n");
} else {
exception_order_SWIG_CException_reset_pending();
}
exception_order_A_barfoo(a, 2);
if (!exception_order_SWIG_CException_get_pending()) {
fprintf(stderr, "barfoo(2): bad exception order\n");
} else {
exception_order_SWIG_CException_reset_pending();
}
exit(0);
}

View file

@ -1,13 +0,0 @@
#include <assert.h>
#include <string.h>
#include "global_vars/global_vars_wrap.h"
int main(int argc, const char *argv[])
{
global_vars_init();
assert(strcmp(global_vars_b_get(), "string b") == 0);
assert(global_vars_x_get() == 1234);
return 0;
}

View file

@ -1,15 +0,0 @@
#include "li_boost_shared_ptr_wrap.h"
#include <assert.h>
#include <string.h>
int main(int argc, const char *argv[]) {
{
li_boost_shared_ptr::Klass k("me oh my");
assert( k.getValue() == "me oh my" );
}
{
li_boost_shared_ptr::Klass k{li_boost_shared_ptr_factorycreate()};
assert( k.getValue() == "factorycreate" );
}
}

View file

@ -1,26 +0,0 @@
#include "li_std_map/li_std_map_wrap.h"
#include <assert.h>
int main() {
li_std_map_A* a1 = li_std_map_A_new_i(3);
li_std_map_A* a2 = li_std_map_A_new_i(7);
li_std_map_mapA* mA = li_std_map_mapA_new();
li_std_map_mapA_set(mA, 1, a1);
li_std_map_mapA_set(mA, 2, a2);
assert( li_std_map_mapA_size(mA) == 2 );
{
li_std_map_A* a = li_std_map_mapA_get(mA, 1);
assert( li_std_map_A_val_get(a) == 3 );
}
assert( !li_std_map_mapA_has_key(mA, 3) );
li_std_map_mapA_delete(mA);
li_std_map_A_delete(a2);
li_std_map_A_delete(a1);
return 0;
}

View file

@ -1,42 +0,0 @@
#include "li_std_pair/li_std_pair_wrap.h"
#include <assert.h>
int main() {
{
li_std_pair_IntPair* intPair = li_std_pair_makeIntPair(7, 6);
assert(li_std_pair_IntPair_first_get(intPair)==7 && li_std_pair_IntPair_second_get(intPair)==6);
assert(li_std_pair_product1(intPair) == 42);
assert(li_std_pair_product2(intPair) == 42);
assert(li_std_pair_product3(intPair) == 42);
li_std_pair_IntPair_delete(intPair);
}
{
li_std_pair_IntPair* intPairPtr = li_std_pair_makeIntPairPtr(7, 6);
assert(li_std_pair_IntPair_first_get(intPairPtr)==7 && li_std_pair_IntPair_second_get(intPairPtr)==6);
assert(li_std_pair_product1(intPairPtr) == 42);
assert(li_std_pair_product2(intPairPtr) == 42);
assert(li_std_pair_product3(intPairPtr) == 42);
}
{
li_std_pair_IntPair* intPairRef = li_std_pair_makeIntPairRef(7, 6);
assert(li_std_pair_IntPair_first_get(intPairRef)==7 && li_std_pair_IntPair_second_get(intPairRef)==6);
assert(li_std_pair_product1(intPairRef) == 42);
assert(li_std_pair_product2(intPairRef) == 42);
assert(li_std_pair_product3(intPairRef) == 42);
}
{
li_std_pair_IntPair* intPairConstRef = li_std_pair_makeIntPairConstRef(7, 6);
assert(li_std_pair_IntPair_first_get(intPairConstRef)==7 && li_std_pair_IntPair_second_get(intPairConstRef)==6);
assert(li_std_pair_product1(intPairConstRef) == 42);
assert(li_std_pair_product2(intPairConstRef) == 42);
assert(li_std_pair_product3(intPairConstRef) == 42);
}
}

View file

@ -1,33 +0,0 @@
#include "li_std_set/li_std_set_wrap.h"
#include <assert.h>
int main() {
{
li_std_set_IntSet* is = li_std_set_IntSet_new();
li_std_set_IntSet_add(is, 1);
li_std_set_IntSet_add(is, 4);
li_std_set_IntSet_add(is, 9);
assert( li_std_set_IntSet_size(is) == 3 );
assert( li_std_set_IntSet_has(is, 4) );
assert( !li_std_set_IntSet_has(is, 16) );
li_std_set_IntSet_delete(is);
}
{
li_std_set_StringSet* ss = li_std_set_StringSet_new();
li_std_set_StringSet_add(ss, "foo");
li_std_set_StringSet_add(ss, "bar");
assert( li_std_set_StringSet_size(ss) == 2 );
assert( li_std_set_StringSet_has(ss, "bar") );
assert( !li_std_set_StringSet_has(ss, "baz") );
li_std_set_StringSet_delete(ss);
}
return 0;
}

View file

@ -1,26 +0,0 @@
#include "li_std_string_wrap.h"
#include <assert.h>
using namespace li_std_string;
int main(int argc, const char *argv[]) {
Structure st;
assert( st.MemberString().empty() );
st.MemberString("bloordyblop");
assert( st.MemberString() == "bloordyblop" );
assert( st.MemberString2() == "member string 2" );
assert( st.ConstMemberString() == "const member string" );
st.StaticMemberString(std::string("static bloordyblop"));
assert( st.StaticMemberString() == "static bloordyblop" );
assert( Structure::StaticMemberString2() == "static member string 2" );
assert( Structure::ConstStaticMemberString() == "const static member string" );
Foo f;
assert( f.test("1+") == "1+1" );
}

View file

@ -1,22 +0,0 @@
#include "li_std_vector/li_std_vector_wrap.h"
#include <assert.h>
int main() {
size_t i;
li_std_vector_IntVector* iv = li_std_vector_IntVector_new();
assert( li_std_vector_IntVector_size(iv) == 0 );
li_std_vector_IntVector_push_back(iv, 1);
li_std_vector_IntVector_push_back(iv, 4);
li_std_vector_IntVector_push_back(iv, 9);
assert( li_std_vector_IntVector_size(iv) == 3 );
for ( i = 0; i < 3; i++ ) {
assert( li_std_vector_IntVector_get(iv, i) == (i + 1)*(i + 1) );
}
li_std_vector_IntVector_delete(iv);
return 0;
}

View file

@ -1,25 +0,0 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "operator_overload/operator_overload_wrap.h"
int main() {
operator_overload_Op_sanity_check();
operator_overload_Op *op1 = operator_overload_Op_new_i(1), *op2 = operator_overload_Op_new_i(2), *op3 = operator_overload_Op_copy(op1);
assert(operator_overload_Op_NotEqual(op1, op2));
operator_overload_Op_PlusPlusPrefix(op3);
assert(operator_overload_Op_EqualEqual(op2, op3));
assert(operator_overload_Op_GreaterThanEqual(op2, op1));
operator_overload_Op_PlusEqual(op3, op1);
assert(operator_overload_Op_LessThan(op1, op2) && operator_overload_Op_LessThan(op2, op3));
assert(3 == *operator_overload_Op_IndexInto(op3, operator_overload_Op_IndexIntoConst(op2, operator_overload_Op_Functor(op1))));
assert(5 == operator_overload_Op_Functor_i(op3, 2));
operator_overload_Op_delete(op1);
operator_overload_Op_delete(op2);
operator_overload_Op_delete(op3);
exit(0);
}

View file

@ -1,25 +0,0 @@
%module c_backend_cpp_exception
%exception {
try {
$action
} catch(SomeKnownException) {
checkVal = 1;
} catch(...) {
checkVal = 2;
}
}
%inline %{
class SomeKnownException{};
class SomeUnkownException{};
int checkVal = 0;
void throwSomeKnownException(void) {
throw SomeKnownException();
}
void throwSomeUnknownException(void) {
throw SomeUnkownException();
}
%}

View file

@ -1,13 +0,0 @@
%module c_backend_cpp_natural_std_string
%feature ("nspace", "1");
%include std_string.i
%inline %{
static std::string& myStringAppend(std::string &someString, const std::string &appendedString)
{
someString += appendedString;
return someString;
}
%}

View file

@ -11,10 +11,8 @@ struct SomeStruct {
auto addAlternateConst(int x, int y) const -> int;
auto addAlternateNoExcept(int x, int y) noexcept -> int;
auto addAlternateConstNoExcept(int x, int y) const noexcept -> int;
#ifndef SWIGC
auto addAlternateMemberPtrParm(int x, int (SomeStruct::*mp)(int, int)) -> int;
auto addAlternateMemberPtrConstParm(int x, int (SomeStruct::*mp)(int, int) const) const -> int;
#endif // !SWIGC
// Returning a reference didn't parse in SWIG < 4.1.0 (#231)
auto output() -> Hello&;
@ -28,7 +26,6 @@ auto SomeStruct::addAlternate(int x, int y) -> int { return x + y; }
auto SomeStruct::addAlternateConst(int x, int y) const -> int { return x + y; }
auto SomeStruct::addAlternateNoExcept(int x, int y) noexcept -> int { return x + y; }
auto SomeStruct::addAlternateConstNoExcept(int x, int y) const noexcept -> int { return x + y; }
#ifndef SWIGC
auto SomeStruct::addAlternateMemberPtrParm(int x, int (SomeStruct::*mp)(int, int)) -> int {
return 100*x + (this->*mp)(x, x);
}
@ -36,6 +33,5 @@ auto SomeStruct::addAlternateMemberPtrConstParm(int x, int (SomeStruct::*mp)(int
return 1000*x + (this->*mp)(x, x);
}
auto SomeStruct::output() -> Hello& { static Hello h; return h; }
#endif // !SWIGC
%}

View file

@ -31,9 +31,7 @@ class Foo {
return -a*num;
}
#ifndef SWIGC
int (Foo::*func_ptr)(int);
#endif // SWIGC
const char* __str__() const { return "Foo"; }
};
@ -102,7 +100,6 @@ Foo Bar::global_fval = Foo(3);
%}
/* member function tests */
#ifndef SWIGC
%inline %{
int (Foo::*get_func1_ptr())(int) {
return &Foo::func1;
@ -117,7 +114,6 @@ int test_func_ptr(Foo *f, int a) {
}
%}
#endif // SWIGC
#ifdef __cplusplus

View file

@ -34,7 +34,7 @@ public:
%}
#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif

View file

@ -1,7 +1,7 @@
/* File : example.i */
%module dynamic_cast
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD) && !defined(SWIGC)
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD)
%apply SWIGTYPE *DYNAMIC { Foo * };
#endif
@ -17,7 +17,7 @@ public:
};
%}
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGO) || defined(SWIGD) || defined(SWIGC)
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGO) || defined(SWIGD)
%typemap(out) Foo *blah {
Bar *downcast = dynamic_cast<Bar *>($1);
*(Bar **)&$result = downcast;
@ -69,7 +69,7 @@ char *do_test(Bar *b) {
}
%}
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD) && !defined(SWIGC)
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD)
// A general purpose function for dynamic casting of a Foo *
%{
static swig_type_info *

View file

@ -1,7 +1,7 @@
%module functors
// Rename operator() only if the language does not already do this by default
#if defined(SWIGC) || defined(SWIGCSHARP) || defined(SWIGGO) || defined(SWIGGUILE) || defined(SWIGJAVA) || defined(SWIGJAVASCRIPT) || defined(SWIGPHP) || defined(SWIGSCILAB) || defined(SWIGTCL)
#if defined(SWIGCSHARP) || defined(SWIGGO) || defined(SWIGGUILE) || defined(SWIGJAVA) || defined(SWIGJAVASCRIPT) || defined(SWIGPHP) || defined(SWIGSCILAB) || defined(SWIGTCL)
%rename(Funktor) operator();
#endif

View file

@ -1,5 +1,5 @@
#if !defined(SWIGC) && !defined(SWIGGO)
// Prevent C/Go from generating a C include/Go module import - this test is not set up as true multiple modules
#if !defined(SWIGGO)
// Prevent Go from generating a Go module import - this test is not set up as true multiple modules
%module import_fragments_a
#endif

View file

@ -128,8 +128,6 @@ struct ExtendingOptArgs1 {};
struct ExtendingOptArgs2 {};
%}
#ifndef SWIGC
// For strlen/strcpy
%{
#include <string.h>
@ -152,5 +150,3 @@ struct VarargConstructor {
}
};
%}
#endif // !SWIGC

View file

@ -44,7 +44,7 @@
# define SWIG_SHARED_PTR_NAMESPACE SwigBoost
#endif
#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGR)
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGR)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif

View file

@ -1,6 +1,6 @@
%module li_boost_shared_ptr_attribute
#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif

View file

@ -1,6 +1,6 @@
%module li_boost_shared_ptr_bits
#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif

View file

@ -4,7 +4,7 @@
#include <boost/shared_ptr.hpp>
%}
#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGR)
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGR)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif

View file

@ -30,7 +30,7 @@
%}
#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif

View file

@ -22,7 +22,7 @@
%template(set_int) std::multiset<int>;
%template(v_int) std::vector<int>;
%template(set_string) std::set<std::string>;
#elif defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP)
#elif defined(SWIGJAVA) || defined(SWIGCSHARP)
// This operator is only defined because it's needed to store objects of
// type Foo in std::set in C++, we don't need to wrap it.
%ignore operator<;

View file

@ -9,20 +9,11 @@ struct ExtendMe {
};
%}
// Use different names for the C backend to be consistent with the global prefix used.
%inline {
#ifdef SWIGC
%#define ADD_PREFIX(name) memberin_extend_ ## name
#else
%#define ADD_PREFIX(name) name
#endif
}
%{
#include <map>
#include <string.h>
std::map<ExtendMe*, char *> ExtendMeStringMap;
void ADD_PREFIX(ExtendMe_thing_set)(ExtendMe *self, const char *val) {
void ExtendMe_thing_set(ExtendMe *self, const char *val) {
char *old_val = ExtendMeStringMap[self];
delete [] old_val;
if (val) {
@ -32,7 +23,7 @@ void ADD_PREFIX(ExtendMe_thing_set)(ExtendMe *self, const char *val) {
ExtendMeStringMap[self] = 0;
}
}
char * ADD_PREFIX(ExtendMe_thing_get)(ExtendMe *self) {
char * ExtendMe_thing_get(ExtendMe *self) {
return ExtendMeStringMap[self];
}
%}

View file

@ -8,37 +8,16 @@ namespace foo {
public:
};
}
%}
// C uses different naming convention, with all functions starting with the class prefix
// and using the global namespace prefix too, if specified (which is the case for the tests).
#ifdef SWIGC
%{
foo::bar *namespace_extend_foo_bar_new() {
return new foo::bar;
}
void namespace_extend_foo_bar_delete(foo::bar *self) {
delete self;
}
int namespace_extend_foo_bar_blah(foo::bar *self, int x) {
return x;
}
%}
#else
%{
foo::bar *new_foo_bar() {
return new foo::bar;
}
void delete_foo_bar(foo::bar *self) {
delete self;
}
int foo_bar_blah(foo::bar *self, int x) {
return x;
}
%}
#endif
namespace foo {
class bar {

View file

@ -16,9 +16,7 @@ public:
int blah(int x);
int spam(int x);
Integer bar(Integer x);
#ifndef SWIGC
void (Foo:: *func_ptr) (int);
#endif
};
inline Foo :: Foo () {}

View file

@ -15,11 +15,6 @@ see bottom for a set of possible tests
SWIGWARN_IGNORE_OPERATOR_LOR);
#endif
#if defined(SWIGC)
%warnfilter(SWIGWARN_IGNORE_OPERATOR_EQ,
SWIGWARN_IGNORE_OPERATOR_PLUSPLUS);
#endif
#if !defined(SWIGLUA) && !defined(SWIGR)
%rename(Equal) operator =;
%rename(PlusEqual) operator +=;

View file

@ -27,19 +27,6 @@ std::string ExceptionVars(double i, double j) {
%}
%rename(ExceptionVars) Space::exceptionvars;
#ifdef SWIGC
%exception Space::exceptionvars %{
$action
result = (char*)$symname(1.0,2.0).c_str(); // Should expand to ExceptionVars
result = (char*)$name(3.0,4.0).c_str(); // Should expand to Space::exceptionvars
// above will not compile if the variables are not expanded properly
result = (char*)"$action $name $symname $overname $wrapname";
%}
#else
%exception Space::exceptionvars %{
$action
result = $symname(1.0,2.0); // Should expand to ExceptionVars
@ -47,9 +34,6 @@ std::string ExceptionVars(double i, double j) {
// above will not compile if the variables are not expanded properly
result = "$action $name $symname $overname $wrapname $parentclassname $parentclasssymname";
%}
#endif
%inline %{
namespace Space {
std::string exceptionvars(double i, double j) {
@ -59,20 +43,6 @@ std::string exceptionvars(double i, double j) {
%}
#ifdef SWIGC
%exception Space::overloadedmethod %{
$action
result = (char*)Space::$symname(1.0).c_str();
result = (char*)$name().c_str();
result = (char*)$name(2.0).c_str();
// above will not compile if the variables are not expanded properly
result = (char*)"$action $name $symname $overname $wrapname";
// $decl
%}
#else
%exception Space::overloadedmethod %{
$action
result = Space::$symname(1.0);
@ -83,8 +53,6 @@ std::string exceptionvars(double i, double j) {
// $decl
%}
#endif
%inline %{
namespace Space {
std::string overloadedmethod(double j) {

View file

@ -9,7 +9,7 @@ struct NoDefaultCtor {
};
%}
#if defined(SWIGC) || defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGD)
#if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGD)
%template(VectorNoDefaultCtor) std::vector<NoDefaultCtor>;
#endif

View file

@ -1,5 +0,0 @@
#ifndef SWIG_SHARED_PTR_NAMESPACE
#define SWIG_SHARED_PTR_NAMESPACE boost
#endif
%include <std_shared_ptr.i>

View file

@ -1,359 +0,0 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* c.swg
* ----------------------------------------------------------------------------- */
%include <cheader.swg>
%insert("runtime") "clabels.swg"
%insert("runtime") %{
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#define SWIG_contract_assert(expr, msg) if(!(expr)) { printf("%s\n", msg); SWIG_exit(0); } else
%}
%fragment("stdbool_inc", "cheader") {#include <stdbool.h>}
%define same_macro_all_primitive_types_but_void(macro_name, TM)
macro_name(TM, short);
macro_name(TM, unsigned short);
macro_name(TM, int);
macro_name(TM, unsigned int);
macro_name(TM, long);
macro_name(TM, unsigned long);
macro_name(TM, long long);
macro_name(TM, unsigned long long);
macro_name(TM, char);
macro_name(TM, signed char);
macro_name(TM, unsigned char);
macro_name(TM, float);
macro_name(TM, double);
macro_name(TM, size_t);
%enddef
// This is used to handle all primitive types as just themselves.
// This macro doesn't cover const references, use either cref_as_value or
// cref_as_ptr below in addition to it.
// Notice that const pointers are mapped to non-const ones as we need to
// declare variables of this type when it's used as a return type, and top
// level const doesn't matter anyhow in the function declarations.
%define same_type(TM, T)
%typemap(TM) T, const T "T"
%typemap(TM) T*, T&, T[ANY], T[] "T *"
%typemap(TM) const T*, const T[ANY], const T[] "const T *"
%typemap(TM) T**, T*&, T*[ANY], T[ANY][ANY] "T **"
%typemap(TM) const T**, const T*&, T *const &, const T*[ANY], const T[ANY][ANY] "const T **"
// constant pointers
%typemap(TM) T * const "T *"
%typemap(TM) T* * const "T* *"
%typemap(TM) const T* * const "const T* *"
%enddef
%define cref_as_value(TM, T)
%typemap(TM) const T& "T"
%enddef
%define cref_as_ptr(TM, T)
%typemap(TM) const T& "T *"
%enddef
%define same_type_all_primitive_types_but_void(TM)
%enddef
//Used by 'in' and 'out' typemaps
%define same_action(TM, T, ACTION, ACTION_CREF)
%typemap(TM) T, const T ACTION
%typemap(TM) const T& ACTION_CREF
%typemap(TM) T*, T&, T[ANY], T[] ACTION
%typemap(TM) const T*, const T[ANY], const T[] ACTION
%typemap(TM) T**, T*&, T*[ANY], T[ANY][ANY] ACTION
%typemap(TM) const T**, const T*&, const T*[ANY], const T[ANY][ANY] ACTION
// constant pointers
%typemap(TM) T * const ACTION
%typemap(TM) T* * const ACTION
%typemap(TM) const T* * const ACTION
%enddef
%define same_action_all_primitive_types(TM, ACTION, ACTION_CREF)
same_action(TM, short, ACTION, ACTION_CREF);
same_action(TM, unsigned short, ACTION, ACTION_CREF);
same_action(TM, int, ACTION, ACTION_CREF);
same_action(TM, unsigned int, ACTION, ACTION_CREF);
same_action(TM, long, ACTION, ACTION_CREF);
same_action(TM, unsigned long, ACTION, ACTION_CREF);
same_action(TM, long long, ACTION, ACTION_CREF);
same_action(TM, unsigned long long, ACTION, ACTION_CREF);
same_action(TM, char, ACTION, ACTION_CREF);
same_action(TM, signed char, ACTION, ACTION_CREF);
same_action(TM, unsigned char, ACTION, ACTION_CREF);
//unsigned only
same_action(TM, float, ACTION, ACTION_CREF);
same_action(TM, double, ACTION, ACTION_CREF);
same_action(TM, size_t, ACTION, ACTION_CREF);
%typemap(TM) void*, void const* ACTION
%enddef
// "ctype" is the type used with C wrapper functions.
// void
%typemap(ctype) void "void"
%typemap(ctype) void*, void& "void *"
%typemap(ctype) const void&, const void* "const void *"
%typemap(ctype) void**, void*& "void **"
%typemap(ctype) const void**, const void*& "const void **"
// constant pointers
%typemap(ctype) void* * const "void* * const"
%typemap(ctype) const void* * const "const void* * const"
same_macro_all_primitive_types_but_void(same_type,ctype);
same_macro_all_primitive_types_but_void(cref_as_value,ctype);
// trivial typemap for arrays of void pointers to avoid applying the object typemaps to them
%typemap(ctype) void*[ANY] "void **"
// objects
%typemap(ctype) SWIGTYPE "$&resolved_type*"
%typemap(ctype) SWIGTYPE * "$resolved_type*"
%typemap(ctype) SWIGTYPE * const & "$resolved_type*"
%typemap(ctype) SWIGTYPE & "$*resolved_type*"
%typemap(ctype) SWIGTYPE [ANY] "$resolved_type*"
%typemap(ctype) SWIGTYPE * [ANY] "$resolved_type**"
// enums
%typemap(ctype) enum SWIGTYPE "$resolved_type"
%typemap(ctype) enum SWIGTYPE * "$resolved_type*"
%typemap(ctype) enum SWIGTYPE & "$*resolved_type*"
%typemap(ctype) enum SWIGTYPE [ANY] "$resolved_type*"
%typemap(ctype, fragment="stdbool_inc") bool, const bool, const bool & "bool"
%typemap(ctype, fragment="stdbool_inc") bool *, const bool *, bool & "bool *"
// Typemaps for assigning wrapper parameters to local variables
same_action_all_primitive_types(in, "$1 = ($1_ltype) $input;", "$1 = &$input;")
%typemap(in) short [ANY], int [ANY], long [ANY], long long [ANY], char [ANY], float [ANY], double [ANY], unsigned char [ANY] "$1 = ($1_basetype *) $input;"
%typemap(in) short * [ANY], int * [ANY], long * [ANY], long long * [ANY], char * [ANY], float * [ANY], double * [ANY] "$1 = ($1_basetype *) $input;"
%typemap(in, fragment="stdbool_inc") bool, bool *, bool **, const bool, const bool * "$1 = ($1_ltype) $input;"
%typemap(in, fragment="stdbool_inc") bool & "$1 = ($1_basetype *) $input;"
%typemap(in, fragment="stdbool_inc") const bool &, const bool * "$1 = ($1_basetype *) $input;"
%typemap(in) enum SWIGTYPE "$1 = ($1_ltype) $input;"
%typemap(in) enum SWIGTYPE &,enum SWIGTYPE * "$1 = ($1_ltype) $input;"
%typemap(in) SWIGTYPE [] "$1 = ($1_ltype) $input;"
%typemap(in) SWIGTYPE ((&)[ANY]) "$1 = ($1_ltype) $input;"
%typemap(in) SWIGTYPE (CLASS::*) {
if ($input)
$1 = *($&1_ltype) &$input;
}
%typemap(in) SWIGTYPE "$1 = *($1_ltype *)$input;"
%typemap(in) SWIGTYPE * "$1 = ($1_ltype) $input;"
%typemap(in) SWIGTYPE *[ANY] {
if ($input) {
$1 = ($1_ltype) malloc($1_dim0 * sizeof($1_basetype));
size_t i = 0;
for ( ; i < $1_dim0; ++i)
if ($input[i])
$1[i] = ($*1_ltype) $input[i];
else
$1[i] = ($*1_ltype) 0;
}
else
$1 = ($1_ltype) 0;
}
%typemap(in) SWIGTYPE [ANY][ANY] {
if ($input) {
$1 = ($1_ltype) malloc($1_dim0 * $1_dim1 * sizeof($1_basetype));
size_t i = 0, j = 0;
for ( ; i < $1_dim0; ++i) {
for ( ; j < $1_dim1; ++j) {
if ($input[i][j])
$1[i][j] = * ($*1_ltype) $input[i][j];
else
$1[i][j] = * ($*1_ltype) 0;
}
}
}
else
$1 = ($1_ltype) 0;
}
%typemap(freearg) SWIGTYPE * [ANY], SWIGTYPE * [ANY][ANY] {
if ($input)
free($input);
}
%typemap(in) SWIGTYPE & %{
$1 = ($1_ltype) $input;
%}
// Typemaps for assigning result values to a special return variable
same_action_all_primitive_types(out, "$result = $1;", "$result = *$1;")
%typemap(out) void ""
%typemap(out, fragment="stdbool_inc") bool, bool *, const bool, const bool * "$result = ($1_ltype) $1;"
%typemap(out, fragment="stdbool_inc") bool &, const bool & "$result = $1;"
%typemap(out) enum SWIGTYPE "$result = (int) $1;"
%typemap(out) enum SWIGTYPE &, enum SWIGTYPE * "$result = $1;"
%typemap(out) SWIGTYPE (CLASS::*) {
*($&1_ltype) &$result = $1;
}
%typemap(out) SWIGTYPE "$result = (SwigObj*)new $1_ltype($1);"
%typemap(out) SWIGTYPE *, SWIGTYPE & "$result = (SwigObj*) $1;"
%typemap(out) SWIGTYPE * [ANY], SWIGTYPE [ANY][ANY] {
static SwigObj **_temp = 0;
if ($1) {
size_t i = 0;
if (_temp) {
for ( ; i < $1_dim0; ++i)
delete ($1_ltype *)_temp[i];
free(_temp);
}
_temp = (SwigObj**) malloc($1_dim0 * sizeof(SwigObj*));
for (i = 0 ; i < $1_dim0; ++i) {
if ($1[i]) {
_temp[i] = $1[i];
}
else
_temp[i] = (SwigObj*) 0;
}
$result = ($1_ltype) _temp;
}
else
$result = ($1_ltype) 0;
}
/* Typecheck typemaps - The purpose of these is merely to issue a warning for overloaded C++ functions
* that cannot be overloaded in the wrappers as more than one C++ type maps to a single C type */
%typecheck(SWIG_TYPECHECK_BOOL)
bool,
const bool &
""
%typecheck(SWIG_TYPECHECK_CHAR)
char,
const char &
""
%typecheck(SWIG_TYPECHECK_INT8)
signed char,
const signed char &
""
%typecheck(SWIG_TYPECHECK_UINT8)
unsigned char,
const unsigned char &
""
%typecheck(SWIG_TYPECHECK_INT16)
short,
const short &
""
%typecheck(SWIG_TYPECHECK_UINT16)
unsigned short,
const unsigned short &
""
%typecheck(SWIG_TYPECHECK_INT32)
int,
long,
const int &,
const long &
""
%typecheck(SWIG_TYPECHECK_UINT32)
unsigned int,
unsigned long,
const unsigned int &,
const unsigned long &
""
%typecheck(SWIG_TYPECHECK_INT64)
long long,
const long long &
""
%typecheck(SWIG_TYPECHECK_UINT64)
unsigned long long,
const unsigned long long &
""
%typecheck(SWIG_TYPECHECK_FLOAT)
float,
const float &
""
%typecheck(SWIG_TYPECHECK_DOUBLE)
double,
const double &
""
%typecheck(SWIG_TYPECHECK_STRING)
char *,
char *&,
char[ANY],
char[]
""
%typecheck(SWIG_TYPECHECK_POINTER)
SWIGTYPE,
SWIGTYPE *,
SWIGTYPE &,
SWIGTYPE &&,
SWIGTYPE *const&,
SWIGTYPE [],
SWIGTYPE (CLASS::*)
""
#ifdef SWIG_CPPMODE
%insert("runtime") %{
typedef struct SwigObj SwigObj;
%}
%insert("cheader") %{
typedef struct SwigObj SwigObj;
%}
#endif // SWIG_CPPMODE
#ifdef SWIG_C_EXCEPT
%include "cexcept.swg"
#else // !SWIG_C_EXCEPT
// Still define the macro used in some standard typemaps, but we can't
// implement it in C, so just allow the user predefining their own version.
%insert("runtime") %{
#ifndef SWIG_exception
#define SWIG_exception(code, msg)
#endif
%}
#endif // SWIG_C_EXCEPT/!SWIG_C_EXCEPT
%insert("runtime") %{
#ifdef __cplusplus
extern "C" {
#endif
SWIGEXPORTC int SWIG_exit(int code) { exit(code); }
#ifdef __cplusplus
}
#endif
%}

View file

@ -1,109 +0,0 @@
/* -----------------------------------------------------------------------------
* clabels.swg
*
* Exception handling code and typemaps for C module.
* ----------------------------------------------------------------------------- */
// This function is special: it's used by various typemaps (via SWIG_exception
// macro below) and needs to be defined, but we don't want to export it.
%ignore SWIG_CException_Raise;
%{
extern "C" void SWIG_CException_Raise(int code, const char* msg);
%}
// This class is special too because its name is used in c.cxx source. It is
// only defined if the code there didn't predefine SWIG_CException_DEFINED
// because the class is already defined in another module.
//
// It has to be seen by SWIG because we want to generate wrappers for its
// public functions to be able to use it from the application code.
%inline %{
#ifndef SWIG_CException_DEFINED
class SWIG_CException {
public:
SWIG_CException(const SWIG_CException& ex) throw() : code(ex.code), msg(strdup(ex.msg)) { }
~SWIG_CException() { free(const_cast<char*>(msg)); }
const int code;
const char* const msg;
static SWIG_CException* get_pending() throw() {
return PendingException;
}
static void reset_pending() throw() {
if (PendingException) {
delete PendingException;
PendingException = 0;
}
}
private:
friend void SWIG_CException_Raise(int code, const char* msg);
static thread_local SWIG_CException* PendingException;
SWIG_CException(int code, const char* msg) : code(code), msg(strdup(msg)) { }
SWIG_CException& operator=(const SWIG_CException& ex);
};
#endif // SWIG_CException_DEFINED
%}
// This part is implementation only and doesn't need to be seen by SWIG.
%{
#ifndef SWIG_CException_DEFINED
thread_local SWIG_CException *SWIG_CException::PendingException = 0;
SWIGEXPORTC void SWIG_CException_Raise(int code, const char* msg) {
delete SWIG_CException::PendingException;
SWIG_CException::PendingException = new SWIG_CException(code, msg);
}
#endif // SWIG_CException_DEFINED
%}
#ifdef SWIG_CXX_WRAPPERS
// This is somewhat of a hack, but our generated header may include another
// generated header, when using multiple modules, and defining swig_check() in
// all of them would result in errors, so we use SWIG_swig_check_DEFINED to
// prevent this from happening.
//
// This also has a nice side effect of allowing the user code to predefine this
// symbol and provide their own SWIG_swig_check_DEFINED implementation to
// customize exception handling.
%insert("cxxcode") %{
#ifndef SWIG_swig_check_DEFINED
#define SWIG_swig_check_DEFINED 1
inline void swig_check() {
if (SWIG_CException* swig_ex = SWIG_CException::get_pending()) {
SWIG_CException swig_ex_copy{*swig_ex};
delete swig_ex;
SWIG_CException::reset_pending();
throw swig_ex_copy;
}
}
template <typename T> T swig_check(T x) {
swig_check();
return x;
}
#endif // SWIG_swig_check_DEFINED
%}
#endif // SWIG_CXX_WRAPPERS
%insert("runtime") "swigerrors.swg"
#define SWIG_exception(code, msg)\
SWIG_CException_Raise(code, msg)
%typemap(throws, noblock="1") char *, const char * {
SWIG_exception(SWIG_RuntimeError, $1);
}
%typemap(throws, noblock="1") SWIGTYPE {
SWIG_exception(SWIG_UnknownError, "exception of type $1_type");
}

View file

@ -1,20 +0,0 @@
/* -----------------------------------------------------------------------------
* cheader.swg
* ----------------------------------------------------------------------------- */
%insert("cheader") %{
#ifndef SWIGIMPORT
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
# if defined(STATIC_LINKED)
# define SWIGDLLIMPORT
# else
# define SWIGDLLIMPORT __declspec(dllimport)
# endif
# else
# define SWIGDLLIMPORT
# endif
# define SWIGIMPORT extern SWIGDLLIMPORT
#endif
#include <stddef.h>
%}

View file

@ -1,19 +0,0 @@
/* -----------------------------------------------------------------------------
* clabels.swg
*
* Definitions of C specific preprocessor symbols.
* ----------------------------------------------------------------------------- */
// this is used instead of default SWIGEXPORT symbol
#ifndef SWIGEXPORTC
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) || defined(__APPLE__)
# define SWIGEXPORTC
# else
# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
# define SWIGEXPORTC __attribute__ ((visibility("default")))
# else
# define SWIGEXPORTC
# endif
# endif
#endif

View file

@ -1,4 +0,0 @@
%include <std_except.i>
%apply size_t { std::size_t };
%apply const size_t& { const std::size_t & };

View file

@ -1,20 +0,0 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_except.i
*
* Typemaps used by the STL wrappers that throw exceptions.
* These typemaps are used when methods are declared with an STL exception specification, such as
* size_t at() const throw (std::out_of_range);
* ----------------------------------------------------------------------------- */
%{
#include <stdexcept>
%}
namespace std
{
%ignore exception;
struct exception {};
}

View file

@ -1,61 +0,0 @@
/* -----------------------------------------------------------------------------
* std_map.i
*
* SWIG typemaps for std::map
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// ------------------------------------------------------------------------
// std::map
// ------------------------------------------------------------------------
%{
#include <map>
#include <stdexcept>
%}
namespace std {
template<class K, class T, class C = std::less<K> > class map {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
typedef std::pair< const K, T > value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
map();
map(const map& other);
size_t size() const;
bool empty() const;
void clear();
%extend {
const T& get(const K& key) throw (std::out_of_range) {
std::map< K, T, C >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(const K& key, const T& x) {
(*self)[key] = x;
}
void del(const K& key) throw (std::out_of_range) {
std::map< K, T, C >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(const K& key) const {
std::map< K, T, C >::const_iterator i = self->find(key);
return i != self->end();
}
}
};
}

View file

@ -1,24 +0,0 @@
%{
#include <utility>
%}
// Ideal, especially for the simple/primitive types, would be to represent
// pair<T,U> as a C struct with the 2 fields, but for now we use the simplest
// possible implementation, with the accessor functions required to work with
// the fields.
namespace std {
template <class T, class U> struct pair {
typedef T first_type;
typedef U second_type;
pair();
pair(T first, U second);
pair(const pair& other);
template <class T2, class U2> pair(const pair<T2, U2> &other);
T first;
U second;
};
}

View file

@ -1,48 +0,0 @@
/* -----------------------------------------------------------------------------
* std_set.i
*
* SWIG typesets for std::set
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// ------------------------------------------------------------------------
// std::set
// ------------------------------------------------------------------------
%{
#include <set>
#include <stdexcept>
%}
namespace std {
template<class T> class set {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T key_type;
typedef T value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
set();
set(const set& other);
size_t size() const;
bool empty() const;
void clear();
%extend {
bool add(const T& item) {
return self->insert(item).second;
}
bool del(const T& item) {
return self->erase(item) != 0;
}
bool has(const T& item) const {
return self->count(item) != 0;
}
}
};
}

View file

@ -1,84 +0,0 @@
// This could be predefined in e.g. our own boost_shared_ptr.i
#ifndef SWIG_SHARED_PTR_NAMESPACE
#define SWIG_SHARED_PTR_NAMESPACE std
#endif
%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
%naturalvar TYPE;
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
// Replace the default "delete arg1" with the code destroying the smart pointer itself instead.
%feature("unref") TYPE "(void)arg1; delete smartarg1;"
// All smart pointers look like normal objects to the code using the interface.
%typemap(ctype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >&,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >*
"$typemap(ctype, TYPE)";
// Typemap for smart pointer type itself: these are somewhat special because we represent empty shared pointers as null pointers at C level because there is
// no advantage in using a non-null pointer in this case, while testing for NULL is much simpler than testing whether a shared pointer is empty.
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > empty) %{
$1 = $input ? *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE>*)$input : empty; %}
%typemap(in) const SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >& (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > empty) %{
$1 = $input ? (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE>*)$input : &empty; %}
// Note that "&" here is required because "$1" ends up being SwigValueWrapper and not the shared pointer itself. This is wrong and should be fixed by disabling
// the use of SwigValueWrapper for shared pointers entirely, as it's never needed for them.
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > %{ $result = (&$1 ? new $1_ltype($1) : 0); %}
// Use of "*" here is due to the fact that "$1" is a pointer, but we want to test the smart pointer itself.
%typemap(out) const SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE>& %{ $result = (*$1 ? $1 : 0); %}
// And for the plain type.
%typemap(in) CONST TYPE (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE > *)$input;
if (!smartarg || !smartarg->get()) {
SWIG_exception(SWIG_RuntimeError, "$1_type value is null");
return $null;
}
$1 = **smartarg;%}
%typemap(out) CONST TYPE %{
$result = (SwigObj*) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE >(new $1_ltype($1));%}
// Plain type pointer.
%typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE > *)$input;
$1 = (TYPE *)(smartarg ? smartarg->get() : 0);%}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * %{
$result = $1 ? (SwigObj*) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;%}
// Plain type references.
%typemap(in) CONST TYPE & (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE > *)$input;
if (!smartarg || !smartarg->get()) {
SWIG_exception(SWIG_RuntimeError, "$1_type reference is null");
return $null;
}
$1 = (TYPE *)smartarg->get();%}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE & %{
$result = (SwigObj*) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr<CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner);%}
// Allow creating null shared pointers and testing them for validity.
%typemap(cxxcode) TYPE %{
static $cxxclassname null() { return $cxxclassname{($cclassptrname)nullptr, false}; }
explicit operator bool() const { return swig_self_ != nullptr; }
%}
// This is required to handle overloads on shared_ptr/normal type correctly.
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *")
TYPE CONST,
TYPE CONST &,
TYPE CONST *,
TYPE *CONST&,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *&
""
%enddef
%include <shared_ptr.i>

View file

@ -1,90 +0,0 @@
%{
#include <string>
%}
%fragment("SwigStrInOut", "header") {
class SwigStrInOut {
std::string str_;
char* ptr_;
size_t len_;
public:
void init(char* ptr) {
ptr_ = ptr;
if (ptr_) {
str_ = ptr_;
len_ = str_.length();
}
}
std::string* str() { return &str_; }
~SwigStrInOut() {
if (ptr_) {
memcpy(ptr_, str_.c_str(), len_);
ptr_[len_] = '\0';
}
}
};
}
%fragment("include_string", "cxxheader") %{
#include <string>
%}
namespace std {
// use "const string &" typemaps for wrapping member strings
%naturalvar string;
class string;
%typemap(ctype) string, const string & "const char *"
%typemap(ctype) string * "char *"
%typemap(ctype) string & "char *"
%typemap(in) string %{
if ($input)
$1 = $input;
%}
%typemap(in) const string & (std::string temp) %{
if ($input)
temp = $input;
$1 = &temp;
%}
%typemap(in, fragment="SwigStrInOut") string * (SwigStrInOut temp), string & (SwigStrInOut temp) %{
temp.init($input);
$1 = temp.str();
%}
// Note that we don't support strings with embedded NULs, as there is no way to
// return their length to C code anyhow.
%typemap(out) string %{
$result = strdup(cppresult.c_str());
%}
%typemap(out) const string &, string *, string & %{
$result = strdup(cppresult->c_str());
%}
// This is required to warn about clashes between the overloaded functions
// taking strings and raw pointers in the generated wrappers.
%typemap(typecheck) string, const string &, string *, string & = char *;
// Define typemaps for wrapping strings back into std::string in C++ wrappers
// and accepting strings directly.
%typemap(cxxintype, fragment="include_string") string, const string & "std::string const&"
%typemap(cxxin) string, const string & "$1.c_str()"
%typemap(cxxouttype, fragment="include_string") string, const string & "std::string"
%typemap(cxxout, noblock="1") string, const string & %{
$result = std::string($cresult);
free(const_cast<char*>($cresult));
%}
}

View file

@ -1,91 +0,0 @@
/* -----------------------------------------------------------------------------
* std_vector.i
*
* SWIG typemaps for std::vector
* ----------------------------------------------------------------------------- */
%include <std_common.i>
%{
#include <vector>
#include <stdexcept>
%}
namespace std {
template<class T> class vector {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
vector();
vector(const vector& other);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
bool empty() const;
void clear();
void push_back(const value_type& x);
%extend {
const_reference get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, const value_type& val) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = val;
else
throw std::out_of_range("vector index out of range");
}
}
};
// bool specialization
template<> class vector<bool> {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef bool value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef bool const_reference;
vector();
vector(size_type n);
vector(const vector& other);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
bool empty() const;
void clear();
void push_back(bool x);
%extend {
bool get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, bool val) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = val;
else
throw std::out_of_range("vector index out of range");
}
}
};
}

View file

@ -1,12 +0,0 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* stl.i
* ----------------------------------------------------------------------------- */
%include <std_common.i>
%include <std_string.i>
%include <std_vector.i>
%include <std_map.i>
%include <std_pair.i>

View file

@ -1,12 +0,0 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* typemaps.i
*
* Pointer handling
* These mappings provide support for input/output arguments and common
* uses for C/C++ pointers.
* ----------------------------------------------------------------------------- */
%include <typemaps/typemaps.swg>

View file

@ -23,28 +23,6 @@ typedef struct SWIGCDATA {
}
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
#elif SWIGC
%insert("cheader") {
typedef struct SWIGCDATA {
char *data;
int len;
} SWIGCDATA;
}
%typemap(ctype) SWIGCDATA "SWIGCDATA"
%typemap(cppouttype) SWIGCDATA "SWIGCDATA"
%typemap(out) SWIGCDATA {
$result = $1;
}
%typemap(ctype) (const void *indata, int inlen) "const SWIGCDATA*"
%typemap(in) (const void *indata, int inlen) {
$1 = $input->data;
$2 = $input->len;
}
#elif SWIGPHP
%typemap(out) SWIGCDATA {

View file

@ -72,7 +72,6 @@ skip-perl5 = test -n "@SKIP_PERL5@"
skip-php = test -n "@SKIP_PHP@"
skip-python = test -n "@SKIP_PYTHON@"
skip-r = test -n "@SKIP_R@"
skip-c = test -n "@SKIP_C@"
skip-ruby = test -n "@SKIP_RUBY@"
skip-scilab = test -n "@SKIP_SCILAB@"
skip-tcl = test -n "@SKIP_TCL@"
@ -114,7 +113,6 @@ check-aliveness:
@$(skip-php) || ./$(TARGET) -php7 -help
@$(skip-python) || ./$(TARGET) -python -help
@$(skip-r) || ./$(TARGET) -r -help
@$(skip-c) || ./$(TARGET) -c -help
@$(skip-ruby) || ./$(TARGET) -ruby -help
@$(skip-scilab) || ./$(TARGET) -scilab -help
@$(skip-tcl) || ./$(TARGET) -tcl -help
@ -173,7 +171,6 @@ check-examples: \
check-php-examples \
check-python-examples \
check-r-examples \
check-c-examples \
check-ruby-examples \
check-scilab-examples \
check-tcl-examples \
@ -193,7 +190,6 @@ perl5_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/perl5/check.list)
php_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/php/check.list)
python_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/python/check.list)
r_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/r/check.list)
c_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/c/check.list)
ruby_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/ruby/check.list)
scilab_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/scilab/check.list)
tcl_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/tcl/check.list)
@ -235,7 +231,6 @@ check-test-suite: \
check-php-test-suite \
check-python-test-suite \
check-r-test-suite \
check-c-test-suite \
check-ruby-test-suite \
check-scilab-test-suite \
check-tcl-test-suite \
@ -283,7 +278,6 @@ all-test-suite: \
all-php-test-suite \
all-python-test-suite \
all-r-test-suite \
all-c-test-suite \
all-ruby-test-suite \
all-scilab-test-suite \
all-tcl-test-suite \
@ -307,12 +301,8 @@ broken-test-suite: \
broken-php-test-suite \
broken-python-test-suite \
broken-r-test-suite \
broken-c-test-suite \
broken-scilab-test-suite \
broken-go-test-suite \
broken-d-test-suite \
broken-javascript-test-suite
broken-ruby-test-suite \
broken-scilab-test-suite \
broken-tcl-test-suite \
broken-%-test-suite:
@ -445,7 +435,7 @@ install-main:
@$(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)$(BIN_DIR)/`echo $(TARGET_NOEXE) | sed '$(transform)'`@EXEEXT@
lib-languages = typemaps tcl perl5 python guile java mzscheme ruby php ocaml octave \
csharp lua r c go d javascript javascript/jsc \
csharp lua r go d javascript javascript/jsc \
javascript/v8 scilab xml
lib-modules = std

View file

@ -264,11 +264,6 @@
/* please leave 750-759 free for R */
#define WARN_C_TYPEMAP_CTYPE_UNDEF 760
#define WARN_C_UNSUPPORTTED 761
/* please leave 760-779 free for C */
#define WARN_RUBY_WRONG_NAME 801
#define WARN_RUBY_MULTIPLE_INHERITANCE 802

View file

@ -45,7 +45,6 @@ eswig_SOURCES = CParse/cscanner.c \
Doxygen/pydoc.h \
Modules/allocate.cxx \
Modules/contract.cxx \
Modules/c.cxx \
Modules/csharp.cxx \
Modules/d.cxx \
Modules/directors.cxx \

File diff suppressed because it is too large Load diff

View file

@ -26,7 +26,6 @@
can be dynamically loaded in future versions. */
extern "C" {
Language *swig_c(void);
Language *swig_csharp(void);
Language *swig_d(void);
Language *swig_go(void);
@ -53,7 +52,6 @@ extern "C" {
static TargetLanguageModule modules[] = {
{"-allegrocl", NULL, "ALLEGROCL", Disabled},
{"-c", swig_c, "C", Experimental},
{"-chicken", NULL, "CHICKEN", Disabled},
{"-clisp", NULL, "CLISP", Disabled},
{"-cffi", NULL, "CFFI", Disabled},

View file

@ -15,7 +15,7 @@
#include "swig.h"
#include "cparse.h"
extern int UseWrapperSuffix; // from main.cxx
extern int UseWrapperSuffix;
static const char *cresult_variable_name = "result";
@ -58,8 +58,7 @@ const char *Swig_cresult_name(void) {
String *Swig_cparm_name(Parm *p, int i) {
String *name = NewStringf("arg%d", i + 1);
if (p) {
String *lname = Getattr(p, "lname");
if (!lname) Setattr(p, "lname", name);
Setattr(p, "lname", name);
}
return name;

View file

@ -181,32 +181,6 @@ String *Swig_name_mangle_type(const SwigType *s) {
return mangled;
}
/* -----------------------------------------------------------------------------
* Swig_name_type()
*
* Returns the name of a type.
* ----------------------------------------------------------------------------- */
String *Swig_name_type(const_String_or_char_ptr tname) {
String *r, *s;
String* f = naming_hash ? Getattr(naming_hash, "type") : NULL;
/* Don't bother doing anything else if there is no special naming format. */
if (f) {
s = Copy(f);
Replace(s, "%c", tname, DOH_REPLACE_ANY);
} else {
s = (String*)tname;
}
r = Swig_name_mangle_string(s);
if (s != tname)
Delete(s);
return r;
}
/* -----------------------------------------------------------------------------
* Swig_name_mangle_string()
*

View file

@ -276,7 +276,6 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern void Swig_name_register(const_String_or_char_ptr method, const_String_or_char_ptr format);
extern void Swig_name_unregister(const_String_or_char_ptr method);
extern String *Swig_name_type(const_String_or_char_ptr tname);
extern String *Swig_name_mangle_string(const String *s);
extern String *Swig_name_mangle_type(const SwigType *s);
extern String *Swig_name_wrapper(const_String_or_char_ptr fname);

Some files were not shown because too many files have changed in this diff Show more