From 09c9ce9d28e4d592a4998b909bd1e5a524e84bd0 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Fri, 2 Jun 2023 18:24:30 -0700 Subject: [PATCH] fix: restore OCaml 4.03 compatibility (#135) * fix: restore OCaml 4.03 compatibility * wip * conditionally run tests * == * wip --- .github/workflows/build.yml | 16 ++++++++++++---- dune-project | 1 + src/ssl.ml | 16 +++++++++++----- src/ssl_stubs.c | 10 +++++++++- ssl.opam | 4 ++-- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 69ce2af..7342c66 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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: diff --git a/dune-project b/dune-project index 5dc002c..2667e48 100644 --- a/dune-project +++ b/dune-project @@ -1,2 +1,3 @@ (lang dune 2.7) + (name ssl) diff --git a/src/ssl.ml b/src/ssl.ml index 1f29659..44e2721 100644 --- a/src/ssl.ml +++ b/src/ssl.ml @@ -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 diff --git a/src/ssl_stubs.c b/src/ssl_stubs.c index 418ba21..875d744 100644 --- a/src/ssl_stubs.c +++ b/src/ssl_stubs.c @@ -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); } diff --git a/ssl.opam b/ssl.opam index f70608d..4341269 100644 --- a/ssl.opam +++ b/ssl.opam @@ -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"