Skip to content
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

Distinguish bytes and string in generated stub code #622

Merged
merged 1 commit into from
Dec 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/cstubs/cstubs_generate_c.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ struct
(value @-> returning (ptr void)),
[x])

let bytes_to_ptr : cexp -> ccomp =
fun x -> `App (reader "CTYPES_PTR_OF_OCAML_BYTES"
(value @-> returning (ptr void)),
[x])

let float_array_to_ptr : cexp -> ccomp =
fun x -> `App (reader "CTYPES_PTR_OF_FLOAT_ARRAY"
(value @-> returning (ptr void)),
Expand Down Expand Up @@ -143,7 +148,7 @@ struct
| Array _ -> report_unpassable "arrays"
| Bigarray _ -> report_unpassable "bigarrays"
| OCaml String -> Some (string_to_ptr x)
| OCaml Bytes -> Some (string_to_ptr x)
| OCaml Bytes -> Some (bytes_to_ptr x)
| OCaml FloatArray -> Some (float_array_to_ptr x)

let prj ty x = prj ty ~orig:ty x
Expand Down
8 changes: 8 additions & 0 deletions src/ctypes/ctypes_cstubs_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
#include <caml/threads.h>
#define CTYPES_PTR_OF_OCAML_STRING(s) \
(String_val(Field(s, 1)) + Long_val(Field(s, 0)))

#ifdef Bytes_val
#define CTYPES_PTR_OF_OCAML_BYTES(s) \
(Bytes_val(Field(s, 1)) + Long_val(Field(s, 0)))
#else
#define CTYPES_PTR_OF_OCAML_BYTES(s) CTYPES_PTR_OF_OCAML_STRING(s)
#endif

#define Ctypes_val_char(c) \
(Val_int((c + 256) % 256))
#define CTYPES_PAIR_WITH_ERRNO(v)
Expand Down