Dmitriev K. S. | 21 Oct 22:35 2014
Picon

Currently supported V8 version

Hello,

Could you please tell me, which V8 version is supported in SWIG 3.0.2? 
My compiler refuses to process a simplest generated wrapper with the 
latest V8 headers (3.8); in particular, it complies on undefined 
'v8::String::New(...)' symbols.

Thank you.

Best regards,
Kirill

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
Sergey K. | 21 Oct 14:19 2014
Picon

Loading extra libraries before the wrapped one

Hello,

so I'm writing the Python wrappers to the C library.

What I have is C header with top-level API, shared library (lib_c.so) and its own separate build process for that library. I cannot make any changes to the library - its not my project at all.

The interface file is very simple

%module lib_c
%{
#include "lib_c.h"
%}

%include "lib_c.h"

When I generate the wrappers and compile them, I'll have two Python modules: lib_c and _lib_c. If I try to import lib_c in Python interpreter, it will try immediately to load _lib_c (which is correct behaviour, obviously). The problem here is that before that I must load the original C library lib_c.so (the one that I cannot modify).

I don't have any extra static libraries from lib_c (original C library) to link with. And unfortunately I cannot change that. But running Python like

LD_PRELOAD=lib_c.so python

would solve the problem.

So the question is - is there any possibility to add extra actions to the Python bindings so the original C library would be loaded before my wrappers (_lib_c in the example above)? Of course I could do that manually by creating extra Python modules, but I think that's kind of a weird solution.
--
BR,
Sergey Khentov
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Alexey Neyman | 15 Oct 06:29 2014
Picon
Picon

[PATCH] mention special treatment of _global_* variables

Hi,

 

The documentation on SWIG does not mention that variables starting with _global_ prefix do not have the $argnum suffix appended. This feature is used at least by one open-source project (Subversion); so it probably should be documented.

 

Patch attached.

 

Regards,

Alexey.

commit cc19f6d6502d321073fcf2dcbca08a88921a1cd5
Author: Alexey Neyman <stilor <at> att.net>
Date:   Tue Oct 14 21:25:41 2014 -0700

    Add clarification on _global_ prefix.

diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html
index cba5241..ec833be 100644
--- a/Doc/Manual/Typemaps.html
+++ b/Doc/Manual/Typemaps.html
 <at>  <at>  -2050,6 +2050,10  <at>  <at>  wrap_foo() {
 </pre>
 </div>

+<p>There is an exception: if the variable name starts with the <tt>_global_≤/tt> prefix,
+the argument number is not appended. Such variables can be used throughout the generated
+wrapper function.</p>
+
 <p>
 Some typemaps do not recognize local variables (or they may simply not
 apply). At this time, only typemaps that apply to argument conversion support this (input typemaps such as
the "in" typemap).
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Russell Owen | 14 Oct 22:42 2014

No constructor in SWIG 3, same code works in SWIG 2 (C++ to Python)

We have a class that is not templated, but has a templated constructor. 
With SWIG 2 we simply %templated that constructor and it all worked. 
With SWIG 3.0.2 the Python wrapper raises AttributeError("No constructor 
defined").

Any idea how I can fix my .i file? I have looked through the release 
notes and I don't see a change that would explain this.

Here is a bit of the C++ header file (simplified):

class FootprintSet : public lsst::daf::base::Citizen {
public:
     template <typename ImagePixelT>
     FootprintSet(image::Image<ImagePixelT> const& img,
                  Threshold const& threshold,
                  int const npixMin=1, bool const setPeaks=true);

     FootprintSet(geom::Box2I region);
...

Here is the .i file (which is %imported by another .i file):

%{
#include "lsst/afw/detection/FootprintSet.h"
#include "lsst/afw/table/Source.h"
%}

%import "lsst/afw/table/Source.i"

%shared_ptr(lsst::afw::detection::FootprintSet);

%include "lsst/afw/detection/FootprintSet.h"

%define %footprintSetOperations(PIXEL)
%template(FootprintSet) FootprintSet<PIXEL>;
%template(makeHeavy) makeHeavy<PIXEL,lsst::afw::image::MaskPixel>;
%template(setMask) setMask<lsst::afw::image::MaskPixel>;
%enddef

%extend lsst::afw::detection::FootprintSet {
%footprintSetOperations(boost::uint16_t)
%footprintSetOperations(int)
%footprintSetOperations(float)
%footprintSetOperations(double)
}

}}}

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
Daniele Nicolodi | 14 Oct 14:46 2014
Picon

Implementing Python buffer interface

Hello,

I would like to expose some data generated in a C++ application and
stored in std::vector of base types to Python via the (new style) buffer
interface https://docs.python.org/2.7/c-api/buffer.html

Searching the web I did not come up with any hint on how to do that. I
have very limited experience with SWIG so I don't know how to tackle
this. Can anyone point me in the right direction?

Thank you very much!

Cheers,
Daniele

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
Byerley | 11 Oct 09:50 2014
Picon

combination of template and INOUT

Hi, I'm having trouble dealing with a template function which receives a
pointer to an int variable.
For example, let's say I'm trying to use the following C++ function from
Ruby.

    template<typename T> void Bar(T* var);

If I instantiate this function by specifying that T is int, then I also have
to write

    void Bar(int *INPUT);    //or OUTPUT or INOUT, depending on how you use
it

so that I can pass Fixnum itself, not a pointer to it from Ruby.
However if I put this INPUT thingy *before* I instantiate the function(just
like I do for normal functions), I get

    Expected argument 1 of type int *, but got Fixnum 0 (TypeError)

So I put it *after* the instantiation, but nothing changed.

Is it possible to apply INPUT thingy to a template function?
How can I fix this problem?

Thanks.

--
View this message in context: http://swig.10945.n7.nabble.com/combination-of-template-and-INOUT-tp14031.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://p.sf.net/sfu/Zoho
warptrosse | 10 Oct 00:11 2014
Picon

Fwd: SWIG and Perl5: undefined symbol SWIG_From_long

Hi, I am trying to set a perl subrutine as callback to be called from a C library.
This is my irssi_indicator.i file:

================================
#if defined(SWIGPERL)
%module irssi_indicator
%{
void init_plugin(void);
void close_plugin(void);
void append_source(const char *id, const char *label,
                   const char *server);
void (*status_changed_cb)(long status);
%}

extern void init_plugin(void);
extern void close_plugin(void);
extern void append_source(const char *id, const char *label,
                          const char *server);
%{
static SV* PlCallBack_status_changed_cb=0;
  void _cbwrap_status_changed_cb(long status){
    int argvi = 0;
    SV *sv;

    dSP;
    if(!PlCallBack_status_changed_cb)return ;
    ENTER;
    SAVETMPS;
    PUSHMARK(sp);
    sv = SWIG_From_long  SWIG_PERL_CALL_ARGS_1((long)(status)); argvi++ ;
    XPUSHs(sv);

    PUTBACK;
    perl_call_sv(SvRV(PlCallBack_status_changed_cb),G_EVAL|G_SCALAR);
    SPAGAIN;
    sv=POPs;

    PUTBACK;
    FREETMPS;
    LEAVE;
    return ;
}
%}
%typemap(perl5,in) SV*{ $target=$source;}
%inline %{
void register_status_changed_cb(SV* plfunc){
    if(!SvROK(plfunc) || SvTYPE(SvRV(plfunc))!=SVt_PVCV){
       croak("Not a Callback %_ for register_status_changed_cb",plfunc);
    }
    if(PlCallBack_status_changed_cb)SvREFCNT_dec(PlCallBack_status_changed_cb);
    PlCallBack_status_changed_cb=plfunc;
    SvREFCNT_inc(plfunc);
}
/* For SWIG Type Conversion */
void __null__status_changed_cb( long status){}
%}

%init %{
    status_changed_cb=_cbwrap_status_changed_cb;
%}
#endif
================================


And these are the steps I follow to compile:

================================
# swig -perl irssi_indicator.i

# gcc -c -fPIC -g -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fstack-protector -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Dbool=char -I/usr/include/messaging-menu -I/usr/lib/perl/5.18/CORE irssi_indicator.c irssi_indicator_wrap.c `pkg-config --cflags --libs gtk+-2.0`

# gcc -shared irssi_indicator.o irssi_indicator_wrap.o -o irssi_indicator.so -lmessaging-menu -lm `pkg-config --cflags --libs gtk+-2.0`
================================


But, when I call the callback (from c) I get the following error:

================================
/home/warp/.irssi/scripts/irssi_indicator.so: undefined symbol: SWIG_From_long
================================


Obviously, the output of nm says that:

================================
# nm irssi_indicator.so  | grep SWIG_From
                 U SWIG_From_long
================================


I found a fragment related to this in swig sources "swig/Lib/perl5/perlprimtypes.swg",
but cannot find where is the library to link or something like that... to solve the problem
(find /usr/lib -name '*.so*' -exec nm --print-file-name --defined-only --dynamic {} \; | grep "Swig_From_long").

I using Ubuntu 14.04, Perl 5.18.2 and swig 2.0.11


Any ideas?

Regards.



--
WARPTROSSE {The knowledge of a man belongs to all the humanity}
------------------------------------------------------------------------------
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
Mike Davies | 9 Oct 10:33 2014

Java Strings via SWIG in Android NDK have strange characters in place of null bytes

Hi,

I also posted this question elsewhere but as it most directly relates to SWIG I hope I can also post it here.

I am using SWIG to generate an interface to some C code which I have compiled as an Android NDK library.  My C code NDK library uses a structure, MY_STRUCT that contains char* elements that pass data in both the in and out directions and the SWIG generated JNI works fine as far as that goes, ie I can read the strings in the C code, set data and read the result in the Java code as required.

However I have a problem in that if I pass in a java String that contains null bytes the nulls are replaced by "\300\200"

Eg, if I create a string in java as follows :

    MY_STRUCT myStruct = new MY_STRUCT();
    byte[] myBytes = new byte[21];
    String myString = new String(myBytes);
    myStruct.setName(myString);

then myStruct has it's name field set to 21 null bytes as required and this is visible in the java debugger, but the string passed across to my NDK library code as seen in the NDK C debugger is as follows :

    "\300\200\300\200\300\200\300\200\300\200\300\200\300\200\300\200\300\200\300\200\300\200\300\200\300\200\300\200\300\200\300\200\300\200\300\200\300\200\300\200\300\200"

My SWIG .i file has the following relevant portion :

    %include various.i
    %include cpointer.i
    %pointer_functions(int, intp);
   
    %include ../../../mydir/myheader.h

myheader.h has the following relevant portion :

    typedef struct
    {
    ...
        char* name;
    ...
    } *P_MY_STRUCT, MY_STRUCT;

The C code debugs fine and I can read and write all the strings pointed to by the name etc elements of MY_STRUCT, the only issue is the transformation of null elements of the strings input to the SWIG generated JNI code into the strange "\300\200" elements in the C code in the NDK library.

From an answer I received elsewhere I understand that this behavious is due to the fact that JNI translates java strings into "Modified UTF-8" strings where the nulls are transcoded to two-byte 0x11000000 ox10000000 form.

My question is : is there any way around this in SWIG ?  I need to be able to tell whether my passed in string is empty and strlen etc return the wrong result because of the unusual encoding.

ALTERNATIVELY :

I have several functions that take byte arrays instead of strings for C-function char* arguments and this is achieved in the myModule.i file as follows :

    bool myFunc(P_MY_STRUCT, char* BYTE, int32_t);
   
Is there any way in SWIG of achieving the equivalent of the BYTE functionality for structure members ?  I tried using the same BYTE trick in myModule.i as follows but it didn't work :

    typedef struct
    {
    ...
        char* BYTE;
    ...
    } *P_MY_STRUCT, MY_STRUCT;

Is there another method of using SWIG to pass java byte[] arrays instead of Strings in the MY_STRUCT fields above ?
 
Thanks,

Mike
------------------------------------------------------------------------------
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
Bill Spotz | 8 Oct 17:57 2014
Picon

Constructors not being wrapped

Hi,

I am trying to wrap a C++ library in Python.

A class I want to wrap, MultiVector, is not having any of its constructors wrapped, and the Python
__init__() method raises an AttributeError saying the class is abstract.

I know that MultiVector is concrete, so SWIG must be getting confused somehow.  MultiVector's base class
has four pure virtual methods, and they are all implemented in MultiVector.  I have suspected several
possibilities: the pure virtual methods are protected, there are four template parameters for this
class, the template names change between classes, the prototypes are broken up into declaration and
definition files.  But when I generate a toy problem to test these issues, SWIG works fine and produces code
with valid constructors for my derived class.

I need help debugging the problem to find out why SWIG thinks MultiVector is abstract.  I have tried the
-debug-classes SWIG command-line option, but it didn't give me the info I needed.  Is there anything else I
can be doing?

Thanks

** Bill Spotz                                              **
** Sandia National Laboratories  Voice: (505)845-0170      **
** P.O. Box 5800                 Fax:   (505)284-0154      **
** Albuquerque, NM 87185-0370    Email: wfspotz <at> sandia.gov **


------------------------------------------------------------------------------
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
Will Boyd | 8 Oct 13:33 2014
Picon

Wrapping a function that takes an array of pointers

Hello,

I want to wrap a C++ routine which takes in an array of class instances. I am having trouble getting this to work with SWIG and would appreciate any help that can be offered. I've tried to boil this issue down to its essence through a simple example. I have attached a tarball of the code. 

The header "test.h" is defined as follows:

/* File test.h */
#include <stdlib.h>
#include <stdio.h>

class Test {
private:
  int my_value;
public:
  Test(int value);
  void printTest();
};

void print_tests(int num_tests, Test* tests);


The implementation is defined in "test.cpp" below:

/* File test.cpp */
#include "test.h"

Test::Test(int value) {  my_value = value;  }

void Test::printTest() {  printf("my value is %d", my_value);  }

void print_tests(int num_tests, Test* tests) {
  for (int i=0; i < num_tests; i++)
    tests[i].printTest();
}


I've written a SWIG interface file to try to accomodate this routine so that I can pass in a Python list of "Test" class instances:

%module test

%{
  #define SWIG_FILE_WITH_INIT
  #include "test.h"
%}

%typemap(in) (int num_tests, Test* tests) {

  if (!PyList_Check($input)) {
    PyErr_SetString(PyExc_ValueError,"Expected a Python list of Tests");
    return NULL;
  }

  $1 = PySequence_Length($input);  // num_tests
  $2 = (Test*) malloc(($1) * sizeof(Test*));

  /* Loop over tests */
  for (int i = 0; i < $1; i++) {

    /* Extract the value from the list at this location */
    PyObject* o = PyList_GetItem($input,i);
    $2[i] = (Test*) o;
  }
}

%include "test.h"


An example of what I would like to be able to do with this in a Python script is the following:

import test

test1 = test.Test(1)
test2 = test.Test(2)
tests = [test1, test2]
test.print_tests(tests)


When I try to wrap the routines and compile the SWIG-generated wrapper file I get the following compile time error:

> swig -python -c++ -o test_wrap.cpp test.i
> gcc -I/usr/include/python2.7 -c test_wrap.cpp -o test_wrap.o -fpic -std=c++0x
test_wrap.cpp: In function ‘PyObject* _wrap_print_tests(PyObject*, PyObject*)’:
test_wrap.cpp:3279:15: error: invalid user-defined conversion from ‘Test*’ to ‘Test&&’ [-fpermissive]
       arg2[i] = (Test*) o;
               ^
In file included from test_wrap.cpp:3038:0:
test.h:9:3: note: candidate is: Test::Test(int) <near match>
   Test(int value);
   ^
test.h:9:3: note:   no known conversion for argument 1 from ‘Test*’ to ‘int’
test_wrap.cpp:3279:15: error: invalid conversion from ‘Test*’ to ‘int’ [-fpermissive]
       arg2[i] = (Test*) o;
               ^
In file included from test_wrap.cpp:3038:0:
test.h:9:3: error:   initializing argument 1 of ‘Test::Test(int)’ [-fpermissive]
   Test(int value);
   ^
test_wrap.cpp:3279:15: error: conversion to non-const reference type ‘class Test&&’ from rvalue of type ‘Test’ [-fpermissive]
       arg2[i] = (Test*) o;


I'm not sure what the problem is, but I clearly am mis-understanding something about how the SWIG interface file must be written to deal with this situation. Any help would be greatly appreciated!

Thank you,

Will Boyd
Nuclear Science & Engineering
Massachusetts Institute of Technology
Cell: 423.413.8469
Attachment (test.tar.gz): application/x-gzip, 2484 bytes
------------------------------------------------------------------------------
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
veejay | 8 Oct 11:50 2014
Picon

non static JNI refernce for c library

I am using swig to generate JNI for c headers. But the generated java file
has static reference to the native methods. Is there any way to generate non
static reference?

--
View this message in context: http://swig.10945.n7.nabble.com/non-static-JNI-refernce-for-c-library-tp14024.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

Gmane