Skip to content

Commit

Permalink
fix: restore OCaml 4.03 compatibility (#135)
Browse files Browse the repository at this point in the history
* fix: restore OCaml 4.03 compatibility

* wip

* conditionally run tests

* ==

* wip
  • Loading branch information
anmonteiro committed Jun 3, 2023
1 parent 5aa2402 commit 09c9ce9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/build.yml
Expand Up @@ -13,22 +13,30 @@ concurrency:

jobs:
build:
runs-on: ${{ matrix.operating-system }}
runs-on: ubuntu-latest
strategy:
matrix:
operating-system: [ubuntu-latest]
ocaml-version: ['4.09.0', '4.14.1', '5.0.0']
setup:
- {ocaml-version: '4.03', runtest: false}
- {ocaml-version: '4.09', runtest: true}
- {ocaml-version: '4.14', runtest: true}
- {ocaml-version: '5.0', runtest: true}
steps:
- uses: actions/checkout@v2
- uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: ${{ matrix.ocaml-version }}
ocaml-compiler: ${{ matrix.setup.ocaml-version }}
- name: Setup opam
run: opam pin add -n .
- name: Install dependencies
run: opam depext -yt mad
- name: Build
if: ${{ ! matrix.setup.runtest }}
run: opam install .
- name: Build and test
if: ${{ matrix.setup.runtest }}
run: opam install -t .

nix-build:
runs-on: ${{ matrix.setup.os }}
strategy:
Expand Down
1 change: 1 addition & 0 deletions dune-project
@@ -1,2 +1,3 @@
(lang dune 2.7)

(name ssl)
16 changes: 11 additions & 5 deletions src/ssl.ml
Expand Up @@ -90,19 +90,25 @@ module Error = struct

let get_error () =
error_struct Get_error

let peek_error () =
error_struct Peek_error

let peek_last_error () =
error_struct Peek_last_error

(** Reproduces the string format from ERR_error_string_n *)
let peek_last_error_string () =
let err = peek_last_error () in
let libstring = Option.value err.lib ~default:"lib(0)" in
let reasonstring = Option.value err.reason ~default:"reason(0)" in
Printf.sprintf "error:%08lX:%s::%s" (Int32.of_int err.code) libstring reasonstring
let libstring = match err.lib with Some lib -> lib | None -> "lib(0)" in
let reasonstring =
match err.reason with Some reason -> reason | None -> "reason(0)"
in
Printf.sprintf
"error:%08lX:%s::%s"
(Int32.of_int err.code)
libstring
reasonstring
end

exception Method_error
Expand Down
10 changes: 9 additions & 1 deletion src/ssl_stubs.c
Expand Up @@ -644,7 +644,15 @@ CAMLprim value ocaml_ssl_digest(value vevp, value vcert)
caml_raise_with_arg(*caml_named_value("ssl_exn_certificate_error"), caml_copy_string(buf));
}
vdigest = caml_alloc_string(digest_size);
memcpy(Bytes_val(vdigest), buf, digest_size);

/* TODO(anmonteiro): switch this to `Bytes_val` when we bump support to
* OCaml 4.06 (https://github.com/ocaml/ocaml/pull/1274)
*
* In the meantime, reproduce `Bytes_val`, which is effectively `String_val`
* + a cast:
* https://github.com/ocaml/ocaml/pull/1274/commits/6bc4f2656e435175188018830e7fe049caacebe9
*/
memcpy((unsigned char *)String_val(vdigest), buf, digest_size);
CAMLreturn(vdigest);
}

Expand Down
4 changes: 2 additions & 2 deletions ssl.opam
Expand Up @@ -14,8 +14,8 @@ run-test: [
["dune" "runtest" "-p" name "-j" jobs]
]
depends: [
"ocaml" {>= "4.02.0"}
"dune" {>= "2.0.7"}
"dune" {>= "2.7"}
"ocaml" {>= "4.03.0"}
"dune-configurator"
"base-unix"
"conf-libssl"
Expand Down

0 comments on commit 09c9ce9

Please sign in to comment.