sploving | 2 May 15:54 2011

java typemap question

Hello all,
  There is a C++ Function like this:
void get_labels(float64_t** p_labels, int32_t* len){
    *len=4;
    *p_labels=(float64_t*) malloc(sizeof(float64_t)* (*len));

    for (int32_t i=0; i<*len; i++)
       (*p_labels)[i]=get_label(i);
}

I write a typemap file to call it from java like this:
double[] y =new double[4]
get_labels(y); // y={1,2,3,4}
It works well. The typemap file is as the following:
%typemap(jni) (float64_t** p_labels, int32_t* len)        %{jdoubleArray%}
%typemap(jtype) (float64_t** p_labels, int32_t* len)        %{double[]%}
%typemap(jstype) (float64_t** p_labels, int32_t* len)    %{double[]%}

%typemap(in) (float64_t** p_labels, int32_t* len) {
    $1 = (float64_t**) malloc(sizeof(float64_t*));
    $2 = (int32_t*) malloc(sizeof(int32_t));
}

%typemap(argout) (float64_t** p_labels, int32_t* len) {
    float64_t* vec = *$1;
    jdouble *arr;
    int i;
    if (!$input)
        return ;
    arr = JCALL2(GetDoubleArrayElements, jenv, $input, 0);
    if (!arr)
        return;
    for (i=0; i < *$2; i++)
        arr[i] = (jdouble)vec[i];
    JCALL3(

ReleaseDoubleArrayElements, jenv, $input, arr, 0);
}

%typemap(javain) (float64_t** p_labels, int32_t* len) "$javainput".

But if I want to use it like this in Java:

double y[];
y = get_labels();// y should be {1,2,3,4}
then how to change the typemap file? I tried to use: typemap(in, numinputs=0) and typemap(argout), but failed. Could anyone give me some advice? thanks.


体验网易邮箱2G超大附件,轻松发优质大电影、大照片,提速3倍!
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
Ian Lance Taylor | 2 May 23:14 2011
Picon

Re: varargs_typemap test is Python specific

William S Fulton <wsf <at> fultondesigns.co.uk> writes:

> On 30/04/11 07:08, Ian Lance Taylor wrote:
>> The new varargs_typemap test is Python specific and will fail for other
>> languages.  At least, it fails for Go, and causes a testsuite failure.
>> What's the right way to handle this?  Should varargs_typemap move from
>> examples/test-suite/common.mk to examples/test-suite/python/Makefile, or
>> should it somehow be adjusted so that it has a chance of working for
>> other languages?
>>
> When adding new test cases the goal should be to make them language
> neutral. However, this isn't possible with custom typemaps like this
> one, so then it should only be added in the language specific
> Makefile, and then prefix the test case name with python_, so let's
> rename it to python_varargs_typemap.

I made this change.

Ian

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
SourceForge.net | 6 May 13:50 2011
Picon
Picon

[ swig-Bugs-3298252 ] Invalid typemaps for raw wchar_t* strings

Bugs item #3298252, was opened at 2011-05-06 11:50
Message generated for change (Tracker Item Submitted) made by 
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=101645&aid=3298252&group_id=1645

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: csharp
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: https://www.google.com/accounts ()
Assigned to: William Fulton (wsfulton)
Summary: Invalid typemaps for raw wchar_t* strings

Initial Comment:
Swig generates invalid code for raw wchar_t * strings. While compiling this code VisualStudio C# compiler
produces error:
 Cannot implicitly convert type 'System.IntPtr' to 'string'	

Example:
>> test.i
%include <wchar.i>
%immutable;
static const wchar_t *g_const;

>> testPINVOKE.cs
public static extern IntPtr g_const_get();

>> test.cs

public static string g_const {
    get {
      string ret = testPINVOKE.g_const_get(); // ERROR: Cannot implicitly convert type 'System.IntPtr' to 'string'	
      return ret;
    } 
  }

> D:\dev\swigwin-2.0.3\swig.exe -csharp -c++ test.i

Currently I'm using the following typemaps to workaround this problem
%typemap(imtype, inattributes="[MarshalAs(UnmanagedType.LPWStr)]", out="string",
outattributes="[return: MarshalAs(UnmanagedType.LPWStr)]" ) wchar_t * "string"
%typemap(out) wchar_t * %{ $result = (wchar_t *)SWIG_csharp_wstring_callback((const wchar_t *)$1); %}

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=101645&aid=3298252&group_id=1645

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
William S Fulton | 7 May 01:13 2011
Picon

next release and python 3.2

Has anyone tried out python 3.2 and the test-suite? There are reports on 
swig-user that swig-2.0.3 and python-3.2 doesn't work. I think we are 
about ready for a new release, but python 3.2 needs to work before we 
push the next release out.

William

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
Stefan Zager | 8 May 00:05 2011
Picon

Re: next release and python 3.2

On Fri, 6 May 2011, William S Fulton wrote:

> Has anyone tried out python 3.2 and the test-suite? There are reports on
> swig-user that swig-2.0.3 and python-3.2 doesn't work. I think we are
> about ready for a new release, but python 3.2 needs to work before we
> push the next release out.

I have been busy for the last week, but I will start working on this.

Stefan

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
SourceForge.net | 8 May 10:06 2011
Picon
Picon

[ swig-Bugs-2380788 ] Bug in SWIG 1.3.35 with std::vector type system?

Bugs item #2380788, was opened at 2008-12-02 18:01
Message generated for change (Comment added) made by szager
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=101645&aid=2380788&group_id=1645

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: code generation (general)
Group: None
>Status: Closed
>Resolution: Duplicate
Priority: 5
Private: No
Submitted By: Ben Webb (benwebb)
Assigned to: Nobody/Anonymous (nobody)
Summary: Bug in SWIG 1.3.35 with std::vector type system?

Initial Comment:
I have encountered a problem with SWIG 1.3.35 and later with a fairly simple usage of std::vector. What
seems to be happening is that the SWIG runtime is getting confused about the type of the std::vector.

For example, running 'make' with the attached Makefile and test.i works (produces no output from Python)
with SWIG 1.3.34, but fails on SWIG 1.3.35, 1.3.36 and SVN r10960 with the error:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "test.py", line 130, in insert
    def insert(self, *args): return _test.vectorf_insert(self, *args)
NotImplementedError: Wrong number of arguments for overloaded function 'vectorf_insert'.
  Possible C/C++ prototypes are:
    insert(std::vector< float > *,std::vector< float >::iterator,std::vector< float >::value_type
const &)
    insert(std::vector< float > *,std::vector< float >::iterator,std::vector< float
>::size_type,std::vector< float >::value_type const &)

Obviously this makes STL vectors rather hard for us to use in practice!

I ran into the problem with Fedora 10's package of SWIG 1.3.35 (Fedora 9's build of 1.3.33 works just fine)
but confirmed that it also fails for me with 1.3.35 built from your upstream sources. (But ideally a
backport of any fix to 1.3.35 would be useful, so that Fedora can patch their package without having to
upgrade to an SVN snapshot.)

----------------------------------------------------------------------

>Comment By: szager (szager)
Date: 2011-05-08 01:06

Message:
Duplicate of bug 2811549, now fixed.

----------------------------------------------------------------------

Comment By: William Fulton (wsfulton)
Date: 2011-02-17 15:06

Message:
Possibly related to #2811549

----------------------------------------------------------------------

Comment By: Ben Webb (benwebb)
Date: 2008-12-04 19:49

Message:
I can certainly help test such a solution, although my experience with the
SWIG internals is minimal. If you can remember anything further about the
Ruby iterator fix, that would be helpful.

----------------------------------------------------------------------

Comment By: William Fulton (wsfulton)
Date: 2008-12-04 14:28

Message:
The warnings are indicative of other problems. How about fixing the
iterators instead? I have a vague recollection that Ruby has the iterators
fixed, so perhaps the Ruby solution can be ported to Python.

----------------------------------------------------------------------

Comment By: Ben Webb (benwebb)
Date: 2008-12-04 10:49

Message:
Thanks - that's just it. Backing out SVN r10322 fixes the problem for me
both with current SVN and 1.3.35. I agree that if you can only have one
version of begin() and friends, it should probably be the non-const version
(I tried backing out the patch and then removing just the const iterators,
and that also works for me). Otherwise, it seems to me that backing out the
patch is the best solution - surely a few warnings are better than code
that fails to run?

----------------------------------------------------------------------

Comment By: Haoyu Bai (bhy)
Date: 2008-12-03 13:26

Message:
This is due to SF patch #1925702 (SVN r10322) "Remove warning 512 when
using std_vector.i":

std_container.i used to provide an interface for both the const and
non-const versions of begin(), end(), rbegin(), and rend(). This causes a
bunch of warning 512's when using std_vector.i. This patch removes the
non-const versions of those four functions, which gets rid of the
warnings.

This patch removed non-const version of begin(), so in SWIG 1.3.35 we got
a const_iterator returned, while std::vector::insert expect a non-const
iterator:

void insert( iterator loc, input_iterator start, input_iterator end );

So seems we should keep the non-const version of begin() etc., and remove
(or rename?) the const version.

----------------------------------------------------------------------

Comment By: Ben Webb (benwebb)
Date: 2008-12-02 18:02

Message:
File Added: test.i

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=101645&aid=2380788&group_id=1645

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
Stefan Zager | 9 May 07:04 2011
Picon

Re: next release and python 3.2

On Fri, 6 May 2011, William S Fulton wrote:

> Has anyone tried out python 3.2 and the test-suite? There are reports on
> swig-user that swig-2.0.3 and python-3.2 doesn't work. I think we are
> about ready for a new release, but python 3.2 needs to work before we
> push the next release out.

I committed a couple of minor fixes for python3.2 this weekend.  I'm now able to
run the full test-suite with python3.2, with and without -O and -builtin.

Stefan

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
SourceForge.net | 9 May 09:51 2011
Picon
Picon

[ swig-Bugs-3299307 ] Does not support repeat cascading

Bugs item #3299307, was opened at 2011-05-09 09:51
Message generated for change (Tracker Item Submitted) made by akimd
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=101645&aid=3299307&group_id=1645

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: preprocessor
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Akim Demaille (akimd)
Assigned to: Nobody/Anonymous (nobody)
Summary: Does not support repeat cascading

Initial Comment:
Hi,

I have been toying with Boost.Preprocessor, and maybe the SWIG preprocessor is not too far from being able
to grok it.  But there is a first issue, demonstrated as follows.

Thanks in advance.

$ swig -version

SWIG Version 2.0.3

Compiled with /usr/bin/g++-4.2 [i386-apple-darwin10.7.0]

Configured options: +pcre

Please see http://www.swig.org for reporting bugs and further information

$ cat /tmp/bar.cc
#define ONE(X) TWO
#define TWO(X) X

ONE(1)(2)

$ swig -E -java /tmp/bar.cc | tail

]

]
%includefile(maininput="/tmp/bar.cc") "/tmp/bar.cc" [

TWO(2)
]

$ g++ -Wall -E /tmp/bar.cc
# 1 "/tmp/bar.cc"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/tmp/bar.cc"

2

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=101645&aid=3299307&group_id=1645

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
SourceForge.net | 9 May 10:28 2011
Picon
Picon

[ swig-Bugs-3299307 ] Does not support cascading macro invocations

Bugs item #3299307, was opened at 2011-05-09 09:51
Message generated for change (Settings changed) made by akimd
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=101645&aid=3299307&group_id=1645

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: preprocessor
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Akim Demaille (akimd)
Assigned to: Nobody/Anonymous (nobody)
>Summary: Does not support cascading macro invocations

Initial Comment:
Hi,

I have been toying with Boost.Preprocessor, and maybe the SWIG preprocessor is not too far from being able
to grok it.  But there is a first issue, demonstrated as follows.

Thanks in advance.

$ swig -version

SWIG Version 2.0.3

Compiled with /usr/bin/g++-4.2 [i386-apple-darwin10.7.0]

Configured options: +pcre

Please see http://www.swig.org for reporting bugs and further information

$ cat /tmp/bar.cc
#define ONE(X) TWO
#define TWO(X) X

ONE(1)(2)

$ swig -E -java /tmp/bar.cc | tail

]

]
%includefile(maininput="/tmp/bar.cc") "/tmp/bar.cc" [

TWO(2)
]

$ g++ -Wall -E /tmp/bar.cc
# 1 "/tmp/bar.cc"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/tmp/bar.cc"

2

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=101645&aid=3299307&group_id=1645

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
SourceForge.net | 10 May 19:54 2011
Picon
Picon

[ swig-Patches-3300072 ] Tcl: fix for multi-import global variable problem

Patches item #3300072, was opened at 2011-05-10 13:54
Message generated for change (Tracker Item Submitted) made by delbaere
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=301645&aid=3300072&group_id=1645

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Christian Delbaere (delbaere)
Assigned to: Nobody/Anonymous (nobody)
Summary: Tcl:  fix for multi-import global variable problem

Initial Comment:
SWIG uses a global variable in the Tcl interpreter to track the first module that was loaded.  Currently, the
code that sets the variable does not explicitly use the global namespace.  This works correctly as long as
you load the modules outside of a namespace and outside of a procedure.  If you load the modules within a
namespace or procedure, or if you using Tcl packaging system, the 2nd module will overwrite the global
variable and there will be no linkage between them.

The attached patch contains a tiny fix for the problem as well as a modification to the tcl imports test to
reproduce the issue.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=301645&aid=3300072&group_id=1645

------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay

Gmane