Skip to content

Commit

Permalink
Revert unixsupport_unix.c to the upstream version when using runtime5
Browse files Browse the repository at this point in the history
  • Loading branch information
mshinwell committed Dec 4, 2023
1 parent d72f3a1 commit 9e9c643
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
37 changes: 35 additions & 2 deletions ocaml/otherlibs/unix/unixsupport_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include <caml/callback.h>
#include <caml/memory.h>
#include <caml/fail.h>
/* BACKPORT
#ifdef CAML_RUNTIME_5
#include <caml/platform.h>
*/
#endif
#include "unixsupport.h"
#include "cst2constr.h"
#include <errno.h>
Expand Down Expand Up @@ -291,6 +291,37 @@ int caml_unix_code_of_unix_error (value error)

static const value * _Atomic caml_unix_error_exn = NULL;

#ifdef CAML_RUNTIME_5

void caml_unix_error(int errcode, const char *cmdname, value cmdarg)
{
CAMLparam0();
CAMLlocal3(name, err, arg);
value res;
const value * exn;

exn = atomic_load_acquire(&caml_unix_error_exn);
if (exn == NULL) {
exn = caml_named_value("Unix.Unix_error");
if (exn == NULL)
caml_invalid_argument("Exception Unix.Unix_error not initialized,"
" please link unix.cma");
atomic_store(&caml_unix_error_exn, exn);
}
arg = cmdarg == Nothing ? caml_copy_string("") : cmdarg;
name = caml_copy_string(cmdname);
err = caml_unix_error_of_code (errcode);
res = caml_alloc_small(4, 0);
Field(res, 0) = *exn;
Field(res, 1) = err;
Field(res, 2) = name;
Field(res, 3) = arg;
caml_raise(res);
CAMLnoreturn;
}

#else

void caml_unix_error(int errcode, const char *cmdname, value cmdarg)
{
CAMLparam0();
Expand Down Expand Up @@ -326,6 +357,8 @@ void caml_unix_error(int errcode, const char *cmdname, value cmdarg)
CAMLnoreturn;
}

#endif

void caml_uerror(const char *cmdname, value cmdarg)
{
caml_unix_error(errno, cmdname, cmdarg);
Expand Down
1 change: 1 addition & 0 deletions ocaml/runtime/caml/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#ifndef CAML_CONFIG_H
#define CAML_CONFIG_H

/* CR ocaml 5 all-runtime5: remove this and all uses of it */
#define CAML_RUNTIME_5

/* CAML_NAME_SPACE was introduced in OCaml 3.08 to declare compatibility with
Expand Down

0 comments on commit 9e9c643

Please sign in to comment.