(I guess the answer is “no!” but let’s ask the question in case anyone has any ideas …)
nbdkit has a concept of “debug flags”. From C code, a debug flag is just a global int
with a specially formatted name.
eg. the debug flag -D foo.bar=1
would be:
int foo_debug_bar;
(nbdkit uses dlsym
to find the symbol in the program symbol table and set the int value directly. These flags don’t have to be registered.)
Translating this concept into OCaml is awkward, manual and error-prone. Here’s my attempt which consists of some C code containing the debug flag and an accessor function which gets called from OCaml to read the value:
Ideally all of that could be generated somehow, so naturally I’m thinking that maybe PPX can do it. Can PPX generate C code? I don’t see anything obvious in ppxlib.
A corollary question is whether this could all be done in pure OCaml. The problem is having OCaml create an extern symbol with a very specific name (by default OCaml symbols appear in the symbol table but they all have the wrong form like camlFoo__bar_123
). And the content of the symbol is another issue since nbdkit expects it to be an int, but OCaml would expect it to be a block.
Any thoughts or ideas gratefully received …