Hello!
Post by Walid TahaCan you find a way to dynamically load these helper functions as well,
rather than have to depend on having a fixed number of them?
Well, in principle this is possible. This is quite complex however:
OCaml generates the _assembler_ code of those functions (which is
placed into a start-up file, along with the other stuff).
Post by Walid TahaIs there a runtime overhead associated with calling dynamically loaded
functions?
No doubt, there is. Currently, btw, we have to invoke the dynamically
loaded code as a `call-back', which includes setting up special
stack frames. There is a lot of indirection involved. It seems there
may be simpler ways (and I have comments to that effect in the code),
whose investigation is left for future work.
Post by Walid TahaAnother way of interpreting this situation is that you guys really need to
include some documentation with this file.
Precisely. Hopefully this discussion will go towards the creation of
this documentation: this discussion is already searchable and
indexable...
Post by Walid Tahahave not been able to eliminate the segfaults entirely.
I should point out the the order of linking libraries into the main
executable matters (as always). In our prior experience with libtk and
gtk, it seems that those tk libraries must come _before_
metanative.cmxa and hookdynlink on the ocamlopt command line. Probably
because these libraries do their own non-trivial initialization and
perhaps dynamic loading as well. I think the current metaocaml script
always places user libraries and files after metanative.cmxa.
Post by Walid TahaI have also noticed in your note that dynlinked code has major
restrictions: no new exceptions, no globals.
Yes, it is the deliberate restriction to make code simpler (and
because these things can never occur in the MetaOcaml-generated
code). Making this more generic requires some work...
In general, if you find a puzzling segfault, please send me at least
the backtrace in gdb... Incidentally, when you compile the libnatdyn
library (see natdyn/Makefile), you may want to add a flag
-DDYN_DEBUG=1
to CFLAGS, and rebuild the library. The debugging information
(printed on stderr) can be quite helpful in determining the cause (at
least we can see what was loaded to where and so can interpret the
addresses in the backtrace intelligently).
Post by Walid TahaI patched Compilenv to generate all caml_apply and caml_curry function
up to an arity of 30. This might become a parameter to the configure
script.
That will work, no doubt. However, I'm a bit uneasy to make any
patches to the OCaml system. So far I have avoided patching of the
source code, and I hope that my changes are resilient against future
versions of Ocaml.
This brings the question to Walid: there were some things Ocaml team
and Xavier Leroy can do to make our lives easier. These are quite
small and hopefully uncontroversial things. I have also a few
suggestions stemmed from my work on shift/reset.