Edouard DEBRY | 22 Sep 10:44 2014
Picon

swig 2.0.11 generate code not compiling


Hello,

When moving to swig 2.0.11 I ran into the following error I did not get
before :

/usr/include/c++/4.6/bits/stl_bvector.h:77:5: note:
std::_Bit_reference::_Bit_reference()
/usr/include/c++/4.6/bits/stl_bvector.h:77:5: note:   candidate expects
0 arguments, 1 provided
/usr/include/c++/4.6/bits/stl_bvector.h:74:5: note:
std::_Bit_reference::_Bit_reference(std::_Bit_type*, std::_Bit_type)
/usr/include/c++/4.6/bits/stl_bvector.h:74:5: note:   candidate expects
2 arguments, 1 provided
/usr/include/c++/4.6/bits/stl_bvector.h:69:10: note:
std::_Bit_reference::_Bit_reference(const std::_Bit_reference&)
/usr/include/c++/4.6/bits/stl_bvector.h:69:10: note:   no known
conversion for argument 1 from 'bool' to 'const std::_Bit_reference&'

the line responsible for this error is :

arg3 = static_cast< std::vector< bool,std::allocator< bool >
>::reference >(val3)

val3 is a bool

this error can be isolated and reproduced with one simple program
around this line.
If I change the line in simply : "arg3 = val3" it compiles.

(Continue reading)

Byerley | 19 Sep 23:43 2014
Picon

Problem with Data_Wrap_Struct?

Hi. I have a C++ class and function:

class Bar {
 public:
	int num;
	Bar(int n) {num = n;};
	~Bar() {};
};

Bar spam(Bar a) {
	std::cout << b.num << std::endl;
	a.num *= 2;
	return a;
}

I wrote in and out typemaps just to see how they work.

%typemap(in) Bar {
	printf("typemap in\n");
	Bar *cpp_obj = NULL;
	Data_Get_Struct($input, Bar, cpp_obj);
	$1 = *cpp_obj;
}

%typemap(out) Bar {
	printf("typemap out\n");
	VALUE tmp = Data_Wrap_Struct(SwigClassBar.klass, NULL, NULL, &$1);
	$result = tmp;
}

(Continue reading)

Masato Asou | 19 Sep 02:58 2014
Picon

problem vtkUnstructuredGrid and wrapper function

Hi all,

I am using VTK and SWIG in my application. My class have one method
SetUSG(vtkUnstructuredGrid *) and two overloaded method
SetUSG2(vtkUnstructuredGrid *) and SetUSG2(vtkUnstructuredGrid *, int).
I wrote %typename in my .i file. Then, I can call SetUSG() from
Python. However, I can't call SetUSG2() from Python.

I investigated the A_wrap.cpp with gdb. The wrapper functions
_wrap_A_SetUSG2__SWIG_0() and _wrap_A_SetUSG2__SWIG_1() are converted
the pointer with vtkPythonUtil::GetPointerFromObject(). However,
_warp_A_SetUSG2() isn't convert the pointer. Therefor,
SWIG_ConvertPtr() was failed, that called from function
_wap_A_SetUSG2().

Does anyone have solutions?

The errors were occurred is as follows:

$ cat check.py 
import vtk
import A
a = A.A()
usg = vtk.vtkUnstructuredGrid()
a.SetUSG(usg)
a.SetUSG2(usg)
$ python check.py
Traceback (most recent call last):
  File "check.py", line 6, in <module>
    a.SetUSG2(usg)
(Continue reading)

Byerley | 19 Sep 02:12 2014
Picon

Geting the dimensions of 2D arrays in typemap(Ruby)

Hi, I'm trying to pass 2D array from Ruby to a C++ function.

For 1D array of some class Cls, I wrote a typemap:

%typemap(in) Cls *arr {
	int size = RARRAY_LEN($input);
	$1 = (Cls *)malloc(sizeof(Cls) * size);
	for (int i = 0; i < size; i++) {
		VALUE rb_obj = rb_ary_entry($input, i);
		Cls *cpp_obj = NULL;
		Data_Get_Struct(rb_obj, Cls, cpp_obj);
		$1[i] = *cpp_obj;
	}
}

And it was successful.
So, for 2D arrays, I wrote,

%typemap(in) Cls **arr {
	int rowSize = RARRAY_LEN($input);
	int colSize = RARRAY_LEN($input[0]);
	...
}

However, the swig gave me the error message, saying
"invalid types ‘long unsigned int[int]’ for array subscript"
I looks like that $input[0] has some problem.

How should I fix my code so that I can get the size of 2D array?

(Continue reading)

Kevin Smith | 18 Sep 21:24 2014
Picon

64-bit Integers in R?

I am wrapping some functions for use in R that return 'long long' values.  However, in the file that is
generated, it looks like they all get cast to 'long' before being converted to R values.  Is it possible to
get 'long long' values returned? 

Kevin D Smith
Kevin.Smith <at> sas.com

------------------------------------------------------------------------------
Slashdot TV.  Video for Nerds.  Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
Alexey Sokolov | 18 Sep 17:31 2014

Re: Use function pointer

[returning swig-user mailing list]

http://stackoverflow.com/a/12574407

2014-09-18 15:45 GMT+01:00 Mikael Plouhinec <miplouhinec <at> sqli.com>:
Thanks for your reply.

I understand that my problem is a c++ only problem and not a swig problem.

I'm sorry but I'm newbie in C++. Could you send me an example of what you tell me? I don't understand what I have to do in order to correct my problem.

Thanks a lot.

Mikaël PLOUHINEC

2014-09-18 16:08 GMT+02:00 Alexey Sokolov <alexey <at> asokolov.org>:
You declared global variable CptlManager::OnButtonPushPtl, but didn't
define it in .cpp
Every declared symbol, be it function, or global variable, or
whatever, needs to be defined somewhere.
Also c++filt can show you what exactly you forgot to define:

$ c++filt _ZN11CptlManager15OnButtonPushPtlE
CptlManager::OnButtonPushPtl


2014-09-18 13:28 GMT+01:00 Mikael Plouhinec <miplouhinec <at> sqli.com>:
> Hello,
>
> I have the following problem. I have a c++ class which have a pointer
> function.
>
> When I want to try to load my module, I have the following error :
> undefined symbol : _ZN11CptlManager15OnButtonPushPtlE
>
> Can someone help me? Do I have some syntax mistake? Do I have to write
> something in my .i file?
>
> Thanks a lot.
>
> Mikaël PLOUHINEC
>
>
> PtlManager.h :
>
>
>
> ------------------------------------------------------------------------------
> Want excitement?
> Manually upgrade your production database.
> When you want reliability, choose Perforce
> Perforce version control. Predictably reliable.
> http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
> _______________________________________________
> Swig-user mailing list
> Swig-user <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/swig-user
>


------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Mikael Plouhinec | 18 Sep 14:28 2014

Use function pointer

Hello,

I have the following problem. I have a c++ class which have a pointer function. 

When I want to try to load my module, I have the following error : 
undefined symbol : _ZN11CptlManager15OnButtonPushPtlE

Can someone help me? Do I have some syntax mistake? Do I have to write something in my .i file?

Thanks a lot.

Mikaël PLOUHINEC


PtlManager.h : 


/*
PtlManager.i
*/
/*
%module PtlManager
%{
#include "PtlManager.h"
%}
extern bool InitPtl();
extern bool SetupPtl(int PtlID, int PtlAddr);
extern bool LightPtl(int PtlID, int PtlAddr, int Color, bool Blink);
extern void RegisterOnPushButtonListener(void (*callback)(int, int));
*/
/*
swig interface
*/

%module(director="1") PtlManager
%{
#include "PtlManager.h"
%}

%feature("director");

%include "PtlManager.h"

Attachment (PtlManager.cpp): text/x-c++src, 5317 bytes
Attachment (PtlManager.h): text/x-chdr, 1033 bytes

import PtlManager

manager = PtlManager.CPtlManager();
val = manager.SetupPtl(1,1574)

print val
------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Witold E Wolski | 18 Sep 11:29 2014
Picon

How to find out which version of swig I am using?

running swig --help does not give me a hint which version of swig I am
acutally using.

scanning the possible parameters also does not give me any equivalent
of --version.

regards

--

-- 
Witold Eryk Wolski

------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
Byerley | 18 Sep 00:21 2014
Picon

Passing Ruby Array to C++ Func. as std::list *

Hi.

Suppose I have a C++ class and two functions which look like the following.

class Cls {
    public:
        int num;
        Cls(int n) {num = n;};
        ~Cls() {};
}

void showList(std::list<Cls> li) {
    for (std::list<Cls>::iterator it = li.begin(); it != li.end(); it++)
        std::cout << (*it).num << std::endl;
}

void showListPtr(std::list<Cls> *li) {
    for (std::list<Cls>::iterator it = li->begin(); it != li->end(); it++)
        std::cout << (*it).num << std::endl;
}

The difference is that the second function receives a pointer to the list
instead of the list itself.

For the first function, I wrote a typemap like below, and it worked fine.

%typemap(in) std::list<Cls> {
	int size = RARRAY_LEN($input);
	std::list<Cls> list;
	for (int i = 0; i < size; i++) {
		VALUE r_obj = rb_ary_entry($input, i);
		Cls *cpp_obj = NULL;
		Data_Get_Struct(r_obj, Cls, cpp_obj);
		list.push_back(*cpp_obj);
	}
	$1 = list;
 }

And for the second function, I changed only the first and last part of this
typemap.
Instead of writing
"%typemap(in) std::list<Cls>" and
"$1 = list",
I wrote
"%typemap(in) std::list<Cls> *" and
"$1 = &list".

I thought this would go fine, but for some reason, it didn't.
When the second function is called, it always shows the first value
correctly, 
but the second value is some random value, and then the program is aborted.

By the way, from Ruby, I called these two functions like below.

arr = []
for i in (0...10)
  arr << Example::Cls.new(i)
end

Example::showList(arr)
Example::showListPtr(arr)

Because everything is basically treated as pointers in Ruby, I thought this
was the right way to call these functions.
But is this why this thing is not going well?
Or is there any other reason that I fail?
Anybody have an idea?

--
View this message in context: http://swig.10945.n7.nabble.com/Passing-Ruby-Array-to-C-Func-as-std-list-tp13985.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
Witold E Wolski | 17 Sep 15:28 2014
Picon

swig %shared_ptr and namespace?

I am trying to get swig working with namespaces.

I have some Cpp code (attached which I can wrap with and compile)
which wraps cleanely without namespace.

By adding a namespace to the .h and .cpp file and update the *.i file
what I think is accordingly
swig produces the following error:
example_wrap.cxx(946): error C2065: 'smartarg1' : undeclared identifier

Furthermore, also the
%shared_ptr declarations seem to break despite including "using namespace"

in the header include section.
%{
#include <boost/shared_ptr.hpp>
#include "example.h"
using namespace example;
%}

A possible solution I thought of is to #define the namespaces "away"
in the headers I am trying to wrap, but what I would like to prefer to
avoid.

regards
Witold

-- 
Witold Eryk Wolski
/* File: example.i */
%module(directors="1") SwigTestWrappers

%{
#include <boost/shared_ptr.hpp>
#include "example.h"
//using namespace example;
%}


%include <boost_shared_ptr.i>
%include <std_vector.i>

%shared_ptr(MyClass)
//typedef boost::shared_ptr<MyClass> MyClassPtr;

%template(MyClassPtrVec) std::vector< boost::shared_ptr<MyClass> >;
%shared_ptr(MyClassPtrVec)
typedef boost::shared_ptr<MyClassPtrVec> MyClassPtrVecPtr;

%include "example.h"



%pragma(java) jniclasscode=%{
  static {
    try {
        System.loadLibrary("IDSuEyeSWIG");
        
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load. \n" + e);
      System.exit(1);
    }
  }
%}
Attachment (example.cpp): text/x-c++src, 1134 bytes
Attachment (example.h): text/x-chdr, 745 bytes
------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Witold E Wolski | 17 Sep 12:56 2014
Picon

shared_ptr of std::vector of shared_ptr with typedefs.

Thank you Chris,

A follow up question...

I have code looking like this:

example.h
#include <boost/shared_ptr.hpp>
#include <vector>

struct MyClass {
    virtual int doSomething() = 0;
    virtual ~MyClass() {};
};

typedef boost::shared_ptr<MyClass> MyClassPtr;
typedef std::vector<MyClassPtr> MyClassPtrVec;
typedef boost::shared_ptr<MyClassPtrVec> MyClassPtrVecPtr;

in the .i file I need to place something like this to get it working in java:
%shared_ptr(MyClass)
%template(MyClassPtrVec) std::vector< boost::shared_ptr<MyClass> >;
%shared_ptr(MyClassPtrVec)

Problem is:

1) that the classes generated in java are actully
MyClass
and MyClassPtrVec

while, what I acutlly want to wrap are :
MyClassPtr, MyClassPtrVecPtr

2)
instaed of writing
%template(MyClassPtrVec) std::vector< boost::shared_ptr<MyClass> >;

I would prefer to use the MyClassPtr typedef, i.e. write (if I have to write it)
%template(MyClassPtrVec) std::vector< MyClassPtr >;

So I think the question boils down to: can I give
%shared_ptr(MyClass)
a name such as MyClassPtr.

regards

On 17 September 2014 12:45, Kris Lamb <lamb.kris <at> gmail.com> wrote:
> Because shared_ptr is a template there isn't really a way around it, the
> solution you are using seems adequate.
>
> Without telling swig about the template it won't know what types to wrap.
>
> I suppose if this becomes a pain because you have a lot of these classes you
> might want to write a script to export all your use cases of shared_ptr.
>
> On Sep 17, 2014 5:54 AM, "Witold E Wolski" <wewolski <at> gmail.com> wrote:
>>
>> Hi,
>>
>> I have an C++ API which looks like
>> has a lot of:
>>
>> typedef boost::shared_ptr<MyClass> MyClassPtr;
>> declared in it (see example below)
>> Not sure, but it seems that for each such typedef I do need to write
>> an equivalent
>>
>> %include <boost_shared_ptr.i>
>> %shared_ptr(MyClass)
>> ....
>>
>> into the I file. If I don't do it Swig seems not to know what the
>> MyClassPtr is.
>> Furthermore, AFAIsee the java code generated for the sample files (h
>> and i) below seems to work, but could someone with better
>> understanding of swig confirm that all is OK please?
>>
>>
>> /*example.h*/
>> #include <boost/shared_ptr.hpp>
>>
>> struct MyClass {
>>     virtual int doSomething() = 0;
>>     virtual ~MyClass() {};
>> };
>>
>> typedef boost::shared_ptr<MyClass> MyClassPtr;
>>
>> struct MyClassProducer {
>>     MyClassProducer();
>>     MyClassPtr produceMyClass();
>>
>> private:
>>     struct Private;
>>     boost::shared_ptr<Private> pimpl;
>> };
>>
>>
>> /* File: example.i */
>>
>> %module(directors="1") SwigTestWrappers
>>
>>
>> %{
>> #include "example.h"
>> %}
>>
>> %include <boost_shared_ptr.i>
>> %shared_ptr(MyClass)
>>
>>
>> %include "example.h"
>>
>> /*example.cpp*/
>> #include "example.h"
>> #include <boost/make_shared.hpp>
>>
>> struct MyBlass : MyClass {
>>
>>     int doSomething() {
>>         return 1;
>>     }
>> };
>>
>>
>> struct MyClassProducer::Private {
>> };
>>
>> MyClassProducer::MyClassProducer() : pimpl(boost::make_shared<
>> MyClassProducer::Private>()) {
>>
>> }
>>
>> MyClassPtr MyClassProducer::produceMyClass() {
>>     return boost::make_shared<MyBlass>();
>> }
>>
>>
>>
>>
>>
>> --
>> Witold Eryk Wolski
>>
>>
>> ------------------------------------------------------------------------------
>> Want excitement?
>> Manually upgrade your production database.
>> When you want reliability, choose Perforce
>> Perforce version control. Predictably reliable.
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Swig-user mailing list
>> Swig-user <at> lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/swig-user

--

-- 
Witold Eryk Wolski

------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk

Gmane