swig

How to wrap a C structure which is defined with __attribute__((packed,aligned(1)))?

断了今生、忘了曾经 提交于 2019-12-12 03:45:56
问题 How do I wrap a C structure which is defined with __attribute__((packed,aligned(1))) in SWIG? 回答1: You need to do almost nothing to make this work, simply #define the attribute away: %module test #define __attribute__(x) struct foo {} __attribute__((packed,aligned(1))); Will parse and work as intended. The reason this works is that SWIG doesn't generate any code that cares about the layout or size of an object. Nor does it generate code that makes any assumptions about it either. Instead all

Ruby with Swig: NameError: uninitialized constant

蓝咒 提交于 2019-12-12 03:36:06
问题 I'm trying to use Qxt library (namely QxtGlobalShortcut) in the ruby. As suggested on: How can I call C++ functions from within ruby I created swig wrapper, however when trying to use generated library I'm stuck with error: NameError: uninitialized constant QxtGlobalShortcut::QxtGlobalShortcut from (irb):5 from /usr/bin/irb:12:in `<main>' My full irb session output: $ irb irb(main):001:0> require 'Qt4' => true irb(main):002:0> require 'QxtGlobalShortcut' => true irb(main):003:0> app = Qt:

python pointer to C structure in SWIG — accessing the struct members

杀马特。学长 韩版系。学妹 提交于 2019-12-12 02:49:13
问题 I'm trying to get a very basic Python-to-C interface working with SWIG where I can pass a pointer to a structure to a C function and the members get populated, and I can then access the members in python. In the below example, everything works except when I try to print the structure members: print swig_test.diags_mem0_get(var) Results in: $ ./runpython.py Traceback (most recent call last): File "./runpython.py", line 11, in <module> print swig_test.diags_mem0_get(var) AttributeError: 'module

How do I check if an externalptr is NULL from within R

两盒软妹~` 提交于 2019-12-12 02:28:25
问题 I'm using SWIG to generate wrapper code to access C code from within the R language. The wrapper code uses the R externalptr type to hold references to C pointers. In some situations, those pointers are NULL on the C side, which show up in R as a nil value when displayed. On the R side, calling is.null() and is.na() on the externalptr both return FALSE . For example: > val = librdf_query_results_get_binding_value(results, 2) > val An object of class "_p_librdf_node_s" Slot "ref": <pointer:

Modifying SWIG Interface file to Support C void* and structure return types

回眸只為那壹抹淺笑 提交于 2019-12-12 01:52:26
问题 I'm using SWIG to generate my JNI layer for a large set of C APIs and I was wondering what is the best practices for the below situations. The below not only pertain to SWIG but JNI in general. When C functions return pointers to Structures, should the SWIG interface file (JNI logic) be heavily used or should C wrapper functions be created to return the data in pieces (i.e. a char array that contains the various data elements)? When C Functions return void* should the C APIs be modified to

Swig bindings for python/lua do not initialize member data properly [closed]

◇◆丶佛笑我妖孽 提交于 2019-12-12 01:17:07
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . I'm trying to build a set of Lua bindings for a collection of C++ classes, but have been toying with Python to see if I get better results. In either

SWIG Convert unsigned char* to 20 byte buffer Java structure

这一生的挚爱 提交于 2019-12-11 22:56:13
问题 I have a C function (composeKey) that has an input unsigned char* parameter ("key"). On the C side, "key" needs to be an empty 20 byte buffer structure. I'm assuming that a Java short array with a size of 20 would be the correct Java structure to pass composeKey's "key" parameter, but I'm unsure. Maybe a byte[20] is what i need. If that is correct, what SWIG Interface file modification is needed to generate the composeKey Java method with a short[] as input for the "key" parameter? C Function

Compile Error Using SWIG %native Function

让人想犯罪 __ 提交于 2019-12-11 16:07:04
问题 I'm attempting to compile a native JNI call using the SWIG %native function and I'm getting the below exception for the header file. I'm including both the jdk-1.6.0_30/include and jdk-1.6.0_30/include/linux in the makefile below, Any ideas? I'm compiling on 32bit linux. Sample.h: JNIEXPORT jobject JNICALL Java_test_jni_GetData (JNIEnv *, jclass); SWIG.i: %module Sample %{ #include "Sample.h" %} %include "Sample.h" %typemap(jstype) DeviceId getID "com.test.jni.DeviceId" %typemap(jtype)

SWIG Configuration to Handle a FILE * C input Parameter in Java

最后都变了- 提交于 2019-12-11 13:28:35
问题 How would you configure the SWIG .i file to handle the C FILE * type? The below function sets a file so that log output can be written to it. I need to call if from a Java class. Currently a public static void setLogFile(SWIGTYPE_p_FILE fd) function is generated by SWIG when I just include the C header file with the below function. Any ideas? C Function: void setLogFile(FILE *fd); I attempted #1 using the below and got the below exception: test.i: %module Example %{ #include "headerLogFile.h"

System.EntryPointNotFoundException error in SWIG on mono 2.8

佐手、 提交于 2019-12-11 12:49:40
问题 I asked about an error for running Swig examples on mono 2.8 here. Adding "-arch i386" solved the issue with simple example, but when I tried to run the other examples, I got the following error, for example, with Examples/csharp/variables : Unhandled Exception: System.EntryPointNotFoundException: CSharp_ivar_set at (wrapper managed-to-native) examplePINVOKE:ivar_set (int) at example.set_ivar (Int32 value) [0x00000] in :0 at runme.Main () [0x00000] in :0 There seems to be no problem in