Paolo Greppi | 30 Jul 13:57 2014

swig/python memory leak on function returning a boost::gregorian::date object

I build this toy wrapper around a function returning a
boost::gregorian::date object:

swig -I. -python test.sw
g++ -std=c++11 -c -o test.o test.cc
g++ -I/usr/include/python2.7 -c -o test_wrap.o test_wrap.c
gcc -shared -fpic test.o test_wrap.o -lstdc++ -o _test.so

When I run the actual test:
./testtest.py

I get this error: "swig/python detected a memory leak of type
'boost::gregorian::date *', no destructor found"

How do I know if SWIG is really leaking memory ? How do I get rid of the
message ?

TIA, Paolo

P.S. Tried on Debian testing (boost 1.55, swig 2.0.12 and python 2.7.8)

==== test.h
#include <boost/date_time/gregorian/gregorian_types.hpp>
boost::gregorian::date date(int year, int month, int day);

==== test.cc
#include "test.h"
boost::gregorian::date date(int year, int month, int day) {
  boost::gregorian::date date(year, month, day);
  return date;
(Continue reading)

Vijay Krishnan | 30 Jul 08:01 2014
Picon

regarding using SWIGTYPE_p_p_char in java

Hi,

      I am using array of constant pointer to char pointer in c.When i use SWIG to generate JNI code for this,it creates SWIGTYPE_p_p_char.java wrapper file.How to make use of this SWIGTYPE_p_p_char ?

Regards,
Vijay K
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Gan, Cindy | 29 Jul 16:47 2014

Applying typemap to type in template

Hello,

 

I am working with C++ to C# in swig 3.0.2. I have a typemap for a typedef’d long and it works except for in a vector template. Inside the vector template, it is like I never wrote a typemap at all.

I suspected this might have something to do with the order that SWIG processes things, so I was thinking to apply the typemap to the type it changes myDate to (int). But in addition to “%apply myDate { std::vector < myDate >::int };” not being a valid SWIG statement, some ints in the vector class should be ints and not myDates.

 

Is there a way I can get the typemap to apply to the type inside a template as well as everywhere else?

 

 

Thank you,

 

Cindy

 

 

The relevant parts look like:

 

typedef long myDate;

 

%typemap(cstype) myDate "System.DateTime"

%typemap(csin,

         pre="   int temp_$csinput = (int)$csinput.ToOADate();"

        ) myDate

         "temp_$csinput"

                               

%typemap(csout, excode=SWIGEXCODE) myDate {

    int tempDate = $imcall;$excode

                var ret = System.DateTime.FromOADate(tempOADate);

                return ret;

}

 

%template ( MyDateVector ) std::vector < myDate >;



IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Lars Nielsen | 28 Jul 22:08 2014
Picon

SWIG and header only library best pratices

Hello.
I have to make a binding/Wrapper for C++ library to Java.
Are there any best pratices an stuff like that ? 
Advice is also welcome 
 
Kind Regards / Med Venlig hilsen:
Lars Nielsen



------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
cedlemo | 28 Jul 19:22 2014
Picon

warning message with vector.i and vector of classes

I use swig to wrap c++ classes to ruby code. Some of my classes return 
`std:vector` of other classes so I use the `std_vector.i` for that.

     %include "std_vector.i"
     namespace std {
       %template(VectorString) vector<string>;
       %template(VectorField) vector<TruckBoris::Field>;
       %template(VectorStructure) vector<TruckBoris::Structure>;
       %template(VectorEnum) vector<TruckBoris::Enum>;
     }

For the classes Enum and Structure I have this kind of warnings:

     parser.cpp:2781:9: warning: destination for this 'memset' call is a 
pointer to dynamic class 'TruckBoris::Enum'; vtable pointer will be 
overwritten [-Wdynamic-class-memaccess]
         memset(v_def,0,sizeof(Type));
                ^
     parser.cpp:2807:66: note: in instantiation of member function 
'swig::traits_as<TruckBoris::Enum, swig::pointer_category>::as' 
requested here
         return traits_as< Type, typename traits< Type >::category 
 >::as(obj, te);
                                                                  ^
     parser.cpp:4236:92: note: in instantiation of function template 
specialization 'swig::as<TruckBoris::Enum>' requested here
         std::vector<TruckBoris::Enum,std::allocator< TruckBoris::Enum > 
 >::value_type val = 
swig::as<std::vector<TruckBoris::Enum,std::allocator< TruckBoris::Enum > 
 >::value_type>( elem...
^
     parser.cpp:2781:9: note: explicitly cast the pointer to silence 
this warning
         memset(v_def,0,sizeof(Type));
                ^
                (void*)

This is just some warnings and my extension is compiling and working as 
expected. But if there are some warnings I think it means that maybe I 
am wrong somewhere.

For information:

I don't have warnings from simple classes like Field but I have warning 
form Enum and Structure classes which both inherits from the same class. 
Here is the code:

       class TagDeclaration
       {
         public:
           TagDeclaration(clang::TagDecl * var);
           ~TagDeclaration(){}
           void setPtr(clang::TagDecl * var); //for ruby interface
           clang::TagDecl * getPtr() const; //for ruby interface
           std::string getName() const;
           bool hasNameForLinkage()const;
           bool hasLinkage() const;
           std::string getTypedefName() const;
           std::string getRaw( clang::SourceManager & sm, const 
clang::LangOptions & lopt) const;
           virtual TagDeclaration& Equals( const TagDeclaration & tag);
         protected:
           clang::TagDecl * m_var;
       };
       class Structure : public TagDeclaration
       {
         public:
           Structure();
           Structure(clang::TagDecl * var);
           ~Structure() {}
     #pragma clang diagnostic push
     #pragma clang diagnostic ignored "-Woverloaded-virtual"
           virtual Structure& Equals(const Structure& tag);
     #pragma clang diagnostic pop
           std::string getTagType() const;
           int getFieldsNumber() const;
           std::vector<Field> getFields() const;
           clang::FieldDecl * getField(int i) const;
         private:
           std::string m_tagType;
       };

------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
alin.chitan | 28 Jul 10:39 2014
Picon

array_class usage for python

Hi,

I looked through carrays.i and carrays.swg and they seem to implement
getitem using value semantics.
My question is: what can go wrong if I make a similar macro that will
implement getitem using reference/pointer semantics?
This would help me manage arrays of user defined types (structs, classes),
and it seems to work ok (with very simple tests at least).
The context in which I'm trying to do this is as follows:
- I have a very large code base I need to wrap
- I cannot tweek/extend individual definitions, as there are too many of
these for a manual approach
- There are quite a lot of structures that contain members which are bounded
arrays of other structures.

If you could help me along this line or, even better, suggest an alternative
approach that takes into account my needs, I would very much appreciate it.

Thanks in advance,
Alin

--
View this message in context: http://swig.10945.n7.nabble.com/array-class-usage-for-python-tp13904.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
Olivier Voyer | 23 Jul 21:08 2014
Picon

Python 3.4

Does SWIG support Python 3.4 yet? I only see support for Python 3.3 in the latest release notes.

--
Olivier
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Bradley Lowekamp | 18 Jul 14:56 2014
Picon

uint64_t with std::vector and java portability

Hello,

My problem is the uint64_t is not get consistently translated to BigInteger for the java type.

I am having some minor issues with the C99 integer and std::vector. Here is a simplified snippet of code:

%module uint64test

%include <std_vector.i>

// Use C99 int support
%include <stdint.i>

%inline %{

#include <stdint.h>
#include <vector>
#include <numeric>

double two( const std::vector<uint64_t> &v )
{
  return std::accumulate(v.begin(), v.end(), 0.0);
}

%}

namespace std
{
%template(VectorUInt64) vector<uint64_t>;
}

Now sometime uint64_t is long and sometimes its long long. On linux 64, the swig generated code gives me an
error when compiled ( many languages ) like:

test_wrap.cxx: In function ‘const long long unsigned int&
std_vector_Sl_uint64_t_Sg__get(std::vector<long unsigned int, std::allocator<long unsigned
int> >*, int)’:
test_wrap.cxx:243: warning: returning reference to temporary
test_wrap.cxx: In function ‘jdouble Java_uint64testJNI_two(JNIEnv*, _jclass*, jlong, _jobject*)’:
test_wrap.cxx:324: error: invalid initialization of reference of type ‘const std::vector<long
unsigned int, std::allocator<long unsigned int> >&’ from expression of type ‘const
std::vector<long long unsigned int, std::allocator<long long unsigned int> >’
test_wrap.cxx:234: error: in passing argument 1 of ‘double two(const std::vector<long unsigned int,
std::allocator<long unsigned int> >&)’

So I now detect if "uint64_t" is the type "unsigned long" and if it is I add the SWIGWORDSIZE64 for command
lines to swig and build to look like this:

/dev/shm/build/SimpleITK/Swig/bin/swig -c++ -java -DSWIGWORDSIZE64 test.i
g++ test_wrap.cxx -o test_wrap.o -I/usr/lib/jvm/java/include -I/usr/lib/jvm/java/include/linux

And this seems to work across platforms and for all the languages I wrap for.

Now for Java, on some platforms the Java type is "long" while others it's BigInteger. So the tests I write for
Java aren't the same. As "Java" long type does not contain the full range of the "unsigned long" type when
64-bits ( which is always how I am using it), this seems a little buggy.

Is there any way I can get consistent translation of this type?

Thanks,
Brad

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
Kurt Werle | 17 Jul 19:42 2014

Beginner swig (ruby?) help

I’m swigging a large C++ library.  My first target language is ruby, and I have noticed that all my method names for a template class have the namespace & classname prepended to them:
➜  build git:(develop) ruby -e "require './ruby/pcl'" -e 'p Pcl::PointCloud_PointXYZ.new.methods'
[:pcl_PointCloud_PointXYZ_Add_To_Self, ... :pcl_PointCloud_PointXYZ_isOrganized, :pcl_PointCloud_PointXYZ_begin... :to_enum, :enum_for, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]

I expect that list to look like:
[:Add_To_Self, ... :isOrganized, :begin... :to_enum, :enum_for, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]

I figure it’s likely that there is something wrong with my .i file[s], and this is not a feature of the ruby swig process, right?
File in question:
Project:

Steps to reproduce (on ubuntu, with many assumptions - you have ruby, python, cmake, and the Point Cloud Library installed):
git clone git <at> github.com:kwerle/pcl-swig.git
cd pcl-swig/build
cmake ..
ruby -e "require './ruby/pcl'" -e 'p Pcl::PointCloud_PointXYZ.new.methods'

Background: 
I’m wrapping the Point Cloud Library (http://pointclouds.org/) so that I can use it in any language other than C++ - which I do not know.
I have coded in C, Obj-C, java, ruby, python, and a few others over the past couple of decades.
I am also not very familiar with swig.
I am picking up this project from someone who initially did the work to swig the PCL -> java, so these .swig files are not my own creation.

Thanks in advance!
Kurt
---
Kurt Werle | Senior Programmer | SolarCity | 805 769-8653 | skype:kwerle | This email contains confidential information

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Chen Xue | 16 Jul 17:21 2014

Swig problem - build a python module

Hi, there,

I will turn C code into Python module and use it in my Python file. The
interface file motorCommon.i is below.

%module motorCommon
 %{
 /* Includes the header in the wrapper code */
 #include "motorCommon.h"
 %}
 %include "cpointer.i"

 /* Parse the header file to generate wrappers */
 %include "motorCommon.h"

 %pointer_functions(int, intp);
 %pointer_functions(double, doublep);

I built as below.

$ swig -python motorCommon.i
$ gcc -c -fPIC motorCommon.c motorCommon_wrap.c -I/usr/include/python2.7
$ ld -shared motorCommon.o motorCommon_wrap.o -o _motorCommon.so

But when I ran python file and used this motorCommon module, I got the
error message.

 def _swig_getattr(self,class_type,name):
TypeError: 'set' object does not support item assignment

Could someone help?

Thanks,

Chen

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
Eric Wing | 13 Jul 12:00 2014
Picon

JavaScript: How do I create a struct instance?

I am hitting some cases where I must create a placeholder struct so I
can pass it into an API that returns a value in it.

So for example:
int SDL_PollEvent(SDL_Event* event);

I need a placeholder struct so the function can fill it with a value.

In the Lua generator, it appears I can do something like:
event = SDL_Event()
SDL_PollEvent(event)

Is there something similar for JavaScript? If not, can you give me any
guidance on where to look/what I need to do to implement this in the
SWIG generator? (I'm looking at JavaScriptCore right now.)

Thanks,
Eric
--

-- 
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/

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

Gmane