Merge branch 'master' into gsoc2017-php7-classes-via-c-api
This commit is contained in:
commit
f72d9c1f21
103 changed files with 2332 additions and 853 deletions
2
CHANGES
2
CHANGES
|
|
@ -21116,7 +21116,7 @@ Version 1.3.7 (September 3, 2001)
|
|||
typedef __name vector<T>;
|
||||
%enddef
|
||||
|
||||
An a specific instantiation is created in exactly the same way:
|
||||
A specific instantiation is created in exactly the same way:
|
||||
|
||||
%template(intvec) vector<int>;
|
||||
|
||||
|
|
|
|||
168
CHANGES.current
168
CHANGES.current
|
|
@ -7,6 +7,174 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.0.0 (in progress)
|
||||
===========================
|
||||
|
||||
2017-08-16: wsfulton
|
||||
Fix #1063. Add using declarations to templates into typedef table.
|
||||
|
||||
Using declarations to templates were missing in SWIG's internal typedef tables.
|
||||
This led to a few problems, such as, templates that did not instantiate and generated
|
||||
C++ code that did not compile as SWIG did not know what scope the template was
|
||||
in. This happened mostly when a using declaration was used on a template type in a
|
||||
completely unrelated namespace.
|
||||
|
||||
2017-08-16: wsfulton
|
||||
Fix type lookup in the presence of using directives and using declarations.
|
||||
|
||||
Fix some cases of type lookup failure via a combination of both using directives and
|
||||
using declarations resulting in C++ code that did not compile as the generated type was
|
||||
not fully qualified for use in the global namespace. Example below:
|
||||
|
||||
namespace Space5 {
|
||||
namespace SubSpace5 {
|
||||
namespace SubSubSpace5 {
|
||||
struct F {};
|
||||
}
|
||||
}
|
||||
using namespace SubSpace5;
|
||||
using SubSubSpace5::F;
|
||||
void func(SubSubSpace5::F f);
|
||||
}
|
||||
|
||||
2017-08-16: wsfulton
|
||||
Issue #1051. %template scope enforcement and class definition fixes.
|
||||
|
||||
The scoping rules around %template have been specified and enforced.
|
||||
The %template directive for a class template is the equivalent to an
|
||||
explicit instantiation of a C++ class template. The scope for a valid
|
||||
%template instantiation is now the same as the scope required for a
|
||||
valid explicit instantiation of a C++ template. A definition of the
|
||||
template for the explicit instantiation must be in scope where the
|
||||
instantiation is declared and must not be enclosed within a different
|
||||
namespace.
|
||||
|
||||
For example, a few %template and C++ explicit instantiations of std::vector
|
||||
are shown below:
|
||||
|
||||
// valid
|
||||
namespace std {
|
||||
%template(vin) vector<int>;
|
||||
template class vector<int>;
|
||||
}
|
||||
|
||||
// valid
|
||||
using namespace std;
|
||||
%template(vin) vector<int>;
|
||||
template class vector<int>;
|
||||
|
||||
// valid
|
||||
using std::vector;
|
||||
%template(vin) vector<int>;
|
||||
template class vector<int>;
|
||||
|
||||
// ill-formed
|
||||
namespace unrelated {
|
||||
using std::vector;
|
||||
%template(vin) vector<int>;
|
||||
template class vector<int>;
|
||||
}
|
||||
|
||||
// ill-formed
|
||||
namespace unrelated {
|
||||
using namespace std;
|
||||
%template(vin) vector<int>;
|
||||
template class vector<int>;
|
||||
}
|
||||
|
||||
// ill-formed
|
||||
namespace unrelated {
|
||||
namespace std {
|
||||
%template(vin) vector<int>;
|
||||
template class vector<int>;
|
||||
}
|
||||
}
|
||||
|
||||
// ill-formed
|
||||
namespace unrelated {
|
||||
%template(vin) std::vector<int>;
|
||||
template class std::vector<int>;
|
||||
}
|
||||
|
||||
When the scope is incorrect, an error now occurs such as:
|
||||
|
||||
cpp_template_scope.i:34: Error: 'vector' resolves to 'std::vector' and
|
||||
was incorrectly instantiated in scope 'unrelated' instead of within scope 'std'.
|
||||
|
||||
Previously SWIG accepted the ill-formed examples above but this led to
|
||||
numerous subtle template scope problems especially in the presence of
|
||||
using declarations and using directives as well as with %feature and %typemap.
|
||||
|
||||
Actually, a valid instantiation is one which conforms to the C++03
|
||||
standard as C++11 made a change to disallow using declarations and
|
||||
using directives to find a template.
|
||||
|
||||
// valid C++03, ill-formed C++11
|
||||
using std::vector;
|
||||
template class vector<int>;
|
||||
|
||||
Similar fixes for defining classes using forward class references have
|
||||
also been put in place. For example:
|
||||
|
||||
namespace Space1 {
|
||||
struct A;
|
||||
}
|
||||
namespace Space2 {
|
||||
struct Space1::A {
|
||||
void x();
|
||||
}
|
||||
}
|
||||
|
||||
will now error out with:
|
||||
|
||||
cpp_class_definition.i:5: Error: 'Space1::A' resolves to 'Space1::A' and
|
||||
was incorrectly instantiated in scope 'Space2' instead of within scope 'Space1'.
|
||||
|
||||
2017-08-16: wsfulton
|
||||
Fix scope lookup for template parameters containing unary scope operators.
|
||||
|
||||
Fixes cases like:
|
||||
|
||||
namespace Alloc {
|
||||
template<typename T> struct Rebind {
|
||||
typedef int Integer;
|
||||
};
|
||||
}
|
||||
%template(RebindBucket) Alloc::Rebind< Bucket >;
|
||||
OR
|
||||
%template(RebindBucket) Alloc::Rebind< ::Bucket >;
|
||||
|
||||
Alloc::Rebind< Bucket >::Integer Bucket1();
|
||||
Alloc::Rebind< ::Bucket >::Integer Bucket2();
|
||||
Alloc::Rebind<::template TemplateBucket<double>>::Integer Bucket3();
|
||||
|
||||
2017-08-16: wsfulton
|
||||
For templates only, the template parameters are fully resolved when
|
||||
handling typemaps. Without this, it is too hard to have decent rules
|
||||
to apply typemaps when parameter types are typedef'd and template
|
||||
parameters have default values.
|
||||
|
||||
Fixes %clear for typedefs in templates, eg:
|
||||
|
||||
%typemap("in") XXX<int>::Long "..."
|
||||
template typename<T> struct XXX {
|
||||
typedef long Long;
|
||||
};
|
||||
%clear XXX<int>::Long;
|
||||
|
||||
as the typemap was previously incorrectly stored as a typemap for long
|
||||
instead of XXX<int>::Long.
|
||||
|
||||
2017-08-05: olly
|
||||
[C++11] Allow static_assert at the top level (and disallow it right
|
||||
after template<T>). Fixes https://github.com/swig/swig/issues/1031
|
||||
reported by Artem V L.
|
||||
|
||||
2017-08-02: wsfulton
|
||||
Fix incorrectly shown warning when an empty template instantiation was used on a
|
||||
class used as a base class and that base class was explicitly ignored with %ignore.
|
||||
Example of the warning which will no longer appear:
|
||||
|
||||
Warning 401: Base class 'Functor< int,int >' has no name as it is an empty
|
||||
template instantiated with '%template()'. Ignored.
|
||||
|
||||
2017-07-17: fflexo
|
||||
[Java] #674 Add std_list.i to add support for std::list containers. The Java proxy
|
||||
extends java.util.AbstractSequentialList and makes the C++ std::list container look
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ SWIG directives. SWIG can be furnished with a header file, but an
|
|||
interface can also be generated without library headers by supplying a
|
||||
simple text file--called the interface file, which is typically named
|
||||
with a <tt>.i</tt> extension--containing any foreign declarations of
|
||||
identifiers you wish to use. The most common approach is to use a an
|
||||
identifiers you wish to use. The most common approach is to use an
|
||||
interface file with directives to parse the needed headers. A straight
|
||||
parse of library headers will result in usable code, but SWIG
|
||||
directives provides much freedom in how a user might tailor the
|
||||
|
|
|
|||
|
|
@ -409,7 +409,7 @@ All the steps required to compile and use a simple hierarchy of classes for shap
|
|||
|
||||
<p>
|
||||
First create an Android project called <tt>SwigClass</tt> in a subdirectory called <tt>class</tt>.
|
||||
The steps below create and build a the JNI C++ app.
|
||||
The steps below create and build the JNI C++ app.
|
||||
Adjust the <tt>--target</tt> id as mentioned earlier in the <a href="Android.html#Android_examples_intro">Examples introduction</a>.
|
||||
</p>
|
||||
|
||||
|
|
|
|||
|
|
@ -411,7 +411,7 @@ following conditions need to be met:
|
|||
|
||||
|
||||
<p>
|
||||
ccache was inspired by the compilercache shell script script written
|
||||
ccache was inspired by the compilercache shell script written
|
||||
by Erik Thiele and I would like to thank him for an excellent piece of
|
||||
work. See
|
||||
<a href="http://www.erikyyy.de/compilercache/">http://www.erikyyy.de/compilercache/</a>
|
||||
|
|
|
|||
|
|
@ -877,7 +877,8 @@ so in this case it is entirely possible to pass an int instead of a double to <t
|
|||
|
||||
|
||||
<p>
|
||||
SWIG correctly parses the new <tt>static_assert</tt> declarations.
|
||||
SWIG correctly parses the new <tt>static_assert</tt> declarations (though 3.0.12 and earlier
|
||||
had a bug which meant this wasn't accepted at file scope).
|
||||
This is a C++ compile time directive so there isn't anything useful that SWIG can do with it.
|
||||
</p>
|
||||
|
||||
|
|
|
|||
|
|
@ -677,7 +677,7 @@ As a result, we get the following method in the module class:
|
|||
<div class="code">
|
||||
<pre>
|
||||
public static void myArrayCopy(int[] sourceArray, int[] targetArray, int nitems) {
|
||||
examplePINVOKE.myArrayCopy(sourceArray, targetArray, nitems);
|
||||
examplePINVOKE.myArrayCopy(sourceArray, targetArray, nitems);
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -997,9 +997,9 @@ When the following C# code is executed:
|
|||
<div class="code">
|
||||
<pre>
|
||||
public class runme {
|
||||
static void Main() {
|
||||
example.positivesonly(-1);
|
||||
}
|
||||
static void Main() {
|
||||
example.positivesonly(-1);
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -1772,7 +1772,7 @@ should pass the call on to <tt>CSharpDefaults.DefaultMethod(int)</tt>using the C
|
|||
|
||||
|
||||
<p>
|
||||
When using <a href="Modules.html#Modules">multiple modules</a> it is is possible to compile each SWIG generated wrapper
|
||||
When using <a href="Modules.html#Modules">multiple modules</a> it is possible to compile each SWIG generated wrapper
|
||||
into a different assembly.
|
||||
However, by default the generated code may not compile if
|
||||
generated classes in one assembly use generated classes in another assembly.
|
||||
|
|
@ -1846,12 +1846,12 @@ and the following usage from C# after running the code through SWIG:
|
|||
|
||||
<div class="code">
|
||||
<pre>
|
||||
Wheel wheel = new Bike(10).getWheel();
|
||||
Console.WriteLine("wheel size: " + wheel.size);
|
||||
// Simulate a garbage collection
|
||||
global::System.GC.Collect();
|
||||
global::System.GC.WaitForPendingFinalizers();
|
||||
global::System.Console.WriteLine("wheel size: " + wheel.size);
|
||||
Wheel wheel = new Bike(10).getWheel();
|
||||
Console.WriteLine("wheel size: " + wheel.size);
|
||||
// Simulate a garbage collection
|
||||
global::System.GC.Collect();
|
||||
global::System.GC.WaitForPendingFinalizers();
|
||||
global::System.Console.WriteLine("wheel size: " + wheel.size);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
|
@ -1980,9 +1980,9 @@ and more or less equivalent usage from C#
|
|||
|
||||
<div class="code">
|
||||
<pre>
|
||||
Container container = new Container();
|
||||
Element element = new Element(20);
|
||||
container.setElement(element);
|
||||
Container container = new Container();
|
||||
Element element = new Element(20);
|
||||
container.setElement(element);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
|
@ -1993,14 +1993,14 @@ In order to understand why, consider a garbage collection occuring...
|
|||
|
||||
<div class="code">
|
||||
<pre>
|
||||
Container container = new Container();
|
||||
Element element = new Element(20);
|
||||
container.setElement(element);
|
||||
Console.WriteLine("element.value: " + container.getElement().value);
|
||||
// Simulate a garbage collection
|
||||
global::System.GC.Collect();
|
||||
global::System.GC.WaitForPendingFinalizers();
|
||||
global::System.Console.WriteLine("element.value: " + container.getElement().value);
|
||||
Container container = new Container();
|
||||
Element element = new Element(20);
|
||||
container.setElement(element);
|
||||
Console.WriteLine("element.value: " + container.getElement().value);
|
||||
// Simulate a garbage collection
|
||||
global::System.GC.Collect();
|
||||
global::System.GC.WaitForPendingFinalizers();
|
||||
global::System.Console.WriteLine("element.value: " + container.getElement().value);
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -246,6 +246,16 @@
|
|||
<li><a href="SWIGPlus.html#SWIGPlus_nn28">Wrapping overloaded operators</a>
|
||||
<li><a href="SWIGPlus.html#SWIGPlus_class_extension">Class extension</a>
|
||||
<li><a href="SWIGPlus.html#SWIGPlus_nn30">Templates</a>
|
||||
<ul>
|
||||
<li><a href="SWIGPlus.html#SWIGPlus_template_directive">The %template directive</a>
|
||||
<li><a href="SWIGPlus.html#SWIGPlus_template_functions">Function templates</a>
|
||||
<li><a href="SWIGPlus.html#SWIGPlus_template_classes">Default template arguments</a>
|
||||
<li><a href="SWIGPlus.html#SWIGPlus_template_class_inheritance">Template base classes</a>
|
||||
<li><a href="SWIGPlus.html#SWIGPlus_template_specialization">Template specialization</a>
|
||||
<li><a href="SWIGPlus.html#SWIGPlus_template_member">Member templates</a>
|
||||
<li><a href="SWIGPlus.html#SWIGPlus_template_scoping">Scoping and templates</a>
|
||||
<li><a href="SWIGPlus.html#SWIGPlus_template_more">More on templates</a>
|
||||
</ul>
|
||||
<li><a href="SWIGPlus.html#SWIGPlus_namespaces">Namespaces</a>
|
||||
<ul>
|
||||
<li><a href="SWIGPlus.html#SWIGPlus_nspace">The nspace feature for namespaces</a>
|
||||
|
|
|
|||
|
|
@ -516,7 +516,7 @@ The special variables are often used in situations where method calls are logged
|
|||
$action
|
||||
}
|
||||
catch (MemoryError) {
|
||||
croak("Out of memory in $decl");
|
||||
croak("Out of memory in $decl");
|
||||
}
|
||||
}
|
||||
void log(const char *message);
|
||||
|
|
|
|||
|
|
@ -280,7 +280,7 @@ class SomeClass : AnInterface, AnotherInterface {
|
|||
...
|
||||
}
|
||||
</pre></div>
|
||||
<p>For this to work, <tt>AnInterface</tt> and <tt>AnotherInterface</tt> have to be in scope. If SWIG is not in split proxy mode, this is already the case, but it it is, they have to be added to the import list via the <tt>dimports</tt> typemap. Additionally, the import statement depends on the package SWIG is configured to emit the modules to.</p>
|
||||
<p>For this to work, <tt>AnInterface</tt> and <tt>AnotherInterface</tt> have to be in scope. If SWIG is not in split proxy mode, this is already the case, but if it is, they have to be added to the import list via the <tt>dimports</tt> typemap. Additionally, the import statement depends on the package SWIG is configured to emit the modules to.</p>
|
||||
<p>The <tt>$importtype</tt> macro helps you to elegantly solve this problem:</p>
|
||||
<div class="code"><pre>
|
||||
%typemap(dimports) RemoteMpe %{
|
||||
|
|
|
|||
|
|
@ -1576,7 +1576,7 @@ return the node for the first class member.
|
|||
|
||||
<div class="indent">
|
||||
Returns the last child node. You might use this if you wanted to append a new
|
||||
node to the of a class.
|
||||
node to the children of a class.
|
||||
</div>
|
||||
|
||||
<p>
|
||||
|
|
@ -2592,36 +2592,36 @@ command line options, simply use code similar to this:
|
|||
<pre>
|
||||
void Language::main(int argc, char *argv[]) {
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (argv[i]) {
|
||||
if (strcmp(argv[i], "-interface") == 0) {
|
||||
if (argv[i+1]) {
|
||||
interface = NewString(argv[i+1]);
|
||||
Swig_mark_arg(i);
|
||||
Swig_mark_arg(i+1);
|
||||
i++;
|
||||
} else {
|
||||
Swig_arg_error();
|
||||
}
|
||||
} else if (strcmp(argv[i], "-globals") == 0) {
|
||||
if (argv[i+1]) {
|
||||
global_name = NewString(argv[i+1]);
|
||||
Swig_mark_arg(i);
|
||||
Swig_mark_arg(i+1);
|
||||
i++;
|
||||
} else {
|
||||
Swig_arg_error();
|
||||
}
|
||||
} else if ((strcmp(argv[i], "-proxy") == 0)) {
|
||||
proxy_flag = 1;
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i], "-keyword") == 0) {
|
||||
use_kw = 1;
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i], "-help") == 0) {
|
||||
fputs(usage, stderr);
|
||||
}
|
||||
...
|
||||
if (argv[i]) {
|
||||
if (strcmp(argv[i], "-interface") == 0) {
|
||||
if (argv[i+1]) {
|
||||
interface = NewString(argv[i+1]);
|
||||
Swig_mark_arg(i);
|
||||
Swig_mark_arg(i+1);
|
||||
i++;
|
||||
} else {
|
||||
Swig_arg_error();
|
||||
}
|
||||
} else if (strcmp(argv[i], "-globals") == 0) {
|
||||
if (argv[i+1]) {
|
||||
global_name = NewString(argv[i+1]);
|
||||
Swig_mark_arg(i);
|
||||
Swig_mark_arg(i+1);
|
||||
i++;
|
||||
} else {
|
||||
Swig_arg_error();
|
||||
}
|
||||
} else if ((strcmp(argv[i], "-proxy") == 0)) {
|
||||
proxy_flag = 1;
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i], "-keyword") == 0) {
|
||||
use_kw = 1;
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i], "-help") == 0) {
|
||||
fputs(usage, stderr);
|
||||
}
|
||||
...
|
||||
}
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
|
|
@ -3164,7 +3164,7 @@ these kinds of problems.
|
|||
</p>
|
||||
|
||||
<dt> <b>Examples/Makefile.in</b>
|
||||
<dd> Nothing special here; see comments at top the of this file
|
||||
<dd> Nothing special here; see comments at the top of this file
|
||||
and look to the existing languages for examples.
|
||||
|
||||
<dt> <b>Examples/qux99/check.list</b>
|
||||
|
|
|
|||
|
|
@ -639,12 +639,12 @@ public:
|
|||
virtual ~FooBarAbstract() {};
|
||||
|
||||
std::string FooBar() {
|
||||
return this->Foo() + ", " + this->Bar();
|
||||
return this->Foo() + ", " + this->Bar();
|
||||
};
|
||||
|
||||
protected:
|
||||
virtual std::string Foo() {
|
||||
return "Foo";
|
||||
return "Foo";
|
||||
};
|
||||
|
||||
virtual std::string Bar() = 0;
|
||||
|
|
|
|||
|
|
@ -3935,9 +3935,9 @@ where <tt>Swig::DirectorException::raise</tt> is a helper method in the Director
|
|||
|
||||
<div class="code">
|
||||
<pre>
|
||||
static void raise(JNIEnv *jenv, jthrowable throwable) {
|
||||
throw DirectorException(jenv, throwable);
|
||||
}
|
||||
static void raise(JNIEnv *jenv, jthrowable throwable) {
|
||||
throw DirectorException(jenv, throwable);
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
|
@ -4105,7 +4105,7 @@ the exception specification or <code>%catches</code> feature.
|
|||
</p>
|
||||
|
||||
<p>Note that the "directorthrows" typemaps are important
|
||||
only if it is important for the the exceptions passed through the C++
|
||||
only if it is important for the exceptions passed through the C++
|
||||
layer to be mapped to distinct C++ exceptions. If director methods
|
||||
are being called by C++ code that is itself wrapped in a
|
||||
SWIG generated Java wrapper and access is always through this wrapper,
|
||||
|
|
@ -4335,16 +4335,16 @@ struct Vector {
|
|||
|
||||
%extend Vector {
|
||||
char *toString() {
|
||||
static char tmp[1024];
|
||||
sprintf(tmp, "Vector(%g, %g, %g)", $self->x, $self->y, $self->z);
|
||||
return tmp;
|
||||
static char tmp[1024];
|
||||
sprintf(tmp, "Vector(%g, %g, %g)", $self->x, $self->y, $self->z);
|
||||
return tmp;
|
||||
}
|
||||
Vector(double x, double y, double z) {
|
||||
Vector *v = (Vector *) malloc(sizeof(Vector));
|
||||
v->x = x;
|
||||
v->y = y;
|
||||
v->z = z;
|
||||
return v;
|
||||
Vector *v = (Vector *) malloc(sizeof(Vector));
|
||||
v->x = x;
|
||||
v->y = y;
|
||||
v->z = z;
|
||||
return v;
|
||||
}
|
||||
};
|
||||
</pre>
|
||||
|
|
@ -5278,7 +5278,7 @@ void * operator new(size_t t) {
|
|||
throw bad_alloc();
|
||||
pJalloc->ref = 0;
|
||||
return static_cast<void *>(
|
||||
static_cast<char *>(static_cast<void *>(pJalloc)) + sizeof(Jalloc));
|
||||
static_cast<char *>(static_cast<void *>(pJalloc)) + sizeof(Jalloc));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -7240,7 +7240,7 @@ public class runme {
|
|||
example.print_args(animals);
|
||||
String args[] = example.get_args();
|
||||
for (int i=0; i<args.length; i++)
|
||||
System.out.println(i + ":" + args[i]);
|
||||
System.out.println(i + ":" + args[i]);
|
||||
}
|
||||
}
|
||||
</pre></div>
|
||||
|
|
|
|||
|
|
@ -411,7 +411,7 @@ void print_array(double x[10]);
|
|||
Now, in a scripting language, you might write this:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<div class="targetlang">
|
||||
<pre>
|
||||
a = new_doubleArray(10) # Create an array
|
||||
for i in range(0, 10):
|
||||
|
|
@ -475,7 +475,7 @@ void print_array(double x[10]);
|
|||
Allows you to do this:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<div class="targetlang">
|
||||
<pre>
|
||||
import example
|
||||
c = example.doubleArray(10) # Create double[10]
|
||||
|
|
@ -801,7 +801,7 @@ target language. In other words, if you were using a language like Tcl,
|
|||
and you wrote this,
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<div class="targetlang">
|
||||
<pre>
|
||||
% foo Hello
|
||||
</pre>
|
||||
|
|
@ -852,7 +852,7 @@ size_t parity(char *str, size_t len, size_t initial);
|
|||
Now, in the target language, you can use binary string data like this:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<div class="targetlang">
|
||||
<pre>
|
||||
>>> s = "H\x00\x15eg\x09\x20"
|
||||
>>> parity(s, 0)
|
||||
|
|
|
|||
|
|
@ -1008,11 +1008,10 @@ The following operators cannot be overloaded (mainly because they are not suppor
|
|||
<p>
|
||||
SWIG also accepts the <tt>__str__()</tt> member function which converts an object to a string. This function should return a const char*, preferably to static memory. This will be used for the <tt>print()</tt> and <tt>tostring()</tt> functions in Lua. Assuming the complex class has a function
|
||||
</p>
|
||||
<div class="code"><pre>const char* __str__()
|
||||
{
|
||||
static char buffer[255];
|
||||
sprintf(buffer, "Complex(%g, %g)", this->re(), this->im());
|
||||
return buffer;
|
||||
<div class="code"><pre>const char* __str__() {
|
||||
static char buffer[255];
|
||||
sprintf(buffer, "Complex(%g, %g)", this->re(), this->im());
|
||||
return buffer;
|
||||
}
|
||||
</pre></div>
|
||||
<p>
|
||||
|
|
@ -1031,11 +1030,10 @@ Complex(10, 12)
|
|||
<p>
|
||||
It is also possible to overload the operator<tt>[]</tt>, but currently this cannot be automatically performed. To overload the operator<tt>[]</tt> you need to provide two functions, <tt>__getitem__()</tt> and <tt>__setitem__()</tt>
|
||||
</p>
|
||||
<div class="code"><pre>class Complex
|
||||
{
|
||||
//....
|
||||
double __getitem__(int i)const; // i is the index, returns the data
|
||||
void __setitem__(int i, double d); // i is the index, d is the data
|
||||
<div class="code"><pre>class Complex {
|
||||
//....
|
||||
double __getitem__(int i)const; // i is the index, returns the data
|
||||
void __setitem__(int i, double d); // i is the index, d is the data
|
||||
};
|
||||
</pre></div>
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -949,7 +949,7 @@ Foo *BarToFoo(Bar *b) {
|
|||
}
|
||||
|
||||
Foo *IncrFoo(Foo *f, int i) {
|
||||
return f+i;
|
||||
return f+i;
|
||||
}
|
||||
%}
|
||||
</pre>
|
||||
|
|
@ -1057,7 +1057,7 @@ produces a single accessor function like this:
|
|||
<div class="code">
|
||||
<pre>
|
||||
int *Foo_x_get(Foo *self) {
|
||||
return self->x;
|
||||
return self->x;
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -1092,11 +1092,11 @@ generates accessor functions such as this:
|
|||
<div class="code">
|
||||
<pre>
|
||||
Foo *Bar_f_get(Bar *b) {
|
||||
return &b->f;
|
||||
return &b->f;
|
||||
}
|
||||
|
||||
void Bar_f_set(Bar *b, Foo *val) {
|
||||
b->f = *val;
|
||||
b->f = *val;
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -1633,9 +1633,8 @@ class DoubleArray {
|
|||
void setitem(int i, double val) {
|
||||
if ((i >= 0) && (i < n))
|
||||
ptr[i] = val;
|
||||
else {
|
||||
else
|
||||
throw RangeError();
|
||||
}
|
||||
}
|
||||
};
|
||||
</pre></div>
|
||||
|
|
@ -1888,9 +1887,9 @@ like this:
|
|||
<div class="targetlang">
|
||||
<pre>
|
||||
%typemap(out) int {
|
||||
$result = sv_newmortal();
|
||||
set_setiv($result, (IV) $1);
|
||||
argvi++;
|
||||
$result = sv_newmortal();
|
||||
set_setiv($result, (IV) $1);
|
||||
argvi++;
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -2313,8 +2312,8 @@ Consider the following data structure:
|
|||
<div class="code"><pre>
|
||||
#define SIZE 8
|
||||
typedef struct {
|
||||
int values[SIZE];
|
||||
...
|
||||
int values[SIZE];
|
||||
...
|
||||
} Foo;
|
||||
|
||||
</pre></div>
|
||||
|
|
@ -2328,10 +2327,10 @@ To make the member writable, a "memberin" typemap can be used.
|
|||
|
||||
<div class="code"><pre>
|
||||
%typemap(memberin) int [SIZE] {
|
||||
int i;
|
||||
for (i = 0; i < SIZE; i++) {
|
||||
$1[i] = $input[i];
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < SIZE; i++) {
|
||||
$1[i] = $input[i];
|
||||
}
|
||||
}
|
||||
|
||||
</pre></div>
|
||||
|
|
@ -2600,48 +2599,48 @@ package example::Vector;
|
|||
%BLESSEDMEMBERS = ();
|
||||
|
||||
sub new () {
|
||||
my $self = shift;
|
||||
my @args = @_;
|
||||
$self = vectorc::new_Vector(@args);
|
||||
return undef if (!defined($self));
|
||||
bless $self, "example::Vector";
|
||||
$OWNER{$self} = 1;
|
||||
my %retval;
|
||||
tie %retval, "example::Vector", $self;
|
||||
return bless \%retval, "Vector";
|
||||
my $self = shift;
|
||||
my @args = @_;
|
||||
$self = vectorc::new_Vector(@args);
|
||||
return undef if (!defined($self));
|
||||
bless $self, "example::Vector";
|
||||
$OWNER{$self} = 1;
|
||||
my %retval;
|
||||
tie %retval, "example::Vector", $self;
|
||||
return bless \%retval, "Vector";
|
||||
}
|
||||
|
||||
sub DESTROY {
|
||||
return unless $_[0]->isa('HASH');
|
||||
my $self = tied(%{$_[0]});
|
||||
delete $ITERATORS{$self};
|
||||
if (exists $OWNER{$self}) {
|
||||
examplec::delete_Vector($self));
|
||||
delete $OWNER{$self};
|
||||
}
|
||||
return unless $_[0]->isa('HASH');
|
||||
my $self = tied(%{$_[0]});
|
||||
delete $ITERATORS{$self};
|
||||
if (exists $OWNER{$self}) {
|
||||
examplec::delete_Vector($self));
|
||||
delete $OWNER{$self};
|
||||
}
|
||||
}
|
||||
|
||||
sub FETCH {
|
||||
my ($self, $field) = @_;
|
||||
my $member_func = "vectorc::Vector_${field}_get";
|
||||
my $val = &$member_func($self);
|
||||
if (exists $BLESSEDMEMBERS{$field}) {
|
||||
return undef if (!defined($val));
|
||||
my %retval;
|
||||
tie %retval, $BLESSEDMEMBERS{$field}, $val;
|
||||
return bless \%retval, $BLESSEDMEMBERS{$field};
|
||||
}
|
||||
return $val;
|
||||
my ($self, $field) = @_;
|
||||
my $member_func = "vectorc::Vector_${field}_get";
|
||||
my $val = &$member_func($self);
|
||||
if (exists $BLESSEDMEMBERS{$field}) {
|
||||
return undef if (!defined($val));
|
||||
my %retval;
|
||||
tie %retval, $BLESSEDMEMBERS{$field}, $val;
|
||||
return bless \%retval, $BLESSEDMEMBERS{$field};
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
sub STORE {
|
||||
my ($self, $field, $newval) = @_;
|
||||
my $member_func = "vectorc::Vector_${field}_set";
|
||||
if (exists $BLESSEDMEMBERS{$field}) {
|
||||
&$member_func($self, tied(%{$newval}));
|
||||
} else {
|
||||
&$member_func($self, $newval);
|
||||
}
|
||||
my ($self, $field, $newval) = @_;
|
||||
my $member_func = "vectorc::Vector_${field}_set";
|
||||
if (exists $BLESSEDMEMBERS{$field}) {
|
||||
&$member_func($self, tied(%{$newval}));
|
||||
} else {
|
||||
&$member_func($self, $newval);
|
||||
}
|
||||
}
|
||||
</pre></div>
|
||||
|
||||
|
|
@ -2842,11 +2841,11 @@ this:
|
|||
|
||||
<div class="targetlang"><pre>
|
||||
sub dot_product {
|
||||
my @args = @_;
|
||||
$args[0] = tied(%{$args[0]}); # Get the real pointer values
|
||||
$args[1] = tied(%{$args[1]});
|
||||
my $result = vectorc::dot_product(@args);
|
||||
return $result;
|
||||
my @args = @_;
|
||||
$args[0] = tied(%{$args[0]}); # Get the real pointer values
|
||||
$args[1] = tied(%{$args[1]});
|
||||
my $result = vectorc::dot_product(@args);
|
||||
return $result;
|
||||
}
|
||||
</pre></div>
|
||||
|
||||
|
|
@ -2985,7 +2984,7 @@ sub set_transform
|
|||
for (my $j = 0; $j < 4, $j++)
|
||||
{
|
||||
mat44_set($a, $i, $j, $x->[i][j])
|
||||
}
|
||||
}
|
||||
}
|
||||
example.set_transform($im, $a);
|
||||
free_mat44($a);
|
||||
|
|
@ -3104,14 +3103,14 @@ the methods one() and two() (but not three()):
|
|||
%feature("director") Foo;
|
||||
class Foo {
|
||||
public:
|
||||
Foo(int foo);
|
||||
virtual void one();
|
||||
virtual void two();
|
||||
Foo(int foo);
|
||||
virtual void one();
|
||||
virtual void two();
|
||||
};
|
||||
|
||||
class Bar: public Foo {
|
||||
public:
|
||||
virtual void three();
|
||||
virtual void three();
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -3279,9 +3278,9 @@ suffice in most cases:
|
|||
<div class="code">
|
||||
<pre>
|
||||
%feature("director:except") {
|
||||
if ($error != NULL) {
|
||||
throw Swig::DirectorMethodException();
|
||||
}
|
||||
if ($error != NULL) {
|
||||
throw Swig::DirectorMethodException();
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -3305,8 +3304,8 @@ suitable exception handler:
|
|||
<div class="code">
|
||||
<pre>
|
||||
%exception {
|
||||
try { $action }
|
||||
catch (Swig::DirectorException &e) { SWIG_fail; }
|
||||
try { $action }
|
||||
catch (Swig::DirectorException &e) { SWIG_fail; }
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ If the module is in PHP's default extension directory, you can omit the path.
|
|||
<p>
|
||||
For some SAPIs (for example, the CLI SAPI) you can instead use the
|
||||
<a href="http://php.net/manual/en/function.dl.php">dl() function</a> to load
|
||||
an extension at run time, by adding a like like this to the start of each
|
||||
an extension at run time, by adding a line like this to the start of each
|
||||
PHP script which uses your extension:
|
||||
</p>
|
||||
|
||||
|
|
@ -986,14 +986,14 @@ the methods one() and two() (but not three()):
|
|||
%feature("director") Foo;
|
||||
class Foo {
|
||||
public:
|
||||
Foo(int foo);
|
||||
virtual void one();
|
||||
virtual void two();
|
||||
Foo(int foo);
|
||||
virtual void one();
|
||||
virtual void two();
|
||||
};
|
||||
|
||||
class Bar: public Foo {
|
||||
public:
|
||||
virtual void three();
|
||||
virtual void three();
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -1125,12 +1125,12 @@ Here is an example:
|
|||
<pre>
|
||||
class Foo {
|
||||
public:
|
||||
...
|
||||
...
|
||||
};
|
||||
class FooContainer {
|
||||
public:
|
||||
void addFoo(Foo *);
|
||||
...
|
||||
void addFoo(Foo *);
|
||||
...
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -1175,9 +1175,9 @@ should suffice in most cases:
|
|||
<div class="code">
|
||||
<pre>
|
||||
%feature("director:except") {
|
||||
if ($error == FAILURE) {
|
||||
throw Swig::DirectorMethodException();
|
||||
}
|
||||
if ($error == FAILURE) {
|
||||
throw Swig::DirectorMethodException();
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -1204,8 +1204,8 @@ suitable exception handler:
|
|||
<div class="code">
|
||||
<pre>
|
||||
%exception {
|
||||
try { $action }
|
||||
catch (Swig::DirectorException &e) { SWIG_fail; }
|
||||
try { $action }
|
||||
catch (Swig::DirectorException &e) { SWIG_fail; }
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -230,8 +230,8 @@ For example, given this C++ class declaration:
|
|||
class Shape
|
||||
{
|
||||
public:
|
||||
static void print();
|
||||
static int nshapes;
|
||||
static void print();
|
||||
static int nshapes;
|
||||
};
|
||||
</pre></div>
|
||||
|
||||
|
|
|
|||
|
|
@ -226,16 +226,15 @@ resulting C file should be built as a python extension, inserting the module
|
|||
#include "example.h"
|
||||
|
||||
int fact(int n) {
|
||||
if (n < 0){ /* This should probably return an error, but this is simpler */
|
||||
return 0;
|
||||
}
|
||||
if (n == 0) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
/* testing for overflow would be a good idea here */
|
||||
return n * fact(n-1);
|
||||
}
|
||||
if (n < 0) { /* This should probably return an error, but this is simpler */
|
||||
return 0;
|
||||
}
|
||||
if (n == 0) {
|
||||
return 1;
|
||||
} else {
|
||||
/* testing for overflow would be a good idea here */
|
||||
return n * fact(n-1);
|
||||
}
|
||||
}
|
||||
|
||||
</pre>
|
||||
|
|
@ -1276,7 +1275,7 @@ Foo *BarToFoo(Bar *b) {
|
|||
}
|
||||
|
||||
Foo *IncrFoo(Foo *f, int i) {
|
||||
return f+i;
|
||||
return f+i;
|
||||
}
|
||||
%}
|
||||
</pre>
|
||||
|
|
@ -1386,7 +1385,7 @@ example, consider this:
|
|||
<div class="code">
|
||||
<pre>
|
||||
struct Bar {
|
||||
int x[16];
|
||||
int x[16];
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -1716,9 +1715,9 @@ Similarly, if you have a class like this,
|
|||
<pre>
|
||||
class Foo {
|
||||
public:
|
||||
Foo();
|
||||
Foo(const Foo &);
|
||||
...
|
||||
Foo();
|
||||
Foo(const Foo &);
|
||||
...
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -1951,11 +1950,11 @@ For example:
|
|||
%rename(Bar_spam) Bar::spam;
|
||||
|
||||
namespace Foo {
|
||||
int spam();
|
||||
int spam();
|
||||
}
|
||||
|
||||
namespace Bar {
|
||||
int spam();
|
||||
int spam();
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -2166,9 +2165,9 @@ have a class like this
|
|||
<pre>
|
||||
class Foo {
|
||||
public:
|
||||
int x;
|
||||
int spam(int);
|
||||
...
|
||||
int x;
|
||||
int spam(int);
|
||||
...
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
|
@ -2179,19 +2178,19 @@ then SWIG transforms it into a set of low-level procedural wrappers. For example
|
|||
<div class="code">
|
||||
<pre>
|
||||
Foo *new_Foo() {
|
||||
return new Foo();
|
||||
return new Foo();
|
||||
}
|
||||
void delete_Foo(Foo *f) {
|
||||
delete f;
|
||||
delete f;
|
||||
}
|
||||
int Foo_x_get(Foo *f) {
|
||||
return f->x;
|
||||
return f->x;
|
||||
}
|
||||
void Foo_x_set(Foo *f, int value) {
|
||||
f->x = value;
|
||||
f->x = value;
|
||||
}
|
||||
int Foo_spam(Foo *f, int arg1) {
|
||||
return f->spam(arg1);
|
||||
return f->spam(arg1);
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -2310,10 +2309,10 @@ please refer to the python documentation:</p>
|
|||
<div class="code">
|
||||
<pre>
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PyObject *dict;
|
||||
PyObject *args;
|
||||
PyObject *message;
|
||||
PyObject_HEAD
|
||||
PyObject *dict;
|
||||
PyObject *args;
|
||||
PyObject *message;
|
||||
} PyBaseExceptionObject;
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -2323,12 +2322,12 @@ typedef struct {
|
|||
<div class="code">
|
||||
<pre>
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
void *ptr;
|
||||
swig_type_info *ty;
|
||||
int own;
|
||||
PyObject *next;
|
||||
PyObject *dict;
|
||||
PyObject_HEAD
|
||||
void *ptr;
|
||||
swig_type_info *ty;
|
||||
int own;
|
||||
PyObject *next;
|
||||
PyObject *dict;
|
||||
} SwigPyObject;
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -2339,13 +2338,13 @@ typedef struct {
|
|||
<pre>
|
||||
class MyException {
|
||||
public:
|
||||
MyException (const char *msg_);
|
||||
~MyException ();
|
||||
MyException (const char *msg_);
|
||||
~MyException ();
|
||||
|
||||
const char *what () const;
|
||||
const char *what () const;
|
||||
|
||||
private:
|
||||
char *msg;
|
||||
char *msg;
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -2372,9 +2371,9 @@ strings, you can define an <tt>'operator+ (const char*)'</tt> method :</p>
|
|||
<pre>
|
||||
class MyString {
|
||||
public:
|
||||
MyString (const char *init);
|
||||
MyString operator+ (const char *other) const;
|
||||
...
|
||||
MyString (const char *init);
|
||||
MyString operator+ (const char *other) const;
|
||||
...
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -2473,11 +2472,12 @@ slot entries. For example, suppose you have this class:
|
|||
<pre>
|
||||
class Twit {
|
||||
public:
|
||||
Twit operator+ (const Twit& twit) const;
|
||||
Twit operator+ (const Twit& twit) const;
|
||||
|
||||
// Forward to operator+
|
||||
Twit add (const Twit& twit) const
|
||||
{ return *this + twit; }
|
||||
// Forward to operator+
|
||||
Twit add (const Twit& twit) const {
|
||||
return *this + twit;
|
||||
}
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -2565,9 +2565,9 @@ the function callback in the tp_hash slot for the builtin type for <tt>MyClass</
|
|||
<div class="code">
|
||||
<pre>
|
||||
static PyHeapTypeObject SwigPyBuiltin__MyClass_type = {
|
||||
...
|
||||
(hashfunc) myHashFunc, /* tp_hash */
|
||||
...
|
||||
...
|
||||
(hashfunc) myHashFunc, /* tp_hash */
|
||||
...
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
|
@ -2636,8 +2636,8 @@ ownership of the result. For example:
|
|||
<pre>
|
||||
class Foo {
|
||||
public:
|
||||
Foo();
|
||||
Foo bar();
|
||||
Foo();
|
||||
Foo bar();
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -2666,9 +2666,9 @@ they came from. Therefore, the ownership is set to zero. For example:
|
|||
<pre>
|
||||
class Foo {
|
||||
public:
|
||||
...
|
||||
Foo *spam();
|
||||
...
|
||||
...
|
||||
Foo *spam();
|
||||
...
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -2707,8 +2707,8 @@ or global variable. For example, consider this interface:
|
|||
%module example
|
||||
|
||||
struct Foo {
|
||||
int value;
|
||||
Foo *next;
|
||||
int value;
|
||||
Foo *next;
|
||||
};
|
||||
|
||||
Foo *head = 0;
|
||||
|
|
@ -2939,15 +2939,15 @@ the methods one() and two() (but not three()):
|
|||
%feature("director") Foo;
|
||||
class Foo {
|
||||
public:
|
||||
Foo(int foo);
|
||||
virtual ~Foo();
|
||||
virtual void one();
|
||||
virtual void two();
|
||||
Foo(int foo);
|
||||
virtual ~Foo();
|
||||
virtual void one();
|
||||
virtual void two();
|
||||
};
|
||||
|
||||
class Bar: public Foo {
|
||||
public:
|
||||
virtual void three();
|
||||
virtual void three();
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -3087,12 +3087,12 @@ references. Here is an example:
|
|||
<pre>
|
||||
class Foo {
|
||||
public:
|
||||
...
|
||||
...
|
||||
};
|
||||
class FooContainer {
|
||||
public:
|
||||
void addFoo(Foo *);
|
||||
...
|
||||
void addFoo(Foo *);
|
||||
...
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -3133,9 +3133,9 @@ suffice in most cases:
|
|||
<div class="code">
|
||||
<pre>
|
||||
%feature("director:except") {
|
||||
if ($error != NULL) {
|
||||
throw Swig::DirectorMethodException();
|
||||
}
|
||||
if ($error != NULL) {
|
||||
throw Swig::DirectorMethodException();
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -3162,8 +3162,8 @@ suitable exception handler:
|
|||
<div class="code">
|
||||
<pre>
|
||||
%exception {
|
||||
try { $action }
|
||||
catch (Swig::DirectorException &e) { SWIG_fail; }
|
||||
try { $action }
|
||||
catch (Swig::DirectorException &e) { SWIG_fail; }
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -3240,7 +3240,7 @@ references, such as
|
|||
<pre>
|
||||
class Foo {
|
||||
…
|
||||
virtual const int& bar();
|
||||
virtual const int& bar();
|
||||
…
|
||||
};
|
||||
</pre>
|
||||
|
|
@ -3258,7 +3258,7 @@ types, wherever possible, for example
|
|||
<pre>
|
||||
class Foo {
|
||||
…
|
||||
virtual int bar();
|
||||
virtual int bar();
|
||||
…
|
||||
};
|
||||
</pre>
|
||||
|
|
@ -3511,7 +3511,7 @@ def bar(*args):
|
|||
|
||||
class Foo {
|
||||
public:
|
||||
int bar(int x);
|
||||
int bar(int x);
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -3548,7 +3548,7 @@ proxy, just before the return statement.
|
|||
|
||||
class Foo {
|
||||
public:
|
||||
int bar(int x);
|
||||
int bar(int x);
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -3577,7 +3577,7 @@ SWIG version 1.3.28 you can use the directive forms
|
|||
|
||||
class Foo {
|
||||
public:
|
||||
int bar(int x);
|
||||
int bar(int x);
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -3606,8 +3606,8 @@ as it will then get attached to all the overloaded C++ methods. For example:
|
|||
|
||||
class Foo {
|
||||
public:
|
||||
int bar(int x);
|
||||
int bar();
|
||||
int bar(int x);
|
||||
int bar();
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -4142,11 +4142,11 @@ Sometimes a C function expects an array to be passed as a pointer. For example,
|
|||
<div class="code">
|
||||
<pre>
|
||||
int sumitems(int *first, int nitems) {
|
||||
int i, sum = 0;
|
||||
for (i = 0; i < nitems; i++) {
|
||||
sum += first[i];
|
||||
}
|
||||
return sum;
|
||||
int i, sum = 0;
|
||||
for (i = 0; i < nitems; i++) {
|
||||
sum += first[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -6046,7 +6046,7 @@ zipimporter requires python-3.5.1 or newer to work with subpackages.
|
|||
|
||||
<p>
|
||||
When SWIG creates wrappers from an interface file, say foo.i, two Python modules are
|
||||
created. There is a pure Python module module (foo.py) and C/C++ code which is
|
||||
created. There is a pure Python module (foo.py) and C/C++ code which is
|
||||
built and linked into a dynamically (or statically) loaded low-level module _foo
|
||||
(see the <a href="Python.html#Python_nn3">Preliminaries section</a> for details). So, the interface
|
||||
file really defines two Python modules. How these two modules are loaded is
|
||||
|
|
@ -6526,7 +6526,7 @@ string that cannot be completely decoded as UTF-8:
|
|||
%inline %{
|
||||
|
||||
const char* non_utf8_c_str(void) {
|
||||
return "h\xe9llo w\xc3\xb6rld";
|
||||
return "h\xe9llo w\xc3\xb6rld";
|
||||
}
|
||||
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -389,7 +389,7 @@ For example
|
|||
/* bar not wrapped unless foo has been defined and
|
||||
the declaration of bar within foo has already been parsed */
|
||||
int foo::bar(int) {
|
||||
... whatever ...
|
||||
... whatever ...
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -1043,14 +1043,14 @@ expect :</p>
|
|||
<div class="targetlang"><pre>
|
||||
# Copy a file
|
||||
def filecopy(source, target):
|
||||
f1 = fopen(source, "r")
|
||||
f2 = fopen(target, "w")
|
||||
buffer = malloc(8192)
|
||||
nbytes = fread(buffer, 8192, 1, f1)
|
||||
while (nbytes > 0):
|
||||
fwrite(buffer, 8192, 1, f2)
|
||||
nbytes = fread(buffer, 8192, 1, f1)
|
||||
free(buffer)
|
||||
f1 = fopen(source, "r")
|
||||
f2 = fopen(target, "w")
|
||||
buffer = malloc(8192)
|
||||
nbytes = fread(buffer, 8192, 1, f1)
|
||||
while (nbytes > 0):
|
||||
fwrite(buffer, 8192, 1, f2)
|
||||
nbytes = fread(buffer, 8192, 1, f1)
|
||||
free(buffer)
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
|
|
@ -1236,9 +1236,9 @@ creating a wrapper equivalent to the following:
|
|||
|
||||
<div class="code"><pre>
|
||||
double wrap_dot_product(Vector *a, Vector *b) {
|
||||
Vector x = *a;
|
||||
Vector y = *b;
|
||||
return dot_product(x, y);
|
||||
Vector x = *a;
|
||||
Vector y = *b;
|
||||
return dot_product(x, y);
|
||||
}
|
||||
</pre></div>
|
||||
|
||||
|
|
@ -1266,12 +1266,12 @@ pointers. As a result, SWIG creates a wrapper like this:
|
|||
|
||||
<div class="code"><pre>
|
||||
Vector *wrap_cross_product(Vector *v1, Vector *v2) {
|
||||
Vector x = *v1;
|
||||
Vector y = *v2;
|
||||
Vector *result;
|
||||
result = (Vector *) malloc(sizeof(Vector));
|
||||
*(result) = cross(x, y);
|
||||
return result;
|
||||
Vector x = *v1;
|
||||
Vector y = *v2;
|
||||
Vector *result;
|
||||
result = (Vector *) malloc(sizeof(Vector));
|
||||
*(result) = cross(x, y);
|
||||
return result;
|
||||
}
|
||||
</pre></div>
|
||||
|
||||
|
|
@ -1280,10 +1280,10 @@ or if SWIG was run with the <tt>-c++</tt> option:</p>
|
|||
|
||||
<div class="code"><pre>
|
||||
Vector *wrap_cross(Vector *v1, Vector *v2) {
|
||||
Vector x = *v1;
|
||||
Vector y = *v2;
|
||||
Vector *result = new Vector(cross(x, y)); // Uses default copy constructor
|
||||
return result;
|
||||
Vector x = *v1;
|
||||
Vector y = *v2;
|
||||
Vector *result = new Vector(cross(x, y)); // Uses default copy constructor
|
||||
return result;
|
||||
}
|
||||
</pre></div>
|
||||
|
||||
|
|
@ -2368,10 +2368,10 @@ defined in the interface. For example:
|
|||
|
||||
<div class="code"><pre>
|
||||
struct Vector *new_Vector() {
|
||||
return (Vector *) calloc(1, sizeof(struct Vector));
|
||||
return (Vector *) calloc(1, sizeof(struct Vector));
|
||||
}
|
||||
void delete_Vector(struct Vector *obj) {
|
||||
free(obj);
|
||||
free(obj);
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -2602,10 +2602,10 @@ like this:
|
|||
<div class="code">
|
||||
<pre>
|
||||
WORD Foo_w_get(Foo *f) {
|
||||
return f->w;
|
||||
return f->w;
|
||||
}
|
||||
void Foo_w_set(FOO *f, WORD value) {
|
||||
f->w = value;
|
||||
f->w = value;
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -2896,7 +2896,7 @@ instead of a method. To do this, you might write some code like this:
|
|||
<pre>
|
||||
// Add a new attribute to Vector
|
||||
%extend Vector {
|
||||
const double magnitude;
|
||||
const double magnitude;
|
||||
}
|
||||
// Now supply the implementation of the Vector_magnitude_get function
|
||||
%{
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -121,15 +121,15 @@ In this example we bind from C a function and a global variable into Scilab. The
|
|||
double Foo = 3.0;
|
||||
|
||||
int fact(int n) {
|
||||
if (n < 0) {
|
||||
return 0;
|
||||
}
|
||||
else if (n == 0) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return n * fact(n-1);
|
||||
}
|
||||
if (n < 0) {
|
||||
return 0;
|
||||
}
|
||||
else if (n == 0) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return n * fact(n-1);
|
||||
}
|
||||
}
|
||||
%}
|
||||
</pre></div>
|
||||
|
|
@ -896,8 +896,8 @@ Let's see it on an example of a struct with two members:
|
|||
%inline %{
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int arr[4];
|
||||
int x;
|
||||
int arr[4];
|
||||
} Foo;
|
||||
|
||||
%}
|
||||
|
|
@ -1136,18 +1136,18 @@ But we can use either use the <tt>get_perimeter()</tt> function of the parent cl
|
|||
As explained in <a href="SWIGPlus.html#SWIGPlus_overloaded_methods">6.15</a> SWIG provides support for overloaded functions and constructors.
|
||||
</p>
|
||||
|
||||
<p>As SWIG knows pointer types, the overloading works also with pointer types, here is is an example with a function <tt>magnify</tt> overloaded for the previous classes <tt>Shape</tt> and <tt>Circle</tt>:
|
||||
<p>As SWIG knows pointer types, the overloading works also with pointer types, here is an example with a function <tt>magnify</tt> overloaded for the previous classes <tt>Shape</tt> and <tt>Circle</tt>:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
%module example
|
||||
|
||||
void magnify(Square *square, double factor) {
|
||||
square->size *= factor;
|
||||
square->size *= factor;
|
||||
};
|
||||
|
||||
void magnify(Circle *circle, double factor) {
|
||||
square->radius *= factor;
|
||||
square->radius *= factor;
|
||||
};
|
||||
</pre></div>
|
||||
|
||||
|
|
@ -1620,11 +1620,11 @@ void printArray(int values[], int len) {
|
|||
|
||||
|
||||
<p>
|
||||
There are no specific typemaps for pointer-to-pointers, they are are mapped as pointers in Scilab.
|
||||
There are no specific typemaps for pointer-to-pointers, they are mapped as pointers in Scilab.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Pointer-to-pointers are sometimes used to implement matrices in C. The following is a an example of this:
|
||||
Pointer-to-pointers are sometimes used to implement matrices in C. The following is an example of this:
|
||||
</p>
|
||||
|
||||
|
||||
|
|
@ -2062,7 +2062,7 @@ In this mode, the following SWIG options may be used to setup the build:
|
|||
Let's give an example how to build a module <tt>example</tt>, composed of two sources, and using a library dependency:
|
||||
</p>
|
||||
<ul>
|
||||
<li>the sources are <tt>baa1.c</tt> and <tt>baa2.c</tt> (and are stored in in the current directory)</li>
|
||||
<li>the sources are <tt>baa1.c</tt> and <tt>baa2.c</tt> (and are stored in the current directory)</li>
|
||||
<li>the library is <tt>libfoo</tt> in <tt>/opt/foo</tt> (headers stored in <tt>/opt/foo/include</tt>, and shared library in <tt>/opt/foo/lib</tt>)</li>
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
|
|
@ -958,7 +958,7 @@ Foo *BarToFoo(Bar *b) {
|
|||
}
|
||||
|
||||
Foo *IncrFoo(Foo *f, int i) {
|
||||
return f+i;
|
||||
return f+i;
|
||||
}
|
||||
%}
|
||||
</pre>
|
||||
|
|
@ -1054,7 +1054,7 @@ example, consider this:
|
|||
<div class="code">
|
||||
<pre>
|
||||
struct Bar {
|
||||
int x[16];
|
||||
int x[16];
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -1456,9 +1456,9 @@ Similarly, if you have a class like this,
|
|||
<pre>
|
||||
class Foo {
|
||||
public:
|
||||
Foo();
|
||||
Foo(const Foo &);
|
||||
...
|
||||
Foo();
|
||||
Foo(const Foo &);
|
||||
...
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -1693,11 +1693,11 @@ For example:
|
|||
%rename(Bar_spam) Bar::spam;
|
||||
|
||||
namespace Foo {
|
||||
int spam();
|
||||
int spam();
|
||||
}
|
||||
|
||||
namespace Bar {
|
||||
int spam();
|
||||
int spam();
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -1886,19 +1886,19 @@ then SWIG transforms it into a set of low-level procedural wrappers. For example
|
|||
<div class="code">
|
||||
<pre>
|
||||
Foo *new_Foo() {
|
||||
return new Foo();
|
||||
return new Foo();
|
||||
}
|
||||
void delete_Foo(Foo *f) {
|
||||
delete f;
|
||||
delete f;
|
||||
}
|
||||
int Foo_x_get(Foo *f) {
|
||||
return f->x;
|
||||
return f->x;
|
||||
}
|
||||
void Foo_x_set(Foo *f, int value) {
|
||||
f->x = value;
|
||||
f->x = value;
|
||||
}
|
||||
int Foo_spam(Foo *f, int arg1) {
|
||||
return f->spam(arg1);
|
||||
return f->spam(arg1);
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -1945,8 +1945,8 @@ ownership of the result. For example:
|
|||
<pre>
|
||||
class Foo {
|
||||
public:
|
||||
Foo();
|
||||
Foo bar();
|
||||
Foo();
|
||||
Foo bar();
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -1975,9 +1975,9 @@ they came from. Therefore, the ownership is set to zero. For example:
|
|||
<pre>
|
||||
class Foo {
|
||||
public:
|
||||
...
|
||||
Foo *spam();
|
||||
...
|
||||
...
|
||||
Foo *spam();
|
||||
...
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -2011,8 +2011,8 @@ or global variable. For example, consider this interface:
|
|||
%module example
|
||||
|
||||
struct Foo {
|
||||
int value;
|
||||
Foo *next;
|
||||
int value;
|
||||
Foo *next;
|
||||
};
|
||||
|
||||
Foo *head = 0;
|
||||
|
|
@ -2465,9 +2465,9 @@ you might define a typemap like this:
|
|||
%module example
|
||||
|
||||
%typemap(in) int {
|
||||
if (Tcl_GetIntFromObj(interp, $input, &$1) == TCL_ERROR)
|
||||
return TCL_ERROR;
|
||||
printf("Received an integer : %d\n", $1);
|
||||
if (Tcl_GetIntFromObj(interp, $input, &$1) == TCL_ERROR)
|
||||
return TCL_ERROR;
|
||||
printf("Received an integer : %d\n", $1);
|
||||
}
|
||||
%inline %{
|
||||
extern int fact(int n);
|
||||
|
|
@ -2585,7 +2585,7 @@ like this:
|
|||
<div class="code">
|
||||
<pre>
|
||||
%typemap(out) int {
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj($1));
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj($1));
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -3215,28 +3215,28 @@ helper functions to access arrays :
|
|||
|
||||
%inline %{
|
||||
double *new_double(int size) {
|
||||
return (double *) malloc(size*sizeof(double));
|
||||
return (double *) malloc(size*sizeof(double));
|
||||
}
|
||||
void delete_double(double *a) {
|
||||
free(a);
|
||||
free(a);
|
||||
}
|
||||
double get_double(double *a, int index) {
|
||||
return a[index];
|
||||
return a[index];
|
||||
}
|
||||
void set_double(double *a, int index, double val) {
|
||||
a[index] = val;
|
||||
a[index] = val;
|
||||
}
|
||||
int *new_int(int size) {
|
||||
return (int *) malloc(size*sizeof(int));
|
||||
return (int *) malloc(size*sizeof(int));
|
||||
}
|
||||
void delete_int(int *a) {
|
||||
free(a);
|
||||
free(a);
|
||||
}
|
||||
int get_int(int *a, int index) {
|
||||
return a[index];
|
||||
return a[index];
|
||||
}
|
||||
int set_int(int *a, int index, int val) {
|
||||
a[index] = val;
|
||||
a[index] = val;
|
||||
}
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -423,8 +423,8 @@ Variable length arguments may be used in typemap specifications. For example:
|
|||
<div class="code">
|
||||
<pre>
|
||||
%typemap(in) (...) {
|
||||
// Get variable length arguments (somehow)
|
||||
...
|
||||
// Get variable length arguments (somehow)
|
||||
...
|
||||
}
|
||||
|
||||
%typemap(in) (const char *fmt, ...) {
|
||||
|
|
|
|||
|
|
@ -30,5 +30,5 @@ f.enum_test(example.Foo.LUDICROUS);
|
|||
// enum value BLUE of enum color is accessed as property of cconst
|
||||
console.log("example.BLUE= " + example.BLUE);
|
||||
|
||||
// enum value LUDICROUS of enum Foo::speed is accessed as as property of cconst
|
||||
// enum value LUDICROUS of enum Foo::speed is accessed as property of cconst
|
||||
console.log("example.speed.LUDICROUS= " + example.Foo.LUDICROUS);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ CEO=@(name) subclass(swigexample.Manager(name),'getPosition',@(self) "CEO");
|
|||
|
||||
# Create an instance of our employee extension class, CEO. The calls to
|
||||
# getName() and getPosition() are standard, the call to getTitle() uses
|
||||
# the director wrappers to call CEO.getPosition. e = CEO("Alice")
|
||||
# the director wrappers to call CEO.getPosition.
|
||||
|
||||
e = CEO("Alice");
|
||||
printf("%s is a %s\n",e.getName(),e.getPosition());
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class CEO(example.Manager):
|
|||
|
||||
# Create an instance of our employee extension class, CEO. The calls to
|
||||
# getName() and getPosition() are standard, the call to getTitle() uses
|
||||
# the director wrappers to call CEO.getPosition. e = CEO("Alice")
|
||||
# the director wrappers to call CEO.getPosition.
|
||||
|
||||
e = CEO("Alice")
|
||||
print e.getName(), "is a", e.getPosition()
|
||||
|
|
|
|||
|
|
@ -2,4 +2,5 @@
|
|||
|
||||
import robin
|
||||
|
||||
assert(robin.run() == "AWAY!")
|
||||
if not(robin.run() == "AWAY!"):
|
||||
raise RuntimeError("test failed")
|
||||
|
|
|
|||
|
|
@ -4,4 +4,5 @@ sys.path.insert(0, 'path1')
|
|||
|
||||
from brave import robin
|
||||
|
||||
assert(robin.run() == "AWAY!")
|
||||
if not(robin.run() == "AWAY!"):
|
||||
raise RuntimeError("test failed")
|
||||
|
|
|
|||
|
|
@ -6,4 +6,5 @@ sys.path.insert(0, 'path3')
|
|||
|
||||
from brave import robin
|
||||
|
||||
assert(robin.run() == "AWAY!")
|
||||
if not(robin.run() == "AWAY!"):
|
||||
raise RuntimeError("test failed")
|
||||
|
|
|
|||
|
|
@ -6,4 +6,5 @@ sys.path.insert(0, 'path3')
|
|||
|
||||
from brave import robin
|
||||
|
||||
assert(robin.run() == "AWAY!")
|
||||
if not(robin.run() == "AWAY!"):
|
||||
raise RuntimeError("test failed")
|
||||
|
|
|
|||
|
|
@ -7,4 +7,5 @@ import pkg1.foo
|
|||
|
||||
print " Finished importing pkg1.foo"
|
||||
|
||||
assert(pkg1.foo.count() == 3)
|
||||
if not(pkg1.foo.count() == 3):
|
||||
raise RuntimeError("test failed")
|
||||
|
|
|
|||
|
|
@ -7,4 +7,5 @@ import pkg1.foo
|
|||
|
||||
print " Finished importing pkg1.foo"
|
||||
|
||||
assert(pkg1.foo.count() == 3)
|
||||
if not(pkg1.foo.count() == 3):
|
||||
raise RuntimeError("test failed")
|
||||
|
|
|
|||
|
|
@ -47,6 +47,6 @@ testdir/README file.
|
|||
Further Documentation
|
||||
---------------------
|
||||
|
||||
There is documentation about the test-suite and how to use use it in
|
||||
There is documentation about the test-suite and how to use it in
|
||||
the SWIG documentation - Doc/Manual/Extending.html#Extending_test_suite.
|
||||
|
||||
|
|
|
|||
160
Examples/test-suite/class_scope_namespace.i
Normal file
160
Examples/test-suite/class_scope_namespace.i
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
// Test a mix of forward class declarations, class definitions, using declarations and using directives.
|
||||
|
||||
%module class_scope_namespace
|
||||
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) H::HH;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Space8::I::II;
|
||||
|
||||
%inline %{
|
||||
struct A;
|
||||
namespace Space1 {
|
||||
namespace SubSpace1 {
|
||||
struct A {
|
||||
void aa(Space1::SubSpace1::A, SubSpace1::A, A) {}
|
||||
};
|
||||
void aaa(Space1::SubSpace1::A, SubSpace1::A, A) {}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Space2 {
|
||||
struct B;
|
||||
}
|
||||
using Space2::B;
|
||||
#ifdef __clang__
|
||||
namespace Space2 {
|
||||
struct B {
|
||||
void bb(Space2::B, B) {}
|
||||
};
|
||||
}
|
||||
#else
|
||||
struct B {
|
||||
void bb(Space2::B, B) {}
|
||||
};
|
||||
#endif
|
||||
void bbb(Space2::B, B) {}
|
||||
|
||||
namespace Space3 {
|
||||
namespace SubSpace3 {
|
||||
struct C;
|
||||
struct D;
|
||||
}
|
||||
}
|
||||
struct C;
|
||||
struct D;
|
||||
namespace Space3 {
|
||||
struct C;
|
||||
struct SubSpace3::C {
|
||||
void cc(Space3::SubSpace3::C, SubSpace3::C) {}
|
||||
};
|
||||
using SubSpace3::D;
|
||||
struct SubSpace3::D {
|
||||
void dd(Space3::SubSpace3::D, SubSpace3::D, D) {}
|
||||
};
|
||||
void ccc(Space3::SubSpace3::C, SubSpace3::C) {}
|
||||
void ddd(Space3::SubSpace3::D, SubSpace3::D, D) {}
|
||||
}
|
||||
|
||||
namespace Space4 {
|
||||
namespace SubSpace4 {
|
||||
struct E;
|
||||
}
|
||||
}
|
||||
using namespace Space4;
|
||||
using SubSpace4::E;
|
||||
// Was added to incorrect namespace in swig-3.0.12
|
||||
struct SubSpace4::E {
|
||||
void ee(Space4::SubSpace4::E, SubSpace4::E, E) {}
|
||||
};
|
||||
void eee(Space4::SubSpace4::E, SubSpace4::E, E) {}
|
||||
|
||||
namespace Space5 {
|
||||
namespace SubSpace5 {
|
||||
namespace SubSubSpace5 {
|
||||
struct F;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace Space5 {
|
||||
using namespace SubSpace5;
|
||||
using SubSubSpace5::F;
|
||||
// Was added to incorrect namespace in swig-3.0.12
|
||||
struct SubSubSpace5::F {
|
||||
void ff(Space5::SubSpace5::SubSubSpace5::F, SubSpace5::SubSubSpace5::F, SubSubSpace5::F, F) {}
|
||||
};
|
||||
void fff(Space5::SubSpace5::SubSubSpace5::F, SubSpace5::SubSubSpace5::F, SubSubSpace5::F, F) {}
|
||||
}
|
||||
|
||||
namespace Space6 {
|
||||
struct G;
|
||||
namespace SubSpace6 {
|
||||
struct G;
|
||||
}
|
||||
}
|
||||
namespace Space6 {
|
||||
struct SubSpace6::G {
|
||||
void gg(Space6::SubSpace6::G, SubSpace6::G) {}
|
||||
};
|
||||
void ggg(Space6::SubSpace6::G, SubSpace6::G) {}
|
||||
}
|
||||
|
||||
struct HH;
|
||||
struct H {
|
||||
struct HH {
|
||||
void hh(H::HH) {}
|
||||
};
|
||||
};
|
||||
void hhh(H::HH) {}
|
||||
|
||||
namespace Space8 {
|
||||
struct II;
|
||||
struct I {
|
||||
struct II {
|
||||
void ii(Space8::I::II, I::II) {}
|
||||
};
|
||||
};
|
||||
void iii(Space8::I::II, I::II) {}
|
||||
}
|
||||
|
||||
struct J;
|
||||
namespace Space9 {
|
||||
namespace SubSpace9 {
|
||||
struct J {
|
||||
void jj(Space9::SubSpace9::J, SubSpace9::J, J) {}
|
||||
};
|
||||
void jjj(Space9::SubSpace9::J, SubSpace9::J, J) {}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Space10 {
|
||||
struct K;
|
||||
}
|
||||
namespace Space10 {
|
||||
namespace SubSpace10 {
|
||||
struct K {
|
||||
void kk(Space10::SubSpace10::K, SubSpace10::K, K) {}
|
||||
};
|
||||
void kkk(Space10::SubSpace10::K, SubSpace10::K, K) {}
|
||||
}
|
||||
}
|
||||
|
||||
namespace OtherSpace {
|
||||
struct L;
|
||||
struct M;
|
||||
}
|
||||
using OtherSpace::L;
|
||||
namespace Space11 {
|
||||
using OtherSpace::M;
|
||||
namespace SubSpace11 {
|
||||
struct L {
|
||||
void ll(Space11::SubSpace11::L, SubSpace11::L, L) {}
|
||||
};
|
||||
void lll(Space11::SubSpace11::L, SubSpace11::L, L) {}
|
||||
struct M {
|
||||
void mm(Space11::SubSpace11::M, SubSpace11::M, M) {}
|
||||
};
|
||||
void mmm(Space11::SubSpace11::M, SubSpace11::M, M) {}
|
||||
}
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
|
|
@ -136,6 +136,7 @@ CPP_TEST_CASES += \
|
|||
char_binary \
|
||||
char_strings \
|
||||
chartest \
|
||||
class_scope_namespace \
|
||||
class_forward \
|
||||
class_ignore \
|
||||
class_scope_weird \
|
||||
|
|
@ -291,6 +292,7 @@ CPP_TEST_CASES += \
|
|||
multiple_inheritance_shared_ptr \
|
||||
name_cxx \
|
||||
name_warnings \
|
||||
namespace_chase \
|
||||
namespace_class \
|
||||
namespace_enum \
|
||||
namespace_extend \
|
||||
|
|
@ -418,6 +420,7 @@ CPP_TEST_CASES += \
|
|||
template_default_inherit \
|
||||
template_default_qualify \
|
||||
template_default_vw \
|
||||
template_empty_inherit \
|
||||
template_enum \
|
||||
template_enum_ns_inherit \
|
||||
template_enum_typedef \
|
||||
|
|
@ -434,6 +437,7 @@ CPP_TEST_CASES += \
|
|||
template_methods \
|
||||
template_namespace_forward_declaration \
|
||||
template_using_directive_and_declaration_forward \
|
||||
template_using_directive_typedef \
|
||||
template_nested \
|
||||
template_nested_typemaps \
|
||||
template_ns \
|
||||
|
|
@ -444,6 +448,7 @@ CPP_TEST_CASES += \
|
|||
template_ns_enum2 \
|
||||
template_ns_inherit \
|
||||
template_ns_scope \
|
||||
template_parameters_global_scope \
|
||||
template_partial_arg \
|
||||
template_partial_specialization \
|
||||
template_partial_specialization_typedef \
|
||||
|
|
|
|||
|
|
@ -1,12 +1,32 @@
|
|||
/* This test case checks whether SWIG correctly parses and ignores the
|
||||
keywords "static_assert()" inside the class or struct.
|
||||
/* This test case checks whether SWIG correctly parses and ignores
|
||||
"static_assert()" in various places.
|
||||
*/
|
||||
%module cpp11_static_assert
|
||||
|
||||
%inline %{
|
||||
static_assert(sizeof(int) >= 2, "What? int size is invalid!");
|
||||
|
||||
namespace dummy {
|
||||
// C++17 allows the message to be omitted, so check that works too.
|
||||
// But only show the C++17 version to SWIG, as the compiler may
|
||||
// lack C++17 support.
|
||||
#ifdef SWIG
|
||||
static_assert(sizeof(int) >= sizeof(short));
|
||||
#else
|
||||
static_assert(sizeof(int) >= sizeof(short), "blah");
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct Check1 {
|
||||
static_assert(sizeof(int) <= sizeof(T), "not big enough");
|
||||
Check1() {
|
||||
#ifdef SWIG
|
||||
static_assert(true);
|
||||
#else
|
||||
static_assert(true, "true");
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class li_std_map_runme {
|
|||
|
||||
public static void Main()
|
||||
{
|
||||
// Set up an int int map
|
||||
// Set up an string to int map
|
||||
StringIntMap simap = new StringIntMap();
|
||||
for (int i = 0; i < collectionSize; i++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace Swig {
|
|||
size_t ExceptionMethod()
|
||||
{
|
||||
// Check positioning of director code in wrapper file
|
||||
// Below is what we really want to test, but director exceptions vary too much across across all languages
|
||||
// Below is what we really want to test, but director exceptions vary too much across all languages
|
||||
// throw Swig::DirectorException("DirectorException was not in scope!!");
|
||||
// Instead check definition of Director class as that is defined in the same place as DirectorException (director.swg)
|
||||
size_t size = sizeof(Swig::Director);
|
||||
|
|
|
|||
26
Examples/test-suite/errors/cpp_class_definition.i
Normal file
26
Examples/test-suite/errors/cpp_class_definition.i
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
%module xxx
|
||||
|
||||
// This should error but doesn't
|
||||
#if 0
|
||||
namespace OtherSpace {
|
||||
struct L;
|
||||
}
|
||||
namespace Space11 {
|
||||
namespace SubSpace11 {
|
||||
using OtherSpace::L;
|
||||
struct L {
|
||||
void ll();
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace Space1 {
|
||||
struct A;
|
||||
}
|
||||
namespace Space2 {
|
||||
struct Space1::A {
|
||||
void x();
|
||||
};
|
||||
}
|
||||
|
||||
1
Examples/test-suite/errors/cpp_class_definition.stderr
Normal file
1
Examples/test-suite/errors/cpp_class_definition.stderr
Normal file
|
|
@ -0,0 +1 @@
|
|||
cpp_class_definition.i:22: Error: 'Space1::A' resolves to 'Space1::A' and was incorrectly instantiated in scope 'Space2' instead of within scope 'Space1'.
|
||||
9
Examples/test-suite/errors/cpp_invalid_template.i
Normal file
9
Examples/test-suite/errors/cpp_invalid_template.i
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
%module cpp_invalid_scope
|
||||
|
||||
%template(abc) SSS::AAA<int>;
|
||||
|
||||
namespace UUU {
|
||||
struct JJJ;
|
||||
}
|
||||
|
||||
%template(xxx) UUU::JJJ<int>;
|
||||
3
Examples/test-suite/errors/cpp_invalid_template.stderr
Normal file
3
Examples/test-suite/errors/cpp_invalid_template.stderr
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
cpp_invalid_template.i:3: Error: Undefined scope 'SSS'
|
||||
cpp_invalid_template.i:3: Error: Template 'SSS::AAA' undefined.
|
||||
cpp_invalid_template.i:9: Error: 'JJJ' is not defined as a template. (classforward)
|
||||
40
Examples/test-suite/errors/cpp_namespace_template_bad.i
Normal file
40
Examples/test-suite/errors/cpp_namespace_template_bad.i
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
%module namespace_template
|
||||
|
||||
namespace test {
|
||||
template<typename T> T max(T a, T b) { return (a > b) ? a : b; }
|
||||
template<typename T> class vector {
|
||||
public:
|
||||
vector() { }
|
||||
~vector() { }
|
||||
};
|
||||
}
|
||||
|
||||
namespace test2 {
|
||||
using namespace test;
|
||||
%template(maxshort) max<short>;
|
||||
%template(vectorshort) vector<short>;
|
||||
}
|
||||
|
||||
namespace test3 {
|
||||
using test::max;
|
||||
using test::vector;
|
||||
%template(maxlong) max<long>;
|
||||
%template(vectorlong) vector<long>;
|
||||
}
|
||||
|
||||
namespace test4 {
|
||||
using namespace test;
|
||||
typedef int Integer;
|
||||
}
|
||||
|
||||
namespace test4 {
|
||||
%template(maxInteger) max<Integer>;
|
||||
%template(vectorInteger) vector<Integer>;
|
||||
}
|
||||
|
||||
using namespace test;
|
||||
namespace test5 {
|
||||
%template(maxdouble) max<double>;
|
||||
%template(vectordouble) vector<double>;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
cpp_namespace_template_bad.i:14: Error: 'max' resolves to 'test::max' and was incorrectly instantiated in scope 'test2' instead of within scope 'test'.
|
||||
cpp_namespace_template_bad.i:15: Error: 'vector' resolves to 'test::vector' and was incorrectly instantiated in scope 'test2' instead of within scope 'test'.
|
||||
cpp_namespace_template_bad.i:21: Error: 'max' resolves to 'test::max' and was incorrectly instantiated in scope 'test3' instead of within scope 'test'.
|
||||
cpp_namespace_template_bad.i:22: Error: 'vector' resolves to 'test::vector' and was incorrectly instantiated in scope 'test3' instead of within scope 'test'.
|
||||
cpp_namespace_template_bad.i:31: Error: 'max' resolves to 'test::max' and was incorrectly instantiated in scope 'test4' instead of within scope 'test'.
|
||||
cpp_namespace_template_bad.i:32: Error: 'vector' resolves to 'test::vector' and was incorrectly instantiated in scope 'test4' instead of within scope 'test'.
|
||||
cpp_namespace_template_bad.i:37: Error: 'max' resolves to 'test::max' and was incorrectly instantiated in scope 'test5' instead of within scope 'test'.
|
||||
cpp_namespace_template_bad.i:37: Error: Template 'max' undefined.
|
||||
cpp_namespace_template_bad.i:38: Error: 'vector' resolves to 'test::vector' and was incorrectly instantiated in scope 'test5' instead of within scope 'test'.
|
||||
|
|
@ -1,2 +1,4 @@
|
|||
cpp_nested_template.i:9: Error: 'Temply' resolves to '::Temply' and was incorrectly instantiated in scope 'A' instead of within scope ''.
|
||||
cpp_nested_template.i:9: Warning 324: Named nested template instantiations not supported. Processing as if no name was given to %template().
|
||||
cpp_nested_template.i:18: Error: 'Temply' resolves to '::Temply' and was incorrectly instantiated in scope 'B' instead of within scope ''.
|
||||
cpp_nested_template.i:18: Warning 324: Named nested template instantiations not supported. Processing as if no name was given to %template().
|
||||
|
|
|
|||
57
Examples/test-suite/errors/cpp_template_scope.i
Normal file
57
Examples/test-suite/errors/cpp_template_scope.i
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
%module xxx
|
||||
|
||||
namespace std {
|
||||
template<typename T> class vector {};
|
||||
}
|
||||
|
||||
struct S1 {};
|
||||
struct S2 {};
|
||||
struct S3 {};
|
||||
struct S4 {};
|
||||
struct S5 {};
|
||||
struct S6 {};
|
||||
struct S7 {};
|
||||
|
||||
// valid
|
||||
namespace std {
|
||||
%template(vi1) vector<S1>;
|
||||
template class vector<S1>;
|
||||
}
|
||||
|
||||
// valid
|
||||
using namespace std;
|
||||
%template(vi2) vector<S2>;
|
||||
template class vector<S2>;
|
||||
|
||||
// valid
|
||||
using std::vector;
|
||||
%template(vi3) vector<S3>;
|
||||
template class vector<S3>;
|
||||
|
||||
// ill-formed
|
||||
namespace unrelated {
|
||||
using std::vector;
|
||||
%template(vi4) vector<S4>;
|
||||
template class vector<S4>;
|
||||
}
|
||||
|
||||
// ill-formed
|
||||
namespace unrelated {
|
||||
using namespace std;
|
||||
%template(vi5) vector<S5>;
|
||||
template class vector<S5>;
|
||||
}
|
||||
|
||||
// ill-formed
|
||||
namespace unrelated {
|
||||
namespace std {
|
||||
%template(vi6) vector<S6>;
|
||||
template class vector<S6>;
|
||||
}
|
||||
}
|
||||
|
||||
// ill-formed
|
||||
namespace unrelated {
|
||||
%template(vi7) std::vector<S7>;
|
||||
template class std::vector<S7>;
|
||||
}
|
||||
11
Examples/test-suite/errors/cpp_template_scope.stderr
Normal file
11
Examples/test-suite/errors/cpp_template_scope.stderr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
cpp_template_scope.i:18: Warning 320: Explicit template instantiation ignored.
|
||||
cpp_template_scope.i:24: Warning 320: Explicit template instantiation ignored.
|
||||
cpp_template_scope.i:29: Warning 320: Explicit template instantiation ignored.
|
||||
cpp_template_scope.i:34: Error: 'vector' resolves to 'std::vector' and was incorrectly instantiated in scope 'unrelated' instead of within scope 'std'.
|
||||
cpp_template_scope.i:35: Warning 320: Explicit template instantiation ignored.
|
||||
cpp_template_scope.i:41: Error: 'vector' resolves to 'std::vector' and was incorrectly instantiated in scope 'unrelated' instead of within scope 'std'.
|
||||
cpp_template_scope.i:42: Warning 320: Explicit template instantiation ignored.
|
||||
cpp_template_scope.i:48: Error: 'vector' resolves to 'std::vector' and was incorrectly instantiated in scope 'unrelated::std' instead of within scope 'std'.
|
||||
cpp_template_scope.i:49: Warning 320: Explicit template instantiation ignored.
|
||||
cpp_template_scope.i:55: Error: 'std::vector' resolves to 'std::vector' and was incorrectly instantiated in scope 'unrelated' instead of within scope 'std'.
|
||||
cpp_template_scope.i:56: Warning 320: Explicit template instantiation ignored.
|
||||
59
Examples/test-suite/java/class_scope_namespace_runme.java
Normal file
59
Examples/test-suite/java/class_scope_namespace_runme.java
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
|
||||
import class_scope_namespace.*;
|
||||
|
||||
public class class_scope_namespace_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("class_scope_namespace");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[])
|
||||
{
|
||||
A a = new A();
|
||||
B b = new B();
|
||||
C c = new C();
|
||||
D d = new D();
|
||||
E e = new E();
|
||||
F f = new F();
|
||||
G g = new G();
|
||||
H.HH h = new H.HH();
|
||||
I.II i = new I.II();
|
||||
J j = new J();
|
||||
K k = new K();
|
||||
L l = new L();
|
||||
M m = new M();
|
||||
|
||||
a.aa(a, a, a);
|
||||
b.bb(b, b);
|
||||
c.cc(c, c);
|
||||
d.dd(d, d, d);
|
||||
e.ee(e, e, e);
|
||||
f.ff(f, f, f, f);
|
||||
g.gg(g, g);
|
||||
h.hh(h);
|
||||
i.ii(i, i);
|
||||
j.jj(j, j, j);
|
||||
k.kk(k, k, k);
|
||||
l.ll(l, l, l);
|
||||
m.mm(m, m, m);
|
||||
|
||||
class_scope_namespace.aaa(a, a, a);
|
||||
class_scope_namespace.bbb(b, b);
|
||||
class_scope_namespace.ccc(c, c);
|
||||
class_scope_namespace.ddd(d, d, d);
|
||||
class_scope_namespace.eee(e, e, e);
|
||||
class_scope_namespace.fff(f, f, f, f);
|
||||
class_scope_namespace.ggg(g, g);
|
||||
class_scope_namespace.hhh(h);
|
||||
class_scope_namespace.iii(i, i);
|
||||
class_scope_namespace.jjj(j, j, j);
|
||||
class_scope_namespace.kkk(k, k, k);
|
||||
class_scope_namespace.lll(l, l, l);
|
||||
class_scope_namespace.mmm(m, m, m);
|
||||
}
|
||||
}
|
||||
19
Examples/test-suite/java/cpp11_template_typedefs_runme.java
Normal file
19
Examples/test-suite/java/cpp11_template_typedefs_runme.java
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import cpp11_template_typedefs.*;
|
||||
|
||||
public class cpp11_template_typedefs_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("cpp11_template_typedefs");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
int alloc1 = cpp11_template_typedefs.get_bucket_allocator1();
|
||||
int alloc2 = cpp11_template_typedefs.get_bucket_allocator2();
|
||||
}
|
||||
}
|
||||
|
||||
26
Examples/test-suite/java/namespace_chase_runme.java
Normal file
26
Examples/test-suite/java/namespace_chase_runme.java
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
import namespace_chase.*;
|
||||
|
||||
public class namespace_chase_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("namespace_chase");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[])
|
||||
{
|
||||
Struct1A s1a = new Struct1A();
|
||||
Struct1B s1b = new Struct1B();
|
||||
Struct1C s1c = new Struct1C();
|
||||
|
||||
namespace_chase.sss3a(s1a, s1b, s1c);
|
||||
namespace_chase.sss3b(s1a, s1b, s1c);
|
||||
// needs fixing
|
||||
// namespace_chase.sss3c(s1a, s1b, s1c);
|
||||
}
|
||||
}
|
||||
32
Examples/test-suite/java/namespace_template_runme.java
Normal file
32
Examples/test-suite/java/namespace_template_runme.java
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
import namespace_template.*;
|
||||
|
||||
public class namespace_template_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("namespace_template");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
vectorchar vc = new vectorchar();
|
||||
vectorshort vs = new vectorshort();
|
||||
vectorint vi = new vectorint();
|
||||
vectorlong vl = new vectorlong();
|
||||
|
||||
vc.blah((char)10);
|
||||
vs.blah((short)10);
|
||||
vi.blah(10);
|
||||
vl.blah(10);
|
||||
|
||||
vc.vectoruse(vc, vc);
|
||||
vs.vectoruse(vs, vs);
|
||||
vi.vectoruse(vi, vi);
|
||||
vl.vectoruse(vl, vl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
import template_parameters_global_scope.*;
|
||||
|
||||
public class template_parameters_global_scope_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("template_parameters_global_scope");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
|
||||
int alloc = 0;
|
||||
|
||||
// Check 1
|
||||
alloc = template_parameters_global_scope.Bucket1();
|
||||
alloc = template_parameters_global_scope.Bucket2();
|
||||
alloc = template_parameters_global_scope.Bucket3();
|
||||
alloc = template_parameters_global_scope.Bucket4();
|
||||
alloc = template_parameters_global_scope.Bucket5();
|
||||
alloc = template_parameters_global_scope.Bucket6();
|
||||
|
||||
// Check 2
|
||||
alloc = template_parameters_global_scope.Spade1();
|
||||
alloc = template_parameters_global_scope.Spade2();
|
||||
alloc = template_parameters_global_scope.Spade3();
|
||||
alloc = template_parameters_global_scope.Spade4();
|
||||
alloc = template_parameters_global_scope.Spade5();
|
||||
alloc = template_parameters_global_scope.Spade6();
|
||||
|
||||
// Check 3
|
||||
alloc = template_parameters_global_scope.Ball1();
|
||||
alloc = template_parameters_global_scope.Ball2();
|
||||
alloc = template_parameters_global_scope.Ball3();
|
||||
alloc = template_parameters_global_scope.Ball4();
|
||||
alloc = template_parameters_global_scope.Ball5();
|
||||
alloc = template_parameters_global_scope.Ball6();
|
||||
|
||||
// Check 4
|
||||
alloc = template_parameters_global_scope.Bat1();
|
||||
alloc = template_parameters_global_scope.Bat2();
|
||||
alloc = template_parameters_global_scope.Bat3();
|
||||
alloc = template_parameters_global_scope.Bat4();
|
||||
alloc = template_parameters_global_scope.Bat5();
|
||||
alloc = template_parameters_global_scope.Bat6();
|
||||
|
||||
// Check 5
|
||||
alloc = template_parameters_global_scope.Chair1();
|
||||
alloc = template_parameters_global_scope.Chair2();
|
||||
alloc = template_parameters_global_scope.Chair3();
|
||||
alloc = template_parameters_global_scope.Chair4();
|
||||
alloc = template_parameters_global_scope.Chair5();
|
||||
alloc = template_parameters_global_scope.Chair6();
|
||||
|
||||
// Check 6
|
||||
alloc = template_parameters_global_scope.Table1();
|
||||
alloc = template_parameters_global_scope.Table2();
|
||||
alloc = template_parameters_global_scope.Table3();
|
||||
alloc = template_parameters_global_scope.Table4();
|
||||
alloc = template_parameters_global_scope.Table5();
|
||||
alloc = template_parameters_global_scope.Table6();
|
||||
|
||||
/*
|
||||
alloc = template_parameters_global_scope.rejig1();
|
||||
alloc = template_parameters_global_scope.rejig2();
|
||||
alloc = template_parameters_global_scope.rejig3();
|
||||
alloc = template_parameters_global_scope.rejig4();
|
||||
alloc = template_parameters_global_scope.rejig5();
|
||||
alloc = template_parameters_global_scope.rejig6();
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
@ -19,32 +19,32 @@ public class template_using_directive_and_declaration_forward_runme {
|
|||
template_using_directive_and_declaration_forward.useit1b(new Thing1Int());
|
||||
template_using_directive_and_declaration_forward.useit1c(new Thing1Int());
|
||||
|
||||
//BROKEN template_using_directive_and_declaration_forward.useit2(new Thing2Int());
|
||||
template_using_directive_and_declaration_forward.useit2(new Thing2Int());
|
||||
template_using_directive_and_declaration_forward.useit2a(new Thing2Int());
|
||||
template_using_directive_and_declaration_forward.useit2b(new Thing2Int());
|
||||
template_using_directive_and_declaration_forward.useit2c(new Thing2Int());
|
||||
template_using_directive_and_declaration_forward.useit2d(new Thing2Int());
|
||||
|
||||
//BROKEN template_using_directive_and_declaration_forward.useit3(new Thing3Int());
|
||||
template_using_directive_and_declaration_forward.useit3(new Thing3Int());
|
||||
template_using_directive_and_declaration_forward.useit3a(new Thing3Int());
|
||||
template_using_directive_and_declaration_forward.useit3b(new Thing3Int());
|
||||
template_using_directive_and_declaration_forward.useit3c(new Thing3Int());
|
||||
template_using_directive_and_declaration_forward.useit3d(new Thing3Int());
|
||||
|
||||
//BROKEN template_using_directive_and_declaration_forward.useit4(new Thing4Int());
|
||||
template_using_directive_and_declaration_forward.useit4(new Thing4Int());
|
||||
template_using_directive_and_declaration_forward.useit4a(new Thing4Int());
|
||||
template_using_directive_and_declaration_forward.useit4b(new Thing4Int());
|
||||
template_using_directive_and_declaration_forward.useit4c(new Thing4Int());
|
||||
template_using_directive_and_declaration_forward.useit4d(new Thing4Int());
|
||||
|
||||
//BROKEN template_using_directive_and_declaration_forward.useit5(new Thing5Int());
|
||||
template_using_directive_and_declaration_forward.useit5(new Thing5Int());
|
||||
template_using_directive_and_declaration_forward.useit5a(new Thing5Int());
|
||||
template_using_directive_and_declaration_forward.useit5b(new Thing5Int());
|
||||
template_using_directive_and_declaration_forward.useit5c(new Thing5Int());
|
||||
template_using_directive_and_declaration_forward.useit5d(new Thing5Int());
|
||||
|
||||
|
||||
//BROKEN template_using_directive_and_declaration_forward.useit7(new Thing7Int());
|
||||
template_using_directive_and_declaration_forward.useit7(new Thing7Int());
|
||||
template_using_directive_and_declaration_forward.useit7a(new Thing7Int());
|
||||
template_using_directive_and_declaration_forward.useit7b(new Thing7Int());
|
||||
template_using_directive_and_declaration_forward.useit7c(new Thing7Int());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
import template_using_directive_typedef.*;
|
||||
|
||||
public class template_using_directive_typedef_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("template_using_directive_typedef");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
Vector_Obj vo = new Vector_Obj();
|
||||
|
||||
Holder h = new Holder();
|
||||
h.holder_use1(vo, vo, vo);
|
||||
h.holder_use2(vo, vo, vo);
|
||||
h.holder_use3(vo, vo, vo);
|
||||
|
||||
template_using_directive_typedef.tns_holder_use(vo, vo);
|
||||
template_using_directive_typedef.tns_use(vo, vo, vo);
|
||||
template_using_directive_typedef.global_holder_use(vo);
|
||||
template_using_directive_typedef.global_use(vo, vo, vo);
|
||||
template_using_directive_typedef.ns1_holder_use(vo);
|
||||
template_using_directive_typedef.ns2_holder_use(vo, vo, vo, vo);
|
||||
}
|
||||
}
|
||||
|
||||
36
Examples/test-suite/namespace_chase.i
Normal file
36
Examples/test-suite/namespace_chase.i
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
%module namespace_chase
|
||||
|
||||
%inline %{
|
||||
namespace Space1A {
|
||||
struct Struct1A {};
|
||||
namespace Space1B {
|
||||
struct Struct1B {};
|
||||
namespace Space1C {
|
||||
struct Struct1C {};
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace Space2A {
|
||||
using namespace Space1A;
|
||||
namespace Space2B {
|
||||
using namespace Space1B;
|
||||
namespace Space2C {
|
||||
using namespace Space1C;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace Space3 {
|
||||
using namespace Space2A;
|
||||
void sss3a(Space1A::Struct1A, Space1A::Space1B::Struct1B, Space1A::Space1B::Space1C::Struct1C) {}
|
||||
void sss3b(Struct1A, Space1B::Struct1B, Space1B::Space1C::Struct1C) {}
|
||||
// To fix: the last two parameters below fail and result in SWIGTYPE_ types instead of proxy classes
|
||||
void sss3c(Space2A::Struct1A, Space2A::Space1B::Struct1B, Space2A::Space1B::Space1C::Struct1C) {}
|
||||
}
|
||||
namespace Space4 {
|
||||
using namespace Space2A;
|
||||
using namespace Space2A::Space2B;
|
||||
using namespace Space2A::Space2B::Space2C;
|
||||
void sss4a(Struct1A, Struct1B, Space2C::Struct1C) {}
|
||||
void sss4b(Struct1A, Struct1B, Struct1C) {}
|
||||
}
|
||||
%}
|
||||
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
%module namespace_template
|
||||
|
||||
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector<int>; /* Ruby, wrong class name */
|
||||
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) test2::vector<short>; /* Ruby, wrong class name */
|
||||
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) test3::vector<long>; /* Ruby, wrong class name */
|
||||
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector<test4::Integer>; /* Ruby, wrong class name */
|
||||
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) test::vector<int>; /* Ruby, wrong class name */
|
||||
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) test::vector<short>; /* Ruby, wrong class name */
|
||||
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) test::vector<long>; /* Ruby, wrong class name */
|
||||
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) test::vector<test::Char>; /* Ruby, wrong class name */
|
||||
|
||||
%{
|
||||
#ifdef max
|
||||
|
|
@ -23,20 +23,9 @@ namespace test {
|
|||
char * blah(T x) {
|
||||
return (char *) "vector::blah";
|
||||
}
|
||||
void vectoruse(vector<T> a, test::vector<T> b) {}
|
||||
};
|
||||
}
|
||||
|
||||
namespace test2 {
|
||||
using namespace test;
|
||||
}
|
||||
|
||||
namespace test3 {
|
||||
using test::max;
|
||||
using test::vector;
|
||||
}
|
||||
|
||||
using namespace test2;
|
||||
namespace T4 = test;
|
||||
%}
|
||||
|
||||
namespace test {
|
||||
|
|
@ -48,6 +37,7 @@ namespace test {
|
|||
char * blah(T x) {
|
||||
return (char *) "vector::blah";
|
||||
}
|
||||
void vectoruse(vector<T> a, test::vector<T> b) {}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -55,30 +45,26 @@ using namespace test;
|
|||
%template(maxint) max<int>;
|
||||
%template(vectorint) vector<int>;
|
||||
|
||||
namespace test2 {
|
||||
using namespace test;
|
||||
namespace test {
|
||||
%template(maxshort) max<short>;
|
||||
%template(vectorshort) vector<short>;
|
||||
}
|
||||
|
||||
namespace test3 {
|
||||
using test::max;
|
||||
using test::vector;
|
||||
namespace test {
|
||||
%template(maxlong) max<long>;
|
||||
%template(vectorlong) vector<long>;
|
||||
}
|
||||
|
||||
%inline %{
|
||||
|
||||
namespace test4 {
|
||||
using namespace test;
|
||||
typedef int Integer;
|
||||
namespace test {
|
||||
typedef char Char;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
namespace test4 {
|
||||
%template(maxInteger) max<Integer>;
|
||||
%template(vectorInteger) vector<Integer>;
|
||||
namespace test {
|
||||
%template(maxchar) max<Char>;
|
||||
%template(vectorchar) vector<Char>;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ Test::More Support
|
|||
==
|
||||
|
||||
Test::More is a standard perl test harness tool.
|
||||
Support was added for for using Test::More in 1.3.28.
|
||||
Support was added for using Test::More in 1.3.28.
|
||||
If adding a new test to this suite, please use Test::More.
|
||||
|
||||
There are a few legacy test cases which do not use Test::More and these ought to be converted:
|
||||
|
|
|
|||
|
|
@ -9,4 +9,3 @@ check::equal('1.5',(new ReflectionExtension('php_pragma'))->getVersion(),"1.5==v
|
|||
check::done();
|
||||
|
||||
?>
|
||||
|
||||
|
|
|
|||
|
|
@ -372,8 +372,9 @@ int methodX(int x) { return x+100; }
|
|||
|
||||
// Comma in macro - Github issue #974
|
||||
%inline %{
|
||||
#define __attribute__(x)
|
||||
#define TCX_PACKED(d) d __attribute__ ((__packed__))
|
||||
#define swig__attribute__(x)
|
||||
#define TCX_PACKED(d) d swig__attribute__ ((__packed__))
|
||||
|
||||
|
||||
TCX_PACKED (typedef struct tcxMessageTestImpl
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
import template_using_directive_typedef
|
||||
|
||||
vo = template_using_directive_typedef.Vector_Obj();
|
||||
|
||||
h = template_using_directive_typedef.Holder();
|
||||
h.holder_use1(vo, vo, vo);
|
||||
h.holder_use2(vo, vo, vo);
|
||||
h.holder_use3(vo, vo, vo);
|
||||
|
||||
template_using_directive_typedef.tns_holder_use(vo, vo);
|
||||
template_using_directive_typedef.tns_use(vo, vo, vo);
|
||||
template_using_directive_typedef.global_holder_use(vo);
|
||||
template_using_directive_typedef.global_use(vo, vo, vo);
|
||||
template_using_directive_typedef.ns1_holder_use(vo);
|
||||
template_using_directive_typedef.ns2_holder_use(vo, vo, vo, vo);
|
||||
32
Examples/test-suite/python/typemap_template_typedef_runme.py
Normal file
32
Examples/test-suite/python/typemap_template_typedef_runme.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from typemap_template_typedef import *
|
||||
|
||||
def check(got, expected):
|
||||
if got != expected:
|
||||
raise RuntimeError("got: " + str(got) + " expected: " + str(expected))
|
||||
|
||||
x = XXXInt()
|
||||
|
||||
check(x.aa1(0), 0)
|
||||
check(x.aa2(0), 55)
|
||||
check(x.aa3(0), 0)
|
||||
check(aa1(0), 0)
|
||||
check(aa2(0), 0)
|
||||
|
||||
check(x.bb1(0), 0)
|
||||
check(x.bb2(0), 66)
|
||||
check(x.bb3(0), 0)
|
||||
check(bb1(0), 0)
|
||||
check(bb2(0), 0)
|
||||
|
||||
check(x.cc1(0), 0)
|
||||
check(x.cc2(0), 77)
|
||||
check(x.cc3(0), 77)
|
||||
check(cc1(0), 0)
|
||||
check(cc2(0), 0)
|
||||
|
||||
check(x.dd1(0), 0)
|
||||
check(x.dd2(0), 88)
|
||||
check(x.dd3(0), 0)
|
||||
check(dd1(0), 0)
|
||||
check(dd2(0), 0)
|
||||
|
||||
|
|
@ -49,11 +49,6 @@ namespace one
|
|||
};
|
||||
}
|
||||
|
||||
%define PTR_DEF(o)
|
||||
typedef one::Ptr<o> o ## _ptr;
|
||||
%template(o ## _ptr) one::Ptr<o>;
|
||||
%enddef
|
||||
|
||||
namespace one
|
||||
{
|
||||
class Obj1
|
||||
|
|
@ -63,7 +58,8 @@ namespace one
|
|||
void donothing() {}
|
||||
};
|
||||
|
||||
PTR_DEF(Obj1)
|
||||
typedef one::Ptr<Obj1> Obj1_ptr;
|
||||
%template(Obj1_ptr) one::Ptr<Obj1>;
|
||||
}
|
||||
|
||||
namespace two
|
||||
|
|
@ -75,6 +71,9 @@ namespace two
|
|||
void donothing() {}
|
||||
};
|
||||
|
||||
PTR_DEF(Obj2)
|
||||
typedef one::Ptr<Obj2> Obj2_ptr;
|
||||
}
|
||||
|
||||
using two::Obj2;
|
||||
%template(Obj2_ptr) one::Ptr<Obj2>;
|
||||
|
||||
|
|
|
|||
33
Examples/test-suite/template_empty_inherit.i
Normal file
33
Examples/test-suite/template_empty_inherit.i
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
%module template_empty_inherit
|
||||
|
||||
%rename(FunctorOperator) operator();
|
||||
|
||||
%inline %{
|
||||
template<class Arg, typename Result> struct Functor {
|
||||
virtual Result operator()(Arg x) const = 0;
|
||||
};
|
||||
%}
|
||||
|
||||
// Bug fix - %ignore was resulting in this warning:
|
||||
// Warning 401: Base class 'Functor< int,int >' has no name as it is an empty template instantiated with '%template()'. Ignored.
|
||||
%ignore Functor<int, int>;
|
||||
%template() Functor<int, int>;
|
||||
|
||||
%inline %{
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
struct SquareFunctor : Functor<int, int> {
|
||||
int operator()(int v) const { return v*v; }
|
||||
};
|
||||
%}
|
||||
|
||||
%include <std_vector.i>
|
||||
%template(VectorInt) std::vector<int>;
|
||||
|
||||
%inline %{
|
||||
std::vector<int> squares(const std::vector<int>& vi) {
|
||||
std::vector<int> result;
|
||||
std::transform(vi.begin(), vi.end(), std::back_inserter(result), SquareFunctor());
|
||||
return result;
|
||||
}
|
||||
%}
|
||||
|
|
@ -1,25 +1,30 @@
|
|||
#pragma SWIG nowarn=SWIGWARN_PARSE_NESTED_TEMPLATE
|
||||
|
||||
%module template_nested_typemaps
|
||||
|
||||
// Testing that the typemaps invoked within a class via %template are picked up by appropriate methods
|
||||
#pragma SWIG nowarn=SWIGWARN_PARSE_NAMED_NESTED_CLASS
|
||||
|
||||
template <typename T> struct Typemap {
|
||||
%typemap(in) T {
|
||||
$1 = -99;
|
||||
}
|
||||
};
|
||||
template <> struct Typemap<short> { // Note explicit specialization
|
||||
%typemap(in) short {
|
||||
$1 = -77;
|
||||
}
|
||||
};
|
||||
// Testing that the typemaps invoked within a class via %template are picked up by appropriate methods
|
||||
// Only for languages that support nested classes
|
||||
|
||||
%inline %{
|
||||
int globalInt1(int s) { return s; }
|
||||
short globalShort1(short s) { return s; }
|
||||
|
||||
template <typename T> struct Breeze {
|
||||
template <typename TMT> struct Typemap {
|
||||
#ifdef SWIG
|
||||
%typemap(in) TMT {
|
||||
$1 = -99;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
template <typename TMT> struct TypemapShort {
|
||||
#ifdef SWIG
|
||||
%typemap(in) short {
|
||||
$1 = -77;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
int methodInt1(int s) { return s; }
|
||||
#if defined(SWIG)
|
||||
%template() Typemap<int>;
|
||||
|
|
@ -29,7 +34,7 @@ template <typename T> struct Breeze {
|
|||
|
||||
short methodShort1(short s) { return s; }
|
||||
#if defined(SWIG)
|
||||
%template(TypemapShort) Typemap<short>; // should issue warning SWIGWARN_PARSE_NESTED_TEMPLATE
|
||||
%template() TypemapShort<short>;
|
||||
#endif
|
||||
short methodShort2(short s) { return s; } // should pick up the typemap within Typemap<short>
|
||||
};
|
||||
|
|
|
|||
133
Examples/test-suite/template_parameters_global_scope.i
Normal file
133
Examples/test-suite/template_parameters_global_scope.i
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
%module template_parameters_global_scope
|
||||
|
||||
%inline %{
|
||||
namespace Alloc {
|
||||
template<typename T> struct Rebind {
|
||||
typedef int Integer;
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
struct Bucket_ {};
|
||||
typedef Bucket_ TDBucket;
|
||||
typedef ::Bucket_ TDGlobalBucket;
|
||||
%}
|
||||
|
||||
// Check 1: %template no unary scope operator
|
||||
%template(RebindBucket) Alloc::Rebind< Bucket_ >;
|
||||
|
||||
%inline %{
|
||||
Alloc::Rebind< Bucket_ >::Integer Bucket1() { return 1; }
|
||||
Alloc::Rebind< ::Bucket_ >::Integer Bucket2() { return 2; }
|
||||
Alloc::Rebind< TDBucket >::Integer Bucket3() { return 3; }
|
||||
Alloc::Rebind< ::TDBucket >::Integer Bucket4() { return 4; }
|
||||
Alloc::Rebind< TDGlobalBucket >::Integer Bucket5() { return 5; }
|
||||
Alloc::Rebind< ::TDGlobalBucket >::Integer Bucket6() { return 6; }
|
||||
%}
|
||||
|
||||
// Check 2: %template with unary scope operator
|
||||
%inline %{
|
||||
struct Spade {};
|
||||
typedef Spade TDSpade;
|
||||
typedef ::Spade TDGlobalSpade;
|
||||
%}
|
||||
%template(RebindSpade) Alloc::Rebind< ::Spade >;
|
||||
|
||||
%inline %{
|
||||
Alloc::Rebind< Spade >::Integer Spade1() { return 1; }
|
||||
Alloc::Rebind< ::Spade >::Integer Spade2() { return 2; }
|
||||
Alloc::Rebind< TDSpade >::Integer Spade3() { return 3; }
|
||||
Alloc::Rebind< ::TDSpade >::Integer Spade4() { return 4; }
|
||||
Alloc::Rebind< TDGlobalSpade >::Integer Spade5() { return 5; }
|
||||
Alloc::Rebind< ::TDGlobalSpade >::Integer Spade6() { return 6; }
|
||||
%}
|
||||
|
||||
// Check 3: %template typedef no unary scope operator
|
||||
%inline %{
|
||||
struct Ball {};
|
||||
typedef Ball TDBall;
|
||||
typedef ::Ball TDGlobalBall;
|
||||
%}
|
||||
%template(RebindBall) Alloc::Rebind< TDBall >;
|
||||
|
||||
%inline %{
|
||||
Alloc::Rebind< Ball >::Integer Ball1() { return 1; }
|
||||
Alloc::Rebind< ::Ball >::Integer Ball2() { return 2; }
|
||||
Alloc::Rebind< TDBall >::Integer Ball3() { return 3; }
|
||||
Alloc::Rebind< ::TDBall >::Integer Ball4() { return 4; }
|
||||
Alloc::Rebind< TDGlobalBall >::Integer Ball5() { return 5; }
|
||||
Alloc::Rebind< ::TDGlobalBall >::Integer Ball6() { return 6; }
|
||||
%}
|
||||
|
||||
// Check 4: %template typedef with unary scope operator
|
||||
%inline %{
|
||||
struct Bat {};
|
||||
typedef Bat TDBat;
|
||||
typedef ::Bat TDGlobalBat;
|
||||
%}
|
||||
%template(RebindBat) Alloc::Rebind< ::TDBat >;
|
||||
|
||||
%inline %{
|
||||
Alloc::Rebind< Bat >::Integer Bat1() { return 1; }
|
||||
Alloc::Rebind< ::Bat >::Integer Bat2() { return 2; }
|
||||
Alloc::Rebind< TDBat >::Integer Bat3() { return 3; }
|
||||
Alloc::Rebind< ::TDBat >::Integer Bat4() { return 4; }
|
||||
Alloc::Rebind< TDGlobalBat >::Integer Bat5() { return 5; }
|
||||
Alloc::Rebind< ::TDGlobalBat >::Integer Bat6() { return 6; }
|
||||
%}
|
||||
|
||||
// Check 5: %template double typedef no unary scope operator
|
||||
%inline %{
|
||||
struct Chair {};
|
||||
typedef Chair TDChair;
|
||||
typedef ::Chair TDGlobalChair;
|
||||
%}
|
||||
%template(RebindChair) Alloc::Rebind< TDGlobalChair >;
|
||||
|
||||
%inline %{
|
||||
Alloc::Rebind< Chair >::Integer Chair1() { return 1; }
|
||||
Alloc::Rebind< ::Chair >::Integer Chair2() { return 2; }
|
||||
Alloc::Rebind< TDChair >::Integer Chair3() { return 3; }
|
||||
Alloc::Rebind< ::TDChair >::Integer Chair4() { return 4; }
|
||||
Alloc::Rebind< TDGlobalChair >::Integer Chair5() { return 5; }
|
||||
Alloc::Rebind< ::TDGlobalChair >::Integer Chair6() { return 6; }
|
||||
%}
|
||||
|
||||
// Check 6: %template double typedef with unary scope operator
|
||||
%inline %{
|
||||
struct Table {};
|
||||
typedef Table TDTable;
|
||||
typedef ::Table TDGlobalTable;
|
||||
%}
|
||||
%template(RebindTable) Alloc::Rebind< ::TDGlobalTable >;
|
||||
|
||||
%inline %{
|
||||
Alloc::Rebind< Table >::Integer Table1() { return 1; }
|
||||
Alloc::Rebind< ::Table >::Integer Table2() { return 2; }
|
||||
Alloc::Rebind< TDTable >::Integer Table3() { return 3; }
|
||||
Alloc::Rebind< ::TDTable >::Integer Table4() { return 4; }
|
||||
Alloc::Rebind< TDGlobalTable >::Integer Table5() { return 5; }
|
||||
Alloc::Rebind< ::TDGlobalTable >::Integer Table6() { return 6; }
|
||||
%}
|
||||
|
||||
#if 0
|
||||
%inline %{
|
||||
namespace Alloc {
|
||||
template<typename T=::Spade/*, typename T2=TDSpade, typename T3=::TDSpade, typename T4=TDGlobalSpade, typename T5=::TDGlobalSpade*/> struct Rejig {
|
||||
typedef int Integer;
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
||||
%template(RejigSpade) Alloc::Rejig<::Spade>;
|
||||
|
||||
%inline %{
|
||||
Alloc::Rejig<>::Integer rejig1() { return 1; }
|
||||
Alloc::Rejig< ::Spade >::Integer rejig2() { return 2; }
|
||||
Alloc::Rejig< ::TDSpade >::Integer rejig3() { return 3; }
|
||||
Alloc::Rejig< ::TDSpade >::Integer rejig4() { return 4; }
|
||||
Alloc::Rejig< TDGlobalSpade >::Integer rejig5() { return 5; }
|
||||
Alloc::Rejig< ::TDGlobalSpade >::Integer rejig6() { return 6; }
|
||||
%}
|
||||
#endif
|
||||
|
|
@ -32,7 +32,7 @@ namespace One {
|
|||
%template(H) One::OneParm<int **>;
|
||||
|
||||
// %template scope explicit specializations
|
||||
namespace ONE {
|
||||
namespace One {
|
||||
%template(I) One::OneParm<float>;
|
||||
%template(J) ::One::OneParm<float *>;
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ namespace One {
|
|||
}
|
||||
|
||||
// %template scope partial specializations
|
||||
namespace ONE {
|
||||
namespace One {
|
||||
%template(BB) One::OneParm<bool *>;
|
||||
%template(BBB) ::One::OneParm<char *>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ namespace One {
|
|||
%template(H) One::OneParm<TypeDef::IntPtrPtr>;
|
||||
|
||||
// %template scope explicit specializations
|
||||
namespace ONE {
|
||||
namespace One {
|
||||
%template(I) One::OneParm<TypeDef::Float>;
|
||||
%template(J) ::One::OneParm<TypeDef::FloatPtr>;
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ namespace One {
|
|||
}
|
||||
|
||||
// %template scope partial specializations
|
||||
namespace ONE {
|
||||
namespace One {
|
||||
%template(BB) One::OneParm<TypeDef::BoolPtr>;
|
||||
%template(BBB) ::One::OneParm<TypeDef::CharPtr>;
|
||||
}
|
||||
|
|
|
|||
44
Examples/test-suite/template_using_directive_typedef.i
Normal file
44
Examples/test-suite/template_using_directive_typedef.i
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
%module template_using_directive_typedef
|
||||
|
||||
%inline %{
|
||||
namespace space {
|
||||
template<typename T> class Vector {};
|
||||
class VectorClass {};
|
||||
}
|
||||
struct Obj {};
|
||||
%}
|
||||
|
||||
%template(Vector_Obj) space::Vector<Obj>;
|
||||
|
||||
%inline %{
|
||||
namespace tns {
|
||||
using space::Vector; // template using directives were not being added into the typedef table
|
||||
using space::VectorClass;
|
||||
typedef Vector<Obj> NSVec;
|
||||
}
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
namespace tns {
|
||||
struct Holder {
|
||||
// using Vec = Vector<Obj>;
|
||||
typedef Vector<Obj> Vec;
|
||||
typedef VectorClass VecClass;
|
||||
Vec items;
|
||||
void holder_use1(space::Vector<Obj>, tns::NSVec, tns::Vector<Obj>) {}
|
||||
void holder_use2(space::Vector<Obj>, NSVec, Vector<Obj>) {}
|
||||
void holder_use3(tns::Holder::Vec, Holder::Vec, Vec) {}
|
||||
};
|
||||
void tns_holder_use(tns::Holder::Vec, Holder::Vec) {}
|
||||
void tns_use(space::Vector<Obj>, NSVec, tns::NSVec) {}
|
||||
}
|
||||
void global_holder_use(tns::Holder::Vec) {}
|
||||
void global_use(space::Vector<Obj>, tns::NSVec, tns::Vector<Obj>) {}
|
||||
namespace ns1 {
|
||||
void ns1_holder_use(tns::Holder::Vec) {}
|
||||
}
|
||||
namespace ns2 {
|
||||
using namespace tns;
|
||||
void ns2_holder_use(tns::Holder::Vec, Holder::Vec, NSVec, Vector<Obj>) {}
|
||||
}
|
||||
%}
|
||||
66
Examples/test-suite/typemap_template_typedef.i
Normal file
66
Examples/test-suite/typemap_template_typedef.i
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
%module typemap_template_typedef
|
||||
//%module("templatereduce") typemap_template_typedef
|
||||
|
||||
%typemap(in) int TMAP55 %{ $1 = 55; /* int TMAP55 typemap */ %}
|
||||
%typemap(in) int TMAP66 %{ $1 = 66; /* int TMAP66 typemap */ %}
|
||||
%typemap(in) int TMAP77 %{ $1 = 77; /* int TMAP77 typemap */ %}
|
||||
%typemap(in) int TMAP88 %{ $1 = 88; /* int TMAP88 typemap */ %}
|
||||
|
||||
%apply int TMAP77 { XXX<int>::Long cc }
|
||||
|
||||
%inline %{
|
||||
typedef int Integer;
|
||||
|
||||
template<typename T> struct XXX {
|
||||
#ifdef SWIG
|
||||
// In swig-3.0.12 'Long aa' was actually stored as 'long aa' in typemap table instead of 'XXX<int>::Long aa'
|
||||
%apply int TMAP55 { Long aa }
|
||||
%apply int TMAP66 { XXX<int>::Long bb }
|
||||
%apply int TMAP88 { XXX<Integer>::Long dd }
|
||||
#endif
|
||||
typedef long Long;
|
||||
long aa1(long aa) { return aa; }
|
||||
long aa2(Long aa) { return aa; }
|
||||
long bb1(long bb) { return bb; }
|
||||
long bb2(Long bb) { return bb; }
|
||||
long cc1(long cc) { return cc; }
|
||||
long cc2(Long cc) { return cc; }
|
||||
long dd1(long dd) { return dd; }
|
||||
long dd2(Long dd) { return dd; }
|
||||
#ifdef SWIG
|
||||
%clear Long aa;
|
||||
%clear XXX<int>::Long bb;
|
||||
%clear XXX<Integer>::Long dd;
|
||||
#endif
|
||||
long aa3(Long aa) { return aa; }
|
||||
long bb3(Long bb) { return bb; }
|
||||
long cc3(Long cc) { return cc; }
|
||||
long dd3(Long dd) { return dd; }
|
||||
};
|
||||
%}
|
||||
|
||||
%template(XXXInt) XXX<Integer>;
|
||||
|
||||
%clear XXX<int>::Long cc;
|
||||
|
||||
%inline %{
|
||||
long aa1(XXX<int>::Long aa) { return aa; }
|
||||
long aa2(long aa) { return aa; }
|
||||
long bb1(XXX<int>::Long bb) { return bb; }
|
||||
long bb2(long bb) { return bb; }
|
||||
long cc1(XXX<int>::Long cc) { return cc; }
|
||||
long cc2(long cc) { return cc; }
|
||||
long dd1(XXX<Integer>::Long dd) { return dd; }
|
||||
long dd2(long dd) { return dd; }
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
typedef Integer INTEGER;
|
||||
template<typename T1, typename T2 = INTEGER> struct YYY {
|
||||
void meff(T1 t1, T2 t2) {}
|
||||
};
|
||||
%}
|
||||
%template(YYYIntInt) YYY<INTEGER>;
|
||||
%inline %{
|
||||
void whyohwhy(YYY<INTEGER> yy) {}
|
||||
%}
|
||||
|
|
@ -162,7 +162,7 @@
|
|||
return ret;
|
||||
}
|
||||
|
||||
// Treat references to arrays like like references to a single element.
|
||||
// Treat references to arrays like references to a single element.
|
||||
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ typedef struct swig_elua_entry {
|
|||
* -------------------------------------------------------------------------- */
|
||||
|
||||
/* Push the string STR on the Lua stack, like lua_pushstring, but
|
||||
prefixed with the the location of the innermost Lua call-point
|
||||
prefixed with the location of the innermost Lua call-point
|
||||
(as formated by luaL_where). */
|
||||
SWIGRUNTIME void
|
||||
SWIG_Lua_pusherrstring (lua_State *L, const char *str)
|
||||
|
|
@ -191,7 +191,7 @@ SWIG_Lua_pusherrstring (lua_State *L, const char *str)
|
|||
}
|
||||
|
||||
/* Push a formatted string generated from FMT and following args on
|
||||
the Lua stack, like lua_pushfstring, but prefixed with the the
|
||||
the Lua stack, like lua_pushfstring, but prefixed with the
|
||||
location of the innermost Lua call-point (as formated by luaL_where). */
|
||||
SWIGRUNTIME void
|
||||
SWIG_Lua_pushferrstring (lua_State *L, const char *fmt, ...)
|
||||
|
|
|
|||
|
|
@ -202,8 +202,8 @@ namespace swig
|
|||
// swig::SwigVar_PyObject item = OctSequence_GetItem(_seq, _index);
|
||||
octave_value item; // * todo
|
||||
try {
|
||||
return swig::as<T>(item, true);
|
||||
} catch (std::exception& e) {
|
||||
return swig::as<T>(item);
|
||||
} catch (const std::exception& e) {
|
||||
char msg[1024];
|
||||
sprintf(msg, "in sequence element %d ", _index);
|
||||
if (!Octave_Error_Occurred()) {
|
||||
|
|
|
|||
|
|
@ -103,14 +103,14 @@ namespace swig {
|
|||
|
||||
template <class Type>
|
||||
struct traits_as<Type, value_category> {
|
||||
static Type as(const octave_value& obj, bool throw_error) {
|
||||
static Type as(const octave_value& obj) {
|
||||
Type v;
|
||||
int res = asval(obj, &v);
|
||||
if (!obj.is_defined() || !SWIG_IsOK(res)) {
|
||||
if (!Octave_Error_Occurred()) {
|
||||
%type_error(swig::type_name<Type>());
|
||||
}
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
throw std::invalid_argument("bad type");
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ namespace swig {
|
|||
|
||||
template <class Type>
|
||||
struct traits_as<Type, pointer_category> {
|
||||
static Type as(const octave_value& obj, bool throw_error) {
|
||||
static Type as(const octave_value& obj) {
|
||||
Type *v = 0;
|
||||
int res = traits_asptr<Type>::asptr(obj, &v);
|
||||
if (SWIG_IsOK(res) && v) {
|
||||
|
|
@ -130,21 +130,17 @@ namespace swig {
|
|||
return *v;
|
||||
}
|
||||
} else {
|
||||
// Uninitialized return value, no Type() constructor required.
|
||||
static Type *v_def = (Type*) malloc(sizeof(Type));
|
||||
if (!Octave_Error_Occurred()) {
|
||||
%type_error(swig::type_name<Type>());
|
||||
}
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
memset(v_def,0,sizeof(Type));
|
||||
return *v_def;
|
||||
throw std::invalid_argument("bad type");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
struct traits_as<Type*, pointer_category> {
|
||||
static Type* as(const octave_value& obj, bool throw_error) {
|
||||
static Type* as(const octave_value& obj) {
|
||||
Type *v = 0;
|
||||
int res = traits_asptr<Type>::asptr(obj, &v);
|
||||
if (SWIG_IsOK(res)) {
|
||||
|
|
@ -153,15 +149,14 @@ namespace swig {
|
|||
if (!Octave_Error_Occurred()) {
|
||||
%type_error(swig::type_name<Type>());
|
||||
}
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
return 0;
|
||||
throw std::invalid_argument("bad type");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
inline Type as(const octave_value& obj, bool te = false) {
|
||||
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
|
||||
inline Type as(const octave_value& obj) {
|
||||
return traits_as<Type, typename traits<Type>::category>::as(obj);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
|
|
|
|||
|
|
@ -392,7 +392,7 @@ SWIG_Perl_NewPackedObj(SWIG_MAYBE_PERL_OBJECT void *ptr, int sz, swig_type_info
|
|||
return result;
|
||||
}
|
||||
|
||||
/* Convert a packed value value */
|
||||
/* Convert a packed pointer value */
|
||||
SWIGRUNTIME int
|
||||
SWIG_Perl_ConvertPacked(SWIG_MAYBE_PERL_OBJECT SV *obj, void *ptr, int sz, swig_type_info *ty) {
|
||||
swig_cast_info *tc;
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@
|
|||
%typemap(in) SWIGTYPE *DISOWN
|
||||
{
|
||||
if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) {
|
||||
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor");
|
||||
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -434,8 +434,8 @@ namespace swig
|
|||
{
|
||||
swig::SwigVar_PyObject item = PySequence_GetItem(_seq, _index);
|
||||
try {
|
||||
return swig::as<T>(item, true);
|
||||
} catch (std::exception& e) {
|
||||
return swig::as<T>(item);
|
||||
} catch (const std::invalid_argument& e) {
|
||||
char msg[1024];
|
||||
sprintf(msg, "in sequence element %d ", (int)_index);
|
||||
if (!PyErr_Occurred()) {
|
||||
|
|
|
|||
|
|
@ -538,7 +538,7 @@ SwigPyObject_dealloc(PyObject *v)
|
|||
PyObject *res;
|
||||
|
||||
/* PyObject_CallFunction() has the potential to silently drop
|
||||
the active active exception. In cases of unnamed temporary
|
||||
the active exception. In cases of unnamed temporary
|
||||
variable or where we just finished iterating over a generator
|
||||
StopIteration will be active right now, and this needs to
|
||||
remain true upon return from SwigPyObject_dealloc. So save
|
||||
|
|
@ -1308,7 +1308,7 @@ SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) {
|
|||
}
|
||||
}
|
||||
|
||||
/* Convert a packed value value */
|
||||
/* Convert a packed pointer value */
|
||||
|
||||
SWIGRUNTIME int
|
||||
SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) {
|
||||
|
|
|
|||
|
|
@ -107,14 +107,14 @@ namespace swig {
|
|||
|
||||
template <class Type>
|
||||
struct traits_as<Type, value_category> {
|
||||
static Type as(PyObject *obj, bool throw_error) {
|
||||
static Type as(PyObject *obj) {
|
||||
Type v;
|
||||
int res = asval(obj, &v);
|
||||
if (!obj || !SWIG_IsOK(res)) {
|
||||
if (!PyErr_Occurred()) {
|
||||
::%type_error(swig::type_name<Type>());
|
||||
}
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
throw std::invalid_argument("bad type");
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ namespace swig {
|
|||
|
||||
template <class Type>
|
||||
struct traits_as<Type, pointer_category> {
|
||||
static Type as(PyObject *obj, bool throw_error) {
|
||||
static Type as(PyObject *obj) {
|
||||
Type *v = 0;
|
||||
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
|
||||
if (SWIG_IsOK(res) && v) {
|
||||
|
|
@ -134,21 +134,17 @@ namespace swig {
|
|||
return *v;
|
||||
}
|
||||
} else {
|
||||
// Uninitialized return value, no Type() constructor required.
|
||||
static Type *v_def = (Type*) malloc(sizeof(Type));
|
||||
if (!PyErr_Occurred()) {
|
||||
%type_error(swig::type_name<Type>());
|
||||
}
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
memset(v_def,0,sizeof(Type));
|
||||
return *v_def;
|
||||
throw std::invalid_argument("bad type");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
struct traits_as<Type*, pointer_category> {
|
||||
static Type* as(PyObject *obj, bool throw_error) {
|
||||
static Type* as(PyObject *obj) {
|
||||
Type *v = 0;
|
||||
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
|
||||
if (SWIG_IsOK(res)) {
|
||||
|
|
@ -157,15 +153,14 @@ namespace swig {
|
|||
if (!PyErr_Occurred()) {
|
||||
%type_error(swig::type_name<Type>());
|
||||
}
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
return 0;
|
||||
throw std::invalid_argument("bad type");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
inline Type as(PyObject *obj, bool te = false) {
|
||||
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
|
||||
inline Type as(PyObject *obj) {
|
||||
return traits_as<Type, typename traits<Type>::category>::as(obj);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
|
|
|
|||
|
|
@ -350,7 +350,7 @@ SWIG_R_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {
|
|||
return ptr ? RSwigPacked_New((void *) ptr, sz, type) : R_NilValue;
|
||||
}
|
||||
|
||||
/* Convert a packed value value */
|
||||
/* Convert a packed pointer value */
|
||||
|
||||
SWIGRUNTIME int
|
||||
SWIG_R_ConvertPacked(SEXP obj, void *ptr, size_t sz, swig_type_info *ty) {
|
||||
|
|
|
|||
|
|
@ -101,12 +101,11 @@ namespace swig {
|
|||
|
||||
template <class Type>
|
||||
struct traits_as<Type, value_category> {
|
||||
static Type as(SWIG_Object obj, bool throw_error) {
|
||||
static Type as(SWIG_Object obj) {
|
||||
Type v;
|
||||
int res = asval(obj, &v);
|
||||
if (!obj || !SWIG_IsOK(res)) {
|
||||
if (throw_error)
|
||||
throw std::invalid_argument("bad type");
|
||||
throw std::invalid_argument("bad type");
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
|
@ -114,7 +113,7 @@ namespace swig {
|
|||
|
||||
template <class Type>
|
||||
struct traits_as<Type, pointer_category> {
|
||||
static Type as(SWIG_Object obj, bool throw_error) {
|
||||
static Type as(SWIG_Object obj) {
|
||||
Type *v = 0;
|
||||
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
|
||||
if (SWIG_IsOK(res) && v) {
|
||||
|
|
@ -126,12 +125,7 @@ namespace swig {
|
|||
return *v;
|
||||
}
|
||||
} else {
|
||||
// Uninitialized return value, no Type() constructor required.
|
||||
static Type *v_def = (Type*) malloc(sizeof(Type));
|
||||
if (throw_error)
|
||||
throw std::invalid_argument("bad type");
|
||||
memset(v_def,0,sizeof(Type));
|
||||
return *v_def;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -152,8 +146,8 @@ namespace swig {
|
|||
};
|
||||
|
||||
template <class Type>
|
||||
inline Type as(SWIG_Object obj, bool te = false) {
|
||||
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
|
||||
inline Type as(SWIG_Object obj) {
|
||||
return traits_as<Type, typename traits<Type>::category>::as(obj);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
|
||||
# This could be provided as a separate run-time library but this
|
||||
# approach allows the code to to be included directly into the
|
||||
# approach allows the code to be included directly into the
|
||||
# generated bindings and so removes the need to have and install an
|
||||
# additional library. We may however end up with multiple copies of
|
||||
# this and some confusion at run-time as to which class to use. This
|
||||
|
|
|
|||
|
|
@ -183,8 +183,8 @@ namespace swig
|
|||
{
|
||||
VALUE item = rb_ary_entry(_seq, _index );
|
||||
try {
|
||||
return swig::as<T>(item, true);
|
||||
} catch (std::exception& e) {
|
||||
return swig::as<T>(item);
|
||||
} catch (const std::invalid_argument& e) {
|
||||
char msg[1024];
|
||||
sprintf(msg, "in sequence element %d ", _index);
|
||||
VALUE lastErr = rb_gv_get("$!");
|
||||
|
|
@ -926,7 +926,7 @@ namespace swig
|
|||
VALUE elem = argv[0];
|
||||
int idx = 0;
|
||||
try {
|
||||
Sequence::value_type val = swig::as<Sequence::value_type>( elem, true );
|
||||
Sequence::value_type val = swig::as<Sequence::value_type>( elem );
|
||||
if ( i >= len ) {
|
||||
$self->resize(i-1, val);
|
||||
return $self;
|
||||
|
|
@ -943,7 +943,7 @@ namespace swig
|
|||
}
|
||||
|
||||
}
|
||||
catch( std::invalid_argument )
|
||||
catch( const std::invalid_argument & )
|
||||
{
|
||||
rb_raise( rb_eArgError, "%s",
|
||||
Ruby_Format_TypeError( "",
|
||||
|
|
@ -967,10 +967,10 @@ namespace swig
|
|||
Sequence::iterator start = $self->begin();
|
||||
VALUE elem = argv[idx];
|
||||
try {
|
||||
Sequence::value_type val = swig::as<Sequence::value_type>( elem, true );
|
||||
Sequence::value_type val = swig::as<Sequence::value_type>( elem );
|
||||
$self->insert( start, val );
|
||||
}
|
||||
catch( std::invalid_argument )
|
||||
catch( const std::invalid_argument & )
|
||||
{
|
||||
rb_raise( rb_eArgError, "%s",
|
||||
Ruby_Format_TypeError( "",
|
||||
|
|
|
|||
|
|
@ -363,7 +363,7 @@ SWIG_Ruby_NewPackedObj(void *ptr, int sz, swig_type_info *type) {
|
|||
return rb_str_new2(result);
|
||||
}
|
||||
|
||||
/* Convert a packed value value */
|
||||
/* Convert a packed pointer value */
|
||||
SWIGRUNTIME int
|
||||
SWIG_Ruby_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty) {
|
||||
swig_cast_info *tc;
|
||||
|
|
|
|||
|
|
@ -115,15 +115,15 @@ namespace swig {
|
|||
|
||||
template <class Type>
|
||||
struct traits_as<Type, value_category> {
|
||||
static Type as(VALUE obj, bool throw_error) {
|
||||
static Type as(VALUE obj) {
|
||||
Type v;
|
||||
int res = asval(obj, &v);
|
||||
if (!SWIG_IsOK(res)) {
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
VALUE lastErr = rb_gv_get("$!");
|
||||
if (lastErr == Qnil) {
|
||||
%type_error(swig::type_name<Type>());
|
||||
}
|
||||
throw std::invalid_argument("bad type");
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
|
@ -131,7 +131,7 @@ namespace swig {
|
|||
|
||||
template <class Type>
|
||||
struct traits_as<Type, pointer_category> {
|
||||
static Type as(VALUE obj, bool throw_error) {
|
||||
static Type as(VALUE obj) {
|
||||
Type *v = 0;
|
||||
int res = traits_asptr<Type>::asptr(obj, &v);
|
||||
if (SWIG_IsOK(res) && v) {
|
||||
|
|
@ -143,40 +143,35 @@ namespace swig {
|
|||
return *v;
|
||||
}
|
||||
} else {
|
||||
// Uninitialized return value, no Type() constructor required.
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
VALUE lastErr = rb_gv_get("$!");
|
||||
if (lastErr == Qnil) {
|
||||
%type_error(swig::type_name<Type>());
|
||||
}
|
||||
static Type *v_def = (Type*) malloc(sizeof(Type));
|
||||
memset(v_def,0,sizeof(Type));
|
||||
return *v_def;
|
||||
throw std::invalid_argument("bad type");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
struct traits_as<Type*, pointer_category> {
|
||||
static Type* as(VALUE obj, bool throw_error) {
|
||||
static Type* as(VALUE obj) {
|
||||
Type *v = 0;
|
||||
int res = traits_asptr<Type>::asptr(obj, &v);
|
||||
if (SWIG_IsOK(res)) {
|
||||
return v;
|
||||
} else {
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
VALUE lastErr = rb_gv_get("$!");
|
||||
if (lastErr == Qnil) {
|
||||
%type_error(swig::type_name<Type>());
|
||||
}
|
||||
return 0;
|
||||
throw std::invalid_argument("bad type");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
inline Type as(VALUE obj, bool te = false) {
|
||||
return traits_as< Type, typename traits< Type >::category >::as(obj, te);
|
||||
inline Type as(VALUE obj) {
|
||||
return traits_as< Type, typename traits< Type >::category >::as(obj);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
|
|
|
|||
|
|
@ -80,35 +80,35 @@ namespace swig {
|
|||
|
||||
template <class Type>
|
||||
struct traits_as<std::shared_ptr<Type>, pointer_category> {
|
||||
static std::shared_ptr<Type> as(VALUE obj, bool throw_error) {
|
||||
static std::shared_ptr<Type> as(VALUE obj) {
|
||||
std::shared_ptr<Type> ret;
|
||||
std::shared_ptr<Type> *v = &ret;
|
||||
int res = traits_asptr<std::shared_ptr<Type> >::asptr(obj, &v);
|
||||
if (SWIG_IsOK(res)) {
|
||||
return ret;
|
||||
} else {
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
|
||||
VALUE lastErr = rb_gv_get("$!");
|
||||
if (lastErr == Qnil)
|
||||
SWIG_Error(SWIG_TypeError, swig::type_name<std::shared_ptr<Type> >());
|
||||
return std::shared_ptr<Type>();
|
||||
throw std::invalid_argument("bad type");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
struct traits_as<std::shared_ptr<Type> *, pointer_category> {
|
||||
static std::shared_ptr<Type> * as(VALUE obj, bool throw_error) {
|
||||
static std::shared_ptr<Type> * as(VALUE obj) {
|
||||
std::shared_ptr<Type> *p = 0;
|
||||
int res = traits_asptr<std::shared_ptr<Type> >::asptr(obj, &p);
|
||||
if (SWIG_IsOK(res)) {
|
||||
return p;
|
||||
} else {
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
|
||||
VALUE lastErr = rb_gv_get("$!");
|
||||
if (lastErr == Qnil)
|
||||
SWIG_Error(SWIG_TypeError, swig::type_name<std::shared_ptr<Type> *>());
|
||||
return 0;
|
||||
throw std::invalid_argument("bad type");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -104,23 +104,21 @@ namespace swig {
|
|||
|
||||
template <class Type>
|
||||
struct traits_as<Type, value_category> {
|
||||
static Type as(const SwigSciObject& obj, bool throw_error) {
|
||||
static Type as(const SwigSciObject& obj) {
|
||||
Type v;
|
||||
int res = asval(obj, &v);
|
||||
if (SWIG_IsOK(res)) {
|
||||
return v;
|
||||
} else {
|
||||
%type_error(swig::type_name<Type>());
|
||||
if (throw_error)
|
||||
throw std::invalid_argument("bad type");
|
||||
return res;
|
||||
%type_error(swig::type_name<Type>());
|
||||
throw std::invalid_argument("bad type");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
struct traits_as<Type, pointer_category> {
|
||||
static Type as(const SwigSciObject& obj, bool throw_error) {
|
||||
static Type as(const SwigSciObject& obj) {
|
||||
Type *v = 0;
|
||||
int res = traits_asptr<Type>::asptr(obj, &v);
|
||||
if (SWIG_IsOK(res) && v) {
|
||||
|
|
@ -132,36 +130,29 @@ namespace swig {
|
|||
return *v;
|
||||
}
|
||||
} else {
|
||||
// Uninitialized return value, no Type() constructor required.
|
||||
static Type *v_def = (Type*) malloc(sizeof(Type));
|
||||
%type_error(swig::type_name<Type>());
|
||||
if (throw_error)
|
||||
throw std::invalid_argument("bad type");
|
||||
memset(v_def,0,sizeof(Type));
|
||||
return *v_def;
|
||||
%type_error(swig::type_name<Type>());
|
||||
throw std::invalid_argument("bad type");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
struct traits_as<Type*, pointer_category> {
|
||||
static Type* as(const SwigSciObject& obj, bool throw_error) {
|
||||
static Type* as(const SwigSciObject& obj) {
|
||||
Type *v = 0;
|
||||
int res = traits_asptr<Type>::asptr(obj, &v);
|
||||
if (SWIG_IsOK(res)) {
|
||||
return v;
|
||||
} else {
|
||||
%type_error(swig::type_name<Type>());
|
||||
if (throw_error)
|
||||
throw std::invalid_argument("bad type");
|
||||
return SWIG_OK;
|
||||
%type_error(swig::type_name<Type>());
|
||||
throw std::invalid_argument("bad type");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
inline Type as(const SwigSciObject& obj, bool te = false) {
|
||||
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
|
||||
inline Type as(const SwigSciObject& obj) {
|
||||
return traits_as<Type, typename traits<Type>::category>::as(obj);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#define SWIG_Object int
|
||||
|
||||
#define %append_output(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR
|
||||
#define %set_constant(name, obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR // Name is managed by the the function name
|
||||
#define %set_constant(name, obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR // Name is managed by the function name
|
||||
#define %raise(obj, type, desc) SWIG_Scilab_Raise(obj, type, desc)
|
||||
#define %set_output(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR
|
||||
#define %set_varoutput(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ SWIG_Tcl_PointerTypeFromString(char *c) {
|
|||
return c;
|
||||
}
|
||||
|
||||
/* Convert a packed value value */
|
||||
/* Convert a packed pointer value */
|
||||
SWIGRUNTIME int
|
||||
SWIG_Tcl_ConvertPacked(Tcl_Interp *SWIGUNUSEDPARM(interp) , Tcl_Obj *obj, void *ptr, int sz, swig_type_info *ty) {
|
||||
swig_cast_info *tc;
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ static String *yyrename = 0;
|
|||
|
||||
/* Forward renaming operator */
|
||||
|
||||
static String *resolve_create_node_scope(String *cname);
|
||||
static String *resolve_create_node_scope(String *cname, int is_class_definition);
|
||||
|
||||
|
||||
Hash *Swig_cparse_features(void) {
|
||||
|
|
@ -815,32 +815,53 @@ static String *remove_block(Node *kw, const String *inputcode) {
|
|||
return modified_code;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
#define RESOLVE_DEBUG 1
|
||||
*/
|
||||
static Node *nscope = 0;
|
||||
static Node *nscope_inner = 0;
|
||||
|
||||
/* Remove the scope prefix from cname and return the base name without the prefix.
|
||||
* The scopes required for the symbol name are resolved and/or created, if required.
|
||||
* For example AA::BB::CC as input returns CC and creates the namespace AA then inner
|
||||
* namespace BB in the current scope. If cname is found to already exist as a weak symbol
|
||||
* (forward reference) then the scope might be changed to match, such as when a symbol match
|
||||
* is made via a using reference. */
|
||||
static String *resolve_create_node_scope(String *cname) {
|
||||
* namespace BB in the current scope. */
|
||||
static String *resolve_create_node_scope(String *cname, int is_class_definition) {
|
||||
Symtab *gscope = 0;
|
||||
Node *cname_node = 0;
|
||||
int skip_lookup = 0;
|
||||
String *last = Swig_scopename_last(cname);
|
||||
nscope = 0;
|
||||
nscope_inner = 0;
|
||||
|
||||
if (Strncmp(cname,"::",2) == 0)
|
||||
skip_lookup = 1;
|
||||
|
||||
cname_node = skip_lookup ? 0 : Swig_symbol_clookup_no_inherit(cname, 0);
|
||||
if (Strncmp(cname,"::" ,2) != 0) {
|
||||
if (is_class_definition) {
|
||||
/* Only lookup symbols which are in scope via a using declaration but not via a using directive.
|
||||
For example find y via 'using x::y' but not y via a 'using namespace x'. */
|
||||
cname_node = Swig_symbol_clookup_no_inherit(cname, 0);
|
||||
if (!cname_node) {
|
||||
Node *full_lookup_node = Swig_symbol_clookup(cname, 0);
|
||||
if (full_lookup_node) {
|
||||
/* This finds a symbol brought into scope via both a using directive and a using declaration. */
|
||||
Node *last_node = Swig_symbol_clookup_no_inherit(last, 0);
|
||||
if (last_node == full_lookup_node)
|
||||
cname_node = last_node;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* For %template, the template needs to be in scope via any means. */
|
||||
cname_node = Swig_symbol_clookup(cname, 0);
|
||||
}
|
||||
}
|
||||
#if RESOLVE_DEBUG
|
||||
if (!cname_node)
|
||||
Printf(stdout, "symbol does not yet exist (%d): [%s]\n", is_class_definition, cname);
|
||||
else
|
||||
Printf(stdout, "symbol does exist (%d): [%s]\n", is_class_definition, cname);
|
||||
#endif
|
||||
|
||||
if (cname_node) {
|
||||
/* The symbol has been defined already or is in another scope.
|
||||
If it is a weak symbol, it needs replacing and if it was brought into the current scope
|
||||
via a using declaration, the scope needs adjusting appropriately for the new symbol.
|
||||
If it is a weak symbol, it needs replacing and if it was brought into the current scope,
|
||||
the scope needs adjusting appropriately for the new symbol.
|
||||
Similarly for defined templates. */
|
||||
Symtab *symtab = Getattr(cname_node, "sym:symtab");
|
||||
Node *sym_weak = Getattr(cname_node, "sym:weak");
|
||||
|
|
@ -848,48 +869,92 @@ static String *resolve_create_node_scope(String *cname) {
|
|||
/* Check if the scope is the current scope */
|
||||
String *current_scopename = Swig_symbol_qualifiedscopename(0);
|
||||
String *found_scopename = Swig_symbol_qualifiedscopename(symtab);
|
||||
int len;
|
||||
if (!current_scopename)
|
||||
current_scopename = NewString("");
|
||||
if (!found_scopename)
|
||||
found_scopename = NewString("");
|
||||
len = Len(current_scopename);
|
||||
if ((len > 0) && (Strncmp(current_scopename, found_scopename, len) == 0)) {
|
||||
if (Len(found_scopename) > len + 2) {
|
||||
/* A matching weak symbol was found in non-global scope, some scope adjustment may be required */
|
||||
String *new_cname = NewString(Char(found_scopename) + len + 2); /* skip over "::" prefix */
|
||||
String *base = Swig_scopename_last(cname);
|
||||
Printf(new_cname, "::%s", base);
|
||||
cname = new_cname;
|
||||
Delete(base);
|
||||
} else {
|
||||
/* A matching weak symbol was found in the same non-global local scope, no scope adjustment required */
|
||||
assert(len == Len(found_scopename));
|
||||
|
||||
{
|
||||
int fail = 1;
|
||||
List *current_scopes = Swig_scopename_tolist(current_scopename);
|
||||
List *found_scopes = Swig_scopename_tolist(found_scopename);
|
||||
Iterator cit = First(current_scopes);
|
||||
Iterator fit = First(found_scopes);
|
||||
#if RESOLVE_DEBUG
|
||||
Printf(stdout, "comparing current: [%s] found: [%s]\n", current_scopename, found_scopename);
|
||||
#endif
|
||||
for (; fit.item && cit.item; fit = Next(fit), cit = Next(cit)) {
|
||||
String *current = cit.item;
|
||||
String *found = fit.item;
|
||||
#if RESOLVE_DEBUG
|
||||
Printf(stdout, " looping %s %s\n", current, found);
|
||||
#endif
|
||||
if (Strcmp(current, found) != 0)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
String *base = Swig_scopename_last(cname);
|
||||
if (Len(found_scopename) > 0) {
|
||||
/* A matching weak symbol was found in a different scope to the local scope - probably via a using declaration */
|
||||
cname = NewStringf("%s::%s", found_scopename, base);
|
||||
|
||||
if (!cit.item) {
|
||||
String *subscope = NewString("");
|
||||
for (; fit.item; fit = Next(fit)) {
|
||||
if (Len(subscope) > 0)
|
||||
Append(subscope, "::");
|
||||
Append(subscope, fit.item);
|
||||
}
|
||||
if (Len(subscope) > 0)
|
||||
cname = NewStringf("%s::%s", subscope, last);
|
||||
else
|
||||
cname = Copy(last);
|
||||
#if RESOLVE_DEBUG
|
||||
Printf(stdout, "subscope to create: [%s] cname: [%s]\n", subscope, cname);
|
||||
#endif
|
||||
fail = 0;
|
||||
Delete(subscope);
|
||||
} else {
|
||||
/* Either:
|
||||
1) A matching weak symbol was found in a different scope to the local scope - this is actually a
|
||||
symbol with the same name in a different scope which we don't want, so no adjustment required.
|
||||
2) A matching weak symbol was found in the global scope - no adjustment required.
|
||||
*/
|
||||
cname = Copy(base);
|
||||
if (is_class_definition) {
|
||||
if (!fit.item) {
|
||||
/* It is valid to define a new class with the same name as one forward declared in a parent scope */
|
||||
fail = 0;
|
||||
} else if (Swig_scopename_check(cname)) {
|
||||
/* Classes defined with scope qualifiers must have a matching forward declaration in matching scope */
|
||||
fail = 1;
|
||||
} else {
|
||||
/* This may let through some invalid cases */
|
||||
fail = 0;
|
||||
}
|
||||
#if RESOLVE_DEBUG
|
||||
Printf(stdout, "scope for class definition, fail: %d\n", fail);
|
||||
#endif
|
||||
} else {
|
||||
#if RESOLVE_DEBUG
|
||||
Printf(stdout, "no matching base scope for template\n");
|
||||
#endif
|
||||
fail = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Delete(found_scopes);
|
||||
Delete(current_scopes);
|
||||
|
||||
if (fail) {
|
||||
String *cname_resolved = NewStringf("%s::%s", found_scopename, last);
|
||||
Swig_error(cparse_file, cparse_line, "'%s' resolves to '%s' and was incorrectly instantiated in scope '%s' instead of within scope '%s'.\n", cname, cname_resolved, current_scopename, found_scopename);
|
||||
cname = Copy(last);
|
||||
Delete(cname_resolved);
|
||||
}
|
||||
Delete(base);
|
||||
}
|
||||
|
||||
Delete(current_scopename);
|
||||
Delete(found_scopename);
|
||||
}
|
||||
} else if (!is_class_definition) {
|
||||
/* A template instantiation requires a template to be found in scope... fail here too?
|
||||
Swig_error(cparse_file, cparse_line, "No template found to instantiate '%s' with %%template.\n", cname);
|
||||
*/
|
||||
}
|
||||
|
||||
if (Swig_scopename_check(cname)) {
|
||||
Node *ns;
|
||||
String *prefix = Swig_scopename_prefix(cname);
|
||||
String *base = Swig_scopename_last(cname);
|
||||
if (prefix && (Strncmp(prefix,"::",2) == 0)) {
|
||||
/* I don't think we can use :: global scope to declare classes and hence neither %template. - consider reporting error instead - wsfulton. */
|
||||
/* Use the global scope */
|
||||
|
|
@ -899,6 +964,7 @@ static String *resolve_create_node_scope(String *cname) {
|
|||
gscope = set_scope_to_global();
|
||||
}
|
||||
if (Len(prefix) == 0) {
|
||||
String *base = Copy(last);
|
||||
/* Use the global scope, but we need to add a 'global' namespace. */
|
||||
if (!gscope) gscope = set_scope_to_global();
|
||||
/* note that this namespace is not the "unnamed" one,
|
||||
|
|
@ -907,6 +973,7 @@ static String *resolve_create_node_scope(String *cname) {
|
|||
nscope = new_node("namespace");
|
||||
Setattr(nscope,"symtab", gscope);;
|
||||
nscope_inner = nscope;
|
||||
Delete(last);
|
||||
return base;
|
||||
}
|
||||
/* Try to locate the scope */
|
||||
|
|
@ -924,7 +991,7 @@ static String *resolve_create_node_scope(String *cname) {
|
|||
String *nname = Swig_symbol_qualifiedscopename(nstab);
|
||||
if (tname && (Strcmp(tname,nname) == 0)) {
|
||||
ns = 0;
|
||||
cname = base;
|
||||
cname = Copy(last);
|
||||
}
|
||||
Delete(tname);
|
||||
Delete(nname);
|
||||
|
|
@ -932,19 +999,10 @@ static String *resolve_create_node_scope(String *cname) {
|
|||
if (ns) {
|
||||
/* we will try to create a new node using the namespaces we
|
||||
can find in the scope name */
|
||||
List *scopes;
|
||||
List *scopes = Swig_scopename_tolist(prefix);
|
||||
String *sname;
|
||||
Iterator si;
|
||||
String *name = NewString(prefix);
|
||||
scopes = NewList();
|
||||
while (name) {
|
||||
String *base = Swig_scopename_last(name);
|
||||
String *tprefix = Swig_scopename_prefix(name);
|
||||
Insert(scopes,0,base);
|
||||
Delete(base);
|
||||
Delete(name);
|
||||
name = tprefix;
|
||||
}
|
||||
|
||||
for (si = First(scopes); si.item; si = Next(si)) {
|
||||
Node *ns1,*ns2;
|
||||
sname = si.item;
|
||||
|
|
@ -990,12 +1048,13 @@ static String *resolve_create_node_scope(String *cname) {
|
|||
nscope_inner = ns2;
|
||||
if (!nscope) nscope = ns2;
|
||||
}
|
||||
cname = base;
|
||||
cname = Copy(last);
|
||||
Delete(scopes);
|
||||
}
|
||||
}
|
||||
Delete(prefix);
|
||||
}
|
||||
Delete(last);
|
||||
|
||||
return cname;
|
||||
}
|
||||
|
|
@ -2631,9 +2690,8 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
|
|||
tscope = Swig_symbol_current(); /* Get the current scope */
|
||||
|
||||
/* If the class name is qualified, we need to create or lookup namespace entries */
|
||||
if (!inclass) {
|
||||
$5 = resolve_create_node_scope($5);
|
||||
}
|
||||
$5 = resolve_create_node_scope($5, 0);
|
||||
|
||||
if (nscope_inner && Strcmp(nodeType(nscope_inner), "class") == 0) {
|
||||
outer_class = nscope_inner;
|
||||
}
|
||||
|
|
@ -2991,6 +3049,9 @@ c_declaration : c_decl {
|
|||
SetFlag($$,"aliastemplate");
|
||||
add_symbols($$);
|
||||
}
|
||||
| cpp_static_assert {
|
||||
$$ = $1;
|
||||
}
|
||||
;
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
|
|
@ -3520,7 +3581,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
|
|||
Setattr($<node>$,"prev_symtab",Swig_symbol_current());
|
||||
|
||||
/* If the class name is qualified. We need to create or lookup namespace/scope entries */
|
||||
scope = resolve_create_node_scope($3);
|
||||
scope = resolve_create_node_scope($3, 1);
|
||||
/* save nscope_inner to the class - it may be overwritten in nested classes*/
|
||||
Setattr($<node>$, "nested:innerscope", nscope_inner);
|
||||
Setattr($<node>$, "nested:nscope", nscope);
|
||||
|
|
@ -4209,9 +4270,6 @@ cpp_temp_possible: c_decl {
|
|||
| cpp_constructor_decl {
|
||||
$$ = $1;
|
||||
}
|
||||
| cpp_static_assert {
|
||||
$$ = $1;
|
||||
}
|
||||
| cpp_template_decl {
|
||||
$$ = 0;
|
||||
}
|
||||
|
|
@ -4469,7 +4527,6 @@ cpp_member : c_declaration { $$ = $1; }
|
|||
default_arguments($$);
|
||||
}
|
||||
| cpp_destructor_decl { $$ = $1; }
|
||||
| cpp_static_assert { $$ = $1; }
|
||||
| cpp_protection_decl { $$ = $1; }
|
||||
| cpp_swig_directive { $$ = $1; }
|
||||
| cpp_conversion_operator { $$ = $1; }
|
||||
|
|
@ -4673,7 +4730,8 @@ cpp_catch_decl : CATCH LPAREN parms RPAREN LBRACE {
|
|||
}
|
||||
;
|
||||
|
||||
/* static_assert(bool, const char*); */
|
||||
/* static_assert(bool, const char*); (C++11)
|
||||
* static_assert(bool); (C++17) */
|
||||
cpp_static_assert : STATIC_ASSERT LPAREN {
|
||||
skip_balanced('(',')');
|
||||
$$ = 0;
|
||||
|
|
|
|||
|
|
@ -990,7 +990,7 @@ private:
|
|||
* overname: The overload string for overloaded function.
|
||||
* wname: The SWIG wrapped name--the name of the C function.
|
||||
* base: A list of the names of base classes, in the case where this
|
||||
* is is a vritual method not defined in the current class.
|
||||
* is a virtual method not defined in the current class.
|
||||
* parms: The parameters.
|
||||
* result: The result type.
|
||||
* is_static: Whether this is a static method or member.
|
||||
|
|
|
|||
|
|
@ -1949,7 +1949,7 @@ int Language::unrollVirtualMethods(Node *n, Node *parent, List *vm, int default_
|
|||
generation of 'empty' director classes.
|
||||
|
||||
But this has to be done outside the previous 'for'
|
||||
an the recursive loop!.
|
||||
and the recursive loop!.
|
||||
*/
|
||||
if (n == parent) {
|
||||
int len = Len(vm);
|
||||
|
|
@ -2078,7 +2078,7 @@ int Language::classDirectorConstructors(Node *n) {
|
|||
needed, since there is a public constructor already defined.
|
||||
|
||||
(scottm) This code is needed here to make the director_abstract +
|
||||
test generate compilable code (Example2 in director_abastract.i).
|
||||
test generate compilable code (Example2 in director_abstract.i).
|
||||
|
||||
(mmatus) This is very strange, since swig compiled with gcc3.2.3
|
||||
doesn't need it here....
|
||||
|
|
@ -3308,7 +3308,7 @@ Node *Language::classLookup(const SwigType *s) const {
|
|||
}
|
||||
if (n) {
|
||||
/* Found a match. Look at the prefix. We only allow
|
||||
the cases where where we want a proxy class for the particular type */
|
||||
the cases where we want a proxy class for the particular type */
|
||||
bool acceptable_prefix =
|
||||
(Len(prefix) == 0) || // simple type (pass by value)
|
||||
(Strcmp(prefix, "p.") == 0) || // pointer
|
||||
|
|
|
|||
|
|
@ -1755,7 +1755,7 @@ public:
|
|||
*
|
||||
* This is to convert the string of Lua code into a proper string, which can then be
|
||||
* emitted into the C/C++ code.
|
||||
* Basically is is a lot of search & replacing of odd sequences
|
||||
* Basically it is a lot of search & replacing of odd sequences
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
void escapeCode(String *str) {
|
||||
|
|
@ -1770,7 +1770,7 @@ public:
|
|||
/* -----------------------------------------------------------------------------
|
||||
* rawGetCArraysHash(String *name)
|
||||
*
|
||||
* A small helper to hide impelementation of how CArrays hashes are stored
|
||||
* A small helper to hide implementation of how CArrays hashes are stored
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
Hash *rawGetCArraysHash(const_String_or_char_ptr name) {
|
||||
|
|
|
|||
|
|
@ -718,7 +718,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
|
|||
function that handles the scoerceout.
|
||||
We need to check if any of the argument types have an entry in
|
||||
that map. If none do, the ignore and call the function straight.
|
||||
Otherwise, generate the a marshalling function.
|
||||
Otherwise, generate a marshalling function.
|
||||
Need to be able to find it in S. Or use an entirely generic one
|
||||
that evaluates the expressions.
|
||||
Handle errors in the evaluation of the function by restoring
|
||||
|
|
|
|||
|
|
@ -187,8 +187,10 @@ class TypePass:private Dispatcher {
|
|||
ilist = alist = NewList();
|
||||
Append(ilist, bcls);
|
||||
} else {
|
||||
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' has no name as it is an empty template instantiated with '%%template()'. Ignored.\n", SwigType_namestr(bname));
|
||||
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "The %%template directive must be written before '%s' is used as a base class and be declared with a name.\n", SwigType_namestr(bname));
|
||||
if (!GetFlag(bcls, "feature:ignore")) {
|
||||
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' has no name as it is an empty template instantiated with '%%template()'. Ignored.\n", SwigType_namestr(bname));
|
||||
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "The %%template directive must be written before '%s' is used as a base class and be declared with a name.\n", SwigType_namestr(bname));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -209,8 +211,10 @@ class TypePass:private Dispatcher {
|
|||
ilist = alist = NewList();
|
||||
Append(ilist, bcls);
|
||||
} else {
|
||||
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' has no name as it is an empty template instantiated with '%%template()'. Ignored.\n", SwigType_namestr(bname));
|
||||
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "The %%template directive must be written before '%s' is used as a base class and be declared with a name.\n", SwigType_namestr(bname));
|
||||
if (!GetFlag(bcls, "feature:ignore")) {
|
||||
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' has no name as it is an empty template instantiated with '%%template()'. Ignored.\n", SwigType_namestr(bname));
|
||||
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "The %%template directive must be written before '%s' is used as a base class and be declared with a name.\n", SwigType_namestr(bname));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Base class '%s' undefined.\n", SwigType_namestr(bname));
|
||||
|
|
@ -1199,10 +1203,7 @@ class TypePass:private Dispatcher {
|
|||
} else if (Strcmp(ntype, "enum") == 0) {
|
||||
SwigType_typedef_using(Getattr(n, "uname"));
|
||||
} else if (Strcmp(ntype, "template") == 0) {
|
||||
/*
|
||||
Printf(stdout, "usingDeclaration template %s --- %s\n", Getattr(n, "name"), Getattr(n, "uname"));
|
||||
SwigType_typedef_using(Getattr(n, "uname"));
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ int is_non_virtual_protected_access(Node *n) {
|
|||
// When vtable is empty, the director class does not get emitted, so a check for an empty vtable should be done.
|
||||
// However, vtable is set in Language and so is not yet set when methods in Typepass call clean_overloaded()
|
||||
// which calls is_non_virtual_protected_access. So commented out below.
|
||||
// Moving the director vtable creation into into Typepass should solve this problem.
|
||||
// Moving the director vtable creation into Typepass should solve this problem.
|
||||
if (is_member_director_helper(parentNode, n) /* && Getattr(parentNode, "vtable")*/)
|
||||
result = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ int Swig_cargs(Wrapper *w, ParmList *p) {
|
|||
SwigType_del_rvalue_reference(tvalue);
|
||||
tycode = SwigType_type(tvalue);
|
||||
if (tycode != T_USER) {
|
||||
/* plain primitive type, we copy the the def value */
|
||||
/* plain primitive type, we copy the def value */
|
||||
String *lstr = SwigType_lstr(tvalue, defname);
|
||||
defvalue = NewStringf("%s = %s", lstr, qvalue);
|
||||
Delete(lstr);
|
||||
|
|
|
|||
|
|
@ -823,10 +823,11 @@ String *Swig_string_emangle(String *s) {
|
|||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_scopename_prefix()
|
||||
* Swig_scopename_split()
|
||||
*
|
||||
* Take a qualified name like "A::B::C" and return the scope name.
|
||||
* In this case, "A::B". Returns NULL if there is no base.
|
||||
* Take a qualified name like "A::B::C" and splits off the last name.
|
||||
* In this case, returns "C" as last and "A::B" as prefix.
|
||||
* Always returns non NULL for last, but prefix may be NULL if there is no prefix.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Swig_scopename_split(const String *s, String **rprefix, String **rlast) {
|
||||
|
|
@ -882,6 +883,12 @@ void Swig_scopename_split(const String *s, String **rprefix, String **rlast) {
|
|||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_scopename_prefix()
|
||||
*
|
||||
* Take a qualified name like "A::B::C" and return the scope name.
|
||||
* In this case, "A::B". Returns NULL if there is no base.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *Swig_scopename_prefix(const String *s) {
|
||||
char *tmp = Char(s);
|
||||
|
|
@ -1067,6 +1074,31 @@ String *Swig_scopename_suffix(const String *s) {
|
|||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_scopename_tolist()
|
||||
*
|
||||
* Take a qualified scope name like "A::B::C" and convert it to a list.
|
||||
* In this case, return a list of 3 elements "A", "B", "C".
|
||||
* Returns an empty list if the input is empty.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
List *Swig_scopename_tolist(const String *s) {
|
||||
List *scopes = NewList();
|
||||
String *name = Len(s) == 0 ? 0 : NewString(s);
|
||||
|
||||
while (name) {
|
||||
String *last = 0;
|
||||
String *prefix = 0;
|
||||
Swig_scopename_split(name, &prefix, &last);
|
||||
Insert(scopes, 0, last);
|
||||
Delete(last);
|
||||
Delete(name);
|
||||
name = prefix;
|
||||
}
|
||||
Delete(name);
|
||||
return scopes;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_scopename_check()
|
||||
*
|
||||
|
|
|
|||
|
|
@ -326,6 +326,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
|
|||
extern String *Swig_scopename_last(const String *s);
|
||||
extern String *Swig_scopename_first(const String *s);
|
||||
extern String *Swig_scopename_suffix(const String *s);
|
||||
extern List *Swig_scopename_tolist(const String *s);
|
||||
extern int Swig_scopename_check(const String *s);
|
||||
extern String *Swig_string_lower(String *s);
|
||||
extern String *Swig_string_upper(String *s);
|
||||
|
|
|
|||
|
|
@ -599,7 +599,7 @@ void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) {
|
|||
Setattr(ccurrent, name, n);
|
||||
}
|
||||
|
||||
/* Multiple entries in the C symbol table. We append to to the symbol table */
|
||||
/* Multiple entries in the C symbol table. We append to the symbol table */
|
||||
if (append) {
|
||||
Node *fn, *pn = 0;
|
||||
cn = Getattr(ccurrent, name);
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue