Jens Schmidt | 3 Sep 16:11 2015

Wrapping two differnet libraries

Hi there,

regarding wrapping to Java:
i want to use two libraries: vtk which comes with its own java wrapping 
and opencascade (occ) for wich i use swig.
There are some classes in occ which use vtk, in particular 
vtkSmartPointer and vtkPolyData.
Now to the problem/chalenge/brainfuck:
a) vkt wrapping to java does not even use vtkSmartPointer
b) when generating the wrapper for occ it also generates java classes 
for vtkSmartPointer and the vtkPolyData, hower those are NOT the same 
objects as in the vtk java wrapping, so i cannot use them together from 
java. What i try to acomplish is this:
-create the occ objects
-create the vtk objects
-hey occ object here is you vtk object to work on
-do stuff
-hey occ object give me that new vtk object you created
-vtk have this object created by occ
-do other stuff

I am a bit at a loss as where to even start, hopefully you have some 
pointers (pun intended :-)

Best regards

Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
(Continue reading)

David Seaward | 3 Sep 15:53 2015

How do I ensure that typedefs in a template are also swigged?

Hello all,

I am wrapping a C++ class [1] for C# using SWIG. I have used the
%template directive to concretise a template class as follows:

%template(PointMatcherFloat) PointMatcher<float>;

However, it turns out the template PointMatcher<T> contains typedefs
and typenames based on <T> and these are not being included in the
SWIG wrapper. Examples:

typedef T ScalarType;
typedef typename Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> Matrix;
typedef Matrix TransformationParameters;

I have tried duplicating the declarations above as an %inline block,
using T and float. (As described in the SWIG 3.0 documentation on
typedef [2].) In both cases the typedefs are simply included in the
.cxx file, but no associated classes or methods are generated.

How do I make sure these types are made available in PointMatcherFloat?

(Full details here: )

Many thanks,


(Continue reading)

David Morris | 29 Aug 21:48 2015

Loading a SWIG library statically linked in iOS App?

Can anyone help with a method to link a static library of SWIG code
into an iOS application?

The app I am creating is using PyQt5 and pyqtdeploy (which all works)
but now I need my SWIG library to be loaded.  I added the following
line to the swig definition:

%include "embed.i"

And included Modules/config.c from the Python source directory I used
to compile for the iOS app.

However this does not run.  Here is the iOS error:

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
ImportError: No module named site

Can anyone provide ideas on how to load a statically linked swig module?

Thank you,

Dave Mazzoni | 28 Aug 16:07 2015

Swig and go1.5

Has anyone done the most simple of programs that uses SWIG to wrap C functionality with go1.5. Most of the user manual is dated compared to the go 1.5 release which makes it difficult to get going.

Please help...
Swig-user mailing list
Swig-user <at>
Stefan Andritoiu | 27 Aug 12:08 2015

Make array typemaps more java like

Hi everyone,

I have a C method that takes a buffer of size 'len' and populates, like this:
 void modifyBuffer (unsigned char * buff, int len);

I am using the following, in the interface file, to convert it to java:
 %include "arrays_java.i";
 %apply unsigned char[] {unsigned char *};

Which creates a Java method that takes a short array and populates it.
 public static void modifyBuffer(short[] buff, int len)

But I would like for it to only take 'int len' as a parameter and
return a new short array; for it to be more Java like, something like;
  public static short[] modifyBuffer(int len)

Can someone help me? I know i should take the code from arrays_java.i"
and modify it a little, but it's beyond me.

Thank you,

Kris Thielemans | 25 Aug 18:13 2015

ignoring operators (MATLAB specific?)


I'm using SWIG to wrap to MATLAB, using Joel's SWIG fork at

I'm getting a lot of this numerical operator warnings like

Warning 365: operator+= ignored

which makes sense as Matlab doesn't support += (sigh). However, I can't get
rid of these warnings by using

%ignore *::operator+=;

Is this a MATLAB-fork specific issue or a standard SWIG issue?

I get the warnings for instance for

class Bin 
  inline Bin&  operator+=(const float dx);



AL13N | 23 Aug 10:55 2015

libyui Event YItem with context parameter (for perl) (aka a method with void* to perl Ref)?

We're trying to use libyui perl-bindings, and at a certain point:

YItem (which is passed in a YMenuEvent) has the following methods:

void YItem::setData(void *data) {self->_data = data;}
void* YItem::data() {return self->_data;}

it never does anything else with _data or anything.

This is purely a pointer you can set to see what YItem is actually
triggerred when an event is triggered.

as a result, this void* _data private variable can be anything.

in order to use this in the perl-bindings (via swig), we tried a lot of
things to get anything.

we even tried to map the void* to a class (YUserData) with director
feature on and try to use this one as a base to a new class that had a
perl Reference in order to get anywhere... or even tried to have a second
parent in our own classes in perl, so that we could link our perl backend
classes to the Item...

but, no deal...

what is the correct way to handle this kind of example?

is there some kind of perl swigtype we can use (like a 'Ref' as it's
called in ISA ?) so that void* would be a Ref ?

or some other way?

Jamie Lahowetz | 19 Aug 20:01 2015

type converting C++ std::map into PHP using SWIG

I have a PHP extension that is in C++ and I used SWIG to wrap it. I am trying to create a class that is implemented in C++ as such:

    Package(const std::map<std::string,std::string> &input_map, const std::queue<std::string> &dates_queue);

in PHP by using this script:

    require "prq.php";

    $input = array("dataset" => "a050119", "station" => "a050119", "flag" => "1");
    $dates = array(1 => "read;chunk;2015-07-01 00:00;2015-07-02 00:00");

    $package = new Package($input, $dates); 

but I get the error: 

    PHP Fatal error:  Type error in argument 1 of new_Package. Expected SWIGTYPE_p_std__mapT_std__string_std__string_t in /home/jlahowetz2/development/package-request-queue/swig/prq.php on line 230

which makes sense... I have no clue how to implement a std::map in PHP. I looked at the C++ wrapper that was created by SWIG and found a type conversion for this:

    static swig_type_info _swigt__p_std__mapT_std__string_std__string_t = {"_p_std__mapT_std__string_std__string_t", "std::map< std::string,std::string > *", 0, 0, (void*)0, 0};

My question is: how do I use this type conversion in PHP to pass a std::map to my constructor? Thank you much.

EDIT1: changed title, wasnt being all that specific
Swig-user mailing list
Swig-user <at>
Bob Hood | 13 Aug 21:58 2015

Applying [ANY] to fixed-sized data types

I have a series of %typemaps that are matching argument literal declarations 
in C headers; e.g:

     %typemap(in) double [3] {

I then apply these to defined data types:

     %apply double [3] { DVector };

In this case, 'DVector' is just something like:

     typedef double  DVector[3];

and my code to process double[3] will stuff the incoming data into a 'DVector' 
if required.

I'm beginning to run into situations where I'm having more and more variations 
on these input arrays (e.g., "double [9]") and it seem logical to convert 
several array %typemaps over to use the ANY keyword to reduce the code 
duplication; e.g.:

     %typemap(in) double [ANY] {

However, where does that leave my %apply?  Would I see any adverse effects if 
I continued to apply using:

     %apply double [ANY] { DVector };

or perhaps could I just continue to use the fixed size value in the interface 

     %apply double [3] { DVector };

and SWIG will just do the right thing?


Juan Ignacio Carrano | 13 Aug 17:34 2015

Python: Avoiding garbage collection of class/struct while there is still a reference to a member.


I am writing the Python binding for a C++ library (LibRaw). The main
data structure is:

class  LibRaw
    libraw_data_t imgdata;
    int verbose;


If, in Python, I create an instance of LibRaw, take a reference to
imgdata and then delete the first object, I get a segfault when
attempting to access imgdata.
In code:

g = LibRaw()
i = g.imgdata     # i is a reference to imgdata inside g
del g     # g gets gc'd and memory is freed. i now points to deallocated memory
print(i.cblack)  # cblack is an int
-> Segmentation Fault

This is quite un-pythonic. I would like to avoid this situation by
making struct members keep a reference to their parents, so the C++
object won't be destroyed until all pointers to it's members are
I couldn't find a "ready-made" solution in SWIG, so I wrote the
following typemap:

%typemap(out) libraw_data_t *
   PyObject * r;

   r = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor, 0 |  0 );
   PyObject_SetAttrString(r, "_c_parent", self);

   $result = r;

I have some questions:

¿Is this the correct way to secure pointers to class member against
destruction of their parent?
¿Can I be sure that the typemap will be used only for member accesses
(so that "self" makes sense)?
¿How can I apply this typemap to all structures / classes that are
members of other structure/class? I thought about making a macro
(%typemap(out) DATA_T * ...etc..) and manually applying it to all
struct types (similar to how numpy.i works).


Juan I Carrano
R&D Engineer

Swig-user mailing list
Swig-user <at>
Andrew Haining | 12 Aug 13:12 2015

%template, stl conainters and memory management

Hi, I’m still fairly new to swig and I’ve been getting on well, I use the Pimpl idiom to allow the bindings to retain the C++ objects for as long as they live in the managed language and this works really well but I’ve hit a bit of an issue with passing collections to the managed language, basically I have a rough setup as follows:



class ObjectImpl





class ObjectImpl;

class Object


  std::shared_ptr<ObjectImpl> pimpl;




%template(ObjectList) std::vector<Object>;


class Object


  ObjectList getObjectList();



Now when I pass an ObjectList to the managed language and get objects out of the ObjectList the getitem method is called which adds the address of the C++ Object to a new C# object, sets it’s swigCMemOwn to false and passes that out. A side effect of this is that when the C# ObjectList goes out of scope, it deletes the C++ std::vector<Object> and the address inside any C# Object retrieved from the list now dangles.


As a workaround, given I’m using the Pimpl idiom, I can safely use getitemcopy as opposed to getitem and they will point to the same underlying object, to do this I had to modify std_vector.i which isn’t ideal. I was wondering if there is any way I can achieve this with swig inside my own .i files? I tried to use a %typemap(cscode) but It didn’t work because it seems only one of these can be used per type and the one inside std_vector.i takes precedent.


I was also wondering if it was possible to provide it as an option for people who use the Pimpl idiom to bind to swig which I expect would be the most common usage? I also had a thought that maybe std_vector.i could be reworked to provide an actual C# List<Object> which took copies of the source C++ Objects and wrapped them at instantiation, this way the C# garbage collector could properly track the objects on a granular basis and it’d solve the one caveat with my own workaround which is pointer comparisons between 2 C# Objects retrieved from the ObjectList would work as expected, whereas I’d currently have to implement a comparison operator that deferred to the Impl comparison to achieve that.


Hope all that makes sense?




Digital Barriers e-Mail Confidentiality and Disclaimer


This message contains confidential information and is intended only for the individual named. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.


Digital Barriers plc is a company registered in England and Wales. Registered number: 7149547. Registered office: Cargo Works, 1-2 Hatfields, London SE1 9PG, United Kingdom. For further information about Digital Barriers, please visit


This email has been scanned by the Symantec Email service.
For more information please visit
Swig-user mailing list
Swig-user <at>