Masato Asou | 18 Sep 11:54 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)

mgundes | 29 Sep 10:35 2014
Picon

ULONG definition error even interface includes windows.i

Hello,

I have a c++ dynamic library and want to use this library with java by wrapping. I checked example/nested codes and used base to my test, however I got error about ULONG definition. There is definition in windows.i file but somehow VisualStudio complain abut ULONG definition. I have a structure includes ULONG.

I added include path to swig command line and see in log like this:

        D:\work\swigwin-3.0.2\swig -c++ -java -ID:\work\swigwin-3.0.2\Lib -ID:\work\swigwin-3.0.2\Lib\java -o example_wrap.cxx d:\work\swigworks\nested\nested\example.i

example.i is like this:

      %module example

      %include <std_string.i>
      %include <windows.i>

      %{
      #include "example.h"
      %}


What can be problem, any guess?

By the way I could not reach archive in link on site:


Regards,
Thanks.

--
Mahmut Gündeş
------------------------------------------------------------------------------
Slashdot TV.  Videos for Nerds.  Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Byerley | 28 Sep 15:39 2014
Picon

** Pointer to a Pointer in typemap(in) (Ruby)

Hi, I have a C++ function which receives a pointer to a pointer to an
instance of a class named Cls.

void test(Cls **dblPtr) {
    *dblPtr = new Cls(...);  // constructor is properly defined.
}

If I call this function from C++, what's ptr is pointing to is gonna be
different.

Cls *ptr = new Cls(...);
test(&ptr);
// *ptr has changed

To do the same thing in Ruby, I wrote a typemap(in) for this function.

%typemap(in) Cls** dblPtr (Cls *cpp_ptr) {
	Data_Get_Struct($input, Cls, cpp_ptr);
	$1 = &cpp_ptr;
}

I thought this would work, but when I checked it, the instances before and
after the call were the same.

How should I fix my code?
Thanks.

--
View this message in context: http://swig.10945.n7.nabble.com/Pointer-to-a-Pointer-in-typemap-in-Ruby-tp14016.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
allanmulin | 26 Sep 12:16 2014
Picon

Certain trailing return types fail to parse

The following trailing return type usage cannot be parsed be `swig 3.0.2`. example.hpp

#pragma once struct Hello { auto output() -> Hello&; }; example.cpp #include "example.hpp" #include <iostream> auto Hello::output() -> Hello& { std::cout << "Hello" << std::endl; return *this; } example.i %module example %{ #include "example.hpp" %} %include "example.hpp" This code causes the following error with swig: `Error: Syntax error in input(3).`, where the error line is `auto output() -> Hello&;`. If instead I write `Hello& output();`, then no errors occur.
View this message in context: Certain trailing return types fail to parse
Sent from the swig-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Byerley | 26 Sep 11:41 2014
Picon

INOUT and strict-aliasing problem (Ruby)

Hi, I'm trying to use INOUT in my *.i file.

Looking at the manual, I found a sample function to which INOUT is applied.
(void negate found on this page ->
http://swig.org/Doc1.3/Ruby.html#Ruby_nn32)

So I copied this function to bar.cpp and wrote its declaration in bar.h.
And I wrote my *.i file like the following.

%module spam
%{
#include "bar.h"
%}
%include "typemaps.i";
void negate(int *INOUT);
%include "bar.h";

I think this is exactly what the manual is doing, but for some reason, if I
run swig, it gives me a warning which says, "dereferencing pointer arg1.188
does break strict-aliasing rules."
My question is,
1. What does this warning mean?
2. What is wrong with my code?

Thanks

--
View this message in context: http://swig.10945.n7.nabble.com/INOUT-and-strict-aliasing-problem-Ruby-tp14013.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
Byerley | 26 Sep 06:40 2014
Picon

Returning a reference for Ruby

Hi, I have a C++ class which has a method that returns a reference to an int
variable.

class Cls {
  private:
    int num[5];
  public:
    int& get(int i);
    ...
};

int& Cls::get(int i) {
    return num[i];
}

In C++, I can do the following.

    Cls* cls = new Cls();    // initializes num[5] in some way
    cls->get(2) = 100;    // num[2] is now a different number

However, I cannnot do the same thing in Ruby.

Is it possible to solve this problem by writing typemap or something?
If so, how?

--
View this message in context: http://swig.10945.n7.nabble.com/Returning-a-reference-for-Ruby-tp14012.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
David Brumley | 24 Sep 12:30 2014
Picon

Problems interacting with 3rd party library

Hi,
I'm trying to get a python binding for a 3rd party linux library. The default function I'm starting with has prototype defined in /usr/include/libcgcef/libcgcef.h:

extern CGCEf *cgcef_begin __P((int __fd, CGCEf_Cmd __cmd, CGCEf *__ref));

The symbol appears to be defined in the text section (if I'm reading nm right)  in libcgcef.a (and in libcgcef.so):
$ nm /usr/lib/libcgcef.a | grep cgcef_begin
00000290 T cgcef_begin
         U cgcef_begin


I tried the "truly lazy" solution of:
%module libcgcef
%{
#include <libcgcef/libcgcef.h>
%}

%include "/usr/include/libcgcef/libcgcef.h"

However, it ends up with all zero-argument functions. Inside libcgcef_wrap.c I see:
4355   result = (CGCEf *)cgcef_begin();

This is likely due to some macro expansion; the header libcgcef has the following preamble:
#ifndef __P
# if (__STDC__ + 0) || defined(__cplusplus) || defined(_WIN32)
#  define __P(args) args
# else /* __STDC__ || defined(__cplusplus) */
#  define __P(args) ()
# endif /* __STDC__ || defined(__cplusplus) */
#endif /* __P */

gcc -E does the correct macro expansion by default (I guess because it defines __STDC__; I don't know what the +0 does).

Since this didn't work, I tried adding a manual declaration:
%module libcgcef
%{
#include <libcgcef/libcgcef.h>
%}

extern CGCEf *cgcef_begin(int __fd, CGCEf_Cmd __cmd, CGCEf *__ref);

and then:
$ swig -python libcgcef.i
$ gcc -c libcgcef_wrap.c -I/usr/include/python2.7/
$ ld -shared /usr/lib/libcgcef.a libcgcef_wrap.o -o _libcgcef.o

This is good. everything compiles. But I'm missing the symbols from libcgcef.a:

$ python
Python 2.7.3 (default, Mar 14 2014, 11:57:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import libcgcef
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "libcgcef.py", line 26, in <module>
    _libcgcef = swig_import_helper()
  File "libcgcef.py", line 22, in swig_import_helper
    _mod = imp.load_module('_libcgcef', fp, pathname, description)
ImportError: ./_libcgcef.so: undefined symbol: cgcef_begin

So clearly the symbol from the archive file isn't getting linked in. This is confirmed with nm:
$ nm -A _libcgcef.o  | grep cgcef_begin
_libcgcef.o:00004a1d t _wrap_cgcef_begin
_libcgcef.o:         U cgcef_begin

What am I doing wrong to get the library symbol to resolve inside the python swig binding? It seems like it should be obvious, but I can't figure it out.

Many Thanks,
David

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Roland Egger | 24 Sep 12:22 2014
Picon
Picon

problems with more than one input for a typemap

Hello,
I wrote a new model for mathematica and now I'm writing the typmap (mathematica.i) file
 
For one input parameter it's quite easy to use $input e.g.
%typemap(in) (int iNumber)
{
   $1 = MArgument_getInteger($input);
}
=> argn = MArgument_getInteger(Args[n])
Where (n) is the argument position e.g. if a function has only one argument then it's the same as
%typemap(in) (int iNumber)
{
   $1 = MArgument_getInteger(Args[0]);
}
 
Is there something like $input2 if I have something like
%typemap(in) (int* LongVector, int LongVectorSize)
 
For a function with only two parameters it would work
%typemap(in) (int* LongVector, int LongVectorSize)
 
{
   MTensor oLongTensor = MArgument_getMTensor(Args[0]);
   mint iSize = MArgument_getInteger(Args[1]);
...
}
 
But if there a functions with more than two parameters this does not work. So something like $inputN would be interesting.
What could I use therefor?
Kind regards,
  Roland
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
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.

This seems due to the fact that vector<bool> is specialized and that
generic method for vector container
do not always work for boolean

Do you know why swig generates this line, is there a workaround ?

Thanks in advance for your help

Best regards

--

Edouard Debry
Institut National de l'Environnement Industriel et des Risques
Direction des Risques Chroniques
Pôle DECI, Unité MOCA
Parc Technologique ALATA - B.P. N*2
60550 Verneuil en Halatte
Tél. : 03.44.61.82.17
Fax : 03.44.55.68.99
Courriel : Edouard.DEBRY <at> ineris.fr ( mailto:Edouard.DEBRY <at> ineris.fr ) 

"La prévision est difficile surtout lorsqu'elle concerne l'avenir." P.
Dac

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
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;
}

>From Ruby, I called the function spam as follows, expecting that the last
value shown would be 20.

a = ModuleName::Bar.new(10)
b = ModuleName::spam(a)
print b.num

However, it always showed some random value.

What's wrong with my code?
I'm guessing that the problem has something to do with Data_Wrap_Struct.
How am I supposed to use this anyway?
What do the second and the third arguments mean?

--
View this message in context: http://swig.10945.n7.nabble.com/Problem-with-Data-Wrap-Struct-tp14001.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Slashdot TV.  Video for Nerds.  Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
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)
  File "/home/asou/work/investigate/vtkUnstructuredGrid/A.py", line 85, in SetUSG2
    def SetUSG2(self, *args): return _A.A_SetUSG2(self, *args)
NotImplementedError: Wrong number or type of arguments for overloaded function 'A_SetUSG2'.
  Possible C/C++ prototypes are:
    A::SetUSG2(vtkUnstructuredGrid *)
    A::SetUSG2(vtkUnstructuredGrid *,int)

$ 

I attached some simplified codes.

Thanks
--
ASOU Masato
%module A

%{
#include <vtkPythonUtil.h>
#include "A.h"
%}

%typemap(out) vtkUnstructuredGrid* {
    PyImport_ImportModule("vtk");
    $result = vtkPythonUtil::GetObjectFromPointer((vtkUnstructuredGrid*)$1);
}

%typemap(in) vtkUnstructuredGrid* {
    $1 = (vtkUnstructuredGrid*)vtkPythonUtil::GetPointerFromObject($input, "vtkUnstructuredGrid");
    if ($1 == NULL) {SWIG_fail;}
}

%include "A.h"
#include <vtkUnstructuredGrid.h>

class A {
	vtkUnstructuredGrid *usg;
	int dimension;

public:
	A(void)
	{
	}

	~A(void)
	{
	}

	void
	SetUSG(vtkUnstructuredGrid *usg)
	{
		this->usg = usg;
	}

	void
	SetUSG2(vtkUnstructuredGrid *usg)
	{
		this->usg = usg;
	}

	void
	SetUSG2(vtkUnstructuredGrid *usg, int dimension)
	{
		this->usg = usg;
		this->dimension = dimension;
	}

	vtkUnstructuredGrid *
	GetUSG(void)
	{
		return usg;
	}
};
------------------------------------------------------------------------------
Slashdot TV.  Video for Nerds.  Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

Gmane