Thomas Leonard's work notes

(see roscidus.com for my main blog)

(Eio and MDX)

Eio

I had a go at using LexiFi/dead_code_analyzer on Eio. There were lots of false positives, but it did find a few things that could be deleted:

  • Remove unused code #941.

One of these was the avail function for finding out how many fixed buffer chunks are available. That could actually be useful, so I made a public way to use it rather than removing it:

  • Add Eio_linux.Low_level.Fixed.avail #940.

Like unhandled, which I mentioned last time, dead_code_analyzer works by scanning the cmt files that OCaml generates when building. This looks like another case where a more general framework for analysis could be useful.

I released Eio 1.6 with the new support for environment variables, opening paths without following symlinks, importing FDs as Eio files, and all the recent Windows path fixes.

Thomas Gazagnaire was working on a small embedded database using Eio and noticed there was no way to synchronise a directory, which is necessary to ensure changes aren't lost if the computer crashes, so I added that:

  • Add Path.sync_dir #943.

Volker Diels-Grabsch had reported that Net.run_server by default doesn't limit the number of connections, which means that on a public server an attacker can crash it fairly easily. Making a service robust to denial-of-service attacks is quite difficult in general, but I added a note with some hints to the documentation:

  • Eio.Net.run_server: add note about running public servers #944.

MDX

I've been using MDX as a pleasant way to write expect tests for a while, but a long-standing annoyance is that it didn't provide a way to skip tests. We've needed this in several places. For example, we can't test certain uring features unless the kernel is recent enough. To solve that, I added an mdx_skip function that skips the rest of a block:

  • Add mdx_skip for skipping tests #483.

It's used like this:

```ocaml
# if Sys.word_size < 64 then mdx_skip "Requires 64-bit words";;
- : unit = ()

# 0x100000000;;
- : int = 4294967296
```

Here are some things that can be fixed once it's released:

  • Skip uring tests if uring isn't available #945.
  • Some tests in tests/main.md fail in some environments #161.

OCaml's toplevel API doesn't seem to be documented much, but what worked in the end was injecting this code as a prelude:

let rec _mdx_skip : string option ref = ref None
and mdx_skip reason =
  _mdx_skip := Some reason;
  failwith reason

Then I used Toploop.getvalue "_mdx_skip" to get a reference to it. Not sure if that's a good way to do it, but it seems to be working.