Skip to content

Commit

Permalink
Use default settings
Browse files Browse the repository at this point in the history
  • Loading branch information
davesnx committed Nov 3, 2023
1 parent 9e35828 commit 9c167ac
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 50 deletions.
1 change: 0 additions & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
profile = janestreet
24 changes: 12 additions & 12 deletions bin/bin.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ let () =
let plen = allocate int 0 in
let error_msg = allocate_n ~count:64 char in
let input = "asdf" in
let input_length = String.length input |> Unsigned.Size_t.of_int in
let length = String.length input |> Unsigned.Size_t.of_int in
let flags = 0 in
let bc =
Libregexp.C.Functions.lre_compile plen error_msg 64 input input_length flags null
Libregexp.C.Functions.lre_compile plen error_msg 64 input length flags null
in
match is_null bc with
| true -> print_endline "Error"
| false ->
let capture = CArray.make char 410 in
let start = CArray.start capture in
let start_capture = allocate (ptr char) start in
let matching = "asdf" in
let matching_length = String.length matching in
let matched =
Libregexp.C.Functions.lre_exec start_capture bc matching 0 matching_length 0 null
in
print_endline ("The result of the regexp is: " ^ Int.to_string matched)
;;
let capture = CArray.make char 410 in
let start = CArray.start capture in
let start_capture = allocate (ptr char) start in
let matching = "asdf" in
let matching_length = String.length matching in
let matched =
Libregexp.C.Functions.lre_exec start_capture bc matching 0
matching_length 0 null
in
print_endline ("The result of the regexp is: " ^ Int.to_string matched)
66 changes: 30 additions & 36 deletions function_description.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,39 @@ module Types = Types_generated
module Functions (F : Ctypes.FOREIGN) = struct
open F

(* uint8_t *lre_compile(
int *plen,
char *error_msg,
int error_msg_size,
const char *buf,
size_t buf_len,
int re_flags,
void *opaque) *)
let lre_compile =
foreign
"lre_compile"
F.foreign "lre_compile"
(* int *plen *)
(Ctypes.ptr Ctypes.int
@-> Ctypes.ptr Ctypes.char
@-> Ctypes.int
@-> Ctypes.string
@-> Ctypes.size_t
@-> Ctypes.int
@-> Ctypes.ptr Ctypes.void
@-> F.returning (Ctypes.ptr Ctypes.uint8_t))
;;
(* char *error_msg *)
@-> Ctypes.ptr Ctypes.char
(* int error_msg_size *)
@-> Ctypes.int
(* const char *buf *)
@-> Ctypes.string
(* size_t buf_len *)
@-> Ctypes.size_t
(* int re_flags *)
@-> Ctypes.int
(* void *opaque *)
@-> Ctypes.ptr Ctypes.void
@-> F.returning (Ctypes.ptr Ctypes.uint8_t))

(* int lre_exec(
uint8_t **capture,
const uint8_t *bc_buf,
const uint8_t *cbuf,
int cindex,
int clen,
int cbuf_type,
void *opaque) *)
let lre_exec =
foreign
"lre_exec"
F.foreign "lre_exec"
(* uint8_t **capture *)
(Ctypes.ptr (Ctypes.ptr Ctypes.char)
@-> Ctypes.ptr Ctypes.uint8_t
@-> Ctypes.string
@-> Ctypes.int
@-> Ctypes.int
@-> Ctypes.int
@-> Ctypes.ptr Ctypes.void
@-> F.returning Ctypes.int)
;;
(* const uint8_t *bc_buf *)
@-> Ctypes.ptr Ctypes.uint8_t
(* const uint8_t *cbuf *)
@-> Ctypes.string
(* int cindex *)
@-> Ctypes.int
(* int clen *)
@-> Ctypes.int
(* int cbuf_type *)
@-> Ctypes.int
(* void *opaque *)
@-> Ctypes.ptr Ctypes.void
@-> F.returning Ctypes.int)
end
4 changes: 3 additions & 1 deletion test/suite.ml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
let _ = Alcotest.run "test suite" [ "test", [ ("test", `Quick, fun () -> assert true) ] ]
let _ =
Alcotest.run "test suite"
[ ("test", [ ("test", `Quick, fun () -> assert true) ]) ]

0 comments on commit 9c167ac

Please sign in to comment.