I am creating a Python wrapper for an existing code base with a DLL and header. I am using SWIG.
The code base has multiple struct pointer defs like so:
typedef struct session* session_t;
In this example, session is not defined anywhere else. All other functions in the DLL take session_t as an input. If I try and reference session anywhere in SWIG generated code I get compile errors that session is not defined. I need a way to access the value of session_t in Python code.
I've tried using cpointer.i and pointer_functions macro, but this doesn't work since it assumes the input type is not a pointer.
I thought if I could redefine the struct:
typedef struct Session {} session, *session_t;
This could work, but I cant find a way to do this with SWIG.
Is there a way to access the value of a struct pointer with SWIG if it's only definition is a typdef struct pointer?
Edit: possible fix is the SWIG %ignore directive. Might be able to ignore the original struct def and replace it in the .i file.
Solved(ish): I marked Mark Tolonen's answer as correct since it has a lot of useful relevant information. The API I'm trying to wrap has a lot of deleted constructors and behaviors locking down how it's used. I ended up writing a C++ wrapper in it's own namespace then telling Swig to ignore everything except my namespace. I then only use standard or my own types to interface with Swig/Python.
struct session {};somewhere in the header file. This way, you must also ensure that you never allocate astruct sessionby yourself.session_t session_open(void)which returns a new instance ofsession_t(like e.g.fopen).session*and perhaps other functions, which usesession*. Take a lot at this answer, stackoverflow.com/questions/32478649/… The base class can be replaced with a simpletypedefto make it more C like