Detect use-after-close of Unix file descriptors

which uses Obj.magic and makes assumptions that a Unix file descriptor is an integer in the OCaml representation. This new representation would likewise break other code that does this.

That would break a large number of libraries. Using Obj.magic to convert between int and file_descr is the officially recommended way to do it: see Impossible to Unix.dup2 to a specific number or to inherit Unix_file_descr by number on startup · Issue #6948 · ocaml/ocaml · GitHub

If you’re only interested in Unix, you might just as well keep using the Obj.magic trick. as it is likely to keep working in the foreseeable future. It would be prudent to check Sys.os_type in an assertion, though.

It’s very popular, e.g. sherlocode file_descr.*Obj.magic.

1 Like