Linda Schey | 23 Jul 20:54 2015
Picon

std::map<std::string, ANY>

Hi,

I have a large number of std::map<std::string, ANY> maps that I want to map to C#. Is there a way to do that, so I don't need to write
%template(StringTypeA_Map) std::map<std::string, TypeA>;
%template(StringTypeB_Map) std::map<std::string, TypeB>;
...
for every type?

Has anybody an idea how to do this?
Thank you in advance.

Kind regards,
Linda Schey
------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Scott Deerwester | 10 Jul 16:53 2015
Picon

Qt 5 typemaps for SWIG

I recently asked Qt support about a set of typemaps for Qt 5 for SWIG. Here is the response:

I am afraid there is nothing much we can do about it, Swig is not our product
and we dont support it. I understand that you want to Qt and Swig together, I
believe Swig will have to add Qt's type so that it can be used together.
I believe best is to ask Swig support team for this.

When people ask about wrapping Qt in SWIG, the usual answers are either "use SIP/PySide/... instead" or "it can't be too different from std...". The first is not a bad answer for Python, but for developers who want to generate bindings for something else, there doesn't appear to be an answer. The SWIG documentation even mentions an old version of Qt support in the OCaml section (31.2.4.2 in the 3.0 manual). Any chance that somebody with some serious typemap chops would be willing to take a crack at it?
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Orion Poplawski | 8 Jul 00:15 2015

swig 3.0.6 breaks plplot builds

Updating from 3.0.5 to 3.0.6 in Fedora Rawhide has broken plplot builds.  New
error:

cd /builddir/build/BUILD/plplot-5.11.0/fedora/bindings/python && /usr/bin/swig
-python -DPL_DOUBLE_INTERFACE -DSWIG_PYTHON -DPYTHON_HAVE_PYBUFFER -outdir
/builddir/build/BUILD/plplot-5.11.0/fedora/bindings/python
-I/builddir/build/BUILD/plplot-5.11.0/include
-I/builddir/build/BUILD/plplot-5.11.0/lib/qsastime
-I/builddir/build/BUILD/plplot-5.11.0/bindings/tcl
-I/builddir/build/BUILD/plplot-5.11.0/bindings/tk
-I/builddir/build/BUILD/plplot-5.11.0/fedora
-I/builddir/build/BUILD/plplot-5.11.0/fedora/include
-I/builddir/build/BUILD/plplot-5.11.0/fedora/bindings/python -I/usr/include
-I/usr/include -I/usr/include -I/usr/include/python2.7
-I/usr/lib/python2.7/site-packages/numpy/core/include/numpy
-I/builddir/build/BUILD/plplot-5.11.0/bindings/swig-support -o
/builddir/build/BUILD/plplot-5.11.0/fedora/bindings/python/plplotcmodulePYTHON_wrap.c
/builddir/build/BUILD/plplot-5.11.0/bindings/python/plplotcmodule.i
/builddir/build/BUILD/plplot-5.11.0/bindings/swig-support/plplotcapi.i:367:
Error: Line indented less than expected (line 2 of pythoncode)
/builddir/build/BUILD/plplot-5.11.0/bindings/swig-support/plplotcapi.i:367:
Error: Line indented less than expected (line 12 of pythoncode)
/builddir/build/BUILD/plplot-5.11.0/bindings/swig-support/plplotcapi.i:367:
Error: Line indented less than expected (line 14 of pythoncode)
/builddir/build/BUILD/plplot-5.11.0/bindings/swig-support/plplotcapi.i:367:
Error: Line indented less than expected (line 16 of pythoncode)
/builddir/build/BUILD/plplot-5.11.0/bindings/swig-support/plplotcapi.i:367:
Error: Line indented less than expected (line 2 of pythoncode)
/builddir/build/BUILD/plplot-5.11.0/bindings/swig-support/plplotcapi.i:367:
Error: Line indented less than expected (line 12 of pythoncode)
/builddir/build/BUILD/plplot-5.11.0/bindings/swig-support/plplotcapi.i:367:
Error: Line indented less than expected (line 14 of pythoncode)
/builddir/build/BUILD/plplot-5.11.0/bindings/swig-support/plplotcapi.i:367:
Error: Line indented less than expected (line 16 of pythoncode)
/builddir/build/BUILD/plplot-5.11.0/bindings/swig-support/plplotcapi.i:370:
Error: Line indented less than expected (line 2 of pythoncode)
/builddir/build/BUILD/plplot-5.11.0/bindings/swig-support/plplotcapi.i:370:
Error: Line indented less than expected (line 11 of pythoncode)
/builddir/build/BUILD/plplot-5.11.0/bindings/swig-support/plplotcapi.i:370:
Error: Line indented less than expected (line 13 of pythoncode)
/builddir/build/BUILD/plplot-5.11.0/bindings/swig-support/plplotcapi.i:370:
Error: Line indented less than expected (line 15 of pythoncode)
/builddir/build/BUILD/plplot-5.11.0/bindings/swig-support/plplotcapi.i:370:
Error: Line indented less than expected (line 2 of pythoncode)
/builddir/build/BUILD/plplot-5.11.0/bindings/swig-support/plplotcapi.i:370:
Error: Line indented less than expected (line 11 of pythoncode)
.....

Line 367 is a function def:

     void
     plgcol0a( PLINT icol0, PLINT *OUTPUT, PLINT *OUTPUT, PLINT *OUTPUT, PLFLT
 *OUTPUT );

     void
367> plgcolbg( PLINT *OUTPUT, PLINT *OUTPUT, PLINT *OUTPUT );

No idea why it wouldn't like that one but seems happy otherwise.  What can I
do to debug this?

--

-- 
Orion Poplawski
Technical Manager                     303-415-9701 x222
NWRA, Boulder/CoRA Office             FAX: 303-415-9702
3380 Mitchell Lane                       orion <at> nwra.com
Boulder, CO 80301                   http://www.nwra.com

------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
Will Boyd | 7 Jul 03:41 2015
Picon

SWIG default treatment of varargs compatibility between version 2 and 3?

I am using SWIG to wrap a mixed C++/CUDA enabled code called OpenMOC. We recently began using the SWIG "%pythonappend" SWIG directive to insert some Python code into the bindings for certain C++ class methods. For example, for a class method "Universe::addCell(Cell* cell), we use the following `"%pythonappend" directive:


     %pythonappend Universe::addCell %{
          args[0].thisown = 0
     %}

Fortunately, this works correctly when using SWIG 2.0.11 (the default version on Ubuntu 14.10) and the SWIG-generated Python file for the C/C++ extension module has the following routine:

    def addCell(self, *args, **kwargs):
        val = _openmoc.Universe_addCell(self, *args, **kwargs)
        args[0].thisown = 0
        return val

However, when using a newer version of SWIG such as 3.0.5, this no longer works since the SWIG-generated routine does not use varargs and instead generates the following routine:

    def addCell(self, cell):
        val = _openmoc.Universe_addCell(self, cell)
        args[0].thisown = 0
        return val

This is obviously incorrect and results in a segmentation fault since there is no "args" parameter. 

Is there any way to create this "%pythonappend" statement in such a way that it will be cross-compatible for SWIG 2 and 3?

--
Will Boyd
Nuclear Science & Engineering
Massachusetts Institute of Technology
Cell: 423.413.8469
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
William S Fulton | 5 Jul 00:51 2015
Picon

Re: Swig C# NullException problem

On 18 June 2015 at 19:45, Prof. Christoph Müller <mch <at> hs-furtwangen.de> wrote:
>> Date: Wed, 10 Jun 2015 22:38:59 +0100
>> From: William S Fulton <wsf <at> fultondesigns.co.uk>
>> Subject: Re: [Swig-user] Swig C# NullException problem
>> To: Linda Schey <linda.schey <at> gmail.com>
>> Cc: swig-user <swig-user <at> lists.sourceforge.net>
>> Message-ID:
>>       <CANGqftDaEe0AHJPo+5uqsJ9s5tKTm_BrWjjxa7erAGzx6eYbGg <at> mail.gmail.com>
>> Content-Type: text/plain; charset=UTF-8
>>
>> On 8 June 2015 at 16:12, Linda Schey <linda.schey <at> gmail.com> wrote:
>> > Hello,
>> >
>> > we have encountered a problem with swig for which we couln't find any
>> > solution in the documentation nor in forum posts.
>> > We are right now developing an universal plugin which will connect the
>> > 3d program Blender with the 3d engine of our university. Blenders API
>> > is written in c/c++ whereas our engine is developed in c#.
>> > We need to swig a lot of classes which lead us to write typemaps that
>> > won't address individual cases but set up rules for all custom types
> etc.
>> >
>> > It's a huge learning process for us but right now we are having
>> > troubles with the exception handling or at least it seems like this is
>> > the error source.
>> > Swig will always create a default exception in the generated c++ file
>> > which results in zero as a return value. But this will create a
>> > compile error with the method of our custom class, that can't have zero
> as a return value.
>> >
>> > We've already gone through the documentation chapters about exception
>> > handling and couldn't find a solution for our problem.
>> >
>> > How can we set up a custom exception that will result in a default
>> > value if the object is null? Is there an obvious mistake we're just
>> > too narrow minded to see? Can the error be fixed in another way? (The
>> > object can never be null which means we really don't need this
>> > exception.)
>> >
>> > Please find below our sample code which includes our typemaps (for the
>> > exception handling and other custom types) and the generated c++ file.
>> >
>> > A huge thank you in advance for any clues and with best wishes,
>> >
>> > Linda Schey and Sarah Haefele
>> > Computer Science in Media Master, Furtwangen University Germany
>> >
>> > --------------------------------------
>> > cpp_file.h
>> > --------------------------------------
>> > std::array<float, 3> FooInArrayOut(Foo f);
>> >
>> > --------------------------------------
>> > cpp_file.i
>> > --------------------------------------
>> > //Map std::array<float,3> To Fusee.Math.float3
>> > %typemap(ctype)  std::array<float, 3> "std::array<float, 3> /*
>> > std::array<float, 3>_ctype */"
>> > %typemap(imtype) std::array<float, 3> "Fusee.Math.float3 /*
>> > Fusee.Math.float3*_imtype */"
>> > %typemap(cstype) std::array<float, 3> "Fusee.Math.float3 /*
>> > iFusee.Math.float3_cstype */"
>> > %typemap(csin)   std::array<float, 3> "$csinput /*
> Fusee.Math.float3_csin
>> > */"
>> > %typemap(in)     std::array<float, 3> %{ $1 = $input /*
> Fusee.Math.float3
>> > in*/; %}
>> > %typemap(out)    std::array<float, 3> %{ /* Fusee.Math.float3
> out*/$result =
>> > $1/* Fusee.Math.float3 out*/; %}
>> > %typemap(csout)  std::array<float, 3> { return $imcall/*
>> > Fusee.Math.float3 csout*/; }
>> >
>> > --------------------------------------
>> > cpp_file_wrap.cxx
>> > --------------------------------------
>> >  SWIGEXPORT std::array<float, 3> /* std::array<float, 3>_ctype */
>> > SWIGSTDCALL CSharp_cpp_file_FooInArrayOut(void * jarg1, void * jarg2) {
>> >   std::array<float, 3> /* std::array<float, 3>_ctype */ jresult ;
>> >   cpp_file *arg1 = (cpp_file *) 0 ;
>> >   Foo arg2 ;
>> >   Foo *argp2 ;
>> >   std::array< float,3 > result;
>> >
>> >   arg1 = (cpp_file *)jarg1;
>> >   argp2 = (Foo *)jarg2;
>> >   if (!argp2) {
>> >
>> > SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullExceptio
>> > n, "Attempt to dereference null Foo", 0);
>> >     return 0;
>> >   }
>> >   arg2 = *argp2;
>> >   result = (arg1)->FooInArrayOut(arg2);
>> >   /* Fusee.Math.float3 out*/jresult = result/* Fusee.Math.float3 out*/;
>> >   return jresult;
>> > }
>> >
>> > --------------------------------------
>> > Error Msg
>> > --------------------------------------
>> > error C2440: 'return' : cannot convert from 'int' to
> 'std::array<float,3>'
>>
>>
>> I don't think you can use std::array<float, 3> as a return type in wrapper
> function. How is the CLI going to know how to marshal this type to
> Fusee.Math.float3 ?
>>
>> The exception handling is written such that the return type return type
> will be void or a type that will accept zero. I don't think any other type
> will easily be handling without overriding quite a bit of default code
> generation.
>>
>> William
>>
>
> The CLI is capable of marshalling any C/C++ POD (plain-old-datatype -
> classes or structs without methods, con- or destructors) to a respective C#
> struct with the same memory layout. We are using this scheme to wrap c++
> methods returning instances (not pointers) to c# methods returning structs.
> It works very well in a big project where we SWIGged the C++ API of Cinema4D
> (currently more than 700 classes wrapped - http://fusee3d.org/c4dexporter/)
> and we're very happy with it. The funny thing is: This only works because
> just by chance none of the numerous C++methods returning a POD on the stack
> takes a pointer to a class as an argument:
>
> A method like this works with the approach mentioned by Linda:
> Vector TestReturnStructOnStack(); // (WORKS JUST FINE)
>
> And a method like that doesn't - because the SWIG-generated C++-Stub tries
> to return 0 (which is not castable to Vector):
> Vector TestReturnStructOnStack(Foo *foo); // (C++ COMPILE ERROR in
> SWIG-C++-Stub - cannot cast int to Vector)
>
> I doubt that this is by design. There should be a customizable typemap-entry
> for "Vector" allowing to change the default return value of any method
> returning "Vector".
> I tried to add a constructor taking an int to Vector. This cures the
> compiler error but then Vector is not a POD anymore and the p/invoke will
> crash.
> Thanks for any help - we have been struggling with this for weeks now.

Ah yes of course, marshalling of value types and std::array can be a
POD. There is actually a solution. You'll notice that the SWIG
exception code uses ' return $null' where $null is a special variable.
SWIG expands $null into 0 unless the 'out' typemap has a 'null'
attribute, in which case it uses the value of this attribute. This is
used for void returns where the 'out' typemap in Lib/csharp/csharp.swg
is:
  %typemap(out, null="") void ""
so 'return' is generated instead of 'return 0'.

So for your case, just modify the out typemap and add in the 'null'
attribute as follows:

%typemap(out, null="std::array<float, 3>()")    std::array<float, 3>
%{ /* Fusee.Math.float3 out*/$result = $1/* Fusee.Math.float3 out*/;
%}

The SWIG documentation ought to have some good examples of value types
typemaps such as the std::array you show and it also ought to have
this explained. A patch to the docs in Doc/Manual/CSharp.html would be
much appreciated!

William

------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
JR Heisey | 2 Jul 21:09 2015

Python 2 and 3

Greetings,

 

I am trying to determine whether it is feasible to support bindings for both Python 2 and 3.

 

It looks like the SWIG 3.0.5 generated source works for either.

The difference then lies to which library it is linked.

This also poses the question of whether the code could dynamically link to the correct DLL at runtime.

And how could it know to which library to connect?

 

I am doing this in Windows only.

 

Has anyone addressed this?

 

Thanks,

J.R. Heisey                            Synaptics, Inc.

Manager, Firmware Tools                1251 McKay Drive

+1 408 904-1598                        San Jose CA 95131

jrheisey <at> synaptics.com                 http://www.synaptics.com

 

------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Lindley French | 25 Jun 20:32 2015
Picon

dynamic_cast support

I can see in the SWIG codebase several attempts to support downcasting in various ways. Java downcasting just doesn't work, and the solution offered in the docs, which is to enumerate all the various subclasses in the out typemap, is a maintenance problem.

I see some attempt to create feature:javadowncast, but it seems to only work with directors. (If you try to use it with everything, it'll generate compile errors for some types.) I see a dynamic_cast test suite which is extremely basic. I don't see any comprehensive solution to the problem.

dynamic_cast in C++ is trivial. The only *real* problem is that it requires the target type to be specified at compile time, which some languages don't support well. There's no way to pass a Java Class object to a C++ dynamic_cast, for instance.

It seems to me that the solution is to add a feature which causes all C++ subclasses of Base to be %extend'ed with a method:
static Derived* DynamicCast(Base* b) {
  return dynamic_cast<Derived*>(b);
}

This could be done manually with %extend, but again that's a maintenance problem. It seems like there should be a way to write an %extend that applies individually to all *subclasses* of a given type, with the concrete type specified in a variable, perhaps $derived.

I don't mind figuring out the code myself, but I thought I'd ask to see if I'm missing anything or if there's a better solution to this problem available.
------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors 
network devices and physical & virtual servers, alerts via email & sms 
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Peter Toft | 23 Jun 19:56 2015
Picon

-fpic needed for C -> Python?

Hi all

I often happily use swig to wrap C/C++ for Python.
I can see that the nice swig documentation 
http://www.swig.org/Doc3.0/SWIGDocumentation.html
writes how to do that. E.g. 
http://www.swig.org/Doc3.0/SWIGDocumentation.html section 6.4

Side-remark: Some time ago I also wrote a small article about that (in 
Danish)
http://www.version2.dk/blog/kald-af-cc-kode-fra-python-53635

I have a problem with a pre-compiled 64 bit C/C++ static library - 
apparently not compiled with -fpic/-fPIC.
Is there any way e.g. with wrappers that I can make a Linux shared 
object (plus a .pyinterface)
which can be used in a vanilla Linux Python?

Best

--

-- 
Peter Toft <pto <at> linuxbog.dk>

------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors 
network devices and physical & virtual servers, alerts via email & sms 
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
Emre Metin | 22 Jun 13:33 2015
Picon

HandleRef

I'm tring to wrap my c++ code to c# with using Swig. If the output
destination of C# files is class library , there is no error and
succesfully build.

However I want to support both windows phone 8.1 and windows 8.1
because of this reason I'm using portable class library rather than
normal class library. In this situation I'm getting error that says;

The type or namespace name 'HandleRef' does not exist in the namespace
'System.Runtime.InteropServices' (are you missing an assembly
reference?)

I really don't know what I am missing. What is the solution of this
problem? My guess windows phone 8.1 and windows 8.1 does not support
HandleRef but I'm not sure. If it so, What should I do?

Stackoverflow link;
http://stackoverflow.com/questions/30978652/swig-in-c-sharp-handleref-could-not-be-found-in-portable-class-library

------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors 
network devices and physical & virtual servers, alerts via email & sms 
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
Kris Lamb | 19 Jun 15:36 2015
Picon

Dependency checking

Hi, I've found the -M option for checking the dependencies from the interface file, is there a similar option to know what files will be generated by swig?

I'm trying to create a tool that will only perform the swig build step if any of the input dependencies have been modified since the last build or if any of the output files are missing.

For instance when wrapping to csharp you get the module_wrap.cxx and then a whole bunch of .cs files for each class that has been wrapped.

Thanks,

Kris
------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Christoph Müller | 19 Jun 08:55 2015
Picon

WG: Re: Swig C# NullException problem


> Date: Wed, 10 Jun 2015 22:38:59 +0100
> From: William S Fulton <wsf <at> fultondesigns.co.uk>
> Subject: Re: [Swig-user] Swig C# NullException problem
> To: Linda Schey <linda.schey <at> gmail.com>
> Cc: swig-user <swig-user <at> lists.sourceforge.net>
> Message-ID:
> 	<CANGqftDaEe0AHJPo+5uqsJ9s5tKTm_BrWjjxa7erAGzx6eYbGg <at> mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
> 
> On 8 June 2015 at 16:12, Linda Schey <linda.schey <at> gmail.com> wrote:
> > Hello,
> >
> > we have encountered a problem with swig for which we couln't find 
> > any solution in the documentation nor in forum posts.
> > We are right now developing an universal plugin which will connect 
> > the 3d program Blender with the 3d engine of our university. 
> > Blenders API is written in c/c++ whereas our engine is developed in c#.
> > We need to swig a lot of classes which lead us to write typemaps 
> > that won't address individual cases but set up rules for all custom
types etc.
> >
> > It's a huge learning process for us but right now we are having 
> > troubles with the exception handling or at least it seems like this 
> > is the error source.
> > Swig will always create a default exception in the generated c++ 
> > file which results in zero as a return value. But this will create a 
> > compile error with the method of our custom class, that can't have zero
as a return value.
> >
> > We've already gone through the documentation chapters about 
> > exception handling and couldn't find a solution for our problem.
> >
> > How can we set up a custom exception that will result in a default 
> > value if the object is null? Is there an obvious mistake we're just 
> > too narrow minded to see? Can the error be fixed in another way? 
> > (The object can never be null which means we really don't need this
> > exception.)
> >
> > Please find below our sample code which includes our typemaps (for 
> > the exception handling and other custom types) and the generated c++
file.
> >
> > A huge thank you in advance for any clues and with best wishes,
> >
> > Linda Schey and Sarah Haefele
> > Computer Science in Media Master, Furtwangen University Germany
> >
> > --------------------------------------
> > cpp_file.h
> > --------------------------------------
> > std::array<float, 3> FooInArrayOut(Foo f);
> >
> > --------------------------------------
> > cpp_file.i
> > --------------------------------------
> > //Map std::array<float,3> To Fusee.Math.float3
> > %typemap(ctype)  std::array<float, 3> "std::array<float, 3> /* 
> > std::array<float, 3>_ctype */"
> > %typemap(imtype) std::array<float, 3> "Fusee.Math.float3 /* 
> > Fusee.Math.float3*_imtype */"
> > %typemap(cstype) std::array<float, 3> "Fusee.Math.float3 /* 
> > iFusee.Math.float3_cstype */"
> > %typemap(csin)   std::array<float, 3> "$csinput /*
Fusee.Math.float3_csin
> > */"
> > %typemap(in)     std::array<float, 3> %{ $1 = $input /*
Fusee.Math.float3
> > in*/; %}
> > %typemap(out)    std::array<float, 3> %{ /* Fusee.Math.float3
out*/$result =
> > $1/* Fusee.Math.float3 out*/; %}
> > %typemap(csout)  std::array<float, 3> { return $imcall/*
> > Fusee.Math.float3 csout*/; }
> >
> > --------------------------------------
> > cpp_file_wrap.cxx
> > --------------------------------------
> >  SWIGEXPORT std::array<float, 3> /* std::array<float, 3>_ctype */ 
> > SWIGSTDCALL CSharp_cpp_file_FooInArrayOut(void * jarg1, void * jarg2) {
> >   std::array<float, 3> /* std::array<float, 3>_ctype */ jresult ;
> >   cpp_file *arg1 = (cpp_file *) 0 ;
> >   Foo arg2 ;
> >   Foo *argp2 ;
> >   std::array< float,3 > result;
> >
> >   arg1 = (cpp_file *)jarg1;
> >   argp2 = (Foo *)jarg2;
> >   if (!argp2) {
> >     
> > SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullExcept
> > io n, "Attempt to dereference null Foo", 0);
> >     return 0;
> >   }
> >   arg2 = *argp2;
> >   result = (arg1)->FooInArrayOut(arg2);
> >   /* Fusee.Math.float3 out*/jresult = result/* Fusee.Math.float3 out*/;
> >   return jresult;
> > }
> >
> > --------------------------------------
> > Error Msg
> > --------------------------------------
> > error C2440: 'return' : cannot convert from 'int' to
'std::array<float,3>'
> 
> 
> I don't think you can use std::array<float, 3> as a return type in wrapper
function. How is the CLI going to know how to marshal this type to
Fusee.Math.float3 ?
> 
> The exception handling is written such that the return type return type
will be void or a type that will accept zero. I don't think any other type
will easily be handling without overriding quite a bit of default code
generation.
> 
> William
> 

The CLI is capable of marshalling any C/C++ POD (plain-old-datatype -
classes or structs without methods, con- or destructors) to a respective C#
struct with the same memory layout. We are using this scheme to wrap c++
methods returning instances (not pointers) to c# methods returning structs.
It works very well in a big project where we SWIGged the C++ API of Cinema4D
(currently more than 700 classes wrapped - http://fusee3d.org/c4dexporter/)
and we're very happy with it. The funny thing is: This only works because
just by chance none of the numerous C++methods returning a POD on the stack
takes a pointer to a class as an argument:

A method like this works with the approach mentioned by Linda:
Vector TestReturnStructOnStack(); // (WORKS JUST FINE)

And a method like that doesn't - because the SWIG-generated C++-Stub tries
to return 0 (which is not castable to Vector):
Vector TestReturnStructOnStack(Foo *foo); // (C++ COMPILE ERROR in
SWIG-C++-Stub - cannot cast int to Vector)

I doubt that this is by design. There should be a customizable typemap-entry
for "Vector" allowing to change the default return value of any method
returning "Vector".
I tried to add a constructor taking an int to Vector. This cures the
compiler error but then Vector is not a POD anymore and the p/invoke will
crash.
Thanks for any help - we have been struggling with this for weeks now.

Prof. Christoph Müller
Computergrafik – Game-Engineering
Fakultät Digitale Medien
Hochschule Furtwangen
http://www.hs-furtwangen.de
http://www.fusee3d.org

------------------------------------------------------------------------------

Gmane