Christian Boltz | 26 Jul 22:12 2016
X-Face
Picon

Problem with python bindings

Hello,

I'm one of the AppArmor developers, and we are using swig to provide 
python bindings for libapparmor.

Unfortunately this broke since openSUSE Tumbleweed upgraded from swig 
3.8.8 to 3.0.10:

===========================
root# aa-logprof 
Traceback (most recent call last):
  File "/usr/lib64/python3.5/site-packages/LibAppArmor/__init__.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "/usr/lib64/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named '_LibAppArmor'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/sbin/aa-logprof", line 18, in <module>
    import apparmor.aa as apparmor
  File "/usr/lib/python3.5/site-packages/apparmor/aa.py", line 29, in <module>
    import apparmor.logparser
  File "/usr/lib/python3.5/site-packages/apparmor/logparser.py", line 19, in <module>
    import LibAppArmor
  File "/usr/lib64/python3.5/site-packages/LibAppArmor/__init__.py", line 21, in <module>
(Continue reading)

Akira | 18 Jul 13:52 2016
Picon
Picon

$ operator in R

Hi,

I am wrapping C++ into R with SWIG.
I have a class that inherits from two other classes.

Class child : public parent_one, parent_two
{
    void child_function();
}

class parent_one
{
    void parent_one_func()
}

class parent_two
{
    void parent_two_func()
}

If child_instance is an instance of the child class, then in R I have the
following:

> is(child_instance)
[1] "_p_child_instance"
[2] "_p_parent_one"
[3] "_p_parent_two"
[4] "C++Reference"
[5] "ExternalReference"

(Continue reading)

Jonathan Stoikovitch | 13 Jul 23:47 2016

SWIG == magic?

Hi All,

First of all, thanks to the contributors for supporting the SWIG community. Disclosure: I'm a SWIG pre-newbie (haven't used it yet).

I'm considering using SWIG to generate the bindings to a purpose-built c++ parser for (at least) python, ruby, golang, java and javascript. The parser would be relying heavily on yaml-cpp to parse a yaml file with specific properties.

What I'm wondering is:
1) is this the right approach vs the alternative which would to write parsers in each target language?
2) why aren't more people designing parsers this way? am I missing something? is this harder than I think? 

Voilà for now.

Thanks,
Jonathan

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Bernardo Frankenfeld | 13 Jul 20:32 2016
Picon

Question about %interface for java

Hello,

I've posted a stack overflow question on the topic, can anyone help me?


copying the content of the question below:


I'm having a problem while wrapping a huge C++ code to JAVA using SWIG.

What I'm trying to do is wrap a Derived class that extends 2 other classes in C++, but one of the classes (Base1 on the example bellow), should be wrapped as an interface. (To account for Java not having multiple inheritance).

I've found the problem and created a simple c++ code that demonstrate the problem:

namespace Space { class Base1 { public: virtual void Method1() = 0; }; class Base2 { public: virtual void Method2(); }; class Derived : public Base1, public Base2 { public: virtual void Method1(); }; }

The code above represents what I want to wrap in JAVA.

When I run Swig on the above example, it creates Base1 as an Interface (as it should)

public interface Base1 { long Base1_GetInterfaceCPtr(); void Method1(); }

And declares (in JAVA) the derived class extending Base2 and implementing Base1 (as it also should), BUT , it DOES NOT create a java method inside the Derived class that implements the interface Base1 ( Method1 inside Derived) the full Derived Java class generated is as follows:

public class Derived extends Base2 implements Base1 { private transient long swigCPtr; protected Derived(long cPtr, boolean cMemoryOwn) { super(SOURCEIJNI.Derived_SWIGUpcast(cPtr), cMemoryOwn); swigCPtr = cPtr; } protected static long getCPtr(Derived obj) { return (obj == null) ? 0 : obj.swigCPtr; } protected void finalize() { delete(); } public synchronized void delete() { if (swigCPtr != 0) { if (swigCMemOwn) { swigCMemOwn = false; SOURCEIJNI.delete_Derived(swigCPtr); } swigCPtr = 0; } super.delete(); } public long Base1_GetInterfaceCPtr() { return SOURCEIJNI.Derived_Base1_GetInterfaceCPtr(swigCPtr); } public Derived() { this(SOURCEIJNI.new_Derived(), true); } }

And so, Im stuck with a Java compilation error of a SWIG generated class (Derived) that does not implement all methods of its interface (Base1)

What am I missing? I've read the documentation and should work...

My ".i" file: (using swig 3.0.10)

%module SOURCEI %include <swiginterface.i> %interface_impl(Space::Base1); %{ #include "Source.h" %} %include "Source.h"


Thank you
Bernardo
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Matěj Cepl | 11 Jul 09:00 2016
Picon
Gravatar

Pre-generated SWIG sources

Hi,

I am trying to revive M2Crypto, which is a Python SWIG-based bindings
for OpenSSL. The main purpose of the maintenance is to support legacy
applications which still use M2Crypto (and there is surprising number of
them), so it is a problem that I currently cannot build M2Crypto on
RHEL-6 (not even mentioning RHEL-5), because it has only swig 1.*. Would
it be possible to pre-generate *.c files on a modern platform with a
more recent SWIG and then package and ship them in tarball? Is there
some support for it it in distutils and python distutils?

Thank you in advance for any replies,

Matěj

-- 
https://matej.ceplovi.cz/blog/, Jabber: mcepl <at> ceplovi.cz
GPG Finger: 3C76 A027 CA45 AD70 98B5  BC1D 7920 5802 880B C9D8

He can compress the most words into the smallest idea of any man
I know.
      -- Abraham Lincoln

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Alex Szakál | 4 Jul 17:56 2016
Picon

Scilab multiple (>3) matrix argument question

Hi SWIG experts!

I ran into a problem that I can't solve while interfacing Scilab with C. Please help!
I want to pass more than two matrices to a C function from Scilab. My example function for two matrices:


///// WORKING EXAMPLE WITH 2 ARGUMENTS //////
%module addMx

%include <matrix.i>

%apply (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (double *matrix, int matrixNbRow, int matrixNbCol) };
%apply (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (double *mx2,    int mx2NbRow,    int mx2NbCol   ) };
%apply (double **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) { (double **outMatrix, int *outMatrixNbRow, int *outMatrixNbCol) };

%inline %{

void addMx(double *matrix, int matrixNbRow, int matrixNbCol,
double *mx2,    int mx2NbRow,    int mx2NbCol,
double **outMatrix, int *outMatrixNbRow, int *outMatrixNbCol) {
  
int i, j;
*outMatrixNbRow = matrixNbRow;
*outMatrixNbCol = matrixNbCol;
*outMatrix = malloc(matrixNbRow * matrixNbCol * sizeof(double));
for (i=0; i < matrixNbRow * matrixNbCol; i++) {
outMatrix[i] = matrix[i] + mx2[i];
}
}

%}

///// END NOT WORKING EXAMPLE WITH 3 ARGUMENTS /////

If I add one more input matrix I get an error message from scilab that the function needs only two arguments. The example file:

///// NOT WORKING EXAMPLE WITH 3 ARGUMENTS /////
%module addMx3

%include <matrix.i>

%apply (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (double *matrix, int matrixNbRow, int matrixNbCol) };
%apply (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (double *mx2,    int mx2NbRow,    int mx2NbCol   ) };
%apply (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (double *mx3,    int mx3NbRow,    int mx3NbCol   ) };
%apply (double **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) { (double **outMatrix, int *outMatrixNbRow, int *outMatrixNbCol) };

%inline %{

void addMx3(double *matrix, int matrixNbRow, int matrixNbCol,
double *mx2,    int mx2NbRow,    int mx2NbCol,  
double *mx3,    int mx3NbRow,    int mx3NbCol,
double **outMatrix, int *outMatrixNbRow, int *outMatrixNbCol) {
  
int i, j;
*outMatrixNbRow = matrixNbRow;
*outMatrixNbCol = matrixNbCol;
*outMatrix = malloc(matrixNbRow * matrixNbCol * sizeof(double));
for (i=0; i < matrixNbRow*matrixNbCol; i++) {
(*outMatrix)[i] = matrix[i] + mx2[i] + mx3[i];
}
}

%}
//////////////////////////// END NOT WORKING EXAMPLE WITH 3 ARGUMENTS /////////////////////////////////

Many thanks if you could help!
Best regards,
Alex Szakál
------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Jimi Damon | 1 Jul 00:45 2016
Gravatar

Problems getting SWIG to make %array_class methods show up in the correct Java package.

Hi,

I have a top level module called Foo;

%module Foo

%array_class(double,doublearray)


I want to use %array_class () to create an array of doubles.  The problem I have is that the methods do not show up inside of my java package  Foo;  

Instead what I keep seeing when compiling is error: type doublearray is not a member of object Foo (for the code )

/* Inside sample.java */
import Foo.*;

doublearray ary = new Foo.doublearray(10) ;  // Fails
// or
doublearray ary = new doublearray(10) ; //succeeds


My code instead has to refer to the doublearray without the Foo.  prefix. I would prefer to require the namespace Foo
 in order to access this doublearray type so it doesn't pollute the main program namespace.

I tried experimenting with %nspace(Foo) before the definition of %array_class(double,doublearray) but this had no effect.

Thanks for any suggestions on how to fix this.

-Jimi






WARNING - This e-mail or its attachments may contain controlled technical data or controlled technology within the definition of the International Traffic in Arms Regulations (ITAR) or Export Administration Regulations (EAR), and are subject to the export control laws of the U.S. Government. Transfer of this data or technology by any means to a foreign person, whether in the United States or abroad, without an export license or other approval from the U.S. Government, is prohibited. The information contained in this document is CONFIDENTIAL and property of ACCES I/O Products, Inc. Any unauthorized review, use, disclosure or distribution is prohibited without express written consent of ACCES I/O Products, Inc. If you are not the intended recipient, please contact the sender and destroy all copies of the original message and enclosed attachments.
------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Andrea Bianco | 29 Jun 10:48 2016
Picon
Picon

Integration between C++ cmake and python (and google tests)

Dear All,

first of all, hello to everyone. I like a lot the idea behind Swig and thanks to the developer of this fantastic project.
I am trying to produce some python swig interfaces from a C++ project using Cmake. I have a problem that I was not able to solve, even googling around quite a lot :)

my directory structure is:
——
cmake/Modules/
ext/
include/
pythonSwig/
src/
test/
CMakeLists.txt

the CMakeLists.txt file is pasted here http://pastebin.com/4fhhfgbF 

and the DMMaker.i file under the directory pythonSwig/ is 

%module DMMaker %include "std_string.i" %{ #include "DMMaker.h" %} %include "DMMaker.h"
everything compiles, but when I try to import the DMMaker class (defined in DMMaker.h, that include  LpList.h):

>>> import DMMaker
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "DMMaker.py", line 28, in <module>
    _DMMaker = swig_import_helper()
  File "DMMaker.py", line 24, in swig_import_helper
    _mod = imp.load_module('_DMMaker', fp, pathname, description)
ImportError: ./_DMMaker.so: undefined symbol: _ZTI6LpList

I also tried to add the line

set_source_files_properties(${SWIG_PROJECTS_DIR}/DMMaker.i PROPERTIES SWIG_FLAG “-importall”)

to the CMakeLists file, but it doesn’t work.

Any suggestion or documentation related to this issue are more than welcome!

Andrea
--
------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
RAVI NANJUNDAPPA | 22 Jun 15:33 2016

Generating doxygen comments for swig-generated C# that wraps C++

Hi All, 

Is it possible to carry-forward the doxygen comments present in C++ code (.h files for classes and methods)
to swig-generated C# bindings ? 

Thanks and Best Regards, 
N Ravi
------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
Akira | 21 Jun 10:41 2016
Picon
Picon

[C++ to R] SWIG objects into lists

Hi,

I wrapped a C++ library to R.
I noticed I cannot add the wrapped C++ classes into lists...
I guess this is because of the copying policy (SWIG uses SEXP and therefore
the objects have a different copying policy. This is of course great on the
one hand, because we normally do not want to copy the C++ object everytime
we give it to a function, but probably not good on the other hand since R
seems to insist on copying if you add the objects to a list).

I will make clear what I mean with an example:

I created an instance of a wrapped C++ class in R

> test = WrappedClass()
> test
An object of class "_p_WrappedClass"
Slot "ref":
<pointer: 0x5fa4440>

If I give this instance to a function an change it, the changes will be made
on the original object (This is exactly what I want).

But if I want to put this object into a list the following happens:

> list(test)
[[1]]
Error in (function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘addNextMethod’ for
signature ‘"function"’

I guess, as descripted above, that he tries to copy it and fails...
So is there any possibility to create objects that can be added to lists?
SWIG creates S4 classes. Would my goal be for example achievable with R6
classes?
And if so, can I create them with SWIG?

Thanks in advance and best regards!
Akira

--
View this message in context: http://swig.10945.n7.nabble.com/C-to-R-SWIG-objects-into-lists-tp14805.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Jake | 15 Jun 18:52 2016
Picon

Enabling swig::from when needed by custom templated types

I'm trying to wrap some code which includes a custom vector type, let's call it MyVector, 
that is more or less like std::array (templated on size and element type) with a bunch of 
additional operations.  It doesn't conform to the sequence format that would let, e.g. 
traits_from_stdseq in pycontainer.swg to apply (I also don't know how I would make it 
apply if it did), but I took some inspiration from there and tried to write a macro:

%define %MyVector_sequence(size, type)
#ifdef SWIGPYTHON
%typemap(out) MyVector<size, type> {
  PyObject *obj = PyTuple_New((Py_ssize_t)size);
  for (decltype(size) i = 0; i < size; ++i) {
    PyTuple_SetItem(obj, i, swig::from<type>($1[i]));
  }
  $result = obj;
}
#endif
%enddef

With a use such as:

%template(MyVector2c)  MyVector<2, char>;
%MyVector_sequence(2, char);

This produces the error:

'type_name' : is not a member of 'swig::traits<char>'

Now, if this appears elsewhere in a used .i file:

%include "std_vector.i"

namespace std {
  %template(CharVector) vector<char>;
}

Then the traits< char >, traits_asval< char > and traits_from< char > specializations
are generated and swig::from<char> compiles.

So, my main question is what causes this registration and how would I trigger it?  
Secondarily, I wonder if it can be triggered automatically based on the template 
instantiation without using an extra macro for each?  Is it possible to do this 
without modifying the original C++ header or repeating its information?

-Jake Cobb
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports. http://pubads.g.doubleclick.net/gampad/clk?id=1444514421&iu=/41014381
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

Gmane