yallop / ocaml-ctypes

Library for binding to C libraries using pure OCaml
MIT License
363 stars 95 forks source link

define `CAML_COMPATIBILITY_H` to allow more idents #712

Open yilinwei opened 1 year ago

yilinwei commented 1 year ago

compatibility.h defines preprocessor macros which means certain identifiers, such as alloc cannot be used. The preprocessor expands the identifier into caml_xxx in the offset_of.

This is a problem when binding with cstubs when structs have fields with the same identifiers. Currently, you can manually add this #define in the preamble manually as a workaround.

Note: compatibility.h is removed in ocaml 5, but is present until 4.14.

MisterDA commented 1 year ago

I think the proper fix is to make sure that we're using "namespaced" identifiers in the C code (that is, starting with caml_ when they're defined in the caml headers, and define CAML_NAME_SPACE which prevents the compatibility.h header from being included. Surely we don't have to support OCaml versions that are older than the switch to prefixed identifiers?