Don Bigler | 27 Apr 17:15 2015

Can't Ignore Conversion/Cast Operators

I have the following operator in one of my SWIG wrapped classes:

/// cast to an EcReal operator const EcReal ( ) const;


Wrapping to Python generates the following warning:

Users/dbigler/Development/Energid/stable/src/foundCore/ecAngle.h:63: Warning 503: Can't wrap 'operator const EcReal
' unless renamed to a valid identifier.

I can’t seem to find the proper %ignore syntax to silence this warning.  I’ve tried the following:

%ignore EcAngle::operator EcReal;
%ignore EcAngle::operator EcReal();
%ignore EcAngle::operator const EcReal;
%ignore EcAngle::operator const EcReal();
%ignore EcAngle::operator const EcReal() const;

Either there is an error in my %ignore syntax or a bug in the latest SWIG (version 3.0.5).

Regards,
Don Bigler


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
alicana | 27 Apr 14:38 2015
Picon

[JAVA] Need help with typedef function pointer

Hi all! I'm new to swig. I read all the documentation, but, still I could not
convert function pointers. I have an interface (.h) file like below. I do
not know which chapter covers this problem. 

I found  this
example
<http://stackoverflow.com/questions/12210129/how-should-i-write-the-i-file-to-wrap-callbacks-in-java-or-c-sharp/12251183#12251183> 
. But, compiler gives an error:

--
View this message in context: http://swig.10945.n7.nabble.com/JAVA-Need-help-with-typedef-function-pointer-tp14355.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
darkshadow | 24 Apr 21:34 2015
Picon

SWIG/Python Memory Leak in pyfprint library

I am getting : swig/python detected a memory leak of type 'struct fp_img *',
no destructor found.

I checked swig interface file but couldn't find anything that is causing
this.
Here is swig interface file : http://paste.ubuntu.com/10880764/

Any help will be appreciated. My code is :

import pyfprint
pyfprint.fp_init()
devs = pyfprint.discover_devices()
dev = devs[0]
dev.open()
fprint, img = dev.enroll_finger() 

--
View this message in context: http://swig.10945.n7.nabble.com/SWIG-Python-Memory-Leak-in-pyfprint-library-tp14349.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
darkshadow | 24 Apr 21:33 2015
Picon

SWIG/Python Memory Leak in pyfprint library

I am getting : swig/python detected a memory leak of type 'struct fp_img *',
no destructor found.

I checked swig interface file but couldn't find anything that is causing
this. 
Here is swig interface file : http://paste.ubuntu.com/10880764/

Any help will be appreciated. My code is :

import pyfprint
pyfprint.fp_init()
devs = pyfprint.discover_devices()
dev = devs[0]
dev.open()
fprint, img = dev.enroll_finger()

--
View this message in context: http://swig.10945.n7.nabble.com/SWIG-Python-Memory-Leak-in-pyfprint-library-tp14348.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
barmaley | 24 Apr 04:04 2015

Can't make %typemap(javapackage) work on std::vector

Hello, I've followed the advice on "Swig and Java" docs: I'm compiling my code and I'm using templates. I provided a javapackage typemap, but SWIG doesn't generate the right JNI field descriptor. Use the template's renamed name as the argument to the "javapackage" typemap: %typemap(javapackage) std::vector "your.package.here" %template(VectorOfInt) std::vector; , but it doesn't work. I have the interface file which looks like this: %module moduleJava %include "std_vector.i" %include "std_wstring.i" %typemap( javapackage ) std::vector "Package"; %typemap( javapackage ) std::vector "Package"; // Instantiate templates used by example %template(DoubleVector) std::vector ; %template(StringVector) std::vector ; %pragma( java ) jniclasspackage = "Package" %include java_file1.i %include java_file2.i In each of the other interface files that are included, I have objects that are in other namespaces, but all within "Package" namespace, like this: //java_file1.i %{ #include "header.h" %} %nspace Package::OtherPackage::Class; %include "header.h" So every class is getting to the right place, folders are created and package indication is inserted... Except DoubleVector and StringVector - they remain unchanged in global scope and jni signatures are not matching the package. Does the %typemap( javapackage ) std::vector "Package"; work? Or what am I doing wrong here? Thanks

View this message in context: Can't make %typemap(javapackage) work on std::vector
Sent from the swig-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Miloš Jakubíček | 22 Apr 11:43 2015
Picon

new style default arguments handling in SWIG3 and Python

Dear all,

we have hit an issue after switching to SWIG3 and Python related to the way how default arguments are now being treated.
With SWIG2 we have been using the following typemaps to automatically encode and decode unicode strings in Python 2:

%typecheck(SWIG_TYPECHECK_UNISTRING) std::string, char *{
    $1 = (PyString_Check($input) || PyUnicode_Check($input)) ? 1 : 0;
}

%fragment("UniToStr", "header") {
     char * UniToStr (PyObject *obj, PyObject **encString, const char *enc) {
         if (!obj) {
            PyErr_SetString(PyExc_ValueError, "NULL string");
             return NULL;
         }
         if PyUnicode_Check(obj) {
             if (enc[0])
                 *encString = PyUnicode_AsEncodedString(obj, enc, "replace");
             else
                 *encString = PyUnicode_AsEncodedString(obj, "UTF-8", "replace");
             if (!encString)
                return NULL;
             return PyString_AsString(*encString);
         } else {
             return PyString_AsString(obj);

%typemap(in, fragment = "UniToStr") char * (PyObject* encString = NULL) {
    $1 = UniToStr($input, &encString, encoding);
}

This worked well and stopped working with SWIG3 which now for a function with a default argument like this one:

func (const char *str, bool flag, const char *filter = NULL);

generates

def func(self, str, flag, filter=None):
        return _module.func(self, str, flag, filter)

instead of what SWIG2 did:

def func(self, *args):
       return _module.func(self, *args)

...and because the typemap doesn't return true for "None" object, it fails (with the usual "Wrong number or type of arguments for overloaded function" error).

A background reading for the changes is this ticket: https://github.com/swig/swig/issues/327 where William Fulton unfortunately got overvoted as for adding a flag that would disable this change.
I think since this change is backward incompatible it should be documented in a much better way as there might be lot of people hitting this issue (recently e.g. https://github.com/swig/swig/issues/377).
Moreover it seems that this change is largely unfinished work as SWIG3, despite calling always func with 4 arguments, still generates the usual wrapper functions with lot of dead code:

SWIGINTERN PyObject *_wrap_func__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
...
}

SWIGINTERN PyObject *_wrap_func__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
...
}

SWIGINTERN PyObject *_wrap_func(PyObject *self, PyObject *args) {
...
  if (argc == 3) {
...
          return _wrap_func__SWIG_1(self, args);
...
  }
...
  if (argc == 4) {
...
        return _wrap_func__SWIG_0(self, args);
...
  }
}

The whole argc == 3 branch is useless, argc is always 4, and the _wrap_func__SWIG_1 function should not be there then as well of course.

Now the question is:

1) is this the intended behaviour or a bug (in the former case, please please this should be documented -- and the C++ code should not have the dead code)

2) I have modified our typemaps so that they account for None objects as well, is this correct?


%typecheck(SWIG_TYPECHECK_UNISTRING) std::string, char *{
    $1 = (PyString_Check($input) || PyUnicode_Check($input) || $input == Py_None) ? 1 : 0;
}


%fragment("UniToStr", "header") {
    char * UniToStr (PyObject *obj, PyObject **encString, const char *enc) {
        if (!obj) {
            PyErr_SetString(PyExc_ValueError, "UniToStr: NULL pointer passed instead of str, unicode or None object");
            return NULL;
        }
        if (obj == Py_None)
            return NULL;
        if PyUnicode_Check(obj) {
            if (enc[0])
                *encString = PyUnicode_AsEncodedString(obj, enc, "replace");
            else
                *encString = PyUnicode_AsEncodedString(obj, "UTF-8", "replace");
            if (!encString)
                PyErr_SetString(PyExc_ValueError, "UniToStr: Failed to decode Unicode string");
            return PyString_AsString(*encString);
        } else {
            return PyString_AsString(obj);
        }
    }
}

I'm not sure about the exception handling - the function now returns NULL both for None and errors.

With kind regards,
Milos Jakubicek


------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Oleg Shirokikh | 16 Apr 20:44 2015

SWIG, Python packages and Visual Studio

I started to swig existing C++ library with the structure similar to the following:

 

    namespace MainNS

    {

        namespace A

        {

            class Class

            {

                //...

            };

        }

   

        namespace B

        {

            class Class

            {

                //...

            };

        }

   

        //...

    }

 

Everything works as expected, except that I'm having troubles with creating Python package hierarchy. Desired hierarchy would be:

 

    MainNSpack/

    MainNSpack/__init__.py

    MainNSpackage/Apack/

    MainNSpackage/Apack/__init__.py

    MainNSpackage/Apack/Class.py

    MainNSpackage/Bpack/

    MainNSpackage/Bpack/__init__.py

    MainNSpackage/Bpack/Class.py

 

I'm trying to follow the instructions in SWIG Docs here http://www.swig.org/Doc3.0/Python.html#Python_nn72, and it's clear that I must define this dir structure and create __init__ files on my own. Based on the intuition, this should work as follows:

 

    //python_main.i

    %module(package "MainNSPack") MainNSPack

   

    %include python_a.i

    %include pythom_b.i

 

    //python_a.i

    %module(package="MainNSPack.Apack") Apack

    %{

        #include "A/Class.h"

    %}

   

    %include "A/Class.h"

 

    //python_b.i

    %module(package="MainNSPack.Bpack") Bpack

    %{

        #include "B/Class.h"

    %}

   

    %include "B/Class.h"

 

The questions (problems) are the following:

 

1. I've tried to learn how `package` directive works when doing `%module(package="Apack") Class` but it seems to have no effect on generated files

2. When importing say `Class`, Python will look for the binary `_Class` - it's hard coded in initialization code within generated swig python files. Does it mean that I have to have separate binary for each of my classes.

3. If answer to 2) is yes, then how can this be handled with Visual Studio environment? I have a single project which contains all SWIG .i files. If I specify different module names then multiple .py files will be produced. But it produces a single DLL. And it seems that this will not work because multiple py files would try to refer to different binaries...

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Oleg Shirokikh | 16 Apr 18:39 2015

Swig+Java: namespaces and packages

Assume the C++ class structure like this:

 

    namespace MainNS

    {

        namespace A

        {

            class Class

            {

                //...

            };

        }

   

        namespace B

        {

            class Class

            {

                //...

            };

        }

   

        //...

    }

 

I have followed this SWIG docs: http://www.swig.org/Doc3.0/Java.html#Java_namespaces

 

In interface files I define the following to create packages on Java side:

 

    %nspace MainNS::A::Class

    %nspace MainNS::B::Class

 

and then have to use `java` pragma to place the JNI file into "appropriate" place (somewhere where classes can access it - that's the core of the problem, please see below):

 

    %pragma(java) jniclasspackage = "MainNS::A" //or "MainNS::B"

 

Now, everyone from class `MainNS::A::Class` (package `MainNS.A`) can access generated `<modulename>JNI` class.

 

However, namespace `B` ended up in different package `MainNS::B` and `MainNS::B::Class` (package `MainNS.B`) can't access `<modulename>JNI` class.

 

What is the solution for this problem? As far as I understand there is no SWIG option to split the generated JNI class with native function signatures?

 

Another independent but somewhat related question how to achieve above with Python? I’ve seen a syntax “%module(package=”abc”) efg” and I expected this to create a folder with __init__.py file but that was not the case, basically nothing happened for me…

 

It should be pretty easy to organize the packages/namespaces (C#/Java/Python) manually after SWIG is done, but I’m afraid that signatures of native calls will not match (e.g. JNI f-ns names) and would require a lot of manual intrusion, which is obviously undesired – one change on native side and swig command wipes everything out…

 

Please advice! Thanks

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Chris Packham | 16 Apr 10:29 2015
Picon

Returning a new C (pointer to a) structure as an output variable

Hi,

I've been grappling with this for a while and so far no luck. I'm creating some Lua bindings for existing C code.

For the simple types I'm able to take code like this

   int func2(int a, int b, int *out);

And create Lua bindings that behave like this

   > r, v = test.func2(1,2)
   > print(r, v)
   0       3

By default the structure/pointer handling works but it's a little non-Lua

  > require 'test'
  > stc = test.STC()
  > r = test.func1(1, 2, stc)
  > print(r, stc.foo, stc.bar)
  0       1       2

I'd like to be able to do the following

  > require 'test'
  > r, stc = test.func1(1, 2)
  > print(r, stc.foo, stc.bar)
  0       1       2

But I just can't seem to get it to work. Based on a bit of reading I think what I want to do is this

  %apply SWIGTYPE* *OUTPUT {STC *out};

This appears to generate something close to what I'd expect for lua binding if I were doing it manually
except for the assignment of temp3 (and the fact that it's a function scope variable);

  STC *arg3 = (STC *) 0 ;
  STC temp3 ;

  temp3 = (STC)0;
  arg3 = &temp3;
  ...
  lua_pushnumber(L, (lua_Number) result); SWIG_arg++;
  SWIG_NewPointerObj(L,*arg3,SWIGTYPE_STC,1); SWIG_arg++;

I think I probably need to create a custom typemap to allocate memory for the structure but I'm not sure where
to start. Any hints would be appreciated.

Thanks,
Chris

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
Dave | 16 Apr 01:49 2015

Strategy for multiple Ruby versions?

Hi

I've been using swig a while now to generate bindings for Python and now Ruby around my own C library.

I'm at the point where I am creating a ruby gem and need to understand the interactions between the Ruby
version and the generated wrappers. How much does the Ruby version influence the generated wrappers (and Makefile)?

Should I generate the wrappers once and include them in the gem for compilation at install time? 

For example, I want the gem to work on Ruby 1.8, 1.9, 2.0 etc..

Or, should I generated a set of wrappers for each Ruby version and include them all in the gem, figuring out at
install time which ones to use?

Your insights would be welcome!

Cheers
Dave

Sent from my iPhone
------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
anb0483 | 15 Apr 15:17 2015
Picon

Wrapping C++ Code with included OpenCV library to Java

Hello community,

I'm new in SWIG wrapping. I have tried some examples at the homepage, how
the SWIG tool is working. This examples are useful but for my problem not
enough.

I want to wrap a C++ function, with included OpenCV library to Java. How is
this possible?

Is it enough to say within the C++ project in visual studio, that I'm using
a OpenCV library and than i can wrap the project with SWIG? Or is it
something special to notice?

Every answer will be helpful for me!
Thanks Andreas 

--
View this message in context: http://swig.10945.n7.nabble.com/Wrapping-C-Code-with-included-OpenCV-library-to-Java-tp14333.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF

Gmane