caml-list - the Caml user's mailing list
 help / Atom feed
From: Frédéric Fort <>
Subject: [Caml-list] Dynlink plugin reevaluates modules of main program
Date: Thu, 8 Nov 2018 11:05:14 +0100 (CET)
Message-ID: <> (raw)


I have an existing program and would like to allow to extend it's functionalities with plugins.
If I simplify my code structure it looks as follows:
 - : "main module" of the program
 - : additional definitions used in
 - : interface for plugins (a collection of function refs)
 - : plugin I would like to load

Now, uses values defined in Some of them are of type string ref
and it seems that the code of is reevaluated when I call
Dynlink.loadfile "/path/to/d.cmxs" which resets them to the empty string.

Is there a way to prevent this from happening ?
Using allow_only and prohibit is not an option, since multiple plugins would each reevaluate C
and undo each others modifications.

Yours sincerely,
Frédéric Fort

P.S.: Here follows a minimal working example.
I compiled it with
ocamlbuild -use-ocamlfind -lib dynlink a.native
ocamlbuild -use-ocamlfind d.cmxs
open Format

let _ =
  B.str := "abc";
  printf "%s\n" !B.str;
      Dynlink.loadfile "./_build/d.cmxs"
    with Dynlink.Error err ->
      failwith (Dynlink.error_message err) end;
  printf "%s\n" !B.str;
  match !C.f with
  | Some(f) -> printf "%s\n" (f 0)
  | None -> ()
let str = ref ""
let f : (int -> string) option ref = ref None
let _ =
  C.f := Some((fun x -> !B.str^(string_of_int x)))

Caml-list mailing list.  Subscription management and archives:
Bug reports:

             reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-08 10:05 Frédéric Fort [this message]
2018-11-08 10:23 ` Gabriel Scherer
2018-11-08 10:23 ` Nicolás Ojeda Bär
2018-11-08 13:04 ` Ivan Gotovchits
2018-11-15 16:35   ` Nicolás Ojeda Bär

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

caml-list - the Caml user's mailing list

Archives are clonable: git clone --mirror

AGPL code for this site: git clone public-inbox