I have this struct in C:
typedef struct THTensor {
...
ptrdiff_t storageOffset;
...
} THTensor;
However, the SWIG-generated Java code is:
public SWIGTYPE_p_ptrdiff_t getStorageOffset() {
return new SWIGTYPE_p_ptrdiff_t(THJNI.THFloatTensor_storageOffset_get(this.swigCPtr, this), true);
}
I'd like that ptrdiff_t is converted to long in Java, not this SWIGTYPE_p_ptrdiff_t, in which I cannot access the actual long value.
How can I control this in SWIG?
There are several options... But
ptrdiff_tis unknown to SWIG and to define it just aslongis not the best idea.I would do the following: add
%include <stdint.i>to the interface file and then either add in the interface file:or add in the source code:
In such way, the code being wrapped in the interface should have appropriate interpretation of
ptrdiff_t, not just an opaque pointer.