William S Fulton | 1 Feb 2009 01:26
Picon
Favicon
Gravatar

ANNOUNCE - swig-1.3.38

*** ANNOUNCE: SWIG 1.3.38 (31 January 2009) ***

http://www.swig.org

We're pleased to announce SWIG-1.3.38, the latest installment in the
SWIG development effort.  SWIG-1.3.38 includes a number of bug fixes
and enhancements.

What is SWIG?
-------------

SWIG is a software development tool that reads C/C++ header files and
generates the wrapper code needed to make C and C++ code accessible
from other languages including Perl, Python, Tcl, Ruby, PHP, Java,
Scheme (Guile, MzScheme, CHICKEN), Ocaml, Lua, Pike, C#, Modula-3, 
Octave, R,
Common Lisp (CLISP, Allegro CL, CFFI, UFFI). SWIG can also export its parse
tree in the form of XML and Lisp s-expressions.  Major applications of
SWIG include generation of scripting language extension modules, rapid
prototyping, testing, and user interface development for large C/C++
systems.

What's New?
===========

SWIG-1.3.38 summary:
- Output directory regression fix and other minor bug fixes

Availability:
-------------
(Continue reading)

Brian Cole | 1 Feb 2009 08:39
Favicon

Python %nothread for everything %extend

I’m trying out the “-threads” flag for our Python wrappers to release the global interpreter lock every time control leaves Python. It works almost too well. We have a lot of hand written code inside %extend and %inline blocks in our interface files to streamline the transition between the two languages. These almost invariably need to work with PyObjects. Luckily, it appears that working with PyObjects without holding the global interpreter lock (even in single threaded mode) will reliably seg fault much of our test suite.

So far I’ve been adding %nothread with much success to prevent these seg faults, but I’m worried because our test suite doesn’t have %100 coverage. I would rather just have SWIG maintain the GIL while it was executing functions that were wrapped from %extend or %inline blocks. Is there any way to do that? Also, is there any canonical documentation on the “-threads” feature and the meaning of the different options shown here: http://matt.eifelle.com/2007/11/23/enabling-thread-support-in-swig-and-python/

Thanks,
Brian
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Tobi | 1 Feb 2009 21:04

returning an unmanaged object

Hi!

I'm trying to make a C++ application extendible by Ruby-"plug-ins".

For this I need Ruby to return object pointers, which are not tracked by
the GC.

So in my Ruby code I have something like:

class Bar
    def create_new
        return Foo.new
    end
end

...where Foo is a wrapped C++ class.

Now I instantiate Bar from my C++ application and call create_new(). The
returned VALUE is converted to a Foo pointer with Data_Get_Struct().

So far, so good... this works fine. The question is: How do I detach the
new Foo object from the GC, so that I can later destroy it manually in the
C++ application?

%newobject doesn't help here, because the instance is not created by a
wrapped method.

thx,

Tobias

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
Christoph Egger | 1 Feb 2009 22:35
Picon
Picon

Re: SWIG and CFFI

Christoph Egger schrieb:
> Hi!
> 
>   I'm trying to get SWIG running for my lisp environment (currently only
> testing if it works). I created some very basic .[chi] files and rand
> swig -cffi in the .i file. However loading the generated .lisp file
> (load "example.lisp") failed with an hint that there is no siuch thing
> as CFFI.
> 
>   I'm running this on Debian testing/unstable/experimental, SWIG is in
> Version 1.3.36 and CFFI is an snapshot from february 2008.
> 
>   Is there anything I do wrong? Anyone had swig+cffi running and could
> point me to some basic example?
> 
> Thanks
> 
>   Christoph
> 

Hi!

  Sorry for the noise but I could get this part working with
    (asdf:oos 'asdf:load-op :cffi)
however loading the swig file still warns me about the function being an
«Undefined alien» and I can not call the function from within lisp.

Regards

  Christoph

-- 
/"\  ASCII Ribbon : GPG-Key ID: 0x0372275D
\ /    Campaign   :
 X   against HTML : Working for Debian
/ \   in eMails   : http://www.debian.org/

http://www.christoph-egger.org/

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Kalyanov Dmitry | 2 Feb 2009 06:26
Picon
Gravatar

Re: SWIG and CFFI

On Monday 02 February 2009 00:35:45 Christoph Egger wrote:
> Christoph Egger schrieb:
> > Hi!
> >
> >   I'm trying to get SWIG running for my lisp environment (currently only
> > testing if it works). I created some very basic .[chi] files and rand
> > swig -cffi in the .i file. However loading the generated .lisp file
> > (load "example.lisp") failed with an hint that there is no siuch thing
> > as CFFI.
> >
> >   I'm running this on Debian testing/unstable/experimental, SWIG is in
> > Version 1.3.36 and CFFI is an snapshot from february 2008.
> >
> >   Is there anything I do wrong? Anyone had swig+cffi running and could
> > point me to some basic example?
> >
> > Thanks
> >
> >   Christoph
>
> Hi!
>
>   Sorry for the noise but I could get this part working with
>     (asdf:oos 'asdf:load-op :cffi)
> however loading the swig file still warns me about the function being an
> «Undefined alien» and I can not call the function from within lisp.
>
> Regards
>
>   Christoph

You need to manually add calls to cffi:load-foreign-library (preferably at the 
beginning of the file). E.g., add this to .i file:

%insert("lisphead") %{
(defpackage :bare-gtk (:use :cl))
  (in-package :bare-gtk)

(unless (cffi:use-foreign-library "libgtk-x11-2.0.so")
        (error "Library libgtk-x11-2.0.so not loaded"))
%}

If the wrapped library needs some initialization, you should add call to it 
after the functions are defined by swig:

%insert("swiglisp") %{
(gtk-init (cffi:foreign-alloc :int :initiial-element 0)
          (cffi:foreign-alloc :string :initial-contents '("/usr/bin/sbcl")))
#+sbcl(sb-ext::set-floating-point-modes :traps nil)
%}
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Tobi | 2 Feb 2009 09:58

Re: returning an unmanaged object

Tobi wrote:

> For this I need Ruby to return object pointers, which are not tracked by
> the GC.
> 
> So in my Ruby code I have something like:
> 
> class Bar
>     def create_new
>         return Foo.new
>     end
> end

The only solution I found so far is:

VALUE obj;

// Load ruby code, instantiate Bar and get obj=bar.create_new()

Data_Get_Struct(obj, Foo, foo);
RDATA(obj)->dfree = 0;

// work with foo

delete(foo);

Is this the way it should be done?
I could do this in the *.i for all Foo objects as well, but I just need it
for the instances passed to the C++ application.

Tobias

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
Alfredo José Muela Romero | 2 Feb 2009 10:53
Picon

Re: returning an unmanaged object

Have you tried by using the swigCMemOwn member?

2009/2/2 Tobi <listaccount <at> e-tobi.net>
Tobi wrote:

> For this I need Ruby to return object pointers, which are not tracked by
> the GC.
>
> So in my Ruby code I have something like:
>
> class Bar
>     def create_new
>         return Foo.new
>     end
> end


The only solution I found so far is:

VALUE obj;

// Load ruby code, instantiate Bar and get obj=bar.create_new()

Data_Get_Struct(obj, Foo, foo);
RDATA(obj)->dfree = 0;

// work with foo

delete(foo);

Is this the way it should be done?
I could do this in the *.i for all Foo objects as well, but I just need it
for the instances passed to the C++ application.

Tobias

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Alfredo José Muela Romero | 2 Feb 2009 11:09
Picon

Re: Getting the Tutorial working

Hi Paul,

I had no problem with that swig interface file in Debian with SWIG Version 1.3.36

I guess that you aren't doing anything wrong in that .i file...


Cheers,

Alfredo.

2009/1/31 Fergus, Paul <P.Fergus <at> ljmu.ac.uk>
Hello All,

This is the first time I have used SWIG and I am having a problem getting the tutorial to work http://www.swig.org/tutorial.html.

My OS is Windows Vista, which from the website says is compatible with the latest version of SWIG.

I have created the interface file:

/* example.i */
%module example
%{
/* Put header files here or function declarations like below */
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
%}

extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();

I then run the following command:

swig -java example.i

I then get an error message as follows:

example.i(1): Error: Syntax error in input(1).

I am probably doing something stupid here. Could anyone advice me on how I may be able to solve this problem.

Kind Regards,

Paul

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Tobi | 2 Feb 2009 11:40

Re: returning an unmanaged object

Alfredo José Muela Romero schrieb:

> Have you tried by using the swigCMemOwn member?

AFAIK this is only available for the Java and C# bindings.

Tobias

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
Alfredo José Muela Romero | 2 Feb 2009 12:05
Picon

Re: returning an unmanaged object

So it seems. Sorry, I didn't know. I haven't used SWIG with any other language than those two yet.


Cheers,

Alfredo.

2009/2/2 Tobi <listaccount <at> e-tobi.net>
Alfredo José Muela Romero schrieb:

> Have you tried by using the swigCMemOwn member?

AFAIK this is only available for the Java and C# bindings.

Tobias

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

Gmane