Merge branch 'master' into directorargout_and_java_typemaps
This commit is contained in:
commit
3e449ea05f
68 changed files with 2861 additions and 2151 deletions
|
|
@ -20,7 +20,7 @@
|
|||
PyObject *o = PyTuple_GetItem(varargs,i);
|
||||
if (!PyString_Check(o)) {
|
||||
PyErr_SetString(PyExc_ValueError,"Expected a string");
|
||||
return NULL;
|
||||
SWIG_fail;
|
||||
}
|
||||
argv[i] = PyString_AsString(o);
|
||||
}
|
||||
|
|
@ -58,11 +58,11 @@
|
|||
&ffi_type_uint, types) == FFI_OK) {
|
||||
ffi_call(&cif, (void (*)()) execlp, &result, values);
|
||||
} else {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!");
|
||||
free(types);
|
||||
free(values);
|
||||
free(arg3);
|
||||
return NULL;
|
||||
PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!");
|
||||
SWIG_fail;
|
||||
}
|
||||
free(types);
|
||||
free(values);
|
||||
|
|
@ -107,9 +107,9 @@ int execlp(const char *path, const char *arg1, ...);
|
|||
argv[i].type = VT_POINTER;
|
||||
argv[i].val.pvalue = (void *) PyString_AsString(o);
|
||||
} else {
|
||||
PyErr_SetString(PyExc_ValueError,"Unsupported argument type");
|
||||
free(argv);
|
||||
return NULL;
|
||||
PyErr_SetString(PyExc_ValueError,"Unsupported argument type");
|
||||
SWIG_fail;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -157,11 +157,11 @@ int execlp(const char *path, const char *arg1, ...);
|
|||
&ffi_type_uint, types) == FFI_OK) {
|
||||
ffi_call(&cif, (void (*)()) printf, &result, values);
|
||||
} else {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!");
|
||||
free(types);
|
||||
free(values);
|
||||
free(args);
|
||||
return NULL;
|
||||
PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!");
|
||||
SWIG_fail;
|
||||
}
|
||||
free(types);
|
||||
free(values);
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ extern int gcdmain(int argc, char *argv[]);
|
|||
PyObject *utf8str;
|
||||
if (!PyUnicode_Check($input)) {
|
||||
PyErr_SetString(PyExc_ValueError,"Expected a string");
|
||||
return NULL;
|
||||
SWIG_fail;
|
||||
}
|
||||
utf8str = PyUnicode_AsUTF8String($input);
|
||||
PyBytes_AsStringAndSize(utf8str, &cstr, &len);
|
||||
|
|
@ -79,7 +79,7 @@ extern int gcdmain(int argc, char *argv[]);
|
|||
%#else
|
||||
if (!PyString_Check($input)) {
|
||||
PyErr_SetString(PyExc_ValueError,"Expected a string");
|
||||
return NULL;
|
||||
SWIG_fail;
|
||||
}
|
||||
$1 = PyString_AsString($input);
|
||||
$2 = (int)PyString_Size($input);
|
||||
|
|
|
|||
|
|
@ -203,6 +203,7 @@ CPP_TEST_CASES += \
|
|||
director_thread \
|
||||
director_unroll \
|
||||
director_using \
|
||||
director_void \
|
||||
director_wombat \
|
||||
disown \
|
||||
dynamic_cast \
|
||||
|
|
@ -259,7 +260,6 @@ CPP_TEST_CASES += \
|
|||
langobj \
|
||||
li_attribute \
|
||||
li_attribute_template \
|
||||
li_boost_array \
|
||||
li_boost_shared_ptr \
|
||||
li_boost_shared_ptr_bits \
|
||||
li_boost_shared_ptr_template \
|
||||
|
|
@ -487,6 +487,7 @@ CPP_TEST_CASES += \
|
|||
typemap_array_qualifiers \
|
||||
typemap_delete \
|
||||
typemap_directorout \
|
||||
typemap_documentation \
|
||||
typemap_global_scope \
|
||||
typemap_manyargs \
|
||||
typemap_namespace \
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
%module cpp11_li_std_array
|
||||
|
||||
#if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGJAVA)
|
||||
#if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGJAVA) || defined(SWIGCSHARP)
|
||||
|
||||
%{
|
||||
#include <array>
|
||||
|
|
|
|||
|
|
@ -22,5 +22,28 @@ public:
|
|||
%}
|
||||
|
||||
%{
|
||||
int StaticMemberTest::static_int;
|
||||
int StaticMemberTest::static_int = 99;
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
struct StaticBase {
|
||||
static int statty;
|
||||
virtual ~StaticBase() {}
|
||||
};
|
||||
struct StaticDerived : StaticBase {
|
||||
static int statty;
|
||||
};
|
||||
%}
|
||||
|
||||
%{
|
||||
int StaticBase::statty = 11;
|
||||
int StaticDerived::statty = 111;
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
#ifdef SWIGPYTHON_BUILTIN
|
||||
bool is_python_builtin() { return true; }
|
||||
#else
|
||||
bool is_python_builtin() { return false; }
|
||||
#endif
|
||||
%}
|
||||
|
|
|
|||
82
Examples/test-suite/csharp/cpp11_li_std_array_runme.cs
Normal file
82
Examples/test-suite/csharp/cpp11_li_std_array_runme.cs
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
// This test tests all the methods in the C# collection wrapper
|
||||
using System;
|
||||
using cpp11_li_std_arrayNamespace;
|
||||
|
||||
public class cpp11_li_std_array_runme
|
||||
{
|
||||
private static ArrayInt6 ToArray6(int[] a)
|
||||
{
|
||||
if (a.Length != 6)
|
||||
throw new Exception("a is incorrect size");
|
||||
return new ArrayInt6(a);
|
||||
}
|
||||
|
||||
private static void compareContainers(ArrayInt6 actual, int[] expected)
|
||||
{
|
||||
if (actual.Count != expected.Length)
|
||||
throw new Exception("Sizes are different: " + actual.Count + " " + expected.Length);
|
||||
for (int i=0; i<actual.Count; ++i)
|
||||
{
|
||||
int actualValue = actual[i];
|
||||
int expectedValue = expected[i];
|
||||
if (actualValue != expectedValue)
|
||||
throw new Exception("Value is wrong for element " + i + ". Expected " + expectedValue + " got: " + actualValue);
|
||||
}
|
||||
if (actual.IsEmpty)
|
||||
throw new Exception("ai should not be empty");
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
ArrayInt6 ai = new ArrayInt6();
|
||||
compareContainers(ai, new int[] { 0, 0, 0, 0, 0, 0 });
|
||||
|
||||
int[] vals = { 10, 20, 30, 40, 50, 60 };
|
||||
for (int i = 0; i < ai.Count; ++i)
|
||||
ai[i] = vals[i];
|
||||
compareContainers(ai, vals);
|
||||
|
||||
// Check return
|
||||
compareContainers(cpp11_li_std_array.arrayOutVal(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_li_std_array.arrayOutConstRef(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_li_std_array.arrayOutRef(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_li_std_array.arrayOutPtr(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
|
||||
// Check passing arguments
|
||||
ai = cpp11_li_std_array.arrayInVal(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
ai = cpp11_li_std_array.arrayInConstRef(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
ai = new ArrayInt6(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
cpp11_li_std_array.arrayInRef(ai);
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
ai = new ArrayInt6(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
cpp11_li_std_array.arrayInPtr(ai);
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
// fill
|
||||
ai.Fill(111);
|
||||
compareContainers(ai, new int[] { 111, 111, 111, 111, 111, 111 });
|
||||
|
||||
// out of range errors
|
||||
try
|
||||
{
|
||||
ai[ai.Count] = 0;
|
||||
throw new Exception("Out of range exception not caught");
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
}
|
||||
try
|
||||
{
|
||||
ai[-1] = 0;
|
||||
throw new Exception("Out of range exception not caught");
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
83
Examples/test-suite/csharp/director_void_runme.cs
Normal file
83
Examples/test-suite/csharp/director_void_runme.cs
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using director_voidNamespace;
|
||||
|
||||
public class runme
|
||||
{
|
||||
private static void WaitForGC()
|
||||
{
|
||||
System.GC.Collect();
|
||||
System.GC.WaitForPendingFinalizers();
|
||||
System.Threading.Thread.Sleep(10);
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
runme r = new runme();
|
||||
r.run();
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
Caller caller = new Caller();
|
||||
{
|
||||
DirectorVoidPointer dvp = new DirectorVoidPointer(5);
|
||||
int x = caller.callVirtualIn(dvp, 6);
|
||||
if (x != 106)
|
||||
throw new Exception("Fail1 should be 106, got " + x);
|
||||
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
|
||||
x = Caller.VoidToInt(ptr);
|
||||
if (x != 106)
|
||||
throw new Exception("Fail2 should be 106, got " + x);
|
||||
x = Caller.VoidToInt(dvp.voidPtrOut());
|
||||
if (x != 106)
|
||||
throw new Exception("Fail3 should be 106, got " + x);
|
||||
}
|
||||
|
||||
{
|
||||
DirectorVoidPointer dvp = new director_void_VoidPointer(5);
|
||||
int x = caller.callVirtualIn(dvp, 6);
|
||||
if (x != 12)
|
||||
throw new Exception("Fail1 should be 12, got " + x);
|
||||
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
|
||||
x = Caller.VoidToInt(ptr);
|
||||
if (x != 25)
|
||||
throw new Exception("Fail2 should be 25, got " + x);
|
||||
x = Caller.VoidToInt(dvp.voidPtrOut());
|
||||
if (x != 1234)
|
||||
throw new Exception("Fail3 should be 1234, got " + x);
|
||||
}
|
||||
|
||||
{
|
||||
DirectorVoidPointer dvp = new DirectorVoidPointer(10);
|
||||
int x = caller.callVirtualOut(dvp);
|
||||
if (x != 10)
|
||||
throw new Exception("Bad1 should be 10, got " + x);
|
||||
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
|
||||
x = dvp.nonVirtualVoidPtrIn(ptr);
|
||||
if (x != 110)
|
||||
throw new Exception("Bad2 should be 110, got " + x);
|
||||
}
|
||||
{
|
||||
DirectorVoidPointer dvp = new director_void_VoidPointer(10);
|
||||
int x = caller.callVirtualOut(dvp);
|
||||
if (x != 1234)
|
||||
throw new Exception("Bad3 should be 1234, got " + x);
|
||||
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
|
||||
x = dvp.nonVirtualVoidPtrIn(ptr);
|
||||
if (x != 1334)
|
||||
throw new Exception("Bad4 should be 1334, got " + x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class director_void_VoidPointer : DirectorVoidPointer {
|
||||
public director_void_VoidPointer(int num) : base(num*num) {
|
||||
}
|
||||
public override int voidPtrIn(global::System.IntPtr p) {
|
||||
return Caller.VoidToInt(p) * 2;
|
||||
}
|
||||
public override global::System.IntPtr voidPtrOut() {
|
||||
setNewValue(1234);
|
||||
return nonVirtualVoidPtrOut();
|
||||
}
|
||||
}
|
||||
|
|
@ -405,6 +405,10 @@ public class runme {
|
|||
if (enum_thorough_typesafe.repeatTest(repeat.llast).swigValue != 3) throw new Exception("repeatTest 5 failed");
|
||||
if (enum_thorough_typesafe.repeatTest(repeat.end).swigValue != 3) throw new Exception("repeatTest 6 failed");
|
||||
}
|
||||
{
|
||||
if (enum_thorough_typesafe.enumWithMacroTest(enumWithMacro.ABCD).swigValue != (('A' << 24) | ('B' << 16) | ('C' << 8) | 'D')) throw new Exception("enumWithMacroTest 1 failed");
|
||||
if (enum_thorough_typesafe.enumWithMacroTest(enumWithMacro.ABCD2).swigValue != enum_thorough_typesafe.enumWithMacroTest(enumWithMacro.ABCD).swigValue) throw new Exception("enumWithMacroTest 2 failed");
|
||||
}
|
||||
// different types
|
||||
{
|
||||
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typeint).swigValue != 10) throw new Exception("differentTypes 1 failed");
|
||||
|
|
@ -413,6 +417,8 @@ public class runme {
|
|||
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typeboolfalse).swigValue != 0) throw new Exception("differentTypes 4 failed");
|
||||
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typechar).swigValue != (int)'C') throw new Exception("differentTypes 5 failed");
|
||||
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typedefaultint).swigValue != (int)'D') throw new Exception("differentTypes 6 failed");
|
||||
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typecharcompound).swigValue != (int)'A' + 1) throw new Exception("differentTypes 7 failed");
|
||||
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typecharcompound2).swigValue != (int)'B' << 2) throw new Exception("differentTypes 8 failed");
|
||||
|
||||
int global_enum = enum_thorough_typesafe.global_typeint;
|
||||
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 10) throw new Exception("global differentTypes 1 failed");
|
||||
|
|
@ -426,6 +432,10 @@ public class runme {
|
|||
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 'C') throw new Exception("global differentTypes 5 failed");
|
||||
global_enum = enum_thorough_typesafe.global_typedefaultint;
|
||||
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 'D') throw new Exception("global differentTypes 6 failed");
|
||||
global_enum = enum_thorough_typesafe.global_typecharcompound;
|
||||
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != (int)'A' + 1) throw new Exception("global differentTypes 7 failed");
|
||||
global_enum = enum_thorough_typesafe.global_typecharcompound2;
|
||||
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != (int)'B' << 2) throw new Exception("global differentTypes 8 failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
47
Examples/test-suite/director_void.i
Normal file
47
Examples/test-suite/director_void.i
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
%module(directors="1") director_void
|
||||
|
||||
%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) voidPtrOut;
|
||||
|
||||
%feature("director") DirectorVoidPointer;
|
||||
|
||||
#if defined(SWIGCSHARP)
|
||||
%apply void *VOID_INT_PTR { void * }
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
class DirectorVoidPointer {
|
||||
int *ptr;
|
||||
public:
|
||||
DirectorVoidPointer(int val) : ptr(new int(val)) {}
|
||||
virtual ~DirectorVoidPointer() { delete ptr; }
|
||||
|
||||
virtual void * voidPtrOut() { return ptr; }
|
||||
virtual int voidPtrIn(void *p) {
|
||||
return nonVirtualVoidPtrIn(p);
|
||||
}
|
||||
|
||||
void setNewValue(int val) {
|
||||
delete ptr;
|
||||
ptr = new int(val);
|
||||
}
|
||||
void *nonVirtualVoidPtrOut() { return ptr; }
|
||||
int nonVirtualVoidPtrIn(void *p) {
|
||||
int val = *(int *)p;
|
||||
setNewValue(val + 100);
|
||||
return *ptr;
|
||||
}
|
||||
};
|
||||
|
||||
struct Caller {
|
||||
int callVirtualIn(DirectorVoidPointer *d, int num) {
|
||||
return d->voidPtrIn(&num);
|
||||
}
|
||||
int callVirtualOut(DirectorVoidPointer *d) {
|
||||
return *(int *)d->voidPtrOut();
|
||||
}
|
||||
static int VoidToInt(void *p) {
|
||||
return *(int *)p;
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
@ -569,6 +569,17 @@ repeat repeatTest(repeat e) { return e; }
|
|||
}
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
namespace EnumWithMacro {
|
||||
#define PACK(C1,C2,C3,C4) ((C1<<24)|(C2<<16)|(C3<<8)|C4)
|
||||
typedef enum {
|
||||
ABCD = PACK('A','B','C','D'),
|
||||
ABCD2 = ABCD
|
||||
} enumWithMacro;
|
||||
enumWithMacro enumWithMacroTest(enumWithMacro e) { return e; }
|
||||
}
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
namespace DifferentSpace {
|
||||
enum DifferentTypes {
|
||||
|
|
@ -577,7 +588,9 @@ enum DifferentTypes {
|
|||
typebooltrue = true,
|
||||
typebooltwo,
|
||||
typechar = 'C',
|
||||
typedefaultint
|
||||
typedefaultint,
|
||||
typecharcompound='A'+1,
|
||||
typecharcompound2='B' << 2
|
||||
};
|
||||
DifferentTypes differentTypesTest(DifferentTypes n) { return n; }
|
||||
|
||||
|
|
@ -587,7 +600,9 @@ enum {
|
|||
global_typebooltrue = true,
|
||||
global_typebooltwo,
|
||||
global_typechar = 'C',
|
||||
global_typedefaultint
|
||||
global_typedefaultint,
|
||||
global_typecharcompound='A'+1,
|
||||
global_typecharcompound2='B' << 2
|
||||
};
|
||||
int globalDifferentTypesTest(int n) { return n; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
%module exception_classname
|
||||
|
||||
%warnfilter(SWIGWARN_RUBY_WRONG_NAME);
|
||||
#ifdef SWIGPHP
|
||||
#if defined(SWIGPHP) || defined(SWIGD)
|
||||
%rename(ExceptionClass) Exception;
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class smart_pointer_ignore_runme {
|
|||
|
||||
public static void main(String argv[]) {
|
||||
DerivedPtr d = smart_pointer_ignore.makeDerived();
|
||||
d.base();
|
||||
d.derived();
|
||||
d.baseMethod();
|
||||
d.derivedMethod();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,87 +0,0 @@
|
|||
%module li_boost_array
|
||||
|
||||
#if defined(SWIGPYTHON) || defined(SWIGRUBY)
|
||||
|
||||
// Hack to use the std::array support for boost::array.
|
||||
// Is limited as it currently exposes some 'using' bugs in SWIG though.
|
||||
// For example, the type system fails to see that pointers to std::array
|
||||
// and pointers to boost::array are the same.
|
||||
|
||||
%{
|
||||
#if __cplusplus >= 201103 || (defined(_MSC_VER) && _MSC_VER >= 1900)
|
||||
// Use C++11 array as this is unfortunately sometimes included by <algorithm>
|
||||
#include <array>
|
||||
namespace boost {
|
||||
using std::array;
|
||||
}
|
||||
#else
|
||||
#include <boost/array.hpp>
|
||||
namespace std {
|
||||
using boost::array;
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
namespace boost {
|
||||
using std::array;
|
||||
}
|
||||
|
||||
%ignore std::array::fill; // Some older versions of boost don't have this function
|
||||
|
||||
%include <std_array.i>
|
||||
|
||||
%template(ArrayInt6) std::array<int, 6>;
|
||||
|
||||
%inline %{
|
||||
boost::array<int, 6> arrayOutVal() {
|
||||
const signed char carray[] = { -2, -1, 0, 0, 1, 2 };
|
||||
boost::array<int, 6> myarray;
|
||||
for (size_t i=0; i<6; ++i) {
|
||||
myarray[i] = carray[i];
|
||||
}
|
||||
return myarray;
|
||||
}
|
||||
|
||||
boost::array<int, 6> & arrayOutRef() {
|
||||
static boost::array<int, 6> a = { -2, -1, 0, 0, 1, 2 };
|
||||
return a;
|
||||
}
|
||||
|
||||
const boost::array<int, 6> & arrayOutConstRef() {
|
||||
static boost::array<int, 6> a = { -2, -1, 0, 0, 1, 2 };
|
||||
return a;
|
||||
}
|
||||
|
||||
boost::array<int, 6> * arrayOutPtr() {
|
||||
static boost::array<int, 6> a = { -2, -1, 0, 0, 1, 2 };
|
||||
return &a;
|
||||
}
|
||||
|
||||
boost::array<int, 6> arrayInVal(boost::array<int, 6> myarray) {
|
||||
for (boost::array<int, 6>::iterator it = myarray.begin(); it!=myarray.end(); ++it) {
|
||||
*it *= 10;
|
||||
}
|
||||
return myarray;
|
||||
}
|
||||
|
||||
const boost::array<int, 6> & arrayInConstRef(const boost::array<int, 6> & myarray) {
|
||||
static boost::array<int, 6> a = myarray;
|
||||
for (boost::array<int, 6>::iterator it = a.begin(); it!=a.end(); ++it) {
|
||||
*it *= 10;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
void arrayInRef(boost::array<int, 6> & myarray) {
|
||||
for (boost::array<int, 6>::iterator it = myarray.begin(); it!=myarray.end(); ++it) {
|
||||
*it *= 10;
|
||||
}
|
||||
}
|
||||
|
||||
void arrayInPtr(boost::array<int, 6> * myarray) {
|
||||
for (boost::array<int, 6>::iterator it = myarray->begin(); it!=myarray->end(); ++it) {
|
||||
*it *= 10;
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
||||
#endif
|
||||
|
|
@ -50,7 +50,7 @@ namespace test {
|
|||
PyComplex_ImagAsDouble($input));
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError,"Expected test_complex.\n");
|
||||
return NULL;
|
||||
SWIG_fail;
|
||||
}
|
||||
}
|
||||
%typemap(freearg) test::test_complex * {
|
||||
|
|
@ -242,7 +242,7 @@ namespace Split {
|
|||
$1 = PyInt_AsLong($input);
|
||||
if ($1 < 0) {
|
||||
PyErr_SetString(PyExc_ValueError,"domain error\n");
|
||||
return NULL;
|
||||
SWIG_fail;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ require "tests.php";
|
|||
require "cpp_static.php";
|
||||
|
||||
// New functions
|
||||
check::functions(array(staticfunctiontest_static_func,staticfunctiontest_static_func_2,staticfunctiontest_static_func_3));
|
||||
check::functions(array(staticfunctiontest_static_func,staticfunctiontest_static_func_2,staticfunctiontest_static_func_3,is_python_builtin));
|
||||
// New classes
|
||||
check::classes(array(StaticMemberTest,StaticFunctionTest));
|
||||
check::classes(array(StaticMemberTest,StaticFunctionTest,cpp_static,StaticBase,StaticDerived));
|
||||
// New vars
|
||||
check::globals(array(staticmembertest_static_int));
|
||||
check::globals(array(staticmembertest_static_int,staticbase_statty,staticderived_statty));
|
||||
|
||||
check::done();
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
// Expressions - runtime tests check the type for any necessary type promotions of the expressions
|
||||
|
||||
#define INT_AND_BOOL 0xFF & true
|
||||
//#define INT_AND_CHAR 0xFF & 'A' /* FIXME compile error */
|
||||
#define INT_AND_CHAR 0xFF & 'A'
|
||||
#define INT_AND_INT 0xFF & 2
|
||||
#define INT_AND_UINT 0xFF & 2u
|
||||
#define INT_AND_LONG 0xFF & 2l
|
||||
|
|
@ -60,8 +60,7 @@
|
|||
#define INT_AND_ULLONG 0xFF & 2ull
|
||||
|
||||
#define BOOL_AND_BOOL true & true // Note integral promotion to type int
|
||||
//#define CHAR_AND_CHAR 'A' & 'B' // Note integral promotion to type int
|
||||
/* FIXME ABOVE */
|
||||
#define CHAR_AND_CHAR 'A' & 'B' // Note integral promotion to type int
|
||||
|
||||
|
||||
#define EXPR_MULTIPLY 0xFF * 2
|
||||
|
|
@ -88,6 +87,9 @@
|
|||
#define EXPR_LOR 0xFF || 1
|
||||
#define EXPR_CONDITIONAL true ? 2 : 2.2
|
||||
|
||||
#define EXPR_CHAR_COMPOUND_ADD 'A' + 12
|
||||
#define EXPR_CHAR_COMPOUND_LSHIFT 'B' << 6
|
||||
#define H_SUPPRESS_SCALING_MAGIC (('s'<<24) | ('u'<<16) | ('p'<<8) | 'p')
|
||||
|
||||
/// constant assignment in enum
|
||||
#if defined(SWIGCSHARP)
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ CPP_TEST_CASES += \
|
|||
python_docstring \
|
||||
python_nondynamic \
|
||||
python_overload_simple_cast \
|
||||
python_pickle \
|
||||
python_pythoncode \
|
||||
python_richcompare \
|
||||
python_strict_unicode \
|
||||
|
|
|
|||
|
|
@ -13,6 +13,31 @@ else:
|
|||
StaticFunctionTest().static_func()
|
||||
StaticFunctionTest().static_func_2(1)
|
||||
StaticFunctionTest().static_func_3(1, 2)
|
||||
StaticMemberTest.static_int = 10
|
||||
if not StaticMemberTest.static_int == 10:
|
||||
raise RuntimeError("static_int not 10")
|
||||
|
||||
if is_python_builtin():
|
||||
if not StaticMemberTest.static_int == 99: raise RuntimeError("static_int not 99")
|
||||
StaticMemberTest.static_int = 10
|
||||
if not StaticMemberTest.static_int == 10: raise RuntimeError("static_int not 10")
|
||||
|
||||
if not StaticBase.statty == 11: raise RuntimeError("statty not 11")
|
||||
if not StaticDerived.statty == 111: raise RuntimeError("statty not 111")
|
||||
StaticBase.statty = 22
|
||||
StaticDerived.statty = 222
|
||||
if not StaticBase.statty == 22: raise RuntimeError("statty not 22")
|
||||
if not StaticDerived.statty == 222: raise RuntimeError("statty not 222")
|
||||
|
||||
# Restore
|
||||
StaticMemberTest.static_int = 99
|
||||
StaticBase.statty = 11
|
||||
StaticDerived.statty = 111
|
||||
|
||||
if not cvar.StaticMemberTest_static_int == 99: raise RuntimeError("cvar static_int not 99")
|
||||
cvar.StaticMemberTest_static_int = 10
|
||||
if not cvar.StaticMemberTest_static_int == 10: raise RuntimeError("cvar static_int not 10")
|
||||
|
||||
if not cvar.StaticBase_statty == 11: raise RuntimeError("cvar statty not 11")
|
||||
if not cvar.StaticDerived_statty == 111: raise RuntimeError("cvar statty not 111")
|
||||
cvar.StaticBase_statty = 22
|
||||
cvar.StaticDerived_statty = 222
|
||||
if not cvar.StaticBase_statty == 22: raise RuntimeError("cvar statty not 22")
|
||||
if not cvar.StaticDerived_statty == 222: raise RuntimeError("cvar statty not 222")
|
||||
|
|
|
|||
|
|
@ -1,55 +0,0 @@
|
|||
from li_boost_array import *
|
||||
import sys
|
||||
|
||||
|
||||
def failed(a, b, msg):
|
||||
raise RuntimeError, msg + " " + str(list(a)) + " " + str(list(b))
|
||||
|
||||
|
||||
def compare_sequences(a, b):
|
||||
if len(a) != len(b):
|
||||
failed(a, b, "different sizes")
|
||||
for i in range(len(a)):
|
||||
if a[i] != b[i]:
|
||||
failed(a, b, "elements are different")
|
||||
|
||||
def compare_containers(pythonlist, swigarray):
|
||||
compare_sequences(pythonlist, swigarray)
|
||||
|
||||
ps = [0, 1, 2, 3, 4, 5]
|
||||
|
||||
ai = ArrayInt6(ps)
|
||||
|
||||
compare_containers(ps, ai)
|
||||
|
||||
# Modify content
|
||||
for i in range(len(ps)):
|
||||
ps[i] = (ps[i] + 1) * 10
|
||||
ai[i] = (ai[i] + 1) * 10
|
||||
compare_containers(ps, ai)
|
||||
|
||||
# Empty
|
||||
ai = ArrayInt6()
|
||||
compare_containers([0, 0, 0, 0, 0, 0], ai)
|
||||
|
||||
# Check return
|
||||
compare_containers(arrayOutVal(), [-2, -1, 0, 0, 1, 2])
|
||||
compare_containers(arrayOutConstRef(), [-2, -1, 0, 0, 1, 2])
|
||||
#compare_containers(arrayOutRef(), [-2, -1, 0, 0, 1, 2])
|
||||
#compare_containers(arrayOutPtr(), [-2, -1, 0, 0, 1, 2])
|
||||
|
||||
# Check passing arguments
|
||||
ai = arrayInVal([9, 8, 7, 6, 5, 4])
|
||||
compare_containers(ai, [90, 80, 70, 60, 50, 40])
|
||||
|
||||
ai = arrayInConstRef([9, 8, 7, 6, 5, 4])
|
||||
compare_containers(ai, [90, 80, 70, 60, 50, 40])
|
||||
|
||||
#ai = ArrayInt6([9, 8, 7, 6, 5, 4])
|
||||
#arrayInRef(ai)
|
||||
#compare_containers(ai, [90, 80, 70, 60, 50, 40])
|
||||
|
||||
#ai = ArrayInt6([9, 8, 7, 6, 5, 4])
|
||||
#arrayInPtr(ai)
|
||||
#compare_containers(ai, [90, 80, 70, 60, 50, 40])
|
||||
|
||||
35
Examples/test-suite/python/python_pickle_runme.py
Normal file
35
Examples/test-suite/python/python_pickle_runme.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import python_pickle
|
||||
|
||||
import pickle
|
||||
import sys
|
||||
|
||||
def is_new_style_class(cls):
|
||||
return hasattr(cls, "__class__")
|
||||
|
||||
def check(p):
|
||||
msg = p.msg
|
||||
if msg != "hi there":
|
||||
raise RuntimeError("Bad, got: " + msg)
|
||||
|
||||
if not is_new_style_class(python_pickle.PickleMe):
|
||||
sys.exit(0)
|
||||
|
||||
python_pickle.cvar.debug = False
|
||||
|
||||
p = python_pickle.PickleMe("hi there")
|
||||
check(p)
|
||||
|
||||
r = p.__reduce__()
|
||||
if python_pickle.cvar.debug:
|
||||
print "__reduce__ returned:", r
|
||||
pickle_string = pickle.dumps(p)
|
||||
newp = pickle.loads(pickle_string)
|
||||
check(newp)
|
||||
|
||||
# Not yet working... some crash and others are not producing a sensible "can't be pickled" error
|
||||
#nfp = python_pickle.NotForPickling("no no")
|
||||
#print nfp.__reduce__()
|
||||
#pickle_string = pickle.dumps(nfp)
|
||||
#print pickle_string
|
||||
#newp = pickle.loads(pickle_string)
|
||||
#print newp.msg
|
||||
20
Examples/test-suite/python/typemap_documentation_runme.py
Normal file
20
Examples/test-suite/python/typemap_documentation_runme.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import typemap_documentation
|
||||
|
||||
f = typemap_documentation.Foo()
|
||||
f.x = 55
|
||||
b = typemap_documentation.Bar()
|
||||
b.y = 44
|
||||
|
||||
if 55 != typemap_documentation.GrabVal(f):
|
||||
raise RuntimeError("bad value")
|
||||
|
||||
try:
|
||||
typemap_documentation.GrabVal(b)
|
||||
raise RuntimeError("unexpected exception")
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
if 55 != typemap_documentation.GrabValFooBar(f):
|
||||
raise RuntimeError("bad f value")
|
||||
if 44 != typemap_documentation.GrabValFooBar(b):
|
||||
raise RuntimeError("bad b value")
|
||||
|
|
@ -2,6 +2,12 @@
|
|||
|
||||
%module python_builtin
|
||||
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
#ifdef SWIGPYTHON_BUILTIN
|
||||
bool is_python_builtin() { return true; }
|
||||
|
|
@ -156,12 +162,12 @@ void Dealloc2Destroyer(PyObject *v) {
|
|||
%feature("python:slot", "sq_length", functype="lenfunc") SimpleArray::__len__;
|
||||
%inline %{
|
||||
class SimpleArray {
|
||||
size_t size;
|
||||
Py_ssize_t size;
|
||||
int numbers[5];
|
||||
public:
|
||||
SimpleArray(size_t size) : size(size) {
|
||||
for (size_t x = 0; x<size; ++x)
|
||||
numbers[x] = x*10;
|
||||
SimpleArray(Py_ssize_t size) : size(size) {
|
||||
for (Py_ssize_t x = 0; x<size; ++x)
|
||||
numbers[x] = (int)x*10;
|
||||
}
|
||||
|
||||
Py_ssize_t __len__() {
|
||||
|
|
@ -192,7 +198,7 @@ void Dealloc2Destroyer(PyObject *v) {
|
|||
if (ii > jj)
|
||||
throw std::invalid_argument("getitem i should not be larger than j");
|
||||
SimpleArray n(jj-ii);
|
||||
for (size_t x = 0; x<size; ++x)
|
||||
for (Py_ssize_t x = 0; x<size; ++x)
|
||||
n.numbers[x] = numbers[x+ii];
|
||||
return n;
|
||||
}
|
||||
|
|
|
|||
56
Examples/test-suite/python_pickle.i
Normal file
56
Examples/test-suite/python_pickle.i
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
%module python_pickle
|
||||
|
||||
|
||||
%include <std_string.i>
|
||||
|
||||
%extend PickleMe {
|
||||
#if 0
|
||||
// Note: %pythoncode can't be used with -builtin
|
||||
%pythoncode %{
|
||||
def __reduce__(self):
|
||||
print "In Python __reduce__"
|
||||
return (type(self), (self.msg, ))
|
||||
%}
|
||||
#else
|
||||
// Equivalent to Python code above
|
||||
PyObject *__reduce__() {
|
||||
if (debug)
|
||||
std::cout << "In C++ __reduce__" << std::endl;
|
||||
PyObject *args = PyTuple_New(1);
|
||||
PyTuple_SetItem(args, 0, SWIG_From_std_string(self->msg));
|
||||
|
||||
swig_type_info *ty = SWIGTYPE_p_PickleMe;
|
||||
SwigPyClientData *data = (SwigPyClientData *)ty->clientdata;
|
||||
#if defined(SWIGPYTHON_BUILTIN)
|
||||
PyObject *callable = (PyObject *)data->pytype;
|
||||
#else
|
||||
PyObject *callable = data->klass;
|
||||
#endif
|
||||
Py_INCREF(callable);
|
||||
|
||||
PyObject *ret = PyTuple_New(2);
|
||||
PyTuple_SetItem(ret, 0, callable);
|
||||
PyTuple_SetItem(ret, 1, args);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
%inline %{
|
||||
#include <iostream>
|
||||
|
||||
bool debug = false;
|
||||
|
||||
struct PickleMe {
|
||||
std::string msg;
|
||||
PickleMe(const std::string& msg) : msg(msg) {
|
||||
if (debug)
|
||||
std::cout << "In C++ constructor " << " [" << msg << "]" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
struct NotForPickling {
|
||||
std::string msg;
|
||||
NotForPickling(const std::string& msg) : msg(msg) {}
|
||||
};
|
||||
%}
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
argc = PyTuple_Size(varargs);
|
||||
if (argc > 10) {
|
||||
PyErr_SetString(PyExc_ValueError, "Too many arguments");
|
||||
return NULL;
|
||||
SWIG_fail;
|
||||
}
|
||||
for (i = 0; i < argc; i++) {
|
||||
PyObject *pyobj = PyTuple_GetItem(varargs, i);
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
PyObject *pystr;
|
||||
if (!PyUnicode_Check(pyobj)) {
|
||||
PyErr_SetString(PyExc_ValueError, "Expected a string");
|
||||
return NULL;
|
||||
SWIG_fail;
|
||||
}
|
||||
pystr = PyUnicode_AsUTF8String(pyobj);
|
||||
str = strdup(PyBytes_AsString(pystr));
|
||||
|
|
@ -28,7 +28,7 @@
|
|||
%#else
|
||||
if (!PyString_Check(pyobj)) {
|
||||
PyErr_SetString(PyExc_ValueError, "Expected a string");
|
||||
return NULL;
|
||||
SWIG_fail;
|
||||
}
|
||||
str = PyString_AsString(pyobj);
|
||||
%#endif
|
||||
|
|
|
|||
|
|
@ -1,70 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
#
|
||||
# Put description here
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
require 'swig_assert'
|
||||
|
||||
require 'li_boost_array'
|
||||
|
||||
include Li_boost_array
|
||||
|
||||
|
||||
def failed(a, b, msg)
|
||||
raise RuntimeError, "#{msg} #{a} #{b}"
|
||||
end
|
||||
|
||||
def compare_sequences(a, b)
|
||||
if a.size != b.size
|
||||
failed(a, b, "different sizes")
|
||||
end
|
||||
for i in 0..a.size-1
|
||||
failed(a, b, "elements are different:") if a[i] != b[i]
|
||||
end
|
||||
end
|
||||
|
||||
def compare_containers(rubyarray, swigarray)
|
||||
compare_sequences(rubyarray, swigarray)
|
||||
end
|
||||
|
||||
ps = [0, 1, 2, 3, 4, 5]
|
||||
|
||||
ai = ArrayInt6.new(ps)
|
||||
|
||||
compare_containers(ps, ai)
|
||||
|
||||
# Modify content
|
||||
for i in 0..ps.size-1
|
||||
ps[i] = ps[i] * 10
|
||||
ai[i] = ai[i] * 10
|
||||
end
|
||||
compare_containers(ps, ai)
|
||||
|
||||
# Empty
|
||||
ai = ArrayInt6.new()
|
||||
|
||||
# Check return
|
||||
compare_containers(arrayOutVal(), [-2, -1, 0, 0, 1, 2])
|
||||
compare_containers(arrayOutConstRef(), [-2, -1, 0, 0, 1, 2])
|
||||
#compare_containers(arrayOutRef(), [-2, -1, 0, 0, 1, 2])
|
||||
#compare_containers(arrayOutPtr(), [-2, -1, 0, 0, 1, 2])
|
||||
|
||||
# Check passing arguments
|
||||
ai = arrayInVal([9, 8, 7, 6, 5, 4])
|
||||
compare_containers(ai, [90, 80, 70, 60, 50, 40])
|
||||
|
||||
ai = arrayInConstRef([9, 8, 7, 6, 5, 4])
|
||||
compare_containers(ai, [90, 80, 70, 60, 50, 40])
|
||||
|
||||
#ai = ArrayInt6.new([9, 8, 7, 6, 5, 4])
|
||||
#arrayInRef(ai)
|
||||
#compare_containers(ai, [90, 80, 70, 60, 50, 40])
|
||||
|
||||
#ai = ArrayInt6.new([9, 8, 7, 6, 5, 4])
|
||||
#arrayInPtr(ai)
|
||||
#compare_containers(ai, [90, 80, 70, 60, 50, 40])
|
||||
|
||||
|
|
@ -6,12 +6,12 @@
|
|||
%inline %{
|
||||
class Base {
|
||||
public:
|
||||
void base() {}
|
||||
void baseMethod() {}
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
public:
|
||||
void derived() {}
|
||||
void derivedMethod() {}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
|
|
|
|||
50
Examples/test-suite/typemap_documentation.i
Normal file
50
Examples/test-suite/typemap_documentation.i
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
%module typemap_documentation
|
||||
|
||||
// A place for checking that documented typemaps are working.
|
||||
// The UTL languages are the only ones that are consistent enough to support these generic typemap functions.
|
||||
// These are in the Typemaps.html chapter.
|
||||
|
||||
%inline %{
|
||||
class Foo {
|
||||
public:
|
||||
int x;
|
||||
};
|
||||
|
||||
class Bar {
|
||||
public:
|
||||
int y;
|
||||
};
|
||||
%}
|
||||
|
||||
#if defined(SWIGUTL)
|
||||
%typemap(in) Foo * {
|
||||
if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 0))) {
|
||||
SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
int GrabVal(Foo *f) {
|
||||
return f->x;
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
#if defined(SWIGUTL)
|
||||
%typemap(in) Foo * {
|
||||
if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 0))) {
|
||||
Bar *temp;
|
||||
if (!SWIG_IsOK(SWIG_ConvertPtr($input, (void **) &temp, $descriptor(Bar *), 0))) {
|
||||
SWIG_exception_fail(SWIG_TypeError, "in method '$symname', expecting type Foo or Bar");
|
||||
}
|
||||
$1 = (Foo *)temp;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
int GrabValFooBar(Foo *f) {
|
||||
return f->x;
|
||||
}
|
||||
%}
|
||||
Loading…
Add table
Add a link
Reference in a new issue