Closed yallop closed 4 years ago
Still insufficent in case of ocaml_bytes.
Bytes_val returns unsigned char *
:
https://github.com/ocaml/ocaml/blob/646d30404e6b5fa0d49aea3860cbf4efe3910601/runtime/caml/mlvalues.h#L269
The corresponding c type for Ctypes.ocaml_bytes
is char *
:
https://github.com/ocamllabs/ocaml-ctypes/blob/4327af50c24dbfdf5f9ba9c22b8f432de290b50d/src/ctypes/ctypes_type_printing.ml#L77
And clang triggers a warning message by default for such casts: https://clang.llvm.org/docs/DiagnosticsReference.html#wpointer-sign
We should it either use ptr uchar
for ocaml_bytes in the snippet above - or cast the unsigned specifier away inside the CTYPES_PTR_OF_OCAML_BYTES macro. Then there is at least the possibility that no warning is triggered.
We should it either use
ptr uchar
forocaml_bytes
in the snippet above
This seems like the best fix to me. #625 makes this change.
OCaml 4.10 defaults to the
force-safe-string
mode, so that theString_val
macro returnsconst char *
.This PR updates ctypes to generate calls to
Bytes_val
rather thanString_val
for uses ofocaml_bytes
, ensuringconst
-correctness and fixing problems such as the one reported here.