swig

How to define swig typemap for returning unsigned char* back to java

久未见 提交于 2019-12-30 07:24:29
问题 I have a Java Application that calls a c library for performing crypto functions. This is a custom library implemented in c that we need to use from some Java programs. I need a way to define a SWIG typemap that will allow me call a function passing bytearray from Java and treat it as an unsigned character pointer in C function where c function fills data and returns it to java Excerpt of my present unhappy interface file is as follows %module CryptoFacade %pointer_functions(int, intp);

string arguments are not recognized by SWIG

前提是你 提交于 2019-12-30 05:08:12
问题 I have a frustrating problem which got me spend a lot of time dealing with it but I did not find any solution. I want to use C++ class in PHP with SWIG. I generated my shared object and it works fine for some methods but I've got this error whenever I call the methods with string arguments as their input: Fatal error: Type error in argument 2 of PKI_Buf_initHex . Expected SWIGTYPE_p_std__string PKI_Buf_initHex is the name of the wrapper class which SWIG made automatically. In my C++ code I

SWIG wrapping C++ for Python: translating a list of strings to an STL vector of STL strings

冷暖自知 提交于 2019-12-30 04:29:09
问题 I would like to wrap a C++ function with SWIG which accepts a vector of STL strings as an input argument: #include <iostream> #include <string> #include <vector> using namespace std; void print_function(vector<string> strs) { for (unsigned int i=0; i < strs.size(); i++) cout << strs[i] << endl; } I want to wrap this into a Python function available in a module called `mymod': /*mymod.i*/ %module mymod %include "typemaps.i" %include "std_string.i" %include "std_vector.i" %{ #include "mymod.hpp

registering java function as a callback in C function

旧时模样 提交于 2019-12-30 03:26:08
问题 I am trying to implement some C code in Java by using SWIG 1.3. Now I have to rebuild some existing C into Java code and to provide a function pointer to a Java function to the C method. The C code: net.c: void register_message_handler( context_t *ctx, message_handler_t handler) { context->msg_handler = (void (*)( void *, coap_queue_t *, void *)) handler; } client.c: void message_handler(context_t *ctx, queue_t *node, void *data) { ... } int main(int argc, char **argv) { // setup ctx register

SWIG: How to wrap std::string& (std::string passed by reference)

被刻印的时光 ゝ 提交于 2019-12-29 04:43:10
问题 I am using SWIG to access C++ code from Java. What is the easiest way to expose a std::string parameter passed by non-const reference? I have primitives passed by reference exposed as Java arrays, thanks to typemaps.i, and const std::string& s exposed as java.lang.String , thanks to std_string.i. But a non-const std::string& is exposed as opaque pointer type SWIGTYPE_p_std__string . Current: // C++ method -> // Java wrapper of C++ method void foo( int & i ) -> public void foo( int[] i ); //

Getting AccessViolation Exception when returning a bool from C++ to C#

て烟熏妆下的殇ゞ 提交于 2019-12-25 18:34:38
问题 I am using a third-party, proprietary DLL for which the source code is not available to me. Wrapper code that appears to have been auto-generated using SWIG 1.3.39 is, however, available to me. The wrapper code consists of a C++ file that compiles (using some headers that describe the DLL) to a DLL and of a C# project that makes PInvoke calls to the C++ wrapper DLL. After inspecting the StackTrace I got the following information: at org.doubango.tinyWRAP.tinyWRAPPINVOKE.MediaSessionMgr

How to pass python list address

此生再无相见时 提交于 2019-12-25 18:28:05
问题 I want to convert c++ code to python. I have created a python module using SWIG to access c++ classes. Now I want to pass the following c++ code to Python C++ #define LEVEL 3 double thre[LEVEL] = { 1.0l, 1.0e+2, 1.0e+5 }; GradedDouble gd(LEVEL, thre); gd.avg(thre); I need to convert the above code to python C++ constructor used for generating python module GradedDouble::GradedDouble(int n, double *thre) { n_ = n; for (int i = 0; i < n_; ++i) { thre_.push_back(thre[i]); grade_.push_back(new

The enums does not get passed to TCL when we have SWIG TCL Static Linking

白昼怎懂夜的黑 提交于 2019-12-25 08:01:33
问题 In continuation to question how to pass enum values from TCL script to C++ class using Swig I have following code 1) File : example.i %module example %{ /* Put header files here or function declarations like below */ #include "example.h" %} %include "example.h" 2 File example.h class myClass { public: enum Type {one,two}; myClass() {} static bool printVal(int val); static bool printEnum(Type val); }; 3) File example.cpp #include "example.h" #include <iostream> using namespace std; bool

SWIG cannot convert typedef type correct

送分小仙女□ 提交于 2019-12-25 07:39:36
问题 I'm using SWIT to convert a vc project to python. I found when a struct has a member which type is like "typedef char TEXT[16]" cannot be converted correctly. for example: typedef char TEXT[16]; struct MYSTRUCT { TEXT TradingDay; }; The wrapper cpp cannot compile all right. "error C2075: 'Target of operator new()' : array initialization needs curly braces" BUT,if typedef is not an array , like this: typedef int NUMBER; struct MYSTRUCT2 { NUMBER Money; }; there will be all right. what should I

Wrap a DLL into Java

陌路散爱 提交于 2019-12-25 05:09:15
问题 I've got some code to talk to a hardware device on windows which is working in C++. The code does something pretty simple to react to a button push on the device and I have this compiled into a dll with an observer that is called when the button is pushed. I now need to interface this with a big Java program. I was intending to use JNA but it only works with C and I cannot see how to do this with an Observer pattern in C. I've looked into using BridJ and SWIG (both of which cliam to work on C