I am wrapping a library using SWIG (Python as target). Library functions contain parameters with data types "uint32_t", "uint8_t", etc. I want to make the interface as cross-platform as possible, so I want to use the original function signatures in my interface.i
file. For instance:
uint32_t func(uint32_t a, uint32_t b);
The problem I'm trying to solve is that SWIG will not recognize the parameter as an integer if there is no typedef
in the uint32_t
type. Right now I am using this in the interface file:
typedef unsigned uint32_t;
Removing this typedef
line will cause the function to not be called from the Python target binding:
>>> mylib.func(2, 2) TypeError: in method 'func', argument 1 of type 'uint32_t'
The previous typedef
is fine on my local machine, but may differ on another compiler / platform. Using the %include "stdint.h"
directive %include "stdint.h"
will throw an error on SWIG:
/usr/include/stdint.h:44: Error: Syntax error in input(1).
This makes sense because SWIG is not a fully functional compiler and cannot fully appreciate all of #ifdef
in this header.
How can I correctly combine SWIG with the data types that the compiler selects in the stdint.h
header? Does it make sense to have strict adherence to the correct data types, or just typedef
all intX_t
to long
in order?
source share