Jesse Wolfe | 30 Aug 03:16 2002

Two Char **OUTPUT return values not working

Hi All...

I just am getting into SWIG... it's very cool.  I'm using it to interface
into a third-party C library, for use in Perl.

The problem is, I have a function that returns several arrays of character
strings. I thought I could use the Perl code given in the SWIG Perl5 page
from the distribution, under typedefs... the argv example.

Two questions... one was a typo I think...

Here's the (in) code from the example:

%module argv

// This tells SWIG to treat char ** as a special case
%typemap(in) char ** {
	AV *tempav;
	I32 len;
	int i;
	SV  **tv;
	if (!SvROK($input))
	    croak("Argument $argnum is not a reference.");
        if (SvTYPE(SvRV($input)) != SVt_PVAV)
	    croak("Argument $argnum is not an array.");
        tempav = (AV*)SvRV($input);
	len = av_len(tempav);
	$1 = (char **) malloc((len+2)*sizeof(char *));
	for (i = 0; i <= len; i++) {
	    tv = av_fetch(tempav, i, 0);
(Continue reading)

David Beazley | 30 Aug 03:42 2002

Two Char **OUTPUT return values not working

Jesse Wolfe writes:
 > Hi All...
 > 
 > I just am getting into SWIG... it's very cool.  I'm using it to interface
 > into a third-party C library, for use in Perl.
 > 
 > The problem is, I have a function that returns several arrays of character
 > strings. I thought I could use the Perl code given in the SWIG Perl5 page
 > from the distribution, under typedefs... the argv example.
 > 
 > Two questions... one was a typo I think...
 > 
 > Here's the (in) code from the example:
 > 
 > %module argv
 > 
 > // This tells SWIG to treat char ** as a special case
 > %typemap(in) char ** {
 > 	AV *tempav;
 > 	I32 len;
 > 	int i;
 > 	SV  **tv;
 > 	if (!SvROK($input))
 > 	    croak("Argument $argnum is not a reference.");
 >         if (SvTYPE(SvRV($input)) != SVt_PVAV)
 > 	    croak("Argument $argnum is not an array.");
 >         tempav = (AV*)SvRV($input);
 > 	len = av_len(tempav);
 > 	$1 = (char **) malloc((len+2)*sizeof(char *));
 > 	for (i = 0; i <= len; i++) {
(Continue reading)

Janusz Gregorczyk | 30 Aug 09:55 2002
Picon

Memory leak in SWIG Python?

Hi,

I'm using Swig 1.3.14 to make Python extension modules out of C++
classes. I'm linking those modules statically with my app, then call
init_Module() after Py_Initialize() to get them working. It all works
fine, except that there seems to be a small memory leak per module.

I've tracked the problem down to PyMem_NEW in SWIG_newvarlink called
from here:

if (!SWIG_globals) SWIG_globals = SWIG_newvarlink();

It's also explained here:
http://www.geocrawler.com/archives/3/1021/2001/7/50/6221163/.

It seems to me this memory is never freed. I could work around it by
hacking init_Module code and adding deinit_Module function. However, I
do believe this was supposed to be automatic.

Am I right?

Cheers,
Janusz Gregorczyk

-------------------------------------
Sztuka tworzenia mebli http://www.iker.com.pl
_______________________________________________
Swig maillist  -  Swig <at> cs.uchicago.edu
http://mailman.cs.uchicago.edu/mailman/listinfo/swig

(Continue reading)

Jesse Wolfe | 30 Aug 10:24 2002

Re: Two Char **OUTPUT return values not working

Hello David... thanks for the quick response...

David Beazley writes:
>
>  > #2) I want to specify a function which returns two char ** pointers,
which I
>  > will deref as arrays in Perl. Thus, in my .i file I have:
>  >
>  > %apply char **OUTPUT { char **memberIDs, char **memberNames };
>  >
>  > long LLP_ListMembers(
>  >     SESSION * session,
>  >     long        MemberType,
>  >     char *Name,
>  >     char **memberIDs,
>  >     char **memberNames);
>  >
>  > It all compiles fine... but it still expects FIVE arguments when I call
the
>  > function, and thus I get a runtime error when I invoke it like this:
>  >
>  > ($rez,$uids,$names)=    Net::LAPI::LLP_ListMembers(
>  >         $SESSION,
>  >         $Net::LAPI::LL_GROUP,
>  >         $LLTESTGROUP
>  >     );
>  >
>  > When run, I get this:
>  >
>  > Usage: LLP_ListMembers(session,MemberType,Name,memberIDs,memberNames);
(Continue reading)

David Beazley | 30 Aug 14:39 2002

Memory leak in SWIG Python?

Janusz Gregorczyk writes:
 > Hi,
 > 
 > I'm using Swig 1.3.14 to make Python extension modules out of C++
 > classes. I'm linking those modules statically with my app, then call
 > init_Module() after Py_Initialize() to get them working. It all works
 > fine, except that there seems to be a small memory leak per module.
 > 
 > I've tracked the problem down to PyMem_NEW in SWIG_newvarlink called
 > from here:
 > 
 > if (!SWIG_globals) SWIG_globals = SWIG_newvarlink();
 > 
 > It's also explained here:
 > http://www.geocrawler.com/archives/3/1021/2001/7/50/6221163/.
 > 
 > It seems to me this memory is never freed. I could work around it by
 > hacking init_Module code and adding deinit_Module function. However, I
 > do believe this was supposed to be automatic.
 > 

What is a "deinit_Module" function?  Is this some sort of new Python
feature?  AFAIK, it's not possible to unload a shared object file in
Python.  Therefore, SWIG doesn't bother to provide a module cleanup
function.

-- Dave

_______________________________________________
Swig maillist  -  Swig <at> cs.uchicago.edu
(Continue reading)

Andres Corrada-Emmanuel | 30 Aug 17:42 2002
Picon

typemap(out) void problem

Hello,

I'm trying to change a C++ function that returns values via arguments to
return them by a tuple, that is

virtual void foo(int &arg1, double &arg2);

is changed by using:

%typemap(ignore) int &arg1{
blah...
}

%typemap(ignore) double &arg2{
blah...
}

%typemap(out) void {
blah...
}

after the function I use %clear statements to remove the typemap
definitions:

%clear int &arg1;
%clear double &arg2;
%clear void;

I find that the %typemap(out) void typemap persists, however, and goes on
to break the behaviour of other functions in the package I am wrapping. If
(Continue reading)

David Beazley | 30 Aug 18:08 2002

typemap(out) void problem

Andres Corrada-Emmanuel writes:
 > Hello,
 > 
 > I'm trying to change a C++ function that returns values via arguments to
 > return them by a tuple, that is
 > 
 > virtual void foo(int &arg1, double &arg2);
 > 
 > is changed by using:
 > 
 > %typemap(ignore) int &arg1{
 > blah...
 > }
 > 
 > %typemap(ignore) double &arg2{
 > blah...
 > }
 > 
 > %typemap(out) void {
 > blah...
 > }
 > 
 > after the function I use %clear statements to remove the typemap
 > definitions:
 > 
 > %clear int &arg1;
 > %clear double &arg2;
 > %clear void;
 > 
 > I find that the %typemap(out) void typemap persists, however, and goes on
(Continue reading)

Duncan, Randy | 30 Aug 18:14 2002
Picon
Picon

Unsatisfied Link Error in java

When I run swig, compile and make a .so and try to load this library in a
java program I get an UnsatisfiedLinkError even though my LD_LIBRARY_PATH
contains the path of the directory my .so is in. Here is the java code.....

public class BDTNew {
static{
//System.out.println(System.getProperty("java.library.path"));
System.loadLibrary("BDTTestClass");

}
public static void main(String args[]) {
long var1 = 0;
String var2 = "SDB";
int var3 = 0;

BDT bdtclass = new BDT(var2, var3, var1);
System.out.println(bdtclass.getBDTSize());

}
}
Here is what I entered at the command line(I am using SUN Workshop 6
compiler).....

unix% swig -c++ -java -proxy BDT.i
unix% CC -c BDT_wrap.cxx BDTTestClass.cc -I/usr/java/include
-I/usr/java/include/solaris
unix% CC -G BDT_wrap.o BDTTestClass.o -L/software/SUNWspro/lib -lCrun -o
libBDTTestClass.so
unix% javac *.java
unix% java BDTNew
(Continue reading)

Andres Corrada-Emmanuel | 30 Aug 19:36 2002
Picon

Re: typemap(out) void problem

I'm using 1.3.13. And using "%typemap(out) void;" does not fix things. The
strange thing is that the way other functions get changed (e.g.
_wrap_delete_BarObject) is that instead of returning a Py_None object they
return PyObjects of type _p_void. This is nothing like what I'm declaring
in the typemap(out) call where I create a Python tuple object. Or put
another way, the comment lines I put in the typemap(out) declaration do
not appear in the broken functions.

Something that may be related to this is a previous message I sent about
about an object not getting recognized as an instance of its base classes.
The problem was that SWIG was returning a "this" that had the form:

<C WeightedIDSet at _p_blah_PseudoFBDocs>

Unable to produce a simple example to contribute to the list, I created a
shadow class hack around it: I extracted the _p_blah_PseudoFBDocs part and
assigned that to self.this.

This current problem is also with the same class.

Andres Corrada-Emmanuel
Senior Research Fellow
Center for Intelligent Information Retrieval
University of Massachusetts, Amherst

On Fri, 30 Aug 2002, David Beazley wrote:

>
> What version of SWIG is this?  There was a bug in %clear at some
> point, but I thought it was fixed in the last release.
(Continue reading)

Janusz Gregorczyk | 30 Aug 19:49 2002
Picon

Re: Memory leak in SWIG Python?

David Beazley wrote:
> Janusz Gregorczyk writes:
>  > I'm using Swig 1.3.14 to make Python extension modules out of C++
>  > classes. I'm linking those modules statically with my app, then call
>  > init_Module() after Py_Initialize() to get them working. It all works
>  > fine, except that there seems to be a small memory leak per module.
 >  > [...]
>  > It seems to me this memory is never freed. I could work around it by
>  > hacking init_Module code and adding deinit_Module function. However, I
>  > do believe this was supposed to be automatic.
>  > 
> 
 > What is a "deinit_Module" function? [...]
 > AFAIK, it's not possible to unload a shared object file in Python.

I haven't explained myself clearly. I do not need to unload a shared 
object as I link generated Module_wrap.cxx with my app statically. 
Application's entry point is in C++ and extension modules are used by an 
embedded interpreter. Therefore, my program looks somewhat like:

extern "C" { void init_Module(); }

int main()
{
	/* Set up C++ code. */

	Py_Initialize();
	init_Module();
	/* Set up Python enviroment (set sys.path, import modules, ...). */

(Continue reading)


Gmane