Merge branch 'rvalue-move'

* rvalue-move:
  rvalue reference outputs
  Remove broken %implicitconv for const SWIGTYPE &&
  Remove unnecessary const SWIGTYPE & typemap
  Temporarily remove rvalue reference python runtime test
  std::auto_ptr emulation fix in test case
  Ocaml typemap typo fix
  Fix Racket tests using schemerunme directory
  Docs on rvalue parameter changes
  Test/fixes to handle NULL pointer for unique_ptr/auto_ptr
  Octave - SWIG now marshalls a C/C++ NULL pointer into the null matrix, []
  Racket - NULL pointer handling
  SWIGTYPE && input typemaps now assume object has been moved - Go and OCaml
  SWIGTYPE && input typemaps now assume object has been moved
  SWIGTYPE && input typemaps now assume object has been moved - Java
  Cosmetic stray semi-colon removal after %typemap using quotes
  Cosmetic stray semi-colon removal after %typemap
This commit is contained in:
William S Fulton 2022-09-08 19:50:31 +01:00
commit c79f7f3d85
132 changed files with 2155 additions and 426 deletions

44
CHANGES
View file

@ -3137,7 +3137,7 @@ Version 3.0.3 (30 Dec 2014)
2014-09-12: olly
[PHP] Add support for specifying any PHP interfaces a wrapped class
implements, e.g.: %typemap("phpinterfaces") MyIterator "Iterator";
implements, e.g.: %typemap("phpinterfaces") MyIterator "Iterator"
2014-09-11: olly
[PHP] Fix throwing a PHP exception through C++ from a subclassed
@ -8396,8 +8396,8 @@ Version 1.3.30 (November 13, 2006)
javabase/csbase typemap, eg in the following, 'Me' will be the base class,
no matter what Foo is really derived from in the C++ layer.
%typemap(javabase, replace="1") Foo "Me";
%typemap(csbase, replace="1") Foo "Me";
%typemap(javabase, replace="1") Foo "Me"
%typemap(csbase, replace="1") Foo "Me"
Previously it was not possible for the javabase/csbase typemaps to override the C++ base.
@ -9884,7 +9884,7 @@ Version 1.3.28 (February 12, 2006)
solutions is to write:
%typemap(in) A * {...}
%typemap(freeag) A * "";
%typemap(freeag) A * ""
overload 'freearg' with an empty definition.
@ -11314,20 +11314,20 @@ Version 1.3.27 (October 15, 2005)
then the typemap will be inserted without the block
imposed by the brackets, similar to
%typemap(in) Hello "...";
%typemap(in) Hello "..."
So, why you don't just use the quote style?, because:
1.- The quote style doesn't get preprocessed, for example
%typemap(in) Hello "$1= SWIG_macro($1);";
%typemap(in) Hello "$1= SWIG_macro($1);"
here, SWIG_macro doesn't get expanded
2.- Inside a quote typemap, you have to use
quotes carefully
%typemap(in) Hello "$1 = \"hello\" ";
%typemap(in) Hello "$1 = \"hello\" "
3.- You can't make emacs and/or other editors
to indent inside a string!.
@ -11529,7 +11529,7 @@ Version 1.3.26 (October 9, 2005)
%define hello(name, Type)
%define name ## a(Type)
%typemap(in) Type "hello;";
%typemap(in) Type "hello;"
%enddef
%enddef
@ -13525,7 +13525,7 @@ Version 1.3.23 (November 11, 2004)
whereupon the default of 0 was used. You can get the same behaviour for C
code by using the "default" typemap:
%typemap(default) int val "$1 = 0;";
%typemap(default) int val "$1 = 0;"
%{
void foo(int val);
%}
@ -13854,9 +13854,11 @@ Version 1.3.22 (September 4, 2004)
specifiers from the C type. This makes it possible, for instance, to control
whether a C "char" argument takes a Lisp character or a Lisp integer value.
The default (taking Lisp characters) is done by these built-in typemaps:
%typemap(ffitype) char ":char"; %typemap(lisptype) char "character";
%typemap(ffitype) char ":char"
%typemap(lisptype) char "character"
If char means an integer instead, use these typemaps:
%typemap(ffitype) char ":char"; %typemap(lisptype) char "integer";
%typemap(ffitype) char ":char"
%typemap(lisptype) char "integer"
08/22/2004: wsfulton
As discussed in bug #772453, the SWIG library directory is now installed
@ -18874,9 +18876,9 @@ Version 1.3.14 (August 12, 2002)
shadowinterface
Note that it is possible to target a particular proxy class:
%typemap(javaimports) Foo "import java.util.*";
%typemap(javaimports) Foo "import java.util.*"
or a particular type wrapper class:
%typemap(javaimports) double* "import java.math.*";
%typemap(javaimports) double* "import java.math.*"
Note that $javaclassname in these typemaps are substituted with either the proxy
classname when using proxy classes or the SWIGTYPE class name.
@ -19614,8 +19616,8 @@ Version 1.3.12 (June 2, 2002)
typemap must exactly match up with the "in" or "ignore"
typemap. For example:
%typemap(in) (char *data, int len) { ... };
%typemap(freearg) char *data { ... };
%typemap(in) (char *data, int len) { ... }
%typemap(freearg) char *data { ... }
void foo(char *data, int len);
@ -21071,7 +21073,7 @@ Version 1.3.11 (January 31, 2002)
Second, a typemap can force a no-match by defining
%typemap(in) sometype "pass";
%typemap(in) sometype "pass"
If this is used, the typemap system will *not* record a
typemap match for "sometype". This can be used to block
@ -21079,7 +21081,7 @@ Version 1.3.11 (January 31, 2002)
a typemap feature for some type, you could do this.
// Do not allow global variables of type 'const char *' to be set.
%typemap(varin) const char * "pass";
%typemap(varin) const char * "pass"
It might also be possible to use this to do subtle and
strange things with typemaps. For example, if you wanted to
@ -21093,8 +21095,8 @@ Version 1.3.11 (January 31, 2002)
... return a value ...
}
/* Block unqualified typemaps defined above */
%typemap(ignore) const blah * "pass";
%typemap(argout) const blah * "pass";
%typemap(ignore) const blah * "pass"
%typemap(argout) const blah * "pass"
%typemap(in) const blah * {
... get input value ...
}
@ -21871,7 +21873,7 @@ Version 1.3.10 (December 10, 2001)
%typemap directive can now accept nearly arbitrary keyword parameters.
For example:
%typemap(in,parse="i",doc="integer") int "...";
%typemap(in,parse="i",doc="integer") int "..."
The purpose of the keyword parameters is to supply code generation
hints to the target language module. The intepretation of the
@ -23949,7 +23951,7 @@ Version 1.3 Alpha 4 (September 4, 2000)
Typemaps can now be specified using string literals like
this:
%typemap(in) int "$target = SvIV($source);";
%typemap(in) int "$target = SvIV($source);"
When code is specified like this, it is *NOT* enclosed
inside a local scope (as with older typemap declarations).

View file

@ -7,6 +7,25 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.0 (in progress)
===========================
2022-08-31: wsfulton
#999 Improve move semantics when using rvalue references.
The SWIGTYPE && input typemaps now assume the object has been moved.
These typemaps have been changed assuming that after the function call,
the rvalue reference parameter has been moved. The parameter's proxy class
that owns the C++ object thus has the underlying pointer set to null
so that the (moved from, but still valid) C++ object cannot be used again
and the the object is additionally deleted.
2022-08-28: wsfulton
[Octave] SWIG now marshalls a C/C++ NULL pointer into the null matrix, [].
SWIG has always marshalled the null matrix into a NULL pointer; this remains
and now we have consistency in representing a NULL pointer.
2022-08-26: wsfulton
[Racket] SWIG now marshalls a C/C++ NULL pointer into a null value by calling
scheme_make_null(), so that scheme's null? is true for a NULL C/C++ pointer value.
2022-08-18: wsfulton
[Racket] Add support for std::unique_ptr in std_unique_ptr.i.
Add support for std::auto_ptr in std_auto_ptr.i.

View file

@ -16,6 +16,8 @@
<ul>
<li><a href="#CPlusPlus11_rvalue_reference_and_move_semantics">Rvalue reference and move semantics</a>
<ul>
<li><a href="#CPlusPlus11_rvalue_reference_inputs">Rvalue reference inputs</a>
<li><a href="#CPlusPlus11_rvalue_reference_outputs">Rvalue reference outputs</a>
<li><a href="#CPlusPlus11_move_only">Movable and move-only types</a>
</ul>
<li><a href="#CPlusPlus11_generalized_constant_expressions">Generalized constant expressions</a>
@ -98,6 +100,7 @@ class MyClass {
...
std::vector&lt;int&gt; numbers;
public:
MyClass() : numbers() {}
MyClass(MyClass &amp;&amp;other) : numbers(std::move(other.numbers)) {}
MyClass &amp; operator=(MyClass &amp;&amp;other) {
numbers = std::move(other.numbers);
@ -107,8 +110,8 @@ public:
</pre></div>
<p>
Rvalue references are designed for C++ temporaries and so are not very useful when used from non-C++ target languages.
Generally you would just ignore them via <tt>%ignore</tt> before parsing the class.
Rvalue references are designed for C++ temporaries and are not particularly useful when used from non-C++ target languages.
One option is to just ignore them via <tt>%ignore</tt>.
For example, ignore the move constructor:
</p>
@ -116,8 +119,49 @@ For example, ignore the move constructor:
%ignore MyClass::MyClass(MyClass &amp;&amp;);
</pre></div>
<H4><a name="CPlusPlus11_rvalue_reference_inputs">7.2.1.1 Rvalue reference inputs</a></H4>
<p>
The plan is to ignore move constructors by default in a future version of SWIG. Note that both normal assignment operators as well as move assignment operators are ignored by default in most target languages with the following warning:
Rvalue reference parameters are useful as input parameters in C++ for implementing move semantics, such as,
in the move constructor and move assignment operator.
This type of usage can be useful from target languages too to avoid copying large objects.
</p>
<p>
If you do wrap a function/contructor with an rvalue reference parameter and pass a proxy class to it, SWIG will assume that after the call, the rvalue reference parameter object will have been 'moved'.
The proxy class passed as the rvalue reference, will own the underlying C++ object up until it is used as an rvalue reference parameter.
Afterwards, the proxy class will have the underlying C++ pointer set to the nullptr so that the proxy class instance cannot be used again and the underlying (moved from) C++ object will be deleted after the function/constructor call has returned.
</p>
<p>
In this way, the SWIG proxy class works much like an exclusively owned smart pointer (think of <tt>std::unique_ptr</tt>), passing ownership to the called C++ function/constructor.
Let's consider an example in Java using the wrapped proxy class from above:
</p>
<div class="targetlang"><pre>
MyClass mc = new MyClass();
MyClass mc1 = new MyClass(mc); // move constructor
MyClass mc2 = new MyClass(mc); // move constructor fails
</pre></div>
<p>
The second call to the move constructor will fail as the <tt>mc</tt> proxy instance has been moved.
Each target language handles the moved proxy class slightly differently when attempting to move it again, but typically you'll get an exception such as in Java:
</p>
<div class="shell">
<pre>
Exception in thread "main" java.lang.RuntimeException: Cannot release ownership as memory is not owned
at MyClass.swigRelease(MyClass.java:27)
at MyClass.&lt;init&gt;(MyClass.java:55)
at runme.main(runme.java:18)
</pre>
</div>
<p>
Note that both normal copy assignment operators as well as move assignment operators are ignored by default in the target languages with the following warning:
</p>
<div class="shell">
@ -126,7 +170,77 @@ example.i:18: Warning 503: Can't wrap 'operator =' unless renamed to a valid ide
</pre>
</div>
<H4><a name="CPlusPlus11_move_only">7.2.1.1 Movable and move-only types</a></H4>
<p>
Using a <tt>%rename</tt> will remove the warning and also makes the move assignment operator available from the target language:
</p>
<div class="code"><pre>
%rename(MoveAssign) MyClass::operator=(MyClass &amp;&amp;);
</pre></div>
<p>
You can then use it, but like the move constructor example above, you cannot use
a proxy class once it has already been moved:
</p>
<div class="targetlang"><pre>
MyClass mc = new MyClass();
MyClass mc2 = mc.MoveAssign(mc);
MyClass mc3 = mc.MoveAssign(mc); // Use of mc again will fail
</pre></div>
<p>
It is of course perfectly possible in C++ for a function/constructor to not move an object passed to it in an rvalue reference parameter. The assumption that SWIG makes would then not hold and customisation of the appropriate input typemaps would be required.
For scripting languages, this would be for the 'in' typemap and for the non-scripting languages additional typemaps such as the 'javain' typemap, which is used to set the memory ownership of the underlying C++ object for Java, would also need copying and modifying appropriately.
</p>
<p>
<b>Compatibility note:</b>
SWIG-4.1.0 changed the way that rvalue reference parameters were handled and implemented typemaps assuming that the
proxy class owns the underlying C++ object and transfers ownership of the object when a function/constructor with an rvalue reference parameter is called.
</p>
<H4><a name="CPlusPlus11_rvalue_reference_outputs">7.2.1.2 Rvalue reference outputs</a></H4>
<p>
While rvalue reference parameter inputs are not uncommon in C++ and can be usefully utilised from target languages, this cannot be said for rvalue reference outputs.
Firstly, it is quite unusual in C++ to have functions that return an rvalue reference.
Secondly, these cases are nigh on impossible to use from a target language.
The main problem is these references are for C++ compiler temporaries used on the stack and the target languages use objects on the heap
and the concept of compiler temporary objects doesn't make sense from another language.
</p>
<p>
Using <tt>MyClass</tt> from earlier and this C++ code:
</p>
<div class="code"><pre>
void use(MyClass &amp;&amp;mc);
MyClass &amp;&amp; get1();
MyClass &amp; get2();
</pre></div>
<p>
SWIG wraps the <tt>get1</tt> and <tt>get2</tt> functions more or less identically.
The returned references are converted into pointers that are not owned by the target language.
It means that the following perfectly valid C++ has no equivalent in any of the target languages:
</p>
<div class="code"><pre>
use(get1());
use(std::move(get2()));
</pre></div>
<p>
An attempt to call the equivalent <tt>use(get1())</tt> from one of the target languages will result in the ownership failure mentioned in the previous section as the object being passed to the <tt>use</tt> function is not owned by the proxy class.
In order to own the object, it would need to be cloned for the object to move from the stack to the heap, for which an appropriate clone function would be required, but may not even be available.
Note that a move constructor or copy constructor may slice the object when inheritance is involved.
Alternatively, customising the input rvalue reference typemap, as mentioned in the previous section, could remove the ownership requirement.
Another alternative would be to modify the output rvalue reference typemap to always clone the rvalue reference object.
Fortunately you're highly unlikely to have to solve any of these issues!
</p>
<H4><a name="CPlusPlus11_move_only">7.2.1.3 Movable and move-only types</a></H4>
<p>

View file

@ -298,6 +298,8 @@
<ul>
<li><a href="CPlusPlus11.html#CPlusPlus11_rvalue_reference_and_move_semantics">Rvalue reference and move semantics</a>
<ul>
<li><a href="CPlusPlus11.html#CPlusPlus11_rvalue_reference_inputs">Rvalue reference inputs</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_rvalue_reference_outputs">Rvalue reference outputs</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_move_only">Movable and move-only types</a>
</ul>
<li><a href="CPlusPlus11.html#CPlusPlus11_generalized_constant_expressions">Generalized constant expressions</a>

View file

@ -668,7 +668,7 @@ results. For example:
<div class="code">
<pre>
%typemap(newfree) char * "free($1);";
%typemap(newfree) char * "free($1);"
...
%newobject strdup;
...

View file

@ -278,7 +278,7 @@ Like, $imcall, this special variable is only expanded in the "dout" typemap.
<p>This macro is used in the <tt>dimports</tt> typemap if a dependency on another D type generated by SWIG is added by a custom typemap.</p>
<p>Consider the following code snippet:</p>
<div class="code"><pre>
%typemap(dinterfaces) SomeClass "AnInterface, AnotherInterface";
%typemap(dinterfaces) SomeClass "AnInterface, AnotherInterface"
</pre></div>
<p>This causes SWIG to add <tt>AnInterface</tt> and <tt>AnotherInterface</tt> to the base class list of <tt>SomeClass</tt>:</p>
<div class="targetlang"><pre>

View file

@ -1114,7 +1114,7 @@ name of the type with namespace scope delimiters (<tt>::</tt>) replaced with a d
change this, you can define your own typemaps for the custom types, e.g:
</p>
<div class="code"><pre>
%typemap(doctype) MyDate "datetime.date";
%typemap(doctype) MyDate "datetime.date"
</pre></div>
<p>

View file

@ -4218,7 +4218,7 @@ You can copy the code below into an interface file and run SWIG on it and examin
%}
// Expose C++ exception as a Java Exception by changing the Java base class and providing a getMessage()
%typemap(javabase) MyNS::MyException "java.lang.RuntimeException";
%typemap(javabase) MyNS::MyException "java.lang.RuntimeException"
%rename(getMessage) MyNS::MyException::whatsup;
%inline %{
@ -7065,7 +7065,7 @@ The corrected interface file looks like:
<pre>
// class Foo is handled in a different interface file:
%import "Foo.i"
%typemap("javapackage") Foo, Foo *, Foo &amp; "com.wombat.foo";
%typemap("javapackage") Foo, Foo *, Foo &amp; "com.wombat.foo"
%feature("director") Example;
%inline {
@ -7093,11 +7093,11 @@ Note the helper macros below, <code>OTHER_PACKAGE_SPEC</code> and <code>ANOTHER_
"package.for.most.classes";
%define OTHER_PACKAGE_SPEC(TYPE...)
%typemap("javapackage") TYPE, TYPE *, TYPE &amp; "package.for.other.classes";
%typemap("javapackage") TYPE, TYPE *, TYPE &amp; "package.for.other.classes"
%enddef
%define ANOTHER_PACKAGE_SPEC(TYPE...)
%typemap("javapackage") TYPE, TYPE *, TYPE &amp; "package.for.another.set";
%typemap("javapackage") TYPE, TYPE *, TYPE &amp; "package.for.another.set"
%enddef
OTHER_PACKAGE_SPEC(Package_2_class_one)
@ -7291,7 +7291,7 @@ The typemaps to use then are as follows:
<div class="code">
<pre>
%typemap(javabase) FileException "java.lang.Exception";
%typemap(javabase) FileException "java.lang.Exception"
%typemap(javacode) FileException %{
public String getMessage() {
return what();

View file

@ -264,7 +264,7 @@ Let's edit the interface file such that the C type "div_t*" is changed
<div class="code"><pre>
%module test
%typemap(cin) div_t* ":my-pointer";
%typemap(cin) div_t* ":my-pointer"
%feature("intern_function", "1");
%feature("export");

View file

@ -363,6 +363,10 @@ octave:2&gt; f=swigexample.fopen("not there", "r");
error: value on right hand side of assignment is undefined
error: evaluating assignment expression near line 2, column 2 </pre></div>
<p>
NULL C/C++ pointers are represented by the Octave null matrix, <tt>[]</tt>.
</p>
<H3><a name="Octave_nn13">30.3.6 Structures and C++ classes</a></H3>

View file

@ -836,7 +836,7 @@ so:
</p>
<div class="code"><pre>
%typemap("phpinterfaces") MyIterator "Iterator";
%typemap("phpinterfaces") MyIterator "Iterator"
</pre></div>
<p>

View file

@ -1707,7 +1707,7 @@ For example: </p>
<div class="code">
<pre>%rename("is_it_safe?") is_it_safe();
%typemap(out) int is_it_safe "$result = ($1 != 0) ? Qtrue : Qfalse;";
%typemap(out) int is_it_safe "$result = ($1 != 0) ? Qtrue : Qfalse;"
int is_it_safe();</pre>
</div>

View file

@ -787,7 +787,7 @@ Here are some examples of valid typemap specifications:
%typemap(in) int {
$1 = PyInt_AsLong($input);
}
%typemap(in) int "$1 = PyInt_AsLong($input);";
%typemap(in) int "$1 = PyInt_AsLong($input);"
%typemap(in) int %{
$1 = PyInt_AsLong($input);
%}
@ -803,7 +803,7 @@ Here are some examples of valid typemap specifications:
}
/* Typemap with modifiers */
%typemap(in, doc="integer") int "$1 = scm_to_int($input);";
%typemap(in, doc="integer") int "$1 = scm_to_int($input);"
/* Typemap applied to patterns of multiple arguments */
%typemap(in) (char *str, int len),
@ -1356,13 +1356,13 @@ const reference are written like this:
<div class="code">
<pre>
%typemap(in) int "... convert to int ...";
%typemap(in) short "... convert to short ...";
%typemap(in) float "... convert to float ...";
%typemap(in) int "... convert to int ..."
%typemap(in) short "... convert to short ..."
%typemap(in) float "... convert to float ..."
...
%typemap(in) const int &amp; "... convert ...";
%typemap(in) const short &amp; "... convert ...";
%typemap(in) const float &amp; "... convert ...";
%typemap(in) const int &amp; "... convert ..."
%typemap(in) const short &amp; "... convert ..."
%typemap(in) const float &amp; "... convert ..."
...
</pre>
</div>
@ -1382,16 +1382,16 @@ Below is a list of the typical default types supplied by language modules, showi
<div class="code">
<pre>
%typemap(in) SWIGTYPE &amp; { ... default reference handling ... };
%typemap(in) SWIGTYPE * { ... default pointer handling ... };
%typemap(in) SWIGTYPE *const { ... default pointer const handling ... };
%typemap(in) SWIGTYPE *const&amp; { ... default pointer const reference handling ... };
%typemap(in) SWIGTYPE[ANY] { ... 1D fixed size arrays handling ... };
%typemap(in) SWIGTYPE [] { ... unknown sized array handling ... };
%typemap(in) enum SWIGTYPE { ... default handling for enum values ... };
%typemap(in) const enum SWIGTYPE &amp; { ... default handling for const enum reference values ... };
%typemap(in) SWIGTYPE (CLASS::*) { ... default pointer member handling ... };
%typemap(in) SWIGTYPE { ... simple default handling ... };
%typemap(in) SWIGTYPE &amp; { ... default reference handling ... }
%typemap(in) SWIGTYPE * { ... default pointer handling ... }
%typemap(in) SWIGTYPE *const { ... default pointer const handling ... }
%typemap(in) SWIGTYPE *const&amp; { ... default pointer const reference handling ... }
%typemap(in) SWIGTYPE[ANY] { ... 1D fixed size arrays handling ... }
%typemap(in) SWIGTYPE [] { ... unknown sized array handling ... }
%typemap(in) enum SWIGTYPE { ... default handling for enum values ... }
%typemap(in) const enum SWIGTYPE &amp; { ... default handling for const enum reference values ... }
%typemap(in) SWIGTYPE (CLASS::*) { ... default pointer member handling ... }
%typemap(in) SWIGTYPE { ... simple default handling ... }
</pre>
</div>
@ -1943,7 +1943,7 @@ Occasionally, typemap code will be specified using a few alternative forms. For
<div class="code">
<pre>
%typemap(in) int "$1 = PyInt_AsLong($input);";
%typemap(in) int "$1 = PyInt_AsLong($input);"
%typemap(in) int %{
$1 = PyInt_AsLong($input);
%}

View file

@ -42,8 +42,8 @@ void *string_to_uintptr(char *in)
// These typemaps convert between an array of strings in Go and a
// const char** that is NULL terminated in C++.
%typemap(gotype) (const char * const *) "[]string";
%typemap(imtype) (const char * const *) "uintptr";
%typemap(gotype) (const char * const *) "[]string"
%typemap(imtype) (const char * const *) "uintptr"
%typemap(goin) (const char * const *) {
if $input == nil || len($input) == 0 {
$result = 0

View file

@ -15,7 +15,7 @@ extern int squareCubed (int n, int *OUTPUT);
extern int gcd(int x, int y);
%typemap(arginit) (int argc, char *argv[]) "$2 = 0;";
%typemap(arginit) (int argc, char *argv[]) "$2 = 0;"
%typemap(in) (int argc, char *argv[]) {
AV *tempav;

View file

@ -14,7 +14,7 @@ extern int squareCubed (int n, int *OUTPUT);
extern int gcd(int x, int y);
%typemap(arginit) (int argc, char *argv[]) "$2 = 0;";
%typemap(arginit) (int argc, char *argv[]) "$2 = 0;"
%typemap(in) (int argc, char *argv[]) {
Tcl_Obj **listobjv = 0;

View file

@ -5,8 +5,8 @@
%feature("autodoc");
// special typemap and its docs
%typemap(in) (int c, int d) "$1 = 0; $2 = 0;";
%typemap(doc,name="hello",type="Tuple") (int c, int d) "hello: int tuple[2]";
%typemap(in) (int c, int d) "$1 = 0; $2 = 0;"
%typemap(doc,name="hello",type="Tuple") (int c, int d) "hello: int tuple[2]"
// testing for different documentation levels
%feature("autodoc","0") A::func0; // names
@ -69,8 +69,8 @@
%typemap(doc) (int c, int d);
// docs for some parameters
%typemap(doc) int a "a: special comment for parameter a";
%typemap(doc) int b "b: another special comment for parameter b";
%typemap(doc) int a "a: special comment for parameter a"
%typemap(doc) int b "b: another special comment for parameter b"
%feature("autodoc","0") C::C(int a, int b, Hola h); // names
%feature("autodoc","1") D::D(int a, int b, Hola h); // names + types

View file

@ -609,7 +609,7 @@ CPP11_TEST_CASES += \
cpp11_rvalue_reference \
cpp11_rvalue_reference2 \
cpp11_rvalue_reference3 \
cpp11_rvalue_reference_move_input \
cpp11_rvalue_reference_move \
cpp11_sizeof_object \
cpp11_static_assert \
cpp11_std_array \

View file

@ -0,0 +1,52 @@
%module cpp11_rvalue_reference_move
// Testcase for testing rvalue reference input typemaps which assume the object is moved during a function call
%include "cpp11_move_only_helper.i"
%catches(std::string) MovableCopyable::check_numbers_match;
%rename(MoveAssign) MovableCopyable::operator=(MovableCopyable &&);
%ignore MovableCopyable::operator=(const MovableCopyable &); // ignore copy assignment operator, keep move assignment operator
%ignore MovableCopyable::MovableCopyable(const MovableCopyable &); // ignore copy constructor, keep the move constructor
%inline %{
#include <iostream>
using namespace std;
bool trace = false;
class MovableCopyable {
int num;
public:
MovableCopyable(int i = 0) : num(i) { if (trace) cout << "MovableCopyable(" << i << ")" << " " << this << endl; Counter::normal_constructor++; }
MovableCopyable(const MovableCopyable &other) : num(other.num) { if (trace) cout << "MovableCopyable(const MovableCopyable &)" << " " << this << " " << &other << endl; Counter::copy_constructor++;}
MovableCopyable & operator=(const MovableCopyable &other) { if (trace) cout << "operator=(const MovableCopyable &)" << " " << this << " " << &other << endl; Counter::copy_assignment++; num = other.num; return *this; }
MovableCopyable(MovableCopyable &&other) noexcept : num(std::move(other.num)) { if (trace) cout << "MovableCopyable(MovableCopyable &&)" << " " << this << endl; Counter::move_constructor++; }
MovableCopyable & operator=(MovableCopyable &&other) noexcept { if (trace) cout << "operator=(MovableCopyable &&)" << " " << this << endl; Counter::move_assignment++; num = std::move(other.num); return *this; }
~MovableCopyable() { if (trace) cout << "~MovableCopyable()" << " " << this << endl; Counter::destructor++; }
int getNum() { return num; }
static void movein(MovableCopyable &&mcin) {
MovableCopyable mc = std::move(mcin);
}
static MovableCopyable && moveout(int i) {
static MovableCopyable instance;
instance = MovableCopyable(i);
return std::move(instance);
}
static bool is_nullptr(MovableCopyable *p) {
return p == nullptr;
}
static void check_numbers_match(MovableCopyable *p, int expected_num) {
if (p->num != expected_num)
throw std::string("Numbers don't match");
}
};
%}

View file

@ -1,37 +0,0 @@
%module cpp11_rvalue_reference_move_input
// Testcase for testing rvalue reference input typemaps which assume the object is moved during a function call
%include "cpp11_move_only_helper.i"
%rename(MoveAssign) MovableCopyable::operator=(MovableCopyable &&);
%ignore MovableCopyable::operator=(const MovableCopyable &); // ignore copy assignment operator, keep move assignment operator
%ignore MovableCopyable::MovableCopyable(const MovableCopyable &); // ignore copy constructor, keep the move constructor
%inline %{
#include <iostream>
using namespace std;
bool trace = false;
class MovableCopyable {
public:
MovableCopyable(int i = 0) { if (trace) cout << "MovableCopyable(" << i << ")" << " " << this << endl; Counter::normal_constructor++; }
MovableCopyable(const MovableCopyable &other) { if (trace) cout << "MovableCopyable(const MovableCopyable &)" << " " << this << " " << &other << endl; Counter::copy_constructor++;}
MovableCopyable & operator=(const MovableCopyable &other) { if (trace) cout << "operator=(const MovableCopyable &)" << " " << this << " " << &other << endl; Counter::copy_assignment++; return *this; }
MovableCopyable(MovableCopyable &&other) noexcept { if (trace) cout << "MovableCopyable(MovableCopyable &&)" << " " << this << endl; Counter::move_constructor++; }
MovableCopyable & operator=(MovableCopyable &&other) noexcept { if (trace) cout << "operator=(MovableCopyable &&)" << " " << this << endl; Counter::move_assignment++; return *this; }
~MovableCopyable() { if (trace) cout << "~MovableCopyable()" << " " << this << endl; Counter::destructor++; }
static void movein(MovableCopyable &&mcin) {
MovableCopyable mc = std::move(mcin);
}
static bool is_nullptr(MovableCopyable *p) {
return p == nullptr;
}
};
%}

View file

@ -63,7 +63,7 @@ std::string useKlassRawPtr(Klass* k) {
std::string takeKlassUniquePtr(std::unique_ptr<Klass> k) {
// std::cout << "takeKlassUniquePtr " << std::hex << (Klass*)k.get() << std::endl;
std::string s(k->getLabel());
std::string s(k ? k->getLabel() : "null smart pointer");
// std::cout << "takeKlassUniquePtr string: " << s << std::endl;
return s;
}
@ -84,6 +84,10 @@ std::unique_ptr<Klass> makeKlassUniquePtr(const char* label) {
return std::unique_ptr<Klass>(new Klass(label));
}
std::unique_ptr<Klass> makeNullUniquePtr() {
return std::unique_ptr<Klass>();
}
%}
#endif

View file

@ -0,0 +1,86 @@
using System;
using cpp11_rvalue_reference_moveNamespace;
public class cpp11_rvalue_reference_move_runme {
public static void Main() {
{
// Function containing rvalue reference parameter
Counter.reset_counts();
MovableCopyable mo = new MovableCopyable(222);
Counter.check_counts(1, 0, 0, 0, 0, 0);
MovableCopyable.movein(mo);
Counter.check_counts(1, 0, 0, 1, 0, 2);
if (!MovableCopyable.is_nullptr(mo))
throw new ApplicationException("is_nullptr failed");
mo.Dispose();
Counter.check_counts(1, 0, 0, 1, 0, 2);
}
{
// Move constructor test
Counter.reset_counts();
MovableCopyable mo = new MovableCopyable(222);
Counter.check_counts(1, 0, 0, 0, 0, 0);
MovableCopyable mo_moved = new MovableCopyable(mo);
Counter.check_counts(1, 0, 0, 1, 0, 1);
if (!MovableCopyable.is_nullptr(mo))
throw new ApplicationException("is_nullptr failed");
mo.Dispose();
Counter.check_counts(1, 0, 0, 1, 0, 1);
mo_moved.Dispose();
Counter.check_counts(1, 0, 0, 1, 0, 2);
}
{
// Move assignment operator test
Counter.reset_counts();
MovableCopyable mo111 = new MovableCopyable(111);
MovableCopyable mo222 = new MovableCopyable(222);
Counter.check_counts(2, 0, 0, 0, 0, 0);
mo111.MoveAssign(mo222);
Counter.check_counts(2, 0, 0, 0, 1, 1);
if (!MovableCopyable.is_nullptr(mo222))
throw new ApplicationException("is_nullptr failed");
mo222.Dispose();
Counter.check_counts(2, 0, 0, 0, 1, 1);
mo111.Dispose();
Counter.check_counts(2, 0, 0, 0, 1, 2);
}
{
// null check
Counter.reset_counts();
bool exception_thrown = false;
try {
MovableCopyable.movein(null);
} catch (ArgumentNullException e) {
if (!e.Message.Contains("MovableCopyable && is null"))
throw new ApplicationException("incorrect exception message:" + e);
exception_thrown = true;
}
if (!exception_thrown)
throw new ApplicationException("Should have thrown null error");
Counter.check_counts(0, 0, 0, 0, 0, 0);
}
{
// output
Counter.reset_counts();
MovableCopyable mc = MovableCopyable.moveout(1234);
Counter.check_counts(2, 0, 0, 0, 1, 1);
MovableCopyable.check_numbers_match(mc, 1234);
bool exception_thrown = false;
try {
MovableCopyable.movein(mc);
} catch (ApplicationException e) {
if (!e.Message.Contains("Cannot release ownership as memory is not owned"))
throw new ApplicationException("incorrect exception message");
exception_thrown = true;
}
if (!exception_thrown)
throw new ApplicationException("Should have thrown 'Cannot release ownership as memory is not owned' error");
Counter.check_counts(2, 0, 0, 0, 1, 1);
}
}
}

View file

@ -87,6 +87,11 @@ public class cpp11_std_unique_ptr_runme {
} // Dispose should not fail, even though already deleted
checkCount(0);
cpp11_std_unique_ptr.takeKlassUniquePtr(null);
cpp11_std_unique_ptr.takeKlassUniquePtr(cpp11_std_unique_ptr.make_null());
checkCount(0);
// unique_ptr as output
Klass k1 = cpp11_std_unique_ptr.makeKlassUniquePtr("first");
if (k1.getLabel() != "first")
@ -110,5 +115,8 @@ public class cpp11_std_unique_ptr_runme {
k2.Dispose();
k2 = null;
checkCount(0);
if (cpp11_std_unique_ptr.makeNullUniquePtr() != null)
throw new Exception("null failure");
}
}

View file

@ -87,6 +87,11 @@ public class li_std_auto_ptr_runme {
} // Dispose should not fail, even though already deleted
checkCount(0);
li_std_auto_ptr.takeKlassAutoPtr(null);
li_std_auto_ptr.takeKlassAutoPtr(li_std_auto_ptr.make_null());
checkCount(0);
// auto_ptr as output
Klass k1 = li_std_auto_ptr.makeKlassAutoPtr("first");
if (k1.getLabel() != "first")
@ -110,5 +115,8 @@ public class li_std_auto_ptr_runme {
k2.Dispose();
k2 = null;
checkCount(0);
if (li_std_auto_ptr.makeNullAutoPtr() != null)
throw new Exception("null failure");
}
}

View file

@ -66,7 +66,7 @@ public class runme
li_std_wstring.test_reference(null);
throw new Exception("NULL check failed");
} catch (ArgumentNullException e) {
if (!e.Message.Contains("type is null"))
if (!e.Message.Contains("is null"))
throw new Exception("Missing text " + e);
}
try {

View file

@ -0,0 +1,86 @@
module cpp11_rvalue_reference_move_runme;
import cpp11_rvalue_reference_move.Counter;
import cpp11_rvalue_reference_move.MovableCopyable;
void main() {
{
// Function containing rvalue reference parameter
Counter.reset_counts();
scope MovableCopyable mo = new MovableCopyable(222);
Counter.check_counts(1, 0, 0, 0, 0, 0);
MovableCopyable.movein(mo);
Counter.check_counts(1, 0, 0, 1, 0, 2);
if (!MovableCopyable.is_nullptr(mo))
throw new Exception("is_nullptr failed");
mo.dispose();
Counter.check_counts(1, 0, 0, 1, 0, 2);
}
{
// Move constructor test
Counter.reset_counts();
scope MovableCopyable mo = new MovableCopyable(222);
Counter.check_counts(1, 0, 0, 0, 0, 0);
MovableCopyable mo_moved = new MovableCopyable(mo);
Counter.check_counts(1, 0, 0, 1, 0, 1);
if (!MovableCopyable.is_nullptr(mo))
throw new Exception("is_nullptr failed");
mo.dispose();
Counter.check_counts(1, 0, 0, 1, 0, 1);
mo_moved.dispose();
Counter.check_counts(1, 0, 0, 1, 0, 2);
}
{
// Move assignment operator test
Counter.reset_counts();
scope MovableCopyable mo111 = new MovableCopyable(111);
scope MovableCopyable mo222 = new MovableCopyable(222);
Counter.check_counts(2, 0, 0, 0, 0, 0);
mo111.MoveAssign(mo222);
Counter.check_counts(2, 0, 0, 0, 1, 1);
if (!MovableCopyable.is_nullptr(mo222))
throw new Exception("is_nullptr failed");
mo222.dispose();
Counter.check_counts(2, 0, 0, 0, 1, 1);
mo111.dispose();
Counter.check_counts(2, 0, 0, 0, 1, 2);
}
{
// null check
Counter.reset_counts();
bool exception_thrown = false;
try {
MovableCopyable.movein(null);
} catch (Exception e) {
if (!canFind(e.msg, "MovableCopyable && is null"))
throw new Exception("incorrect exception message:" ~ e.msg);
exception_thrown = true;
}
if (!exception_thrown)
throw new Exception("Should have thrown null error");
Counter.check_counts(0, 0, 0, 0, 0, 0);
}
{
// output
Counter.reset_counts();
MovableCopyable mc = MovableCopyable.moveout(1234);
Counter.check_counts(2, 0, 0, 0, 1, 1);
MovableCopyable.check_numbers_match(mc, 1234);
bool exception_thrown = false;
try {
MovableCopyable.movein(mc);
} catch (Exception e) {
if (!canFind(e.msg, "Cannot release ownership as memory is not owned"))
throw new Exception("incorrect exception message: " ~ e.msg);
exception_thrown = true;
}
if (!exception_thrown)
throw new Exception("Should have thrown 'Cannot release ownership as memory is not owned' error");
Counter.check_counts(2, 0, 0, 0, 1, 1);
}
}

View file

@ -0,0 +1,87 @@
module cpp11_rvalue_reference_move_runme;
import cpp11_rvalue_reference_move.Counter;
import cpp11_rvalue_reference_move.MovableCopyable;
import std.algorithm;
void main() {
{
// Function containing rvalue reference parameter
Counter.reset_counts();
scope MovableCopyable mo = new MovableCopyable(222);
Counter.check_counts(1, 0, 0, 0, 0, 0);
MovableCopyable.movein(mo);
Counter.check_counts(1, 0, 0, 1, 0, 2);
if (!MovableCopyable.is_nullptr(mo))
throw new Exception("is_nullptr failed");
mo.dispose();
Counter.check_counts(1, 0, 0, 1, 0, 2);
}
{
// Move constructor test
Counter.reset_counts();
scope MovableCopyable mo = new MovableCopyable(222);
Counter.check_counts(1, 0, 0, 0, 0, 0);
MovableCopyable mo_moved = new MovableCopyable(mo);
Counter.check_counts(1, 0, 0, 1, 0, 1);
if (!MovableCopyable.is_nullptr(mo))
throw new Exception("is_nullptr failed");
mo.dispose();
Counter.check_counts(1, 0, 0, 1, 0, 1);
mo_moved.dispose();
Counter.check_counts(1, 0, 0, 1, 0, 2);
}
{
// Move assignment operator test
Counter.reset_counts();
scope MovableCopyable mo111 = new MovableCopyable(111);
scope MovableCopyable mo222 = new MovableCopyable(222);
Counter.check_counts(2, 0, 0, 0, 0, 0);
mo111.MoveAssign(mo222);
Counter.check_counts(2, 0, 0, 0, 1, 1);
if (!MovableCopyable.is_nullptr(mo222))
throw new Exception("is_nullptr failed");
mo222.dispose();
Counter.check_counts(2, 0, 0, 0, 1, 1);
mo111.dispose();
Counter.check_counts(2, 0, 0, 0, 1, 2);
}
{
// null check
Counter.reset_counts();
bool exception_thrown = false;
try {
MovableCopyable.movein(null);
} catch (Exception e) {
if (!canFind(e.msg, "MovableCopyable && is null"))
throw new Exception("incorrect exception message:" ~ e.msg);
exception_thrown = true;
}
if (!exception_thrown)
throw new Exception("Should have thrown null error");
Counter.check_counts(0, 0, 0, 0, 0, 0);
}
{
// output
Counter.reset_counts();
MovableCopyable mc = MovableCopyable.moveout(1234);
Counter.check_counts(2, 0, 0, 0, 1, 1);
MovableCopyable.check_numbers_match(mc, 1234);
bool exception_thrown = false;
try {
MovableCopyable.movein(mc);
} catch (Exception e) {
if (!canFind(e.msg, "Cannot release ownership as memory is not owned"))
throw new Exception("incorrect exception message: " ~ e.msg);
exception_thrown = true;
}
if (!exception_thrown)
throw new Exception("Should have thrown 'Cannot release ownership as memory is not owned' error");
Counter.check_counts(2, 0, 0, 0, 1, 1);
}
}

View file

@ -87,6 +87,11 @@ void main() {
} // dispose should not fail, even though already deleted
checkCount(0);
takeKlassUniquePtr(null);
takeKlassUniquePtr(make_null());
checkCount(0);
// unique_ptr as output
Klass k1 = makeKlassUniquePtr("first");
if (k1.getLabel() != "first")
@ -103,4 +108,7 @@ void main() {
k2.dispose();
checkCount(0);
if (makeNullUniquePtr() !is null)
throw new Exception("null failure");
}

View file

@ -87,6 +87,11 @@ void main() {
} // dispose should not fail, even though already deleted
checkCount(0);
takeKlassUniquePtr(null);
takeKlassUniquePtr(make_null());
checkCount(0);
// unique_ptr as output
Klass k1 = makeKlassUniquePtr("first");
if (k1.getLabel() != "first")
@ -103,4 +108,7 @@ void main() {
k2.dispose();
checkCount(0);
if (makeNullUniquePtr() !is null)
throw new Exception("null failure");
}

View file

@ -87,6 +87,11 @@ void main() {
} // dispose should not fail, even though already deleted
checkCount(0);
takeKlassAutoPtr(null);
takeKlassAutoPtr(make_null());
checkCount(0);
// auto_ptr as output
Klass k1 = makeKlassAutoPtr("first");
if (k1.getLabel() != "first")
@ -103,4 +108,7 @@ void main() {
k2.dispose();
checkCount(0);
if (makeNullAutoPtr() !is null)
throw new Exception("null failure");
}

View file

@ -87,6 +87,11 @@ void main() {
} // dispose should not fail, even though already deleted
checkCount(0);
takeKlassAutoPtr(null);
takeKlassAutoPtr(make_null());
checkCount(0);
// auto_ptr as output
Klass k1 = makeKlassAutoPtr("first");
if (k1.getLabel() != "first")
@ -103,4 +108,7 @@ void main() {
k2.dispose();
checkCount(0);
if (makeNullAutoPtr() !is null)
throw new Exception("null failure");
}

View file

@ -144,7 +144,7 @@
%rename(renamed2arg) Foo::renameme(int x) const;
%rename(renamed1arg) Foo::renameme() const;
%typemap(default) double* null_by_default "$1=0;";
%typemap(default) double* null_by_default "$1=0;"
%inline %{
typedef void* MyHandle;

View file

@ -21,7 +21,7 @@ int bar(int a)
}
%}
%typemap(in,fragment="Hi") int hola "$1 = 123;";
%typemap(in,fragment="Hi") int hola "$1 = 123;"
%inline %{

View file

@ -161,8 +161,8 @@ void *string_to_uintptr(char *in)
// These typemaps convert between an array of strings in Go and a
// const char** that is NULL terminated in C++.
%typemap(gotype) (const char * const *) "[]string";
%typemap(imtype) (const char * const *) "uintptr";
%typemap(gotype) (const char * const *) "[]string"
%typemap(imtype) (const char * const *) "uintptr"
%typemap(goin) (const char * const *) {
if $input == nil || len($input) == 0 {
$result = 0

View file

@ -0,0 +1,3 @@
(dynamic-call "scm_init_cpp11_rvalue_reference_move_module" (dynamic-link "./libcpp11_rvalue_reference_move"))
(load "testsuite.scm")
(load "../schemerunme/cpp11_rvalue_reference_move.scm")

View file

@ -0,0 +1,3 @@
(dynamic-call "scm_init_null_pointer_module" (dynamic-link "./libnull_pointer"))
(load "testsuite.scm")
(load "../schemerunme/null_pointer.scm")

View file

@ -2,11 +2,11 @@
%module ignore_parameter
%typemap(in,numinputs=0) char* a "static const char* hi = \"hello\"; $1 = const_cast<char *>(hi);";
%typemap(in,numinputs=0) int bb "$1 = 101; called_argout = 0;";
%typemap(in,numinputs=0) double ccc "$1 = 8.8;";
%typemap(in,numinputs=0) char* a "static const char* hi = \"hello\"; $1 = const_cast<char *>(hi);"
%typemap(in,numinputs=0) int bb "$1 = 101; called_argout = 0;"
%typemap(in,numinputs=0) double ccc "$1 = 8.8;"
%typemap(freearg) char* a ""; // ensure freearg is not generated (needed for Java at least)
%typemap(freearg) char* a "" // ensure freearg is not generated (needed for Java at least)
%typemap(argout) int bb "called_argout = 1;"

View file

@ -1,11 +1,11 @@
import cpp11_rvalue_reference_move_input.*;
import cpp11_rvalue_reference_move.*;
public class cpp11_rvalue_reference_move_input_runme {
public class cpp11_rvalue_reference_move_runme {
static {
try {
System.loadLibrary("cpp11_rvalue_reference_move_input");
System.loadLibrary("cpp11_rvalue_reference_move");
} 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);
@ -15,6 +15,7 @@ public class cpp11_rvalue_reference_move_input_runme {
public static void main(String argv[]) {
{
// Function containing rvalue reference parameter
Counter.reset_counts();
MovableCopyable mo = new MovableCopyable(222);
Counter.check_counts(1, 0, 0, 0, 0, 0);
@ -56,5 +57,41 @@ public class cpp11_rvalue_reference_move_input_runme {
mo111.delete();
Counter.check_counts(2, 0, 0, 0, 1, 2);
}
{
// null check
Counter.reset_counts();
boolean exception_thrown = false;
try {
MovableCopyable.movein(null);
} catch (NullPointerException e) {
if (!e.getMessage().contains("MovableCopyable && is null"))
throw new RuntimeException("incorrect exception message");
exception_thrown = true;
}
if (!exception_thrown)
throw new RuntimeException("Should have thrown null error");
Counter.check_counts(0, 0, 0, 0, 0, 0);
}
{
// output
Counter.reset_counts();
MovableCopyable mc = MovableCopyable.moveout(1234);
Counter.check_counts(2, 0, 0, 0, 1, 1);
MovableCopyable.check_numbers_match(mc, 1234);
boolean exception_thrown = false;
try {
MovableCopyable.movein(mc);
} catch (RuntimeException e) {
if (!e.getMessage().contains("Cannot release ownership as memory is not owned"))
throw new RuntimeException("incorrect exception message");
exception_thrown = true;
}
if (!exception_thrown)
throw new RuntimeException("Should have thrown 'Cannot release ownership as memory is not owned' error");
Counter.check_counts(2, 0, 0, 0, 1, 1);
}
}
}

View file

@ -107,6 +107,11 @@ public class cpp11_std_unique_ptr_runme {
checkCount(0);
}
cpp11_std_unique_ptr.takeKlassUniquePtr(null);
cpp11_std_unique_ptr.takeKlassUniquePtr(cpp11_std_unique_ptr.make_null());
checkCount(0);
// unique_ptr as output
Klass k1 = cpp11_std_unique_ptr.makeKlassUniquePtr("first");
if (!k1.getLabel().equals("first"))
@ -125,5 +130,8 @@ public class cpp11_std_unique_ptr_runme {
k2.delete();
k2 = null;
checkCount(0);
if (cpp11_std_unique_ptr.makeNullUniquePtr() != null)
throw new RuntimeException("null failure");
}
}

View file

@ -107,6 +107,11 @@ public class li_std_auto_ptr_runme {
checkCount(0);
}
li_std_auto_ptr.takeKlassAutoPtr(null);
li_std_auto_ptr.takeKlassAutoPtr(li_std_auto_ptr.make_null());
checkCount(0);
// auto_ptr as output
Klass k1 = li_std_auto_ptr.makeKlassAutoPtr("first");
if (!k1.getLabel().equals("first"))
@ -125,5 +130,8 @@ public class li_std_auto_ptr_runme {
k2.delete();
k2 = null;
checkCount(0);
if (li_std_auto_ptr.makeNullAutoPtr() != null)
throw new RuntimeException("null failure");
}
}

View file

@ -139,7 +139,7 @@
%rename(MyJavaException2) MyNS::Exception2;
%rename(MyJavaUnexpected) MyNS::Unexpected;
%typemap(javabase) ::MyNS::Exception1,::MyNS::Exception2,::MyNS::Unexpected "java.lang.Exception";
%typemap(javabase) ::MyNS::Exception1,::MyNS::Exception2,::MyNS::Unexpected "java.lang.Exception"
%rename(getMessage) what() const; // Rename all what() methods
namespace MyNS {

View file

@ -146,7 +146,7 @@
%rename(MyJavaException2) MyNS::Exception2;
%rename(MyJavaUnexpected) MyNS::Unexpected;
%typemap(javabase) ::MyNS::Exception1,::MyNS::Exception2,::MyNS::Unexpected "java.lang.Exception";
%typemap(javabase) ::MyNS::Exception1,::MyNS::Exception2,::MyNS::Unexpected "java.lang.Exception"
%rename(getMessage) what() const; // Rename all what() methods
namespace MyNS {

View file

@ -88,7 +88,7 @@ int ioTest() { return 0; }
%}
// except feature (%javaexception) specifying a checked exception class for the throws clause
%typemap(javabase) MyException "Throwable";
%typemap(javabase) MyException "Throwable"
%typemap(javacode) MyException %{
public static final long serialVersionUID = 0x52151000; // Suppress ecj warning
%}

View file

@ -3,21 +3,21 @@
%module java_typemaps_proxy
%typemap(javaimports) SWIGTYPE "import java.math.*;";
%typemap(javaimports) SWIGTYPE "import java.math.*;"
%typemap(javacode) NS::Farewell %{
public void saybye(BigDecimal num_times) {
// BigDecimal requires the java.math library
}
%}
%typemap(javaclassmodifiers) NS::Farewell "public final class";
%typemap(javaclassmodifiers) NS::Farewell "public final class"
%typemap(javaimports) NS::Greeting %{
import java.util.*; // for EventListener
import java.lang.*; // for Exception
%};
%typemap(javabase) NS::Greeting "Exception";
%typemap(javainterfaces) NS::Greeting "EventListener";
%typemap(javabase) NS::Greeting "Exception"
%typemap(javainterfaces) NS::Greeting "EventListener"
%typemap(javacode) NS::Greeting %{
public static final long serialVersionUID = 0x52151000; // Suppress ecj warning
// Pure Java code generated using %typemap(javacode)
@ -60,7 +60,7 @@ import java.lang.*; // for Exception
%}
// get rid of the finalize method for NS::Farewell
%typemap(javafinalize) NS::Farewell "";
%typemap(javafinalize) NS::Farewell ""
// Test typemaps are being found for templated classes
%typemap(javacode) NS::Adieu<int**> %{
@ -89,7 +89,7 @@ namespace NS {
%template(AdieuIntPtrPtr) NS::Adieu<int**>;
// Check the premature garbage collection prevention parameter can be turned off
%typemap(jtype, nopgcpp="1") Without * "long";
%typemap(jtype, nopgcpp="1") Without * "long"
%pragma(java) jniclassclassmodifiers="public class"
%inline %{
@ -109,7 +109,7 @@ struct With {
void global_method_with(With *p) {}
%}
%typemap(jtype, nopgcpp="1") const ConstWithout * "long";
%typemap(jtype, nopgcpp="1") const ConstWithout * "long"
%inline %{
class ConstWithout {
public:

View file

@ -3,7 +3,7 @@
%module java_typemaps_typewrapper
%typemap(javaimports) SWIGTYPE * "import java.math.*;";
%typemap(javaimports) SWIGTYPE * "import java.math.*;"
%typemap(javacode) Farewell * %{
public static $javaclassname CreateNullPointer() {
return new $javaclassname();
@ -12,15 +12,15 @@
// BigDecimal requires the java.math library
}
%}
%typemap(javaclassmodifiers) Farewell * "public final class";
%typemap(javaclassmodifiers) Farewell * "public final class"
%typemap(javaimports) Greeting * %{
import java.util.*; // for EventListener
import java.lang.*; // for Exception
%};
%typemap(javabase) Greeting * "Exception";
%typemap(javainterfaces) Greeting * "EventListener";
%typemap(javabase) Greeting * "Exception"
%typemap(javainterfaces) Greeting * "EventListener"
%typemap(javacode) Greeting * %{
public static final long serialVersionUID = 0x52151000; // Suppress ecj warning
// Pure Java code generated using %typemap(javacode)

View file

@ -0,0 +1,87 @@
var cpp11_rvalue_reference_move = require("cpp11_rvalue_reference_move");
{
// Function containing rvalue reference parameter
cpp11_rvalue_reference_move.Counter.reset_counts();
mo = new cpp11_rvalue_reference_move.MovableCopyable(222);
cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 0, 0, 0);
cpp11_rvalue_reference_move.MovableCopyable.movein(mo);
cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 1, 0, 2);
if (!cpp11_rvalue_reference_move.MovableCopyable.is_nullptr(mo))
throw new Error("is_nullptr failed");
delete mo;
cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 1, 0, 2);
}
{
// Move constructor test
cpp11_rvalue_reference_move.Counter.reset_counts();
mo = new cpp11_rvalue_reference_move.MovableCopyable(222);
cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 0, 0, 0);
mo_moved = new cpp11_rvalue_reference_move.MovableCopyable(mo);
cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 1, 0, 1);
if (!cpp11_rvalue_reference_move.MovableCopyable.is_nullptr(mo))
throw new Error("is_nullptr failed");
delete mo;
cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 1, 0, 1);
// delete mo_moved;
// cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 1, 0, 2);
// Above not deleting the C++ object(node v12) - can't reliably control GC - use the movein function instead to delete
cpp11_rvalue_reference_move.MovableCopyable.movein(mo_moved);
cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 2, 0, 3);
}
{
// Move assignment operator test
cpp11_rvalue_reference_move.Counter.reset_counts();
mo111 = new cpp11_rvalue_reference_move.MovableCopyable(111);
mo222 = new cpp11_rvalue_reference_move.MovableCopyable(222);
cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 0, 0);
mo111.MoveAssign(mo222);
cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 1, 1);
if (!cpp11_rvalue_reference_move.MovableCopyable.is_nullptr(mo222))
throw new Error("is_nullptr failed");
delete mo222;
cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 1, 1);
// delete mo111;
// cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 1, 2);
// Above not deleting the C++ object(node v12) - can't reliably control GC - use the movein function instead to delete
cpp11_rvalue_reference_move.MovableCopyable.movein(mo111);
cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 1, 1, 3);
}
{
// null check
cpp11_rvalue_reference_move.Counter.reset_counts();
exception_thrown = false;
try {
cpp11_rvalue_reference_move.MovableCopyable.movein(null);
} catch (e) {
if (!e.message.includes("invalid null reference"))
throw new Error("incorrect exception message " + e.message);
exception_thrown = true;
}
if (!exception_thrown)
throw new Error("Should have thrown null error");
cpp11_rvalue_reference_move.Counter.check_counts(0, 0, 0, 0, 0, 0);
}
{
// output
cpp11_rvalue_reference_move.Counter.reset_counts();
var mc = cpp11_rvalue_reference_move.MovableCopyable.moveout(1234);
cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 1, 1);
cpp11_rvalue_reference_move.MovableCopyable.check_numbers_match(mc, 1234);
exception_thrown = false;
try {
cpp11_rvalue_reference_move.MovableCopyable.movein(mc);
} catch (e) {
if (!e.message.includes("cannot release ownership as memory is not owned"))
throw new Error("incorrect exception message " + e.message);
exception_thrown = true;
}
if (!exception_thrown)
throw new Error("Should have thrown 'Cannot release ownership as memory is not owned' error");
cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 1, 1);
}

View file

@ -90,6 +90,11 @@ var checkCount = function(expected_count) {
checkCount(0);
}
cpp11_std_unique_ptr.takeKlassUniquePtr(null);
cpp11_std_unique_ptr.takeKlassUniquePtr(cpp11_std_unique_ptr.make_null());
checkCount(0);
// unique_ptr as output
k1 = cpp11_std_unique_ptr.makeKlassUniquePtr("first");
if (k1.getLabel() !== "first")
@ -110,3 +115,6 @@ if (k2.getLabel() !== "second")
// Above not deleting the C++ object(node v12) - can't reliably control GC
cpp11_std_unique_ptr.takeKlassUniquePtr(k2);
checkCount(0);
if (cpp11_std_unique_ptr.makeNullUniquePtr() != null)
throw new Error("null failure");

View file

@ -90,6 +90,11 @@ var checkCount = function(expected_count) {
checkCount(0);
}
li_std_auto_ptr.takeKlassAutoPtr(null);
li_std_auto_ptr.takeKlassAutoPtr(li_std_auto_ptr.make_null());
checkCount(0);
// auto_ptr as output
k1 = li_std_auto_ptr.makeKlassAutoPtr("first");
if (k1.getLabel() !== "first")
@ -109,4 +114,8 @@ if (k2.getLabel() !== "second")
// delete k2;
// Above not deleting the C++ object(node v12) - can't reliably control GC
li_std_auto_ptr.takeKlassAutoPtr(k2);
if (li_std_auto_ptr.makeNullAutoPtr() != null)
throw new Error("null failure");
checkCount(0);

View file

@ -44,6 +44,7 @@ namespace std {
auto_ptr(auto_ptr&& a) : ptr(a.ptr) { a.ptr = 0;}
~auto_ptr() { delete ptr; }
T *release() { T *p = ptr; ptr = 0; return p; }
T* get() const { return ptr; }
void reset(T *p = 0) { delete ptr; ptr = p; }
T &operator*() const { return *ptr; }
T *operator->() const { return ptr; }
@ -110,11 +111,14 @@ std::string useKlassRawPtr(Klass* k) {
std::string takeKlassAutoPtr(std::auto_ptr<Klass> k) {
// std::cout << "takeKlassAutoPtr " << std::hex << (Klass*)k.get() << std::endl;
std::string s(k->getLabel());
std::string s(k.get() ? k->getLabel() : "null smart pointer");
// std::cout << "takeKlassAutoPtr string: " << s << std::endl;
return s;
}
Klass *make_null() {
return 0;
}
bool is_nullptr(Klass *p) {
return p == 0;
@ -128,6 +132,10 @@ std::auto_ptr<Klass> makeKlassAutoPtr(const char* label) {
return std::auto_ptr<Klass>(new Klass(label));
}
std::auto_ptr<Klass> makeNullAutoPtr() {
return std::auto_ptr<Klass>();
}
%}
#endif

View file

@ -0,0 +1,66 @@
require("import") -- the import fn
import("cpp11_rvalue_reference_move") -- import code
-- catch "undefined" global variables
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
-- Function containing rvalue reference parameter
cpp11_rvalue_reference_move.Counter.reset_counts()
mo = cpp11_rvalue_reference_move.MovableCopyable(222)
cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 0, 0, 0)
cpp11_rvalue_reference_move.MovableCopyable.movein(mo)
cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 1, 0, 2)
if not (cpp11_rvalue_reference_move.MovableCopyable_is_nullptr(mo)) then
error("is_nullptr failed")
end
mo = nil
cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 1, 0, 2)
-- Move constructor test
cpp11_rvalue_reference_move.Counter.reset_counts()
mo = cpp11_rvalue_reference_move.MovableCopyable(222)
cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 0, 0, 0)
mo_moved = cpp11_rvalue_reference_move.MovableCopyable(mo)
cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 1, 0, 1)
if not (cpp11_rvalue_reference_move.MovableCopyable_is_nullptr(mo)) then
error("is_nullptr failed")
end
mo = nil
cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 1, 0, 1)
mo_moved = nil
collectgarbage() -- gc nudge needed here
cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 1, 0, 2)
-- Move assignment operator test
cpp11_rvalue_reference_move.Counter.reset_counts()
mo111 = cpp11_rvalue_reference_move.MovableCopyable(111)
mo222 = cpp11_rvalue_reference_move.MovableCopyable(222)
cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 0, 0)
mo111:MoveAssign(mo222)
cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 1, 1)
if not (cpp11_rvalue_reference_move.MovableCopyable_is_nullptr(mo222)) then
error("is_nullptr failed")
end
mo222 = nil
cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 1, 1)
mo111 = nil
collectgarbage() -- gc nudge needed here
cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 1, 2)
-- null check
cpp11_rvalue_reference_move.Counter.reset_counts()
s, msg = pcall(function() cpp11_rvalue_reference_move.MovableCopyable.movein(nil) end)
assert(s == false and msg:find("Error in MovableCopyable::movein (arg 1), expected 'MovableCopyable &&' got 'nil'", 1, true))
cpp11_rvalue_reference_move.Counter.check_counts(0, 0, 0, 0, 0, 0)
-- output
cpp11_rvalue_reference_move.Counter.reset_counts()
mc = cpp11_rvalue_reference_move.MovableCopyable.moveout(1234)
cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 1, 1)
cpp11_rvalue_reference_move.MovableCopyable.check_numbers_match(mc, 1234)
s, msg = pcall(function() cpp11_rvalue_reference_move.MovableCopyable.movein(mc) end)
assert(s == false and msg:find("Cannot release ownership as memory is not owned", 1, true))
cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 1, 1)

View file

@ -0,0 +1,100 @@
require("import") -- the import fn
import("cpp11_std_unique_ptr") -- import code
-- catch "undefined" global variables
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
function checkCount(expected_count)
-- call gc to make unused objects are collected
collectgarbage()
actual_count = cpp11_std_unique_ptr.Klass.getTotal_count()
if not (actual_count == expected_count) then
error("Counts incorrect, expected:"..expected_count.." actual:"..actual_count)
end
end
--Test raw pointer handling involving virtual inheritance
kini = cpp11_std_unique_ptr.KlassInheritance("KlassInheritanceInput")
checkCount(1)
s = cpp11_std_unique_ptr.useKlassRawPtr(kini)
if not (s == "KlassInheritanceInput") then
error("Incorrect string: "..s)
end
kini = nil
checkCount(0)
-- unique_ptr as input
kin = cpp11_std_unique_ptr.Klass("KlassInput")
checkCount(1)
s = cpp11_std_unique_ptr.takeKlassUniquePtr(kin)
checkCount(0)
if not (s == "KlassInput") then
error("Incorrect string: "..s)
end
if not (cpp11_std_unique_ptr.is_nullptr(kin)) then
error("is_nullptr failed")
end
kin = nil -- Should not fail, even though already deleted
checkCount(0)
kin = cpp11_std_unique_ptr.Klass("KlassInput")
checkCount(1)
s = cpp11_std_unique_ptr.takeKlassUniquePtr(kin)
checkCount(0)
if not (s == "KlassInput") then
error("Incorrect string: "..s)
end
if not (cpp11_std_unique_ptr.is_nullptr(kin)) then
error("is_nullptr failed")
end
s, msg = pcall(function() cpp11_std_unique_ptr.takeKlassUniquePtr(kin) end)
assert(s == false and msg == "Cannot release ownership as memory is not owned for argument 1 of type 'Klass *' in takeKlassUniquePtr")
kin = nil -- Should not fail, even though already deleted
checkCount(0)
kin = cpp11_std_unique_ptr.Klass("KlassInput")
notowned = cpp11_std_unique_ptr.get_not_owned_ptr(kin)
s, msg = pcall(function() cpp11_std_unique_ptr.takeKlassUniquePtr(notowned) end)
assert(s == false and msg == "Cannot release ownership as memory is not owned for argument 1 of type 'Klass *' in takeKlassUniquePtr")
checkCount(1)
kin = nil
checkCount(0)
kini = cpp11_std_unique_ptr.KlassInheritance("KlassInheritanceInput")
checkCount(1)
s = cpp11_std_unique_ptr.takeKlassUniquePtr(kini)
checkCount(0)
if not (s == "KlassInheritanceInput") then
error("Incorrect string: "..s)
end
if not (cpp11_std_unique_ptr.is_nullptr(kini)) then
error("is_nullptr failed")
end
kini = nil -- Should not fail, even though already deleted
checkCount(0)
cpp11_std_unique_ptr.takeKlassUniquePtr(nil);
cpp11_std_unique_ptr.takeKlassUniquePtr(cpp11_std_unique_ptr.make_null());
checkCount(0);
-- unique_ptr as output
k1 = cpp11_std_unique_ptr.makeKlassUniquePtr("first")
k2 = cpp11_std_unique_ptr.makeKlassUniquePtr("second")
checkCount(2)
k1 = nil
checkCount(1)
if not (k2:getLabel() == "second") then
error("wrong object label")
end
k2 = nil
checkCount(0)
assert(cpp11_std_unique_ptr.makeNullUniquePtr() == nil)

View file

@ -77,6 +77,11 @@ end
kini = nil -- Should not fail, even though already deleted
checkCount(0)
li_std_auto_ptr.takeKlassAutoPtr(nil);
li_std_auto_ptr.takeKlassAutoPtr(li_std_auto_ptr.make_null());
checkCount(0);
-- auto_ptr as output
k1 = li_std_auto_ptr.makeKlassAutoPtr("first")
k2 = li_std_auto_ptr.makeKlassAutoPtr("second")
@ -91,3 +96,5 @@ end
k2 = nil
checkCount(0)
assert(li_std_auto_ptr.makeNullAutoPtr() == nil)

View file

@ -40,18 +40,18 @@ $importtype(IRemoteAsyncIO)
#endif
// Modify multiple inherited base classes into inheriting interfaces
%typemap(javainterfaces) RemoteMpe "IRemoteSyncIO, IRemoteAsyncIO";
%typemap(javabase, replace="1") RemoteMpe "";
%typemap(javainterfaces) RemoteMpe "IRemoteSyncIO, IRemoteAsyncIO"
%typemap(javabase, replace="1") RemoteMpe ""
// Turn the proxy class into an interface
%typemap(javaclassmodifiers) IRemoteSyncIO "public interface";
%typemap(javaclassmodifiers) IRemoteAsyncIO "public interface";
%typemap(javabody) IRemoteSyncIO "";
%typemap(javabody) IRemoteAsyncIO "";
%typemap(javafinalize) IRemoteSyncIO "";
%typemap(javafinalize) IRemoteAsyncIO "";
%typemap(javadestruct) IRemoteSyncIO "";
%typemap(javadestruct) IRemoteAsyncIO "";
%typemap(javaclassmodifiers) IRemoteSyncIO "public interface"
%typemap(javaclassmodifiers) IRemoteAsyncIO "public interface"
%typemap(javabody) IRemoteSyncIO ""
%typemap(javabody) IRemoteAsyncIO ""
%typemap(javafinalize) IRemoteSyncIO ""
%typemap(javafinalize) IRemoteAsyncIO ""
%typemap(javadestruct) IRemoteSyncIO ""
%typemap(javadestruct) IRemoteAsyncIO ""
// Turn the methods into abstract methods
%typemap(javaout) void IRemoteSyncIO::syncmethod ";"

View file

@ -0,0 +1,68 @@
(load-extension "cpp11_rvalue_reference_move.so")
(require (lib "defmacro.ss"))
; Copied from ../schemerunme/cpp11_rvalue_reference_move.scm and modified for exceptions
; Function containing rvalue reference parameter
(Counter-reset-counts)
(define mo (new-MovableCopyable 222))
(Counter-check-counts 1 0 0 0 0 0)
(MovableCopyable-movein mo)
(Counter-check-counts 1 0 0 1 0 2)
(unless (MovableCopyable-is-nullptr mo)
(error "is_nullptr failed"))
(delete-MovableCopyable mo)
(Counter-check-counts 1 0 0 1 0 2)
; Move constructor test
(Counter-reset-counts)
(define mo (new-MovableCopyable 222))
(Counter-check-counts 1 0 0 0 0 0)
(define mo_moved (new-MovableCopyable mo))
(Counter-check-counts 1 0 0 1 0 1)
(unless (MovableCopyable-is-nullptr mo)
(error "is_nullptr failed"))
(delete-MovableCopyable mo)
(Counter-check-counts 1 0 0 1 0 1)
(delete-MovableCopyable mo_moved)
(Counter-check-counts 1 0 0 1 0 2)
; Move assignment operator test
(Counter-reset-counts)
(define mo111 (new-MovableCopyable 111))
(define mo222 (new-MovableCopyable 222))
(Counter-check-counts 2 0 0 0 0 0)
(MovableCopyable-MoveAssign mo111 mo222)
(Counter-check-counts 2 0 0 0 1 1)
(unless (MovableCopyable-is-nullptr mo222)
(error "is_nullptr failed"))
(delete-MovableCopyable mo222)
(Counter-check-counts 2 0 0 0 1 1)
(delete-MovableCopyable mo111)
(Counter-check-counts 2 0 0 0 1 2)
; null check
(Counter-reset-counts)
(define exception_thrown "no exception thrown for kin")
(with-handlers ([exn:fail? (lambda (exn)
(set! exception_thrown (exn-message exn)))])
(MovableCopyable-movein '()))
(unless (string=? exception_thrown "MovableCopyable-movein: swig-type-error (null reference)")
(error (format "incorrect exception message: ~a" exception_thrown)))
(Counter-check-counts 0 0 0 0 0 0)
; output
(Counter-reset-counts)
(define mc (MovableCopyable-moveout 1234))
(Counter-check-counts 2 0 0 0 1 1)
(MovableCopyable-check-numbers-match mc 1234)
(define exception_thrown "no exception thrown for kin")
(with-handlers ([exn:fail? (lambda (exn)
(set! exception_thrown (exn-message exn)))])
(MovableCopyable-movein mc))
(unless (string-contains? exception_thrown "cannot release ownership as memory is not owned")
(error (format "incorrect exception message: ~a" exception_thrown)))
(Counter-check-counts 2 0 0 0 1 1)
(exit 0)

View file

@ -0,0 +1,100 @@
(load-extension "cpp11_std_unique_ptr.so")
(require (lib "defmacro.ss"))
; Copied from ../schemerunme/cpp11_std_unique_ptr.scm and modified for exceptions
; Define an equivalent to Guile's gc procedure
(define-macro (gc)
`(collect-garbage 'major))
(define checkCount
(lambda (expected-count)
(define actual-count (Klass-getTotal-count))
(unless (= actual-count expected-count) (error (format "Counts incorrect, expected:~a actual:~a" expected-count actual-count)))))
; Test raw pointer handling involving virtual inheritance
(define kini (new-KlassInheritance "KlassInheritanceInput"))
(checkCount 1)
(define s (useKlassRawPtr kini))
(unless (string=? s "KlassInheritanceInput")
(error "Incorrect string: " s))
(set! kini '()) (gc)
(checkCount 0)
; unique_ptr as input
(define kin (new-Klass "KlassInput"))
(checkCount 1)
(define s (takeKlassUniquePtr kin))
(checkCount 0)
(unless (string=? s "KlassInput")
(error "Incorrect string: " s))
(unless (is-nullptr kin)
(error "is_nullptr failed"))
(set! kini '()) (gc) ; Should not fail, even though already deleted
(checkCount 0)
(define kin (new-Klass "KlassInput"))
(checkCount 1)
(define s (takeKlassUniquePtr kin))
(checkCount 0)
(unless (string=? s "KlassInput")
(error "Incorrect string: " s))
(unless (is-nullptr kin)
(error "is_nullptr failed"))
(define exception_thrown "no exception thrown for kin")
(with-handlers ([exn:fail? (lambda (exn)
(set! exception_thrown (exn-message exn)))])
(takeKlassUniquePtr kin))
(unless (string=? exception_thrown "takeKlassUniquePtr: cannot release ownership as memory is not owned for argument 1 of type 'Klass *'")
(error "Wrong or no exception thrown: " exception_thrown))
(set! kin '()) (gc) ; Should not fail, even though already deleted
(checkCount 0)
(define kin (new-Klass "KlassInput"))
(define notowned (get-not-owned-ptr kin))
(set! exception_thrown "no exception thrown for notowned")
(with-handlers ([exn:fail? (lambda (exn)
(set! exception_thrown (exn-message exn)))])
(takeKlassUniquePtr notowned))
(unless (string=? exception_thrown "takeKlassUniquePtr: cannot release ownership as memory is not owned for argument 1 of type 'Klass *'")
(error "Wrong or no exception thrown: " exception_thrown))
(checkCount 1)
(set! kin '()) (gc)
(checkCount 0)
(define kini (new-KlassInheritance "KlassInheritanceInput"))
(checkCount 1)
(define s (takeKlassUniquePtr kini))
(checkCount 0)
(unless (string=? s "KlassInheritanceInput")
(error "Incorrect string: " s))
(unless (is-nullptr kini)
(error "is_nullptr failed"))
(set! kini '()) (gc) ; Should not fail, even though already deleted
(checkCount 0)
(define null '())
(takeKlassUniquePtr null)
(takeKlassUniquePtr (make-null))
(checkCount 0)
; unique_ptr as output
(define k1 (makeKlassUniquePtr "first"))
(define k2 (makeKlassUniquePtr "second"))
(checkCount 2)
(set! k1 '()) (gc)
(checkCount 1)
(unless (string=? (Klass-getLabel k2) "second")
(error "wrong object label" ))
(set! k2 '()) (gc)
(checkCount 0)
(unless (null? (makeNullUniquePtr))
(error "null failure"))
(exit 0)

View file

@ -6,4 +6,4 @@
,form
#f))
(load "../schemerunme/integers.scm")
(load (build-path (path-only (path->complete-path (find-system-path 'run-file))) "../schemerunme/integers.scm"))

View file

@ -74,6 +74,12 @@
(set! kini '()) (gc) ; Should not fail, even though already deleted
(checkCount 0)
(define null '())
(takeKlassAutoPtr null)
(takeKlassAutoPtr (make-null))
(checkCount 0)
; auto_ptr as output
(define k1 (makeKlassAutoPtr "first"))
(define k2 (makeKlassAutoPtr "second"))
@ -88,4 +94,7 @@
(set! k2 '()) (gc)
(checkCount 0)
(unless (null? (makeNullAutoPtr))
(error "null failure"))
(exit 0)

View file

@ -6,4 +6,4 @@
(define-macro (gc)
`(collect-garbage 'major))
(load "../schemerunme/newobject1.scm")
(load (build-path (path-only (path->complete-path (find-system-path 'run-file))) "../schemerunme/newobject1.scm"))

View file

@ -0,0 +1,3 @@
(load-extension "null_pointer.so")
(load (build-path (path-only (path->complete-path (find-system-path 'run-file))) "../schemerunme/null_pointer.scm"))

View file

@ -0,0 +1,85 @@
# do not dump Octave core
if exist("crash_dumps_octave_core", "builtin")
crash_dumps_octave_core(0);
endif
cpp11_rvalue_reference_move
# Function containing rvalue reference parameter
Counter.reset_counts();
mo = MovableCopyable(222);
Counter.check_counts(1, 0, 0, 0, 0, 0);
MovableCopyable.movein(mo);
Counter.check_counts(1, 0, 0, 1, 0, 2);
if (!MovableCopyable_is_nullptr(mo))
error("is_nullptr failed");
endif
clear mo;
Counter.check_counts(1, 0, 0, 1, 0, 2);
# Move constructor test
Counter.reset_counts();
mo = MovableCopyable(222);
Counter.check_counts(1, 0, 0, 0, 0, 0);
mo_moved = MovableCopyable(mo);
Counter.check_counts(1, 0, 0, 1, 0, 1);
if (!MovableCopyable_is_nullptr(mo))
error("is_nullptr failed");
endif
clear mo;
Counter.check_counts(1, 0, 0, 1, 0, 1);
clear mo_moved;
Counter.check_counts(1, 0, 0, 1, 0, 2);
# Move assignment operator test
Counter.reset_counts();
mo111 = MovableCopyable(111);
mo222 = MovableCopyable(222);
Counter.check_counts(2, 0, 0, 0, 0, 0);
mo111.MoveAssign(mo222);
Counter.check_counts(2, 0, 0, 0, 1, 1);
if (!MovableCopyable_is_nullptr(mo222))
error("is_nullptr failed");
endif
clear mo222;
Counter.check_counts(2, 0, 0, 0, 1, 1);
clear mo111;
Counter.check_counts(2, 0, 0, 0, 1, 2);
# null check
null = []; # NULL pointer
Counter.reset_counts();
exception_thrown = false;
try
MovableCopyable.movein(null);
catch e
if (isempty(strfind(e.message, "invalid null reference")))
error("incorrect exception message: %s", e.message)
endif
exception_thrown = true;
end_try_catch
if (!exception_thrown)
error("Should have thrown null error");
endif
Counter.check_counts(0, 0, 0, 0, 0, 0);
# output
Counter.reset_counts();
mc = MovableCopyable.moveout(1234);
Counter.check_counts(2, 0, 0, 0, 1, 1);
MovableCopyable.check_numbers_match(mc, 1234);
exception_thrown = false;
try
MovableCopyable.movein(mc);
catch e
if (isempty(strfind(e.message, "cannot release ownership as memory is not owned")))
error("incorrect exception message: %s", e.message)
endif
exception_thrown = true;
end_try_catch
if (!exception_thrown)
error("Should have thrown 'Cannot release ownership as memory is not owned' error");
endif
Counter.check_counts(2, 0, 0, 0, 1, 1);

View file

@ -93,6 +93,13 @@ endif
clear kini; # Should not fail, even though already deleted
checkCount(0);
null = []; # NULL pointer
null_ptr = make_null();
takeKlassUniquePtr([]);
takeKlassUniquePtr(null);
takeKlassUniquePtr(null_ptr);
checkCount(0);
# unique_ptr as output
k1 = makeKlassUniquePtr("first");
@ -112,3 +119,8 @@ endif
clear k2;
checkCount(0);
null_smart_prt = makeNullUniquePtr();
assert(ismatrix(null_smart_prt))
assert(size(null_smart_prt) == size([]))
assert(isequal([], null_smart_prt))

View file

@ -93,6 +93,13 @@ endif
clear kini; # Should not fail, even though already deleted
checkCount(0);
null = []; # NULL pointer
null_ptr = make_null();
takeKlassAutoPtr([]);
takeKlassAutoPtr(null);
takeKlassAutoPtr(null_ptr);
checkCount(0);
# auto_ptr as output
k1 = makeKlassAutoPtr("first");
@ -112,3 +119,8 @@ endif
clear k2;
checkCount(0);
null_smart_prt = makeNullAutoPtr();
assert(ismatrix(null_smart_prt))
assert(size(null_smart_prt) == size([]))
assert(isequal([], null_smart_prt))

View file

@ -6,3 +6,13 @@ endif
null_pointer;
assert(funk([]));
null_ptr = getnull();
assert(ismatrix(null_ptr))
assert(size(null_ptr) == size([]))
assert(isequal([], null_ptr))
# Can't use isnull as a test due to null matrix not being copyable...
# n = []
# isnull(n) # ans = 0
# isnull([]) # ans = 1
# isnull(getnull()) # ans = 0

View file

@ -5,7 +5,7 @@
#include <stdlib.h>
%}
%typemap(default) double y "$1=1000;";
%typemap(default) double y "$1=1000;"
#endif
#ifdef SWIGLUA

View file

@ -1,6 +1,6 @@
%module overload_extend2
%typemap(default) int int2 "$1=1000;";
%typemap(default) int int2 "$1=1000;"
%inline %{
typedef struct Foo {

View file

@ -0,0 +1,70 @@
use strict;
use warnings;
use Test::More tests => 7;
BEGIN { use_ok('cpp11_rvalue_reference_move') }
require_ok('cpp11_rvalue_reference_move');
{
# Function containing rvalue reference parameter
cpp11_rvalue_reference_move::Counter::reset_counts();
my $mo = new cpp11_rvalue_reference_move::MovableCopyable(222);
cpp11_rvalue_reference_move::Counter::check_counts(1, 0, 0, 0, 0, 0);
cpp11_rvalue_reference_move::MovableCopyable::movein($mo);
cpp11_rvalue_reference_move::Counter::check_counts(1, 0, 0, 1, 0, 2);
is(cpp11_rvalue_reference_move::MovableCopyable::is_nullptr($mo), 1, "is_nullptr check");
undef $mo;
cpp11_rvalue_reference_move::Counter::check_counts(1, 0, 0, 1, 0, 2);
}
{
# Move constructor test
cpp11_rvalue_reference_move::Counter::reset_counts();
my $mo = new cpp11_rvalue_reference_move::MovableCopyable(222);
cpp11_rvalue_reference_move::Counter::check_counts(1, 0, 0, 0, 0, 0);
my $mo_moved = new cpp11_rvalue_reference_move::MovableCopyable($mo);
cpp11_rvalue_reference_move::Counter::check_counts(1, 0, 0, 1, 0, 1);
is(cpp11_rvalue_reference_move::MovableCopyable::is_nullptr($mo), 1, "is_nullptr check");
undef $mo;
cpp11_rvalue_reference_move::Counter::check_counts(1, 0, 0, 1, 0, 1);
undef $mo_moved;
cpp11_rvalue_reference_move::Counter::check_counts(1, 0, 0, 1, 0, 2);
}
{
# Move assignment operator test
cpp11_rvalue_reference_move::Counter::reset_counts();
my $mo111 = new cpp11_rvalue_reference_move::MovableCopyable(111);
my $mo222 = new cpp11_rvalue_reference_move::MovableCopyable(222);
cpp11_rvalue_reference_move::Counter::check_counts(2, 0, 0, 0, 0, 0);
$mo111->MoveAssign($mo222);
cpp11_rvalue_reference_move::Counter::check_counts(2, 0, 0, 0, 1, 1);
is(cpp11_rvalue_reference_move::MovableCopyable::is_nullptr($mo222), 1, "is_nullptr check");
undef $mo222;
cpp11_rvalue_reference_move::Counter::check_counts(2, 0, 0, 0, 1, 1);
undef $mo111;
cpp11_rvalue_reference_move::Counter::check_counts(2, 0, 0, 0, 1, 2);
}
{
# null check
cpp11_rvalue_reference_move::Counter::reset_counts();
eval {
cpp11_rvalue_reference_move::MovableCopyable::movein(undef);
};
like($@, qr/\binvalid null reference/, "Should have thrown null error");
cpp11_rvalue_reference_move::Counter::check_counts(0, 0, 0, 0, 0, 0);
}
{
# output
cpp11_rvalue_reference_move::Counter::reset_counts();
my $mc = cpp11_rvalue_reference_move::MovableCopyable::moveout(1234);
cpp11_rvalue_reference_move::Counter::check_counts(2, 0, 0, 0, 1, 1);
cpp11_rvalue_reference_move::MovableCopyable::check_numbers_match($mc, 1234);
eval {
cpp11_rvalue_reference_move::MovableCopyable::movein($mc);
};
like($@, qr/\bcannot release ownership as memory is not owned\b/, "Should have thrown 'Cannot release ownership as memory is not owned' error");
cpp11_rvalue_reference_move::Counter::check_counts(2, 0, 0, 0, 1, 1);
}

View file

@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 28;
use Test::More tests => 30;
BEGIN { use_ok('cpp11_std_unique_ptr') }
require_ok('cpp11_std_unique_ptr');
@ -73,6 +73,11 @@ sub checkCount {
checkCount(0);
}
cpp11_std_unique_ptr::takeKlassUniquePtr(undef);
cpp11_std_unique_ptr::takeKlassUniquePtr(cpp11_std_unique_ptr::make_null());
checkCount(0);
# unique_ptr as output
my $k1 = cpp11_std_unique_ptr::makeKlassUniquePtr("first");
my $k2 = cpp11_std_unique_ptr::makeKlassUniquePtr("second");
@ -85,3 +90,5 @@ is($k2->getLabel, "second", "proper label");
undef $k2;
checkCount(0);
is(cpp11_std_unique_ptr::makeNullUniquePtr(), undef);

View file

@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 28;
use Test::More tests => 30;
BEGIN { use_ok('li_std_auto_ptr') }
require_ok('li_std_auto_ptr');
@ -73,6 +73,11 @@ sub checkCount {
checkCount(0);
}
li_std_auto_ptr::takeKlassAutoPtr(undef);
li_std_auto_ptr::takeKlassAutoPtr(li_std_auto_ptr::make_null());
checkCount(0);
# auto_ptr as output
my $k1 = li_std_auto_ptr::makeKlassAutoPtr("first");
my $k2 = li_std_auto_ptr::makeKlassAutoPtr("second");
@ -85,3 +90,5 @@ is($k2->getLabel, "second", "proper label");
undef $k2;
checkCount(0);
is(li_std_auto_ptr::makeNullAutoPtr(), undef);

View file

@ -0,0 +1,80 @@
<?php
require "tests.php";
# Function containing rvalue reference parameter
Counter::reset_counts();
$mo = new MovableCopyable(222);
Counter::check_counts(1, 0, 0, 0, 0, 0);
MovableCopyable::movein($mo);
Counter::check_counts(1, 0, 0, 1, 0, 2);
try {
MovableCopyable::is_nullptr($mo);
check::fail("is_nullptr check");
} catch (TypeError $e) {
}
$mo = NULL;
Counter::check_counts(1, 0, 0, 1, 0, 2);
# Move constructor test
Counter::reset_counts();
$mo = new MovableCopyable(222);
Counter::check_counts(1, 0, 0, 0, 0, 0);
$mo_moved = new MovableCopyable($mo);
Counter::check_counts(1, 0, 0, 1, 0, 1);
try {
MovableCopyable::is_nullptr($mo);
check::fail("is_nullptr check");
} catch (TypeError $e) {
}
$mo = NULL;
Counter::check_counts(1, 0, 0, 1, 0, 1);
$mo_moved = NULL;
Counter::check_counts(1, 0, 0, 1, 0, 2);
# Move assignment operator test
Counter::reset_counts();
$mo111 = new MovableCopyable(111);
$mo222 = new MovableCopyable(222);
Counter::check_counts(2, 0, 0, 0, 0, 0);
$mo111->MoveAssign($mo222);
Counter::check_counts(2, 0, 0, 0, 1, 1);
try {
MovableCopyable::is_nullptr($mo222);
check::fail("is_nullptr check");
} catch (TypeError $e) {
}
$mo222 = NULL;
Counter::check_counts(2, 0, 0, 0, 1, 1);
$mo111 = NULL;
Counter::check_counts(2, 0, 0, 0, 1, 2);
# null check
Counter::reset_counts();
$exception_thrown = false;
try {
MovableCopyable::movein(NULL);
} catch (TypeError $e) {
check::str_contains($e->getMessage(), "Invalid null reference", "incorrect exception message: {$e->getMessage()}");
$exception_thrown = true;
}
check::equal($exception_thrown, true, "Should have thrown null error");
Counter::check_counts(0, 0, 0, 0, 0, 0);
# output
Counter::reset_counts();
$mc = MovableCopyable::moveout(1234);
Counter::check_counts(2, 0, 0, 0, 1, 1);
MovableCopyable::check_numbers_match($mc, 1234);
$exception_thrown = false;
try {
MovableCopyable::movein($mc);
} catch (TypeError $e) {
check::str_contains($e->getMessage(), "Cannot release ownership as memory is not owned", "incorrect exception message: {$e->getMessage()}");
$exception_thrown = true;
}
check::equal($exception_thrown, true, "Should have thrown 'Cannot release ownership as memory is not owned' error");
Counter::check_counts(2, 0, 0, 0, 1, 1);
check::done();

View file

@ -40,20 +40,27 @@ try {
check::fail("is_nullptr check");
} catch (TypeError $e) {
}
$exception_thrown = false;
try {
takeKlassUniquePtr($kin);
} catch (TypeError $e) {
check::equal($e->getMessage(), "Cannot release ownership as memory is not owned for argument 1 of type 'Klass *' of takeKlassUniquePtr", "Unexpected exception: {$e->getMessage()}");
check::equal($e->getMessage(), "Cannot release ownership as memory is not owned for argument 1 of SWIGTYPE_p_Klass of takeKlassUniquePtr", "Unexpected exception: {$e->getMessage()}");
$exception_thrown = true;
}
check::equal($exception_thrown, true, "double usage of takeKlassUniquePtr should have been an error");
$kin = NULL; # Should not fail, even though already deleted
checkCount(0);
$kin = new Klass("KlassInput");
$exception_thrown = false;
$notowned = get_not_owned_ptr($kin);
try {
takeKlassUniquePtr($notowned);
} catch (TypeError $e) {
check::equal($e->getMessage(), "Cannot release ownership as memory is not owned for argument 1 of type 'Klass *' of takeKlassUniquePtr", "Unexpected exception: {$e->getMessage()}");
check::equal($e->getMessage(), "Cannot release ownership as memory is not owned for argument 1 of SWIGTYPE_p_Klass of takeKlassUniquePtr", "Unexpected exception: {$e->getMessage()}");
$exception_thrown = true;
}
check::equal($exception_thrown, true, "double usage of takeKlassUniquePtr should have been an error");
checkCount(1);
$kin = NULL;
checkCount(0);
@ -72,6 +79,11 @@ try {
$kini = NULL; # Should not fail, even though already deleted
checkCount(0);
takeKlassUniquePtr(NULL);
takeKlassUniquePtr(make_null());
checkCount(0);
# unique_ptr as output
$k1 = makeKlassUniquePtr("first");
$k2 = makeKlassUniquePtr("second");
@ -85,4 +97,6 @@ check::equal($k2->getLabel(), "second", "proper label");
$k2 = NULL;
checkCount(0);
check::equal(makeNullUniquePtr(), NULL);
check::done();

View file

@ -40,20 +40,27 @@ try {
check::fail("is_nullptr check");
} catch (TypeError $e) {
}
$exception_thrown = false;
try {
takeKlassAutoPtr($kin);
} catch (TypeError $e) {
check::equal($e->getMessage(), "Cannot release ownership as memory is not owned for argument 1 of type 'Klass *' of takeKlassAutoPtr", "Unexpected exception: {$e->getMessage()}");
check::equal($e->getMessage(), "Cannot release ownership as memory is not owned for argument 1 of SWIGTYPE_p_Klass of takeKlassAutoPtr", "Unexpected exception: {$e->getMessage()}");
$exception_thrown = true;
}
check::equal($exception_thrown, true, "double usage of takeKlassAutoPtr should have been an error");
$kin = NULL; # Should not fail, even though already deleted
checkCount(0);
$kin = new Klass("KlassInput");
$exception_thrown = false;
$notowned = get_not_owned_ptr($kin);
try {
takeKlassAutoPtr($notowned);
} catch (TypeError $e) {
check::equal($e->getMessage(), "Cannot release ownership as memory is not owned for argument 1 of type 'Klass *' of takeKlassAutoPtr", "Unexpected exception: {$e->getMessage()}");
check::equal($e->getMessage(), "Cannot release ownership as memory is not owned for argument 1 of SWIGTYPE_p_Klass of takeKlassAutoPtr", "Unexpected exception: {$e->getMessage()}");
$exception_thrown = true;
}
check::equal($exception_thrown, true, "double usage of takeKlassAutoPtr should have been an error");
checkCount(1);
$kin = NULL;
checkCount(0);
@ -72,6 +79,11 @@ try {
$kini = NULL; # Should not fail, even though already deleted
checkCount(0);
takeKlassAutoPtr(NULL);
takeKlassAutoPtr(make_null());
checkCount(0);
# auto_ptr as output
$k1 = makeKlassAutoPtr("first");
$k2 = makeKlassAutoPtr("second");
@ -85,4 +97,6 @@ check::equal($k2->getLabel(), "second", "proper label");
$k2 = NULL;
checkCount(0);
check::equal(makeNullAutoPtr(), NULL);
check::done();

View file

@ -178,6 +178,11 @@ class check {
return TRUE;
}
static function str_contains($a,$b,$message=null) {
# Use strpos as PHP function str_contains requires PHP 8
return check::equal(strpos($a,$b)!==false,true,$message);
}
static function isnull($a,$message=null) {
return check::equal($a,NULL,$message);
}

View file

@ -1,7 +1,7 @@
/* php_iterator.i - PHP-specific testcase for wrapping to a PHP Iterator */
%module php_iterator
%typemap("phpinterfaces") MyIterator "Iterator";
%typemap("phpinterfaces") MyIterator "Iterator"
%inline %{

View file

@ -0,0 +1,69 @@
from cpp11_rvalue_reference_move import *
# Function containing rvalue reference parameter
Counter.reset_counts()
mo = MovableCopyable(222)
Counter.check_counts(1, 0, 0, 0, 0, 0)
MovableCopyable.movein(mo)
Counter.check_counts(1, 0, 0, 1, 0, 2)
if not MovableCopyable.is_nullptr(mo):
raise RuntimeError("is_nullptr check")
del mo
Counter.check_counts(1, 0, 0, 1, 0, 2)
# Move constructor test
Counter.reset_counts()
mo = MovableCopyable(222)
Counter.check_counts(1, 0, 0, 0, 0, 0)
mo_moved = MovableCopyable(mo)
Counter.check_counts(1, 0, 0, 1, 0, 1)
if not MovableCopyable.is_nullptr(mo):
raise RuntimeError("is_nullptr check")
del mo
Counter.check_counts(1, 0, 0, 1, 0, 1)
del mo_moved
Counter.check_counts(1, 0, 0, 1, 0, 2)
# Move assignment operator test
Counter.reset_counts()
mo111 = MovableCopyable(111)
mo222 = MovableCopyable(222)
Counter.check_counts(2, 0, 0, 0, 0, 0)
mo111.MoveAssign(mo222)
Counter.check_counts(2, 0, 0, 0, 1, 1)
if not MovableCopyable.is_nullptr(mo222):
raise RuntimeError("is_nullptr check")
del mo222
Counter.check_counts(2, 0, 0, 0, 1, 1)
del mo111
Counter.check_counts(2, 0, 0, 0, 1, 2)
# null check
Counter.reset_counts()
exception_thrown = False
try:
MovableCopyable.movein(None)
except ValueError as e:
if "invalid null reference" not in str(e):
raise RuntimeError("incorrect exception message:" + str(e))
exception_thrown = True
if not exception_thrown:
raise RuntimeError("Should have thrown null error")
Counter.check_counts(0, 0, 0, 0, 0, 0)
# output
Counter.reset_counts()
mc = MovableCopyable.moveout(1234)
Counter.check_counts(2, 0, 0, 0, 1, 1)
MovableCopyable.check_numbers_match(mc, 1234)
exception_thrown = False
try:
MovableCopyable.movein(mc)
except RuntimeError as e:
if "cannot release ownership as memory is not owned" not in str(e):
raise RuntimeError("incorrect exception message:" + str(e))
exception_thrown = True
if not exception_thrown:
raise RuntimeError("Should have thrown 'Cannot release ownership as memory is not owned' error")
Counter.check_counts(2, 0, 0, 0, 1, 1)

View file

@ -4,24 +4,24 @@ a = cpp11_rvalue_reference.A()
a.setAcopy(5)
if a.getAcopy() != 5:
raise RunTimeError("int A::getAcopy() value is ",
raise RuntimeError("int A::getAcopy() value is ",
a.getAcopy(), " should be 5")
ptr = a.getAptr()
a.setAptr(ptr)
if a.getAcopy() != 5:
raise RunTimeError("after A::setAptr(): int A::getAcopy() value is ", a.getAcopy(
raise RuntimeError("after A::setAptr(): int A::getAcopy() value is ", a.getAcopy(
), " should be 5")
a.setAref(ptr)
if a.getAcopy() != 5:
raise RunTimeError("after A::setAref(): int A::getAcopy() value is ", a.getAcopy(
raise RuntimeError("after A::setAref(): int A::getAcopy() value is ", a.getAcopy(
), " should be 5")
rvalueref = a.getAmove()
a.setAmove(rvalueref)
a.setAref(rvalueref)
if a.getAcopy() != 5:
raise RunTimeError("after A::setAmove(): int A::getAcopy() value is ", a.getAcopy(
raise RuntimeError("after A::setAmove(): int A::getAcopy() value is ", a.getAcopy(
), " should be 5")

View file

@ -77,6 +77,11 @@ if not is_nullptr(kini):
del kini # Should not fail, even though already deleted
checkCount(0)
takeKlassUniquePtr(None)
takeKlassUniquePtr(make_null())
checkCount(0)
# unique_ptr as output
k1 = makeKlassUniquePtr("first")
k2 = makeKlassUniquePtr("second")
@ -90,3 +95,6 @@ if k2.getLabel() != "second":
del k2
checkCount(0)
if (makeNullUniquePtr() != None):
raise RuntimeError("null failure")

View file

@ -77,6 +77,11 @@ if not is_nullptr(kini):
del kini # Should not fail, even though already deleted
checkCount(0)
takeKlassAutoPtr(None)
takeKlassAutoPtr(make_null())
checkCount(0)
# auto_ptr as output
k1 = makeKlassAutoPtr("first")
k2 = makeKlassAutoPtr("second")
@ -90,3 +95,6 @@ if k2.getLabel() != "second":
del k2
checkCount(0)
if (makeNullAutoPtr() != None):
raise RuntimeError("null failure")

View file

@ -8,8 +8,8 @@
%feature("autodoc","0") A::func0static; // names
%feature("autodoc","1") A::func1static; // names + types
// special typemap and its docs
%typemap(in) (int c, int d) "$1 = 0; $2 = 0;";
%typemap(doc,name="hello",type="Tuple") (int c, int d) "hello: int tuple[2]";
%typemap(in) (int c, int d) "$1 = 0; $2 = 0;"
%typemap(doc,name="hello",type="Tuple") (int c, int d) "hello: int tuple[2]"
%extend A {
static int staticextended(int i) { return i; }

View file

@ -0,0 +1,106 @@
#!/usr/bin/env ruby
require 'swig_assert'
require 'cpp11_rvalue_reference_move'
# Function containing rvalue reference parameter
Cpp11_rvalue_reference_move::Counter.reset_counts()
mo = Cpp11_rvalue_reference_move::MovableCopyable.new(222)
Cpp11_rvalue_reference_move::Counter.check_counts(1, 0, 0, 0, 0, 0)
Cpp11_rvalue_reference_move::MovableCopyable.movein(mo)
Cpp11_rvalue_reference_move::Counter.check_counts(1, 0, 0, 1, 0, 2)
exception_thrown = false
begin
Cpp11_rvalue_reference_move::MovableCopyable.is_nullptr(mo)
rescue ObjectPreviouslyDeleted
exception_thrown = true
end
if (!exception_thrown)
raise RuntimeError, "is_nullptr failed to throw"
end
mo = nil
Cpp11_rvalue_reference_move::Counter.check_counts(1, 0, 0, 1, 0, 2)
# Move constructor test
Cpp11_rvalue_reference_move::Counter.reset_counts()
mo = Cpp11_rvalue_reference_move::MovableCopyable.new(222)
Cpp11_rvalue_reference_move::Counter.check_counts(1, 0, 0, 0, 0, 0)
mo_moved = Cpp11_rvalue_reference_move::MovableCopyable.new(mo)
Cpp11_rvalue_reference_move::Counter.check_counts(1, 0, 0, 1, 0, 1)
exception_thrown = false
begin
Cpp11_rvalue_reference_move::MovableCopyable.is_nullptr(mo)
rescue ObjectPreviouslyDeleted
exception_thrown = true
end
if (!exception_thrown)
raise RuntimeError, "is_nullptr failed to throw"
end
mo = nil
Cpp11_rvalue_reference_move::Counter.check_counts(1, 0, 0, 1, 0, 1)
# mo_moved = nil
# Cpp11_rvalue_reference_move::Counter.check_counts(1, 0, 0, 1, 0, 2)
# Above not deleting the C++ object(node v12) - can't reliably control GC - use the movein function instead to delete
Cpp11_rvalue_reference_move::MovableCopyable.movein(mo_moved)
Cpp11_rvalue_reference_move::Counter.check_counts(1, 0, 0, 2, 0, 3)
# Move assignment operator test
Cpp11_rvalue_reference_move::Counter.reset_counts()
mo111 = Cpp11_rvalue_reference_move::MovableCopyable.new(111)
mo222 = Cpp11_rvalue_reference_move::MovableCopyable.new(222)
Cpp11_rvalue_reference_move::Counter.check_counts(2, 0, 0, 0, 0, 0)
mo111.MoveAssign(mo222)
Cpp11_rvalue_reference_move::Counter.check_counts(2, 0, 0, 0, 1, 1)
exception_thrown = false
begin
Cpp11_rvalue_reference_move::MovableCopyable.is_nullptr(mo222)
rescue ObjectPreviouslyDeleted
exception_thrown = true
end
if (!exception_thrown)
raise RuntimeError, "is_nullptr failed to throw"
end
mo222 = nil
Cpp11_rvalue_reference_move::Counter.check_counts(2, 0, 0, 0, 1, 1)
# mo111 = nil
# Cpp11_rvalue_reference_move::Counter.check_counts(2, 0, 0, 0, 1, 2)
# Above not deleting the C++ object(node v12) - can't reliably control GC - use the movein function instead to delete
Cpp11_rvalue_reference_move::MovableCopyable.movein(mo111)
Cpp11_rvalue_reference_move::Counter.check_counts(2, 0, 0, 1, 1, 3)
# null check
Cpp11_rvalue_reference_move::Counter.reset_counts()
exception_thrown = false
begin
Cpp11_rvalue_reference_move::MovableCopyable.movein(nil)
rescue ArgumentError => e
if (!e.to_s.include? "invalid null reference")
raise RuntimeError, "incorrect exception message: #{e.to_s}"
end
exception_thrown = true
end
if (!exception_thrown)
raise RuntimeError, "Should have thrown null error"
end
Cpp11_rvalue_reference_move::Counter.check_counts(0, 0, 0, 0, 0, 0)
# output
Cpp11_rvalue_reference_move::Counter.reset_counts()
mc = Cpp11_rvalue_reference_move::MovableCopyable.moveout(1234)
Cpp11_rvalue_reference_move::Counter.check_counts(2, 0, 0, 0, 1, 1)
Cpp11_rvalue_reference_move::MovableCopyable.check_numbers_match(mc, 1234)
exception_thrown = false
begin
Cpp11_rvalue_reference_move::MovableCopyable.movein(mc)
rescue RuntimeError => e
if (!e.to_s.include? "cannot release ownership as memory is not owned")
raise RuntimeError, "incorrect exception message: #{e.to_s}"
end
exception_thrown = true
end
if (!exception_thrown)
raise RuntimeError, "Should have thrown 'Cannot release ownership as memory is not owned' error"
end
Cpp11_rvalue_reference_move::Counter.check_counts(2, 0, 0, 0, 1, 1)

View file

@ -116,6 +116,11 @@ end
kini = nil
checkCount(0)
Cpp11_std_unique_ptr::takeKlassUniquePtr(nil)
Cpp11_std_unique_ptr::takeKlassUniquePtr(Cpp11_std_unique_ptr::make_null())
checkCount(0)
# unique_ptr as output
k1 = Cpp11_std_unique_ptr::makeKlassUniquePtr("first")
k2 = Cpp11_std_unique_ptr::makeKlassUniquePtr("second")
@ -131,3 +136,4 @@ gc_check(1)
k2 = nil
gc_check(0)
swig_assert_equal_simple(Cpp11_std_unique_ptr::makeNullUniquePtr(), nil)

View file

@ -116,6 +116,11 @@ end
kini = nil
checkCount(0)
Li_std_auto_ptr::takeKlassAutoPtr(nil)
Li_std_auto_ptr::takeKlassAutoPtr(Li_std_auto_ptr::make_null())
checkCount(0)
# auto_ptr as output
k1 = Li_std_auto_ptr::makeKlassAutoPtr("first")
k2 = Li_std_auto_ptr::makeKlassAutoPtr("second")
@ -131,3 +136,4 @@ gc_check(1)
k2 = nil
gc_check(0)
swig_assert_equal_simple(Li_std_auto_ptr::makeNullAutoPtr(), nil)

View file

@ -1,7 +1,7 @@
%module ruby_manual_proxy
%typemap(in, numinputs=0) SWIGTYPE ** ($*1_ltype temp) "$1 = &temp;";
%typemap(in, numinputs=0) SWIGTYPE ** ($*1_ltype temp) "$1 = &temp;"
%typemap(argout) SWIGTYPE **OUTPARAM {
$result = SWIG_Ruby_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));

View file

@ -0,0 +1,57 @@
; Function containing rvalue reference parameter
(Counter-reset-counts)
(define mo (new-MovableCopyable 222))
(Counter-check-counts 1 0 0 0 0 0)
(MovableCopyable-movein mo)
(Counter-check-counts 1 0 0 1 0 2)
(unless (MovableCopyable-is-nullptr mo)
(error "is_nullptr failed"))
(delete-MovableCopyable mo)
(Counter-check-counts 1 0 0 1 0 2)
; Move constructor test
(Counter-reset-counts)
(define mo (new-MovableCopyable 222))
(Counter-check-counts 1 0 0 0 0 0)
(define mo_moved (new-MovableCopyable mo))
(Counter-check-counts 1 0 0 1 0 1)
(unless (MovableCopyable-is-nullptr mo)
(error "is_nullptr failed"))
(delete-MovableCopyable mo)
(Counter-check-counts 1 0 0 1 0 1)
(delete-MovableCopyable mo_moved)
(Counter-check-counts 1 0 0 1 0 2)
; Move assignment operator test
(Counter-reset-counts)
(define mo111 (new-MovableCopyable 111))
(define mo222 (new-MovableCopyable 222))
(Counter-check-counts 2 0 0 0 0 0)
(MovableCopyable-MoveAssign mo111 mo222)
(Counter-check-counts 2 0 0 0 1 1)
(unless (MovableCopyable-is-nullptr mo222)
(error "is_nullptr failed"))
(delete-MovableCopyable mo222)
(Counter-check-counts 2 0 0 0 1 1)
(delete-MovableCopyable mo111)
(Counter-check-counts 2 0 0 0 1 2)
; null check
(Counter-reset-counts)
(expect-throw 'misc-error
(MovableCopyable-movein '()))
; TODO: check the exception message
(Counter-check-counts 0 0 0 0 0 0)
; output
(Counter-reset-counts)
(define mc (MovableCopyable-moveout 1234))
(Counter-check-counts 2 0 0 0 1 1)
(MovableCopyable-check-numbers-match mc 1234)
(expect-throw 'misc-error
(MovableCopyable-movein mc))
; TODO: check the exception message
(Counter-check-counts 2 0 0 0 1 1)
(exit 0)

View file

@ -58,6 +58,14 @@
(set! kini '()) (gc) ; Should not fail, even though already deleted
(checkCount 0)
(define null '())
(takeKlassUniquePtr null)
(define nullnil #nil)
(takeKlassUniquePtr nullnil)
(takeKlassUniquePtr (make-null))
(checkCount 0)
; unique_ptr as output
(define k1 (makeKlassUniquePtr "first"))
(define k2 (makeKlassUniquePtr "second"))
@ -72,4 +80,7 @@
(set! k2 '()) (gc)
(checkCount 0)
(unless (null? (makeNullUniquePtr))
(error "null failure"))
(exit 0)

View file

@ -58,6 +58,14 @@
(set! kini '()) (gc) ; Should not fail, even though already deleted
(checkCount 0)
(define null '())
(takeKlassAutoPtr null)
(define nullnil #nil)
(takeKlassAutoPtr nullnil)
(takeKlassAutoPtr (make-null))
(checkCount 0)
; auto_ptr as output
(define k1 (makeKlassAutoPtr "first"))
(define k2 (makeKlassAutoPtr "second"))
@ -72,4 +80,7 @@
(set! k2 '()) (gc)
(checkCount 0)
(unless (null? (makeNullAutoPtr))
(error "null failure"))
(exit 0)

View file

@ -0,0 +1,8 @@
(define null '())
(unless (funk null)
(error "funk(null) does not return true"))
(unless (null? (getnull))
(error "NULL pointer should be null"))
(exit 0)

View file

@ -0,0 +1,82 @@
if [ catch { load ./cpp11_rvalue_reference_move[info sharedlibextension] cpp11_rvalue_reference_move} err_msg ] {
puts stderr "Could not load shared object:\n$err_msg"
}
# Function containing rvalue reference parameter
Counter_reset_counts
MovableCopyable mo 222
Counter_check_counts 1 0 0 0 0 0
MovableCopyable_movein mo
Counter_check_counts 1 0 0 1 0 2
if {![MovableCopyable_is_nullptr mo]} {
error "is_nullptr failed to throw"
}
mo -delete
Counter_check_counts 1 0 0 1 0 2
# Move constructor test
Counter_reset_counts
MovableCopyable mo 222
Counter_check_counts 1 0 0 0 0 0
MovableCopyable mo_moved mo
Counter_check_counts 1 0 0 1 0 1
if {![MovableCopyable_is_nullptr mo]} {
error "is_nullptr failed to throw"
}
mo -delete
Counter_check_counts 1 0 0 1 0 1
mo_moved -delete
Counter_check_counts 1 0 0 1 0 2
# Move assignment operator test
Counter_reset_counts
MovableCopyable mo111 111
MovableCopyable mo222 222
Counter_check_counts 2 0 0 0 0 0
mo111 MoveAssign mo222
Counter_check_counts 2 0 0 0 1 1
if {![MovableCopyable_is_nullptr mo222]} {
error "is_nullptr failed to throw"
}
mo222 -delete
Counter_check_counts 2 0 0 0 1 1
mo111 -delete
Counter_check_counts 2 0 0 0 1 2
# null check
Counter_reset_counts
set exception_thrown 0
if [ catch {
MovableCopyable_movein "NULL"
} e ] {
if {[string first "invalid null reference" $e] == -1} {
error "incorrect exception message: $e"
}
set exception_thrown 1
}
if {!$exception_thrown} {
error "Should have thrown null error"
}
Counter_check_counts 0 0 0 0 0 0
# output
Counter_reset_counts
set mc [MovableCopyable_moveout 1234]
Counter_check_counts 2 0 0 0 1 1
MovableCopyable_check_numbers_match $mc 1234
set exception_thrown 0
if [ catch {
MovableCopyable_movein $mc
} e ] {
if {[string first "cannot release ownership as memory is not owned" $e] == -1} {
error "incorrect exception message: $e"
}
set exception_thrown 1
}
if {!$exception_thrown} {
error "Should have thrown 'Cannot release ownership as memory is not owned' error"
}
Counter_check_counts 2 0 0 0 1 1

View file

@ -126,6 +126,11 @@ if {![is_nullptr kini]} {
kini -delete # Should not fail, even though already deleted
checkCount 0
takeKlassUniquePtr "NULL"
takeKlassUniquePtr [make_null]
checkCount 0
# unique_ptr as output
set k1 [makeKlassUniquePtr "first"]
set k2 [makeKlassUniquePtr "second"]
@ -140,3 +145,7 @@ if {[$k2 getLabel] != "second"} {
$k2 -delete
checkCount 0
if {[makeNullUniquePtr] != "NULL"} {
error "null failure"
}

View file

@ -97,6 +97,11 @@ if {![is_nullptr kini]} {
kini -delete # Should not fail, even though already deleted
checkCount 0
takeKlassAutoPtr "NULL"
takeKlassAutoPtr [make_null]
checkCount 0
# auto_ptr as output
set k1 [makeKlassAutoPtr "first"]
set k2 [makeKlassAutoPtr "second"]
@ -111,3 +116,7 @@ if {[$k2 getLabel] != "second"} {
$k2 -delete
checkCount 0
if {[makeNullAutoPtr] != "NULL"} {
error "null failure"
}

View file

@ -11,9 +11,9 @@ template<class T, class U> class map {
};
%}
//%typemap(in) vector<int> "$target = new vector<int>();";
//%typemap(in) vector<unsigned int> "$target = new vector<unsigned int>();";
//%typemap(in) map<int,int> "$target = new map<int, int>();";
//%typemap(in) vector<int> "$target = new vector<int>();"
//%typemap(in) vector<unsigned int> "$target = new vector<unsigned int>();"
//%typemap(in) map<int,int> "$target = new map<int, int>();"
%inline %{
void foo(vector<int > v) {}

View file

@ -68,12 +68,12 @@
%clear int Space::nspace;
%clear int Space::Struct::smember;
%ignore Space::Struct::member;
%typemap(varin) int globul "TYPEMAP_VARIABLES_FAIL";
%typemap(varout, noblock=1, fragment=SWIG_From_frag(int)) int globul "if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, SWIG_From_int($result)))) return SWIG_ERROR;";
%typemap(varin) int Space::nspace "TYPEMAP_VARIABLES_FAIL";
%typemap(varout, noblock=1, fragment=SWIG_From_frag(int)) int Space::nspace "if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, SWIG_From_int($result)))) return SWIG_ERROR;";
%typemap(varin) int Space::Struct::smember "TYPEMAP_VARIABLES_FAIL";
%typemap(varout, noblock=1, fragment=SWIG_From_frag(int)) int Space::Struct::smember "if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, SWIG_From_int($result)))) return SWIG_ERROR;";
%typemap(varin) int globul "TYPEMAP_VARIABLES_FAIL"
%typemap(varout, noblock=1, fragment=SWIG_From_frag(int)) int globul "if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, SWIG_From_int($result)))) return SWIG_ERROR;"
%typemap(varin) int Space::nspace "TYPEMAP_VARIABLES_FAIL"
%typemap(varout, noblock=1, fragment=SWIG_From_frag(int)) int Space::nspace "if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, SWIG_From_int($result)))) return SWIG_ERROR;"
%typemap(varin) int Space::Struct::smember "TYPEMAP_VARIABLES_FAIL"
%typemap(varout, noblock=1, fragment=SWIG_From_frag(int)) int Space::Struct::smember "if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, SWIG_From_int($result)))) return SWIG_ERROR;"
#endif
%inline %{

View file

@ -5,62 +5,62 @@
/* Typespecs for basic types. */
%typemap(cin) void ":void";
%typemap(cin) void ":void"
%typemap(cin) char ":char";
%typemap(cin) char * ":string";
%typemap(cin) unsigned char ":unsigned-char";
%typemap(cin) signed char ":char";
%typemap(cin) char ":char"
%typemap(cin) char * ":string"
%typemap(cin) unsigned char ":unsigned-char"
%typemap(cin) signed char ":char"
%typemap(cin) short ":short";
%typemap(cin) signed short ":short";
%typemap(cin) unsigned short ":unsigned-short";
%typemap(cin) short ":short"
%typemap(cin) signed short ":short"
%typemap(cin) unsigned short ":unsigned-short"
%typemap(cin) int ":int";
%typemap(cin) signed int ":int";
%typemap(cin) unsigned int ":unsigned-int";
%typemap(cin) int ":int"
%typemap(cin) signed int ":int"
%typemap(cin) unsigned int ":unsigned-int"
%typemap(cin) long ":long";
%typemap(cin) signed long ":long";
%typemap(cin) unsigned long ":unsigned-long";
%typemap(cin) long ":long"
%typemap(cin) signed long ":long"
%typemap(cin) unsigned long ":unsigned-long"
%typemap(cin) long long ":long-long";
%typemap(cin) signed long long ":long-long";
%typemap(cin) unsigned long long ":unsigned-long-long";
%typemap(cin) long long ":long-long"
%typemap(cin) signed long long ":long-long"
%typemap(cin) unsigned long long ":unsigned-long-long"
%typemap(cin) float ":float";
%typemap(cin) double ":double";
%typemap(cin) SWIGTYPE ":pointer";
%typemap(cin) float ":float"
%typemap(cin) double ":double"
%typemap(cin) SWIGTYPE ":pointer"
%typemap(cout) void ":void";
%typemap(cout) void ":void"
%typemap(cout) char ":char";
%typemap(cout) char * ":string";
%typemap(cout) unsigned char ":unsigned-char";
%typemap(cout) signed char ":char";
%typemap(cout) char ":char"
%typemap(cout) char * ":string"
%typemap(cout) unsigned char ":unsigned-char"
%typemap(cout) signed char ":char"
%typemap(cout) short ":short";
%typemap(cout) signed short ":short";
%typemap(cout) unsigned short ":unsigned-short";
%typemap(cout) short ":short"
%typemap(cout) signed short ":short"
%typemap(cout) unsigned short ":unsigned-short"
%typemap(cout) int ":int";
%typemap(cout) signed int ":int";
%typemap(cout) unsigned int ":unsigned-int";
%typemap(cout) int ":int"
%typemap(cout) signed int ":int"
%typemap(cout) unsigned int ":unsigned-int"
%typemap(cout) long ":long";
%typemap(cout) signed long ":long";
%typemap(cout) unsigned long ":unsigned-long";
%typemap(cout) long ":long"
%typemap(cout) signed long ":long"
%typemap(cout) unsigned long ":unsigned-long"
%typemap(cout) long long ":long-long";
%typemap(cout) signed long long ":long-long";
%typemap(cout) unsigned long long ":unsigned-long-long";
%typemap(cout) long long ":long-long"
%typemap(cout) signed long long ":long-long"
%typemap(cout) unsigned long long ":unsigned-long-long"
%typemap(cout) float ":float";
%typemap(cout) double ":double";
%typemap(cout) SWIGTYPE ":pointer";
%typemap(cout) float ":float"
%typemap(cout) double ":double"
%typemap(cout) SWIGTYPE ":pointer"
%typemap(ctype) bool "int";
%typemap(ctype) bool "int"
%typemap(ctype) char, unsigned char, signed char,
short, signed short, unsigned short,
int, signed int, unsigned int,
@ -68,9 +68,9 @@
float, double, long double, char *, void *, void,
enum SWIGTYPE, SWIGTYPE *,
SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$1_ltype";
%typemap(ctype) SWIGTYPE "$&1_type";
%typemap(ctype) SWIGTYPE "$&1_type"
%typemap(in) bool "$1 = (bool)$input;";
%typemap(in) bool "$1 = (bool)$input;"
%typemap(in) char, unsigned char, signed char,
short, signed short, unsigned short,
int, signed int, unsigned int,
@ -78,10 +78,10 @@
float, double, long double, char *, void *, void,
enum SWIGTYPE, SWIGTYPE *,
SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$1 = $input;";
%typemap(in) SWIGTYPE "$1 = *$input;";
%typemap(in) SWIGTYPE "$1 = *$input;"
%typemap(out) void "";
%typemap(out) bool "$result = (int)$1;";
%typemap(out) void ""
%typemap(out) bool "$result = (int)$1;"
%typemap(out) char, unsigned char, signed char,
short, signed short, unsigned short,
int, signed int, unsigned int,
@ -114,22 +114,22 @@
SWIGTYPE[ANY], SWIGTYPE { $1 = 1; };
/* This maps C/C++ types to Lisp classes for overload dispatch */
%typemap(lisptype) bool "cl:boolean";
%typemap(lisptype) char "cl:character";
%typemap(lisptype) unsigned char "cl:integer";
%typemap(lisptype) signed char "cl:integer";
%typemap(lisptype) bool "cl:boolean"
%typemap(lisptype) char "cl:character"
%typemap(lisptype) unsigned char "cl:integer"
%typemap(lisptype) signed char "cl:integer"
%typemap(lispclass) bool "t";
%typemap(lispclass) char "cl:character";
%typemap(lispclass) bool "t"
%typemap(lispclass) char "cl:character"
%typemap(lispclass) unsigned char, signed char,
short, signed short, unsigned short,
int, signed int, unsigned int,
long, signed long, unsigned long,
enum SWIGTYPE "cl:integer";
/* CLOS methods can't be specialized on single-float or double-float */
%typemap(lispclass) float "cl:number";
%typemap(lispclass) double "cl:number";
%typemap(lispclass) char * "cl:string";
%typemap(lispclass) float "cl:number"
%typemap(lispclass) double "cl:number"
%typemap(lispclass) char * "cl:string"
/* Array reference typemaps */
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }

View file

@ -420,14 +420,15 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%}
%typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
if (!$1) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type type is null", 0);
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type is null", 0);
return $null;
} %}
%typemap(in, canthrow=1) SWIGTYPE && %{ $1 = ($1_ltype)$input;
%typemap(in, canthrow=1, fragment="<memory>") SWIGTYPE && (std::unique_ptr<$*1_ltype> rvrdeleter) %{ $1 = ($1_ltype)$input;
if (!$1) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type type is null", 0);
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type is null", 0);
return $null;
} %}
}
rvrdeleter.reset($1); %}
%typemap(out) SWIGTYPE * %{ $result = (void *)$1; %}
%typemap(out, fragment="SWIG_PackData") SWIGTYPE (CLASS::*) %{
char buf[128];
@ -613,7 +614,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
"$csinput"
%typemap(csin) char *, char *&, char[ANY], char[] "$csinput"
%typemap(csin) SWIGTYPE "$&csclassname.getCPtr($csinput)"
%typemap(csin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] "$csclassname.getCPtr($csinput)"
%typemap(csin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] "$csclassname.getCPtr($csinput)"
%typemap(csin) SWIGTYPE && "$csclassname.swigRelease($csinput)"
%typemap(csin) SWIGTYPE (CLASS::*) "$csclassname.getCMemberPtr($csinput)"
/* The csout typemap is used for converting function return types from the return type

View file

@ -16,7 +16,7 @@
%define SWIG_STD_ARRAY_INTERNAL(T, N)
%typemap(csinterfaces) std::array< T, N > "global::System.IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)>\n";
%typemap(csinterfaces) std::array< T, N > "global::System.IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)>\n"
%proxycode %{
public $csclassname(global::System.Collections.ICollection c) : this() {
if (c == null)

View file

@ -19,7 +19,7 @@
// MACRO for use within the std::list class body
%define SWIG_STD_LIST_MINIMUM_INTERNAL(CSINTERFACE, CTYPE...)
%typemap(csinterfaces) std::list< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable, global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n";
%typemap(csinterfaces) std::list< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable, global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n"
%apply void *VOID_INT_PTR { std::list< CTYPE >::iterator * };

View file

@ -26,7 +26,7 @@
/* K is the C++ key type, T is the C++ value type */
%define SWIG_STD_MAP_INTERNAL(K, T, C)
%typemap(csinterfaces) std::map< K, T, C > "global::System.IDisposable \n , global::System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n";
%typemap(csinterfaces) std::map< K, T, C > "global::System.IDisposable \n , global::System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n"
%proxycode %{
public $typemap(cstype, T) this[$typemap(cstype, K) key] {

View file

@ -28,7 +28,7 @@ namespace std {
template <class T>
class set {
%typemap(csinterfaces) std::set<T> "global::System.IDisposable, global::System.Collections.Generic.ISet<$typemap(cstype, T)>\n";
%typemap(csinterfaces) std::set<T> "global::System.IDisposable, global::System.Collections.Generic.ISet<$typemap(cstype, T)>\n"
%proxycode %{
void global::System.Collections.Generic.ICollection<$typemap(cstype, T)>.Add($typemap(cstype, T) item) {
((global::System.Collections.Generic.ISet<$typemap(cstype, T)>)this).Add(item);

View file

@ -19,7 +19,7 @@
// MACRO for use within the std::vector class body
%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CSINTERFACE, CONST_REFERENCE, CTYPE...)
%typemap(csinterfaces) std::vector< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable, global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n";
%typemap(csinterfaces) std::vector< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable, global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n"
%proxycode %{
public $csclassname(global::System.Collections.IEnumerable c) : this() {
if (c == null)

View file

@ -122,7 +122,7 @@
%typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
if (!$1) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type type is null");
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type is null");
return $null;
} %}
%typemap(out) SWIGTYPE & "$result = (void *)$1;"
@ -157,11 +157,12 @@
* Rvalue reference conversion typemaps.
*/
%typemap(in, canthrow=1) SWIGTYPE && %{ $1 = ($1_ltype)$input;
%typemap(in, canthrow=1, fragment="<memory>") SWIGTYPE && (std::unique_ptr<$*1_ltype> rvrdeleter) %{ $1 = ($1_ltype)$input;
if (!$1) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type type is null");
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type is null");
return $null;
} %}
}
rvrdeleter.reset($1); %}
%typemap(out) SWIGTYPE && "$result = (void *)$1;"
%typemap(directorin) SWIGTYPE &&
@ -182,7 +183,7 @@
%typemap(din,
nativepointer="cast(void*)$dinput"
) SWIGTYPE && "$dclassname.swigGetCPtr($dinput)"
) SWIGTYPE && "$dclassname.swigRelease($dinput)"
%typemap(dout, excode=SWIGEXCODE,
nativepointer="{\n auto ret = cast($dtype)$imcall;$excode\n return ret;\n}") SWIGTYPE && {
$dclassname ret = new $dclassname($imcall, $owner);$excode

View file

@ -388,8 +388,9 @@
%typemap(gotype) SWIGTYPE &&
%{$gotypename%}
%typemap(in) SWIGTYPE &&
%{ $1 = *($&1_ltype)&$input; %}
%typemap(in, fragment="<memory>") SWIGTYPE && (std::unique_ptr<$*1_ltype> rvrdeleter)
%{ $1 = *($&1_ltype)&$input;
rvrdeleter.reset($1); %}
%typemap(out) SWIGTYPE &&
%{ *($&1_ltype)&$result = $1; %}

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