You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to produce bindings that support multiple versions of a library. It generally went smoothly, but I hit a snag. The library used to have this definition:
typedefintOGRErr;
#defineOGRERR_NONE 0
#defineOGRERR_NOT_ENOUGH_DATA 1 /* not enough data to deserialize */#defineOGRERR_NOT_ENOUGH_MEMORY 2
#defineOGRERR_UNSUPPORTED_GEOMETRY_TYPE 3
#defineOGRERR_UNSUPPORTED_OPERATION 4
#defineOGRERR_CORRUPT_DATA 5
#defineOGRERR_FAILURE 6
#defineOGRERR_UNSUPPORTED_SRS 7
#defineOGRERR_INVALID_HANDLE 8
which was later replaced by:
#ifdefSTRICT_OGRERR_TYPE/** Type for a OGR error */typedefenum
{
OGRERR_NONE, /**< Success */OGRERR_NOT_ENOUGH_DATA, /**< Not enough data to deserialize */OGRERR_NOT_ENOUGH_MEMORY, /**< Not enough memory */OGRERR_UNSUPPORTED_GEOMETRY_TYPE, /**< Unsupported geometry type */OGRERR_UNSUPPORTED_OPERATION, /**< Unsupported operation */OGRERR_CORRUPT_DATA, /**< Corrupt data */OGRERR_FAILURE, /**< Failure */OGRERR_UNSUPPORTED_SRS, /**< Unsupported SRS */OGRERR_INVALID_HANDLE, /**< Invalid handle */OGRERR_NON_EXISTING_FEATURE/**< Non existing feature. Added in GDAL 2.0 */
} OGRErr;
#else/** Type for a OGR error */typedefintOGRErr;
#defineOGRERR_NONE 0 /**< Success */#defineOGRERR_NOT_ENOUGH_DATA 1 /**< Not enough data to deserialize */#defineOGRERR_NOT_ENOUGH_MEMORY 2 /**< Not enough memory */#defineOGRERR_UNSUPPORTED_GEOMETRY_TYPE 3 /**< Unsupported geometry type */#defineOGRERR_UNSUPPORTED_OPERATION 4 /**< Unsupported operation */#defineOGRERR_CORRUPT_DATA 5 /**< Corrupt data */#defineOGRERR_FAILURE 6 /**< Failure */#defineOGRERR_UNSUPPORTED_SRS 7 /**< Unsupported SRS */#defineOGRERR_INVALID_HANDLE 8 /**< Invalid handle */#defineOGRERR_NON_EXISTING_FEATURE 9 /**< Non existing feature. Added in GDAL 2.0 */#endif
The other enumerations in the library really are enums. I used the constified_enum_module option for them, and I wanted to also use it for the one above. However, I can't find a way to produce code that works with both versions of the library.
One approach I tried was to provide a replacement for the OGRErr definition:
/** * <div rustbindgen replaces="OGRErr"></div> */typedefenum
{
OGRERR_NONE, /**< Success */OGRERR_NOT_ENOUGH_DATA, /**< Not enough data to deserialize */OGRERR_NOT_ENOUGH_MEMORY, /**< Not enough memory */OGRERR_UNSUPPORTED_GEOMETRY_TYPE, /**< Unsupported geometry type */OGRERR_UNSUPPORTED_OPERATION, /**< Unsupported operation */OGRERR_CORRUPT_DATA, /**< Corrupt data */OGRERR_FAILURE, /**< Failure */OGRERR_UNSUPPORTED_SRS, /**< Unsupported SRS */OGRERR_INVALID_HANDLE, /**< Invalid handle */OGRERR_NON_EXISTING_FEATURE/**< Non existing feature. Added in GDAL 2.0 */
} StrictOGRErr;
But that doesn't work because it redefines the enum values and rustbingen replaces doesn't seem to consider them:
I guess the issue why you need to use STRICT_OGRERR_NONE instead of just OGRERR_NONE is because otherwise the C code doesn't build due to name clashes? That's indeed annoying :(.
We can add an annotation to rename enum variants, would that work for you?
I'm trying to produce bindings that support multiple versions of a library. It generally went smoothly, but I hit a snag. The library used to have this definition:
which was later replaced by:
The other enumerations in the library really are
enums
. I used theconstified_enum_module
option for them, and I wanted to also use it for the one above. However, I can't find a way to produce code that works with both versions of the library.One approach I tried was to provide a replacement for the
OGRErr
definition:But that doesn't work because it redefines the
enum
values andrustbingen replaces
doesn't seem to consider them:produces:
Is there a better way to do this?
The text was updated successfully, but these errors were encountered: