David Hysom | 25 May 02:13 2015
Picon

javac symbol not found

I'm trying to get the example in http://swig.org/Doc1.3/Java.html
"section 21.2.1 Running SWIG" to work. This is on a linux box
running redhat. Here is what I ran (after cut-n-paste the example code):

$ swig  -java example.i   /* works */

$ gcc -fno-strict-aliasing -fPIC -c example_wrap.c  -I/usr/lib/jvm/java-1.6.0-sun-1.6.0.91.x86_64/include/linux  /* works */

$ ld -shared example_wrap.o -o libexample.so  /* works */

$ javac -cp . *.java
symbol  : variable example
location: class runme
    System.out.println(example.fact(4));
                       ^
1 error

Can anyone offer advice? I've been unable to google anything useful,
or find this question asked/answered in the SWIG mail archives.

Let me know if I didn't provide sufficient information.

Thanks, David
------------------------------------------------------------------------------
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
Ari Jolma | 24 May 20:07 2015
Picon

A couple of issues with default arguments

Hi,

I'm new on this list so sorry for being ignorant if these issues have 
been discussed already. I did not find such discussions however.

I'm working on GDAL Swig bindings which currently support actively four 
languages Java, CSharp, Python, and Perl. I'm mostly interested in Perl.

As I understand the default behaviour concerning default arguments has 
changed since early Swig. We started the project long time ago, so the 
interface files more or less assume the old behaviour and it has been 
patched to support new Swig.

Two issues:

- %feature("kwargs") seems to have a bit stealthy side effect for 
example on Java bindings since it does not take into account whether the 
target language supports keyword arguments or not. In docs chapter 6.7, 
last paragraph says this. It automatically turns on compactdefaultargs. 
I don't think it should do that for Java. This adds for us a requirement 
to write #if .. #endif to limit the effect to kwargs only for those 
languages which support it.

- Also on compactdefaultargs. I would actually want to not use that for 
Perl bindings but it seems to create unnecessary complication due to the 
checks Swig puts into the dispatch function for arguments. We have in 
many methods an optional callback argument, which needs a function. I 
have written some code with which I can use Perl subroutines as these 
callbacks but if I turn off the compactdefaultargs it does not work. The 
code I have written is one C function and a couple of typemaps, which 
check the argument to be a Perl subroutine and work on it and then give 
a callback to the library. The typemaps are however not any help since 
the Swig dispatch code checks and discards the arguments earlier. I can 
of course write some additional wrapping to convert the arguments into 
something that Swig accepts (function pointer) but that seems 
unnecessary complication.

I'm using Swig 2.0.11 since that's the default version in Linux Mint but 
it seems that version 3 is not better in this respect.

Best regards,

Ari

ps. GDAL is https://github.com/OSGeo/gdal and I've forked it for work on 
bindings at https://github.com/ajolma/gdal

------------------------------------------------------------------------------
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
Jorj McKie | 24 May 19:10 2015
Picon

C-level of wrapper code?

Hi everyone,

 

I am a complete newbee with SWIG – want to write a Python wrapper for an existing C application on Windows 7. My development env ist VS 2013.

I found out that my SWIG-generated

 

module_wrap.c

 

is C99 level code – which VC++ can not understand.

Is this inevitable?

Or can I control this behaviour to get C89?

Have I made a mistake?

 

Thanks a lot!

 

Jorj

------------------------------------------------------------------------------
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
Will Newton | 24 May 00:34 2015
Picon

Go C++ binding issue on ARM

Hi all,

I am seeing a crash with some Go bindings of C++ code on an ARM
target. The same code runs seemingly ok on x86_64.

The crash seems to be caused by the Go stack becoming corrupted and a
bad LR value being popped off the stack.

The Go wrapper looks like this:

type SwigcptrGMatrix uintptr

func _swig_wrap_GMatrix_cols(base SwigcptrGMatrix) (_ int64) {
        _swig_p := uintptr(unsafe.Pointer(&base))
        _cgo_runtime_cgocall(_wrap_GMatrix_cols, _swig_p)
        return
}

So at this point _swig_p is in C terms a pointer to unitptr.

In the C++ side of the wrapper we have:

void
_wrap_GMatrix_cols(void *swig_v)
{
  GClasses::GMatrix *arg1 = (GClasses::GMatrix *) 0 ;
  size_t result;
  GClasses::GMatrix *_swig_go_0;
  long long _swig_go_result;
  char *swig_stktop;

  struct swigargs {
    GClasses::GMatrix *arg1;
    long : 0;
    long long result;
  } *swig_a = (struct swigargs *) swig_v;

  _swig_go_0 = swig_a->arg1;
  arg1 = *(GClasses::GMatrix **)&_swig_go_0;

  swig_stktop = _swig_topofstack();
  result = ((GClasses::GMatrix const *)arg1)->cols();
  _swig_go_result = result;
  swig_a = (struct swigargs*)((char*)swig_a + (_swig_topofstack() -
swig_stktop));
  swig_a->result = _swig_go_result;
}

At this point I am not sure why it is safe to cast swig_v to struct
swigargs *, as it only points to allocated space for uintptr. When we
write the value for swig_a->result it trashes a value on the stack
causing a control flow failure when we return.

Is my reasoning correct here or is there some other reason why this
might be happening?

Thanks,

------------------------------------------------------------------------------
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
Ayman Habib | 20 May 21:24 2015
Picon

Object ownership Transfer: Java, Python

Hi, 

I'm wrapping a C++ library to both Python and Java. I have a few functions that look 
like this

MyNameSpace::MyObjectSet{
   ...
   appendObject(MyObject* myobj) {
// MyObjectSet takes ownership of passed in myobj 
....
   }

}

I'd like to communicate to both  python and Java environments that ownership has been 
transferred so the myobj is not garbage collected. I have tried to inject code to handle 
the ownership flag of the proxy classes by replacing method body with another that 
injects the proper line or using pythonprepend/append but I wonder if there's a better 
way to do this that works cross target languages. 

Thanks much,
-Ayman


------------------------------------------------------------------------------
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
Ivan Metzlar | 14 May 19:25 2015
Picon

Go (and GT.M bindings)

Hello all,

I have been playing with SWIG for Go using this article: http://zacg.github.io/blog/2013/06/06/calling-c-plus-plus-code-from-go-with-swig/

Please see my fork of Zac's repo here: https://github.com/metzlar/simplelib

The whole thing seems to compile and install successfully:

make;make build;make install;make cleanall

But when I run this little test, I get panic:

gtm := gtmlib.NewGTM()
fmt.Printf("Hello gtm %s", gtm)

The output is:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x4373eb]

goroutine 1 [running]:
simplelib._swig_wrap_new_GTM(0x0)
        $GOROOT/src/simplelib/gtmlib.go:48 +0x4b
simplelib.NewGTM(0x0, 0x0)
        $GOROOT/src/simplelib/gtmlib.go:53 +0x31
main.main()
        ~/GoProjects/gogtm/gtmtest/main.go:9 +0x27

The CPP code is from this Github repo here: https://github.com/OSEHRA-Sandbox/gtm-bindings/tree/master/Source that wraps GT.M into a C++ class. It works for Python. This makes it hard to reproduce without installing GT.M

I was hoping someone could tell me what the panic means or how I can debug this?
------------------------------------------------------------------------------
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
Scapegoat Sarthak | 13 May 16:06 2015
Picon

Wrapping ITK Project

Hi,

I have a project that uses ITK extensively and I would like to expose the classes for use in another Python project. I am familiar with using SWIG and generating pure CPP classes but I am confused regarding how dependencies on external projects work.

Any help would be appreciated.

Thanks,
Sarthak 
------------------------------------------------------------------------------
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
Qingnan Zhou | 12 May 17:49 2015
Picon

How to use %pythonprepend and %pythonappend to access arguments and return values?

Dear all,

I would like to have some python code to pre and post-process the input and output of a swig-wrapped C++ method so my python interface is more minimalistic.  It seems %pythonprepend and %pythonappend are ideal for such use cases.  However, the swig documentation does not provide ways of accessing the arguments and return values.  I have used the solution proposed in the following link, which works with swig 3.0.0 but is broken for swig 3.0.5


So my question is if there is any way to pre/post process C++ input/output?  And how are%pythonappend and %pythonprepend used in practice?  Thanks a lot!

best,
James
------------------------------------------------------------------------------
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
Will Boyd | 11 May 17:52 2015
Picon

SWIG breaks when wrapping std::printf

Hello,

I am using SWIG to wrap a mixed C++/CUDA enabled code called OpenMOC (https://github.com/mit-crpg/OpenMOC). I recently upgraded from CUDA 5.5 to 7.0 and have run into a compiler error which seems to be related to SWIG's attempt to make all printf statements into calls to PySys_WriteStdout. The compilation error is the following:

error: ‘PySys_WriteStdout’ is not a member of ‘std’
    std::printf("%s\n", message);

I believe that newer version(s) of NVIDIA CUDA must use std::printf rather than printf. If I understand this issue correctly, SWIG is using a macro to replace printf with PySys_WriteStdout which expands to std::PySys_WriteStdout which is invalid.

Any advice on how to instruct SWIG to look for std::printf rather than printf? Or alternatively, how to instruct SWIG to NOT replace printf in some included files, namely those in the CUDA headers?

The complete error stack is below for reference:

gcc -DFP_PRECISION=float -DSINGLE -DCUDA -DCCACHE_CC=nvcc -I/usr/local/cuda/include -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c openmoc/cuda/openmoc_cuda_wrap.cpp -o build/temp.linux-x86_64-2.7/openmoc/cuda/openmoc_cuda_wrap.o -c -O3 -ffast-math -fopenmp -std=c++0x -fpic
In file included from /usr/local/cuda/include/thrust/system/cuda/detail/bulk/detail/throw_on_error.hpp:20:0,
                 from /usr/local/cuda/include/thrust/system/cuda/detail/bulk/future.hpp:21,
                 from /usr/local/cuda/include/thrust/system/cuda/detail/bulk/execution_policy.hpp:19,
                 from /usr/local/cuda/include/thrust/system/cuda/detail/bulk/bulk.hpp:20,
                 from /usr/local/cuda/include/thrust/system/cuda/detail/bulk.h:47,
                 from /usr/local/cuda/include/thrust/system/cuda/detail/for_each.inl:25,
                 from /usr/local/cuda/include/thrust/system/cuda/detail/for_each.h:64,
                 from /usr/local/cuda/include/thrust/system/detail/adl/for_each.h:32,
                 from /usr/local/cuda/include/thrust/detail/for_each.inl:27,
                 from /usr/local/cuda/include/thrust/for_each.h:279,
                 from /usr/local/cuda/include/thrust/system/detail/generic/transform.inl:19,
                 from /usr/local/cuda/include/thrust/system/detail/generic/transform.h:105,
                 from /usr/local/cuda/include/thrust/detail/transform.inl:25,
                 from /usr/local/cuda/include/thrust/transform.h:724,
                 from /usr/local/cuda/include/thrust/system/detail/generic/reduce_by_key.inl:29,
                 from /usr/local/cuda/include/thrust/system/detail/generic/reduce_by_key.h:88,
                 from /usr/local/cuda/include/thrust/detail/reduce.inl:26,
                 from /usr/local/cuda/include/thrust/reduce.h:784,
                 from openmoc/cuda/../../src/accel/cuda/GPUSolver.h:17,
                 from openmoc/cuda/openmoc_cuda_wrap.cpp:3057:
/usr/local/cuda/include/thrust/system/cuda/detail/bulk/detail/terminate.hpp: In function ‘void thrust::system::cuda::detail::bulk_::detail::terminate_with_message(const char*)’:
/usr/local/cuda/include/thrust/system/cuda/detail/bulk/detail/terminate.hpp:45:3: error: ‘PySys_WriteStdout’ is not a member of ‘std’
   std::printf("%s\n", message);
   ^
/usr/local/cuda/include/thrust/system/cuda/detail/bulk/detail/terminate.hpp:45:3: note: suggested alternative:
In file included from /usr/include/python2.7/Python.h:129:0,
                 from openmoc/cuda/openmoc_cuda_wrap.cpp:154:
/usr/include/python2.7/sysmodule.h:17:18: note:   ‘PySys_WriteStdout’
 PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...)
                  ^
error: command 'gcc' failed with exit status 1

Thank you for your help,

Will Boyd
Nuclear Science & Engineering
Massachusetts Institute of Technology
Email: wboyd <at> mit.edu
Cell: 423.413.8469
------------------------------------------------------------------------------
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
emacstheviking | 10 May 16:00 2015
Picon

GNU Prolog output generator interface wrapper thingy...

Hi,

I've been a big fan and GNU Prolog, I wrote a redis client for it recently and that's listed on the Redis clients page which is nice of them. I recently began a "manual" port of SDL2 as I want to be able to combine Redis, SDL and GNU Prolog but the full enormity of the task is beginning to settle in! I have a working init/quit/create_window API but I think it is not feasible to do by hand as it is fragile.

I remembered using SWIG in the past as a consumer, not it seems I may have to actually write a wrapper / interface / whatever-its-called-in-SWIG-terminology for GNU Prologs.

I did consider using Prolog and DCG-s to write my own header file read and translator, that's still an option but I am prepared to see how far I can get using this kit first, after all, it has been around a long time and has a really great reputation. I too have been around a long time but have no reputation ;) Plus, I've only been "into" Prolog for a bout a year or two now, my interested being peeked when I heard Erlang was initially written with it, something I used everyday.

As I understand it, I need to write some C/C++ code (not a problem, I have plenty of both) to take the output from SWIG and generate the correctly typed FFI declarations (in Prolog) and in C "to call SDL".

I love stuff like this to be honest, it's probably more interesting and fun that actually "working for a living" which always gets in the way of the technically challenging things.

All I need is some good examples or places to find good tutorials; the one thing I am having difficulty with right now is actually knowing where to start!

Many thanks in advance.

Sean Charles.


------------------------------------------------------------------------------
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
Ben Webb | 6 May 03:05 2015

Re: Smart pointer typemaps

On 5/5/15 4:02 PM, Lindley French wrote:
> [...] I have a type with an instrusive reference count modified via
> addref() and removeref() methods.
>
> [...] I can use feature("ref") and feature("unref") to do this for objects
> created within Java. However, objects created in C++ and passed to Java
> will not use these features.

We do something almost identical (except that our methods are called 
ref() and unref(), and we're wrapping to Python, not Java). We use 
feature("ref") combined with "out" typemaps; the latter takes care of 
objects created in C++ (you may also need to specialize traits_from if 
messing with STL iterators). See 
https://github.com/salilab/imp/tree/develop/modules/kernel/pyext and 
grep for ref() in swig.i-in, include/IMP_kernel.types.i and 
include/IMP_kernel.refcount.i.

	Ben
--

-- 
ben <at> salilab.org                      http://salilab.org/~ben/
"It is a capital mistake to theorize before one has data."
	- Sir Arthur Conan Doyle

------------------------------------------------------------------------------
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

Gmane