|
20 | 20 | #include <caml/callback.h>
|
21 | 21 | #include <caml/memory.h>
|
22 | 22 | #include <caml/fail.h>
|
23 |
| -/* BACKPORT |
| 23 | +#ifdef CAML_RUNTIME_5 |
24 | 24 | #include <caml/platform.h>
|
25 |
| -*/ |
| 25 | +#endif |
26 | 26 | #include "unixsupport.h"
|
27 | 27 | #include "cst2constr.h"
|
28 | 28 | #include <errno.h>
|
@@ -291,6 +291,37 @@ int caml_unix_code_of_unix_error (value error)
|
291 | 291 |
|
292 | 292 | static const value * _Atomic caml_unix_error_exn = NULL;
|
293 | 293 |
|
| 294 | +#ifdef CAML_RUNTIME_5 |
| 295 | + |
| 296 | +void caml_unix_error(int errcode, const char *cmdname, value cmdarg) |
| 297 | +{ |
| 298 | + CAMLparam0(); |
| 299 | + CAMLlocal3(name, err, arg); |
| 300 | + value res; |
| 301 | + const value * exn; |
| 302 | + |
| 303 | + exn = atomic_load_acquire(&caml_unix_error_exn); |
| 304 | + if (exn == NULL) { |
| 305 | + exn = caml_named_value("Unix.Unix_error"); |
| 306 | + if (exn == NULL) |
| 307 | + caml_invalid_argument("Exception Unix.Unix_error not initialized," |
| 308 | + " please link unix.cma"); |
| 309 | + atomic_store(&caml_unix_error_exn, exn); |
| 310 | + } |
| 311 | + arg = cmdarg == Nothing ? caml_copy_string("") : cmdarg; |
| 312 | + name = caml_copy_string(cmdname); |
| 313 | + err = caml_unix_error_of_code (errcode); |
| 314 | + res = caml_alloc_small(4, 0); |
| 315 | + Field(res, 0) = *exn; |
| 316 | + Field(res, 1) = err; |
| 317 | + Field(res, 2) = name; |
| 318 | + Field(res, 3) = arg; |
| 319 | + caml_raise(res); |
| 320 | + CAMLnoreturn; |
| 321 | +} |
| 322 | + |
| 323 | +#else |
| 324 | + |
294 | 325 | void caml_unix_error(int errcode, const char *cmdname, value cmdarg)
|
295 | 326 | {
|
296 | 327 | CAMLparam0();
|
@@ -326,6 +357,8 @@ void caml_unix_error(int errcode, const char *cmdname, value cmdarg)
|
326 | 357 | CAMLnoreturn;
|
327 | 358 | }
|
328 | 359 |
|
| 360 | +#endif |
| 361 | + |
329 | 362 | void caml_uerror(const char *cmdname, value cmdarg)
|
330 | 363 | {
|
331 | 364 | caml_unix_error(errno, cmdname, cmdarg);
|
|
0 commit comments