Jimi Damon | 28 Apr 02:36 2016
Gravatar

Java ( and other languages ) equivalent to %perlcode and %pythoncode

Hi,

I'm try to get around a problem I have where one of my C functions takes 
a callback function as one of it's arguments.  I want the user to be 
able to pass it a function pointer / reference in their native language 
and have this function call it.

I found a nice way around it for both Perl and Python where I just 
create brand new functions just for each language and I can do
that very easily with the expressions %perlcode and %pythoncode such as

#if defined(SWIGPYTHON)
%pythoncode %{
...

%}
#elif defined(SWIGPERL)
%perlcode %{
...

%}

My issue is that I really want to do the same sort of thing for my Java 
wrappers that I'm generating, but I can't find a %pragma or 
%insert(java)  where this code would make it into my top level Java 
class file.

I've noticed the same sort of thing for Ruby, but I find the C API 
easier to understand so I think I can just write an "inline" function to 
call any passed in lambda.
(Continue reading)

Jimi Damon | 27 Apr 21:00 2016
Gravatar

Is there a configuration parameter to change the names of Perl getter/setter methods

Hi,

I was just curious if there is a best practice to change the name of the 
methods that get generated for Perl methods ?

Right now , I'm seeing

*swig_size_get = *SomeClassc::Ushort_Array_size_get;
*swig_size_set = *SomeClassc::Ushort_Array_size_set;

Ideally, I would like to remove the swig_ prefix .

Is there a recommended way to do this other than post-process the 
AIOUSB.pm file that is generated ?

Thanks

-Jimi

--

-- 
WARNING - This e-mail or its attachments may contain controlled technical 
data or controlled technology within the definition of the International 
Traffic in Arms Regulations (ITAR) or Export Administration Regulations 
(EAR), and are subject to the export control laws of the U.S. Government. 
Transfer of this data or technology by any means to a foreign person, 
whether in the United States or abroad, without an export license or other 
approval from the U.S. Government, is prohibited. The information contained 
in this document is CONFIDENTIAL and property of ACCES I/O Products, Inc. 
Any unauthorized review, use, disclosure or distribution is prohibited 
without express written consent of ACCES I/O Products, Inc. If you are not 
(Continue reading)

Cuong Trinh Manh | 23 Apr 19:10 2016
Picon
Gravatar

Help Swig with NodeJS


Hi All,
I'm working on project wrapper C++ code for NodeJS.
I have a trouble when call function from NodeJS.
In Code C++ . I have 2 fucntion:
typedef void* A;
A  CreatePointer();
void UpdatePointer(A)

My code on NodeJS:
var pointer_a = CreatePointer();
UpdatePointer(pointer_a);

when I run appear error in function UpdatePointer

Error: in method 'UpdatePointer', argument 1 of type 'A'

What is wrong in my code ? Or I'm missing something when create wrapper ?

Thanks


-- 

nguoithichkhampha
----------------------------------------------------------------
***************************************************
Cuong Trinh Manh
Android Team Leader
Emotiv Ha Noi
Mobile: +841689902704
Skype:  nguoithichkhampha
Email:   nguoithichkhampha <at> gmail.com 
             cuong <at> emotiv.vn


***************************************************
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Akira | 20 Apr 16:51 2016
Picon
Picon

Output Typemap for one specific function

Hi,

I am wrapping a C++ library to Python.
This C++ library could potentially change afterwards, so I want to avoid
copying the C++ interface into the Swig interface and use 
%include "myheader.h"
instead.
Until now, this worked totally fine since you have things like "ignore".
But now I want to use an out typemap on one particular function which has,
unfortunately, a pretty common return value (char *).
Normally, I would add the typemap exactly at the point where I need it and
remove it afterwards. But for this I have to copy the header into the swig
interface.

Is there a way to specify exactly the function on which you want to apply
the (output) typemap?
I did not find anything about this in the doc or by searching...
There is, for example, an old swig-user post about this offering a work
around (which does not really works for out typemaps).
http://swig.10945.n7.nabble.com/Function-specific-Typemaps-with-C-td144.html

Thanks a lot in advance,
Akira

--
View this message in context: http://swig.10945.n7.nabble.com/Output-Typemap-for-one-specific-function-tp14714.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
Oliver Peters | 20 Apr 10:19 2016
Picon

octave shared_ptr bug: "Assertion `!newmemory' failed"

Hello,
I am trying to wrap a library for octave, which involves std::shared_ptr templates. I couldn't work around a bug (tried both swig2.0 and swig3.0), which I will demonstrate in the following small example:

=== shared.i ===
%module shared

%{
class A{
};
class B: public A{
};
void fun(std::shared_ptr<A> a){
}
%}

#define SWIG_SHARED_PTR_NAMESPACE std
%include <boost_shared_ptr.i>

%shared_ptr(A)
%shared_ptr(B)

class A{
};

class B: public A{
};

void fun(std::shared_ptr<A> a);
=== end of shared.i ===

=== Makefile ===
shared.oct: shared_wrap.cpp
     CPPFLAGS="-std=c++11" /usr/bin/mkoctfile $^ -o $ <at>

shared_wrap.cpp: shared.i
    swig3.0 -octave -c++ -o $ <at> $^
=== end of Makefile ===

I test this example (in octave 3.8.2) by passing an instance of B to fun(std::shared_ptr<A> a):

octave:1> shared
octave:2> a=shared.A();
octave:3> b=shared.B();
octave:4> shared.fun(a); %ok
octave:5> shared.fun(b);
octave-cli: shared_wrap.cpp:1350: void* octave_swig_type::cast(swig_type_info*, int*, int): Assertion `!newmemory' failed.
panic: Aborted -- stopping myself...
attempting to save variables to 'octave-workspace'...
save to 'octave-workspace' complete
Aborted (core dumped)

Is is possible to fix this bug, or is the octave target too incomplete to get this example functional?
Thanks
Olli
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
BRENNER Pat | 18 Apr 23:49 2016

Using C out parameters with SWIG/Python

Hi all,

 

I have a C API that I am calling from Python via SWIG.  One of my C functions looks like this:

 

int GetValueAndQuality(char *id, float *value, int *quality);

 

So my return value is a success code.  The id is an input string, for which I am getting the value and quality as out parameters.

 

How do I invoke this from Python so that I get the out parameters correctly filled?  Do I need to give SWIG some extra hints?

 

Thanks,

 

Pat Brenner

SCADA Software Engineer

Applications Engineering

Grid Solutions

a GE and Alstom joint venture

 

T +1 425 250 2547

pat.brenner <at> ge.com

www.gegridsolutions.com

 

10865 Willows Road NE

Redmond WA  98052  USA

 

Imagination at work

 


CONFIDENTIALITY : This e-mail and any attachments are confidential and may be privileged. If you are not a named recipient, please notify the sender immediately and do not disclose the contents to another person, use it for any purpose or store or copy the information in any medium.
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Akira | 14 Apr 15:00 2016
Picon
Picon

Position hand-written code for typemaps

Hi,

I have a rather big wrapping project and I use Swig.
Some of the functions I like to wrap return a C++ container class and I
would like to have some nice Python structure (like namedtuples) instead.
If I use a really high frequently used python structure like dictionaries,
everything works totally fine.
But in some cases (expecially in the case of the namedtuples) I have to
write my own Python type and have to add this type to the module.

If you would do this by hand, you would write your code to gather all the
infos your Type need and after you created you module, you add this type to
your module.

 Swig creates the module its SWIG_init function. So for example it would be
a solution to paste my hand-written code in this init function.

m = PyModule_Create(&SWIG_module); //creation of the module by swig

/* Begin of my Code*/
if (0 == PyStructSequence_InitType2(&MyType, &my_type_desc)) // MyType and
my_type_desc already created and positioned automatically at the right place
by SWIG
{
    Py_INCREF((PyObject*)&MyType);
    PyModule_AddObject(m, "my_type", (PyObject*)&MyType);
}
else
{
    PyErr_SetString(PyExc_Exception, "PyStructSequence_InitType2 for MyType
failed.");
}

/* End of my Code*/

But, of course, I do not want to paste this manually... Is there a way to
paste hand-written code manually? Or can I somehow tell swig to add
hand-written modules to my module?
The problem is, that I do create a new python type in the wrapper code and
want to use this type as return value in a type map.

Thanks in advance,
Akira

--
View this message in context: http://swig.10945.n7.nabble.com/Position-hand-written-code-for-typemaps-tp14700.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
Ahti Legonkov | 14 Apr 12:32 2016
Picon
Gravatar

Director lifetime management

Hi

I have a problem with directors being garbage collected too early. I have come up with couple of half-solutions that don't quite work or are too tedious for user or myself. If there is a known good solution for this problem, I would be interested to know about it.
I have C++ code similar to this one

    // test.h
    struct Callback
    {
        // no more callbacks after i==j
        virtual void onCallback(int i, int j) = 0;
    };

    // Call the callback repeatedly and delay unspecified amount of time in between
    void func(Callback* cb);


wrapping this for java works with following swig file

    %module(directors="1") Test
    %feature("director") Callback;
    %include "test.h"


The problem is that the instance of callback gets garbage collected when used like this in Java:

    func(new Callback() {
          <at> Override
          public void onCallback(int i, int j) {/* do interesting stuff here*/ }
    });
When keeping a reference to Callback somewhere (class member for example), there is no problem, but that is not OK because it would require users to write ugly code.

Digging in generated code I found that the Java wrapper class contains functions swigReleaseOwnership and swigTakeOwnership which called at appropriate times should prevent callback from being garbage collected. Like this:

    Callback cb = new Callback() {
      <at> Override
      public void onCallback(int i, int j) {
        /* do interesting stuff here*/

        if (i == j) cb.swigTakeOwnership();
      }
    });
    cb.swigReleaseOwnership();
    func(cb);

It seems to work but is tedious and error prone. I think encapsulating this knowledge in a utility class can simplify things for users a bit, but requiring users to do that or doing it by hand is not feasible.

  class MyCallback extends Callback {
    public MyCallback() { swigReleaseOwnership(); }
    <at> Override
    public void onCallback(int i, int j) { if (i == j) swigTakeOwnership(); }
  }

This is kind of ok, but I think it will never be garbage collected if onCallback with i==j is not invoked.

I also thought about modifying the wrapper for func so that it looked like this:

  public void func(Callback cb) {
    cb.swigReleaseOwnership(); // <-- ADD THIS
    TestJNI.func(swigCPtr, this, Callback.getCPtr(cb), cb);
  }

and somehow make onCallback look like this:

 class Callback {
 ...
  public void onCallback(int i, int j) {
    if (i==j) swigTakeOwnership(); // <-- ADD THIS
    TestJNI.Callback_onCallback(swigCPtr, this, i, j);
  }
 }

I think this suffers from the same problems as the previous solution, except it's a bit simpler because there is no extra class. If I can generate this with swig, I think I can live with these problems. What typemaps should I look into for making swig generate code like that?

--
Ahti Legonkov
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
BRENNER Pat | 13 Apr 19:03 2016

Unable to load my SWIG-generated library into Python

Hi all,

 

I’m building a C library that I want to be called from Python on Windows, called PYTHEXT.DLL.

 

Here’s what I have working so far:

·         I have a C module with several math functions, and a header file for the module.

·         I have a SWIG interface file which includes the C header file.

·         I have the C module and the SWIG-generated C file as part of my Visual Studio project.

·         The build of my project first generates the C file from SWIG, and then that file is then built into the resulting PYTHEXT.DLL.

·         The build also generates a PYTHEXT.PY file, which I assume is my Python module that I import in other Python modules.

 

This is where I get stuck—the module doesn’t load for me.

 

Here is the content of my DOMATH.PY script file:

 

a = 10

b = 11

import pythext

c = pythext.imathadd(a, b)

print(c)

exit()

 

When I run DOMATH.PY file so I can try invoking one of the functions in my library, I get the following error output:

 

D:\users\pbrenner\Python>python domath.py

Traceback (most recent call last):

  File "D:\users\pbrenner\Python\pythext.py", line 18, in swig_import_helper

    fp, pathname, description = imp.find_module('_pythext', [dirname(__file__)])

  File "C:\Users\haba0\AppData\Local\Programs\Python\Python35-32\lib\imp.py", line 296, in find_module

    raise ImportError(_ERR_MSG.format(name), name=name)

ImportError: No module named '_pythext'

 

During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

  File "domath.py", line 3, in <module>

    import pythext

  File "D:\users\pbrenner\Python\pythext.py", line 28, in <module>

    _pythext = swig_import_helper()

  File "D:\users\pbrenner\Python\pythext.py", line 20, in swig_import_helper

    import _pythext

ImportError: No module named '_pythext'

 

I’m sure I must be missing something simple, but what is it?  I haven’t found any clues in the SWIG or Python documentation.

Have I misnamed my DLL?  I’ve tried renaming it to various other filenames and it never gets loaded.

 

I appreciate any help you can provide.  Thanks,

 

Pat Brenner

SCADA Software Engineer

Applications Engineering

Grid Solutions

a GE and Alstom joint venture

 

T +1 425 250 2547

pat.brenner <at> ge.com

www.gegridsolutions.com

 

10865 Willows Road NE

Redmond WA  98052  USA

 

Imagination at work

 


CONFIDENTIALITY : This e-mail and any attachments are confidential and may be privileged. If you are not a named recipient, please notify the sender immediately and do not disclose the contents to another person, use it for any purpose or store or copy the information in any medium.
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Luke Foley | 11 Apr 19:52 2016
Picon

Re: C# wchar_t[] to string

<!-- .ExternalClass .ecxhmmessage P { padding:0px; } .ExternalClass body.ecxhmmessage { font-size:12pt; font-family:Calibri; } -->
Thanks for the reply Andrew.

I've taken a look at arrays_csharp.i and can see the following references to a standard char array:

CSHARP_ARRAYS_FIXED(unsigned char, byte)
CSHARP_ARRAYS_FIXED(signed char, sbyte)
CSHARP_ARRAYS(unsigned char, byte)
CSHARP_ARRAYS(signed char, sbyte)

Therefore mapping the unsigned/signed char to a unsigned/signed byte.

I'm a little confused as to what I'm mean to add into this file if I'm being honest. Lines for Unsigned/Signed wchar_t's mapped to anything seems to have no impact on the application what-so-ever and I still end up with a SWIGTYPE_p_wchar_t.cs file being generated and containing no functionality other than returning a pointer to the object.

Are you able to offer any further advise please?

From: andrew.haining <at> digitalbarriers.com
To: swig-user <at> lists.sourceforge.net
Date: Mon, 11 Apr 2016 17:09:04 +0100
Subject: Re: [Swig-user] C# wchar_t[] to string

<!-- .ExternalClass p.ecx1b961245-8985-476c-94bb-f762d97c2958, .ExternalClass li.ecx1b961245-8985-476c-94bb-f762d97c2958, .ExternalClass div.ecx1b961245-8985-476c-94bb-f762d97c2958, .ExternalClass table.ecx1b961245-8985-476c-94bb-f762d97c2958Table { } .ExternalClass div.ecxSection1 { } --><!-- .ExternalClass p.ecxMsoNormal, .ExternalClass li.ecxMsoNormal, .ExternalClass div.ecxMsoNormal { font-size:12.0pt; font-family:"Times New Roman",serif; } .ExternalClass a:link, .ExternalClass span.ecxMsoHyperlink { color:#0563C1; text-decoration:underline; } .ExternalClass span.ecxMsoHyperlinkFollowed { color:#954F72; text-decoration:underline; } .ExternalClass p { font-size:12.0pt; font-family:"Times New Roman",serif; } .ExternalClass span.ecxapple-tab-span { } .ExternalClass span.ecxEmailStyle19 { font-family:"Calibri",sans-serif; color:#1F497D; } .ExternalClass .ecxMsoChpDefault { font-size:10.0pt; } .ExternalClass div.ecxWordSection1 { } -->

Adding it to arrays_csharp.i should do the trick I think

 

From: Luke Foley [mailto:lukefoley2010 <at> live.co.uk]
Sent: 11 April 2016 16:46
To: swig-user <at> lists.sourceforge.net
Subject: [Swig-user] C# wchar_t[] to string

 

Good Afternoon All,

 

I've been franticly scouring the internet looking for advise on how to implement a suitable typemap for marshalling at wchar_t array to a String in c#. I've tested using a char[] instead of wchar_t[] and this works successfully, however I can't get an implementation working for wchar_t. The application I'm currently working on is for the Windows Platform and has been built only with Unicode in mind, hence wchar instead of char.

 

Can anyone offer any advise on how I implement this please?

 

For reference, the wchar_t array is defined below:

 

struct PIDUserGroup

{

            unsigned int ID;

            wchar_t Name[64];

};

 

Additionally, I've also tested this using std::wstring and SWIG successfully marshals to a string in C# too, however this application will be creating a Random Access File with Fixed Record Sizes.

 

Many Thanks,

Luke


______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________


 

Digital Barriers e-Mail Confidentiality and Disclaimer

                   

This message contains confidential information and is intended only for the individual named. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

 

Digital Barriers plc is a company registered in England and Wales. Registered number: 7149547. Registered office: Cargo Works, 1-2 Hatfields, London SE1 9PG, United Kingdom. For further information about Digital Barriers, please visit www.digitalbarriers.com.

 

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

------------------------------------------------------------------------------ Find and fix application performance issues faster with Applications Manager Applications Manager provides deep performance insights into multiple tiers of your business applications. It resolves application problems quickly and reduces your MTTR. Get your free trial! http://pubads.g.doubleclick.net/ gampad/clk?id=1444514301&iu=/ca-pub-7940484522588532
_______________________________________________ Swig-user mailing list Swig-user <at> lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/swig-user
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial! http://pubads.g.doubleclick.net/
gampad/clk?id=1444514301&iu=/ca-pub-7940484522588532
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Luke Foley | 11 Apr 17:46 2016
Picon

C# wchar_t[] to string

Good Afternoon All,

I've been franticly scouring the internet looking for advise on how to implement a suitable typemap for marshalling at wchar_t array to a String in c#. I've tested using a char[] instead of wchar_t[] and this works successfully, however I can't get an implementation working for wchar_t. The application I'm currently working on is for the Windows Platform and has been built only with Unicode in mind, hence wchar instead of char.

Can anyone offer any advise on how I implement this please?

For reference, the wchar_t array is defined below:

struct PIDUserGroup
{
unsigned int ID;
wchar_t Name[64];
};

Additionally, I've also tested this using std::wstring and SWIG successfully marshals to a string in C# too, however this application will be creating a Random Access File with Fixed Record Sizes.

Many Thanks,
Luke
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial! http://pubads.g.doubleclick.net/
gampad/clk?id=1444514301&iu=/ca-pub-7940484522588532
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

Gmane