Mathieu Malaterre | 9 Feb 11:04
Picon

Anyone using JavaScript ?

Hi there,

  Is anyone using JavaScript ? What are people using for JavaScript
bindings ? I see Flusspferd, nodejs... but they seems to target a
single JS implementation.

Thanks for comments,
--

-- 
Mathieu

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
Build Master | 8 Feb 21:58
Picon

Buggy Mono marshalling for Unicode string

Hi SWIG,

On Mac OS X, I've been having bugs when marshalling Mono string back and forth
between managed and unmanaged code with SWIG, like input string "abc"
becomes "ac" when coming into my unmanaged side. My managed code
in myPINVOKE.cs:

  [DllImport("SwigMonoString", EntryPoint="CSharp_SetPath")]
  public static extern string SetPath([MarshalAs(UnmanagedType.LPWStr)]string jarg1);

the corresponding unmanaged C++ function:

    DLLEXPORT std::string SetPath(const wchar_t* path)
    {
        std::wstring ws(path);
        std::string s;
       
        s.reserve(ws.length()*2);
        s.resize(ws.length()*2, '0');
       
        std::copy(ws.begin(), ws.end(), s.begin());       
       
        return s;
    }

Then the returned strings are totally wrong, which seem to not only have
missing characters but also have been shuffled.

The similar code works fine for char* version.
And the same code works on Windows.

I came across this old post from 2008 saying it's SWIG's bug.
http://old.nabble.com/C--marshaling-Unicode-characters-incorrectly-td16013560.html
I wonder if what it says still holds and does anyone have an idea about how to fix my problem?
Do I have to customize string modules like std_wstring.i??


Thanks.
Beinan

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Favicon

uchar_t[] question

Hi,


First of all many thanks to Bob Hood for sorting out my last question on pointers to pointers. I am now looking at passing/receiving another (slightly simpler) structure:

typedef struct _Guid
{
        uchar_t guid[16];
} Guid;

But again I'm having difficulty actually getting the uchar_t as an to be returned in Python (so I have to convert to a python string), and then using it as an argument to the following call:

int GetViewEntryList( Guid *lu, viewEntryList **EntryList);

Following on from Bob's advice I created the pointer to pointer swappers and they work fine, however, when I try to create a Guid type, say for example in:

x = example.Guid();
x.guid = '600144F042AB4C0000004F2967D005A3'

I always get the error back (and I know the string above is incorrect, but this is here to throw the error):

TypeError: in method 'Guid_guid_set', argument 2 of type 'uchar_t [16]'

I understand that it's a wrapper, and that the first arg is the Guid structure itself (which appears to get sent over correctly) - but how do I construct a uchar_t [16] in python so I can pass it as a valid assignment (or argument) so that x.guid = <whatever is required> will work or am I confused in that SWUG may have references to uchar_t but not know how to create/manipulate them etc.

Many thanks for any suggestions.

Paul
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Favicon

Problem with threads::shared in perl.

Hi,

I have a small program that works correctly without thread. To use 
threads, I must share some of the variable with htreads::shared.
I get a message like "TypeError in method 'foo_bar', argument 1 of type 
'foo *'" every time I try to pass a threads::shared variable to one of 
my C function.

example.i:
    %module example

    %{
      typedef struct foo {
        int data;
      } foo;
      foo *new_foo(int data) {
        foo *fo = malloc(sizeof(foo));
        fo->data = data;
        return fo;
      }
      int foo_bar(foo *fo) {
        return fo->data;
      }
    %}

    typedef struct foo {
      int data;
    } foo;

    %extend foo {
      foo(int data);
      int bar();
    }

working example without threads (example.pl):
    #!/usr/bin/perl
    use lib '.';
    use example;

    my $foo;
    $foo = example::foo->new(5);
    $r = $foo->bar();
    print "$r\n";

$ ./example.pl
5

not working example with threads (example_shared.pl):
    #!/usr/bin/perl
    use lib '.';
    use threads;
    use threads::shared;
    use example;

    my $foo : shared;
    $foo = shared_clone(example::foo->new(5));
    $r = $foo->bar();
    print "$r\n";

$ ./example_shared.pl
TypeError in method 'foo_bar', argument 1 of type 'foo *'

What can I do to use threads::Shared variable with swig?

Jean-Louis

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
greg mills | 5 Feb 17:01
Favicon
Gravatar

C++ and python

Hello there!
What a strange thing? I strictly following the manual and obtain an
error trying to wrap C++ for Python.

_______________ example.cpp ______________________
double fact(double n) {
  double a = 10.1;
  return a;
}
________________ example.i ________________________
%module example
double fact(double n);
___________________________________________________
# swig -c++ -python -o example_wrap.cpp example.i
# g++ -c example_wrap.cpp -I/usr/include/python2.7
example_wrap.cpp: In function ‘PyObject* _wrap_fact(PyObject*,
PyObject*)’:
example_wrap.cpp:3104:29: error: ‘fact’ was not declared in this scope

Swig 2.0.4
gcc (Debian 4.6.2-11) 4.6.2
Debian Linux 3.1.0-1-686
-- 
  greg mills

--

-- 
http://www.fastmail.fm - Faster than the air-speed velocity of an
                          unladen european swallow

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
jcupitt | 3 Feb 14:39
Picon
Gravatar

OUTPUT args from C++ member functions?

Hi all,

I'm having some trouble with output args from C++ member functions in
swig 1.3.40 (the one that comes with current ubuntu).

I have a class like this in a header:

-------
class VImage ... {
    ...
    double test_member( double a, double b, double *c, double *d );

}
--------

With a body like this (ie. it returns three doubles, two via output args):

------
double VImage::test_member( double a, double b, double *c, double *d )
{
        *c = a + b;
        *d = a - b;
        return a * b;
}
--------

In my VImage.i file I have this:

-------
%include "typemaps.i"

extern double vips::VImage::test_member(double INPUT, double INPUT,
        double *OUTPUT, double *OUTPUT);

%include VImage.h
------

Looking at the generated code, it seems to have linked up the typemap
with the member, since it includes things like this:

----
res4 = SWIG_ConvertPtr(obj3, &argp4,SWIGTYPE_p_double, 0 |  0 );
  if (!SWIG_IsOK(res4)) {
----

ie. it's understood that arg4 is a result, but the Python wrapper
still insists on 4 arguments:

print a.test_member(1, 2)
TypeError: VImage_test_member() takes exactly 5 arguments (3 given)

I'm sure I'm being dumb :( Can anyone shed any light on my dumbness?

John

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
redapple | 2 Feb 15:27
Picon
Gravatar

Static Function in 64 bit Machine


I used swig to wrapped some C++ classes used in the python. On 32 bit
windows, it works very well.
Recently I build all my applications on 64 bit machine, still using swig to
wrap the same classes into the python. However, some classes caused the
python interpreter crash.

For example, I have a util.lib in C++ which includes a few c++ classes. I
have a util.i to define what classes should wrapped out. Then generated
_util.pyd used in python.

Then in python 2.7,

import _util
quit()    ----- python interpreter crash!

I checked and found _util.pyd works (no crash) if I remove a class A from
util.lib, this class A defines static function which returns a pointer.

I'm wondering what causing the crash problem and how to fix it. Any help
will be appreciated.

BTW, python is 2.7.2 64 bit version.  My application is build by MSVS 2008
amd64 compiler.

Thank you.

--

-- 
View this message in context: http://old.nabble.com/Static-Function-in-64-bit-Machine-tp33238570p33238570.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
Russell Johnston | 1 Feb 19:16
Picon
Gravatar

SWIG struct members are freed prematurely by Java's garbage collector

I have a C++ library that is called by Java through a SWIG-based
interface. On the Java side, I build up a structure containing
pointers to arrays of other structures, using the default struct
interface andcarrays.i's %array_class.

Because Java's garbage collector is not aware of the members of the
top-level struct, the array is sometimes freed, whereon its finalizer
delete[]s its backing memory. I need a way around this, preferably
without duplicating the struct in Java, since it's rather large.

A minimal example looks like this (although it probably won't trigger
the bug since it doesn't do much):

C++/SWIG:

%module example

%include "carrays.i"
%array_class(object, objectArray);

struct object {
    unsigned int id;
    char *name;
};

struct data {
    size_t nobjects;
    object *objects;
};

void use_data(data*);

Java:

public class Example {
    private static data writeData() {
        data d = new data();
        objectArray os = new objectArray(3);
        for (int i = 0; i < 3; i++) {
            object o = new object();
            o.setId(i);
            o.setName("obj" + i);
            os.setitem(i, o);
        }
        d.setNobjects(3);
        d.setObjects(os.cast());

        return d;
    }

    public static void main(String[] args) {
        data d = writeData();
        example.use_data(d);
    }
}

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Favicon

Declaring pointers to pointers C->Python

Hi,

I am trying to use a pointer to a pointer in Python but I cannot seem to work out the correct syntax, the declaration for the C functions is:

typedef struct _GroupList
{
        uint32_t cnt;
        char *name[1];
} GroupList;

int getGroupList(GroupList **myGroupList);

It's a supplied system call so I cannot change the argument call. In python I do:

import example
GroupList = example.GroupList()

print GroupList
example.getGroupList( GroupList )

Which results in:

<example.GroupList; proxy of <Swig Object of type 'GroupList *' at 0x81679b0> >
Traceback (most recent call last):
  File "test.py", line 7, in <module>
    example.getGroupList( GroupList )
TypeError: in method 'getGroupList', argument 1 of type 'GroupList **'

I just cannot work out how to get a pointer to a pointer rather than just a pointer (and I do understand why I just get a pointer) - any help would be most appreciated.

Many Thanks,

Paul Griffiths
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Jim Bosch | 31 Jan 00:58
Picon

instantiate templates with different signatures

If I have multiple templated functions with the same name and same 
template parameters, but different signatures, is there any way to 
instantiate those templates with different types?

Here's an example:

template <typename T>
struct int_thing;

template <typename T>
struct float_thing;

template <typename T>
void func(int_thing<T> * t);

template <typename T>
void func(float_thing<T> * t);

I'd like to do the %template equivalent of the following C++ explicit 
instantiations:

template void func(int_thing<int> *);
template void func(int_thing<long> *);

template void func(float_thing<float> *);
template void func(float_thing<double> *);

Is there any way to do this?

Thanks!

Jim Bosch

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
John Pye | 27 Jan 23:35
Favicon
Gravatar

Any success building SWIG/Python extensions with MinGW-w64?

Hi all

I have been trying to compile my SWIG-based Python extension using
MinGW-w64, the MinGW compiler that targets 64-bit Windows. I have a
example that works fine on Linux but fails with a segfaul on Windows
during Python shutdown.

Has anyone got any suggestions to offer in relation to MinGW-w64? Anyone
at all succeeding in building a working extension with that compiler?

Full details of what I've done, including the test code tarball, are
here:
http://ascend4.org/Building_ASCEND_for_64-bit_Windows#Python_bindings

Cheers
JP

PS the only possible issue I can think of so far is that I haven't
linked to msvcr90.dll correctly. Otherwise, I'm stumped.
--

-- 
John Pye
john <at> curioussymbols.com

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2

Gmane