New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#define Val_some #5154
Comments
Comment author: @mshinwell @doligez I find the lack of this functionality to be a bit of a nuisance as well; what do you think? |
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
Val_some(activity) |
@ygrek: would you consider submitting a PR? |
I took the liberty of making a PR with his patch #9569 |
Just for reference, some projects had already defined some of the macros. For instance, see ocaml-mccs. Although they share the same definition, some compilers raise warnings when redefining macros (e.g. MSVC 2019). In some setups, warnings are turned to errors and the build of a package fails (e.g. building Opam…). I’m submitting patches to fix that, I think that checking #if OCAML_VERSION < 41200
#define Val_none Val_int(0)
#define Some_val(v) Field(v, 0)
#endif EDIT: changed |
Thanks for the heads-up @MisterDA! Yes, checking |
But which version? If the commit won’t be included before 4.12, then |
Indeed, the patch in question will only be included in 4.12, and not in the 4.11.x releases. |
Macros `Val_none` and `Some_val` are part of the standard library starting with OCaml 4.12. In some environments, redefining a macro triggers a compiler warning. When warnings are treated as errors, the build fails. Issue discussing the introduction of the macros, the problem, and the fix: ocaml/ocaml#5154 Commit introducing the macros in the standard library: ocaml/ocaml@973eeb1
If an OCaml C library already defines some of the new `Val_none`, `Some_val`, `Is_none`, `Is_some`, `caml_alloc_some`, or `Tag_some` macros; then the C compiler will likely warn for macro redefinition, even if the macro definition are identical. In some setups that always turn warnings to errors, this will block the compilation of the library. This problem happens in [ocaml-mccs][1]. The proposed [fix][2] for libraries is to only define the macros when compiling with OCaml strictly older than 4.12, i.e.: #if OCAML_VERSION < 41200 #define ... #endif [1]: ocaml-opam/ocaml-mccs#30 [2]: ocaml#5154 (comment)
If an OCaml C library already defines some of the new `Val_none`, `Some_val`, `Is_none`, `Is_some`, `caml_alloc_some`, or `Tag_some` macros; then the C compiler will likely warn for macro redefinition, even if the macro definition are identical. This problem happens in [ocaml-mccs][1]. The proposed [fix][2] for libraries is to only define the macros when compiling with OCaml strictly older than 4.12, i.e.: #if OCAML_VERSION < 41200 #define ... #endif [1]: ocaml-opam/ocaml-mccs#30 [2]: ocaml#5154 (comment)
Original bug ID: 5154
Reporter: @ygrek
Assigned to: @damiendoligez
Status: assigned (set by @mshinwell on 2016-12-08T08:46:17Z)
Resolution: open
Priority: normal
Severity: feature
Version: 3.11.2
Category: runtime system and C interface
Tags: patch
Monitored by: @hcarty
Bug description
OCaml C interface defines many macros to construct/access primitive ocaml values from C code. One thing that I often find missing and have to copy-paste myself in almost every binding is code to handle option type.
Additional information
#define Val_none Val_int(0)
value Val_some(value v)
{
CAMLparam1(v);
CAMLlocal1(some);
some = caml_alloc_small(1, 0);
Field(some, 0) = v;
CAMLreturn(some);
}
#define Some_val(v) Field(v,0)
The text was updated successfully, but these errors were encountered: