swig

Use information from one argument to create another argument in typemap(in)

Use information from one argument to create another argument in typemap(in) Question: Currently I have the following C snippet: typedef struct My_Struct { int x; int y; } my_struct_t; void generate_buffer(my_struct_t info, uint8_t* buffer_out); I am trying to come up with a python swig interface to call this function. The output buffer size is in …

Total answers: 1

Python Swig interface for C function allocating a list of structures

Python Swig interface for C function allocating a list of structures Question: I’m trying to get the following C function to be exposed as a python interface. void myfunc(struct MyStruct** list, int* size) { int n = 10; *size = n; *list = (struct MyStruct*) malloc(n * sizeof(struct MyStruct)); for (int i = 0; i …

Total answers: 2

SWIG: Passing a list as a vector<double> pointer to a constructor

SWIG: Passing a list as a vector<double> pointer to a constructor Question: Trying to use swig to pass a python list as input for c++ class with a (one of many) constructor taking a std::vector<double> * as input. Changing the C++ implementation of the codebase is not possible. <EDIT> : What I am looking for …

Total answers: 2

Unable to generate .pyd file using swig

Unable to generate .pyd file using swig Question: I am trying to implement the example given in swig. I am using windows 11 64-bit pc. It has 3 files I file /* File: example.i */ %module example %{ #define SWIG_FILE_WITH_INIT #include "example.h" %} int fact(int n); C file /* File: example.c */ #include "example.h" int …

Total answers: 1

Swig deferencing python temporaries in typemap

Swig deferencing python temporaries in typemap Question: I want to pass a Python datetime object to the function printme below, seamlessly. struct DateTime { uint64_t epochns; }; void printme(DateTime dt); So far I was able to create this SWIG typemap to convert from datetime to DateTime %typemap(in) DateTime { PyObject* str = PyString_FromString( "timestamp" ); …

Total answers: 1

Swig pass Python datetime object to C++

Swig pass Python datetime object to C++ Question: I have a function in C++ that is passed a uint64_t as nanoseconds from epoch. I have wrapped this number in an object DateTime as in struct DateTime { uint64_t epochns; }; void print( DateTime ts ); Obviously the function is not exactly print as I could …

Total answers: 1

Optional Output from Bazel Action? (SWIG rule for Bazel)

Optional Output from Bazel Action? (SWIG rule for Bazel) Question: I’m working on a bazel rule (using version 5.2.0) that uses SWIG (version 4.0.1) to make a python library from C++ code, adapted from a rule in the tensorflow library. The problem I’ve run into is that, depending on the contents of ctx.file.source.path, the swig …

Total answers: 2

C++ & Python: Pass and return a 2D double pointer array from python to c++

C++ & Python: Pass and return a 2D double pointer array from python to c++ Question: I want to pass a 2D array from Python to a C++ function and then return an array of the same type, same dimensions, to Python. I am aware this question has already been asked several times, but I …

Total answers: 1

Python can't install Box2D swig.exe failed with error code 1

Python can't install Box2D swig.exe failed with error code 1 Question: I try to install Box2D on python but I get the error log: C:>pip3 install Box2D Collecting Box2D Using cached https://files.pythonhosted.org/packages/cc/7b/ddb96fea1fa5b24f8929714ef483f64c33e9649e7aae066e5f5023ea426a/Box2D-2.3.2.tar.gz Building wheels for collected packages: Box2D Running setup.py bdist_wheel for Box2D … error Complete output from command c:usershp-laptopappdatalocalprogramspythonpython36python.exe -u -c “import setuptools, tokenize;__file__=’C:\Users\HP-LAP~1\AppData\Local\Temp\pip-install-r48_7g5v\Box2D\setup.py’;f=getattr(tokenize, …

Total answers: 5