From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by c5ff346549e7 (Postfix) with ESMTPS id 35FB95D4 for ; Thu, 8 Nov 2018 10:23:17 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.54,478,1534802400"; d="scan'208,217";a="354708681" Received: from sympa.inria.fr ([193.51.193.213]) by mail2-relais-roc.national.inria.fr with ESMTP; 08 Nov 2018 11:23:15 +0100 Received: by sympa.inria.fr (Postfix, from userid 20132) id D9F4782533; Thu, 8 Nov 2018 11:23:15 +0100 (CET) Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id C6157824E4 for ; Thu, 8 Nov 2018 11:23:11 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-qk1-f181.google.com IronPort-PHdr: =?us-ascii?q?9a23=3AlPSo9x193csvr8LSsmDT+DRfVm0co7zxezQtwd8Z?= =?us-ascii?q?seIVI/ad9pjvdHbS+e9qxAeQG9mDtLQc06L/iOPJYSQ4+5GPsXQPItRndiQuro?= =?us-ascii?q?EopTEmG9OPEkbhLfTnPGQQFcVGU0J5rTngaRAGUMnxaEfPrXKs8DUcBgvwNRZv?= =?us-ascii?q?JuTyB4Xek9m72/q99pHPYQhEniaxba9vJxiqsAvdsdUbj5F/Iagr0BvJpXVIe+?= =?us-ascii?q?VSxWx2IF+Yggjx6MSt8pN96ipco/0u+dJOXqX8ZKQ4UKdXDC86PGAv5c3krgfM?= =?us-ascii?q?QA2S7XYBSGoWkx5IAw/Y7BHmW5r6ryX3uvZh1CScIMb7S60/Vza/4KdxUBLnhy?= =?us-ascii?q?kHODw5/m/ZicJ+kbxVrw66qhNl34LZepuYOOZicq7fe94RWGpPXt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A1C8sympoAOhYkXdqliR/H0myhBLpHz7E=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0AvAAClDeRbh7XeVdFjHgEGBwaBUggLA?= =?us-ascii?q?YIoQU8zJ4M5P4Edgl6QGIINigONL4F6DSOESQKDDxoHAQQxDA0BAwEBAgEBAQE?= =?us-ascii?q?BEwEBAQgNCQgpIwyCNiKCYwECAgEMFwQZARsSBQYBAwELBgMCCxodAgIiAREBB?= =?us-ascii?q?QEcGYMhAYFoAQMNCA+MB5AHPIsNexYFAReCdwWESQoZJw1agTcCBhKLZ4FYP4N?= =?us-ascii?q?1LoRWVYJXglcCiRiWMAcCghcEhBdAhhWEDxiCI45JjSCCbodTDyGBEhIBggozG?= =?us-ascii?q?iNQMYI7CYISGoNTgT6CYnSFP0Ewiy+CPgEB?= X-IPAS-Result: =?us-ascii?q?A0AvAAClDeRbh7XeVdFjHgEGBwaBUggLAYIoQU8zJ4M5P4E?= =?us-ascii?q?dgl6QGIINigONL4F6DSOESQKDDxoHAQQxDA0BAwEBAgEBAQEBEwEBAQgNCQgpI?= =?us-ascii?q?wyCNiKCYwECAgEMFwQZARsSBQYBAwELBgMCCxodAgIiAREBBQEcGYMhAYFoAQM?= =?us-ascii?q?NCA+MB5AHPIsNexYFAReCdwWESQoZJw1agTcCBhKLZ4FYP4N1LoRWVYJXglcCi?= =?us-ascii?q?RiWMAcCghcEhBdAhhWEDxiCI45JjSCCbodTDyGBEhIBggozGiNQMYI7CYISGoN?= =?us-ascii?q?TgT6CYnSFP0Ewiy+CPgEB?= X-IronPort-AV: E=Sophos;i="5.54,478,1534802400"; d="scan'208,217";a="354708636" Received: from mail-qk1-f181.google.com ([209.85.222.181]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 08 Nov 2018 11:23:10 +0100 Received: by mail-qk1-f181.google.com with SMTP id w204so536103qka.2 for ; Thu, 08 Nov 2018 02:23:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vhY5gj5vBILWRZFLSt0LD/p8SkH8HgedIiY1RKpms/c=; b=jyMlThUVbjPGXTjv9Z+OBz2+5NUk8SECDKjn5B0nQmYAVw52zx4alz5mCM5FU1eiTY XUcePvAiv1sXG6i8c3lsZP6ACfJFD3YvDU7bbJnfYRSwWoSt4JjA0YR7rf2h6+o7r0Op WOPvLyZca7wKmwP0XmBTwXEXCnedy5WqzJubhaR0tw6D2wZwNbn8fqboj79bXO2OX+tL kk0P7WrWvSSaGm7+vfDgwjD7kU9hGutWjqyqFH16QGfKktgqYjAiCAuRPY7D2DvvIOJn dO1U8aXKRQDOM3zc6agBdqPLKCz/UxuGr+XO6c1+DdLqoi3xEW0772Qb0td0DYgPxFgg EVJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vhY5gj5vBILWRZFLSt0LD/p8SkH8HgedIiY1RKpms/c=; b=qvn11+Qe9OMEKKq/P+lYQymUh9AVycPcujUfyunZ42Lru/iQI/5nTqxGILZXL0RUt6 RalsmN0eZrkboennJcQlnD1xmi2jtvN2qM19+G74+iF83cOcktoXzaRh/HYueCOkbCQ3 dT2Bwogc6D8FxctPbleuxGCQ0qibpmDkrhzy2y0xwUBjybZvSjfsTA/4c+O0HPVvRadT H9EzklkrRe3BaNtF+qMpWmqCLY0ylAi0q58Tsp5uemkizIOei5K4Ft1LzsK91FWjiH1G 4/xm7GsAFYyPEERHMj8GJ2RrsTZNVaRfzgeblN3zoRNF+zHBS3kEomKsYOziSE0E6wND 4CUg== X-Gm-Message-State: AGRZ1gIFRUEcDIMzXLciyyjE7jXoHiyMWZZEKnh2W0sC6VxN9WLK5V/l NwyUi9dfRbPPFa8TBvw8B7GKqAgG4jx6zGjGFFJ2xg== X-Google-Smtp-Source: AJdET5cvuHnt/Ri9sjR1V1Au029Lis8N+1BrHLgeBbZB+uxuEcGwALJYFNma8dsw7f5ZS68si+F/CQyg/CcRxrLW2sg= X-Received: by 2002:ae9:ef8a:: with SMTP id d132mr3482414qkg.11.1541672589663; Thu, 08 Nov 2018 02:23:09 -0800 (PST) MIME-Version: 1.0 References: <1238750250.1711857.1541671514743.JavaMail.zimbra@univ-lille.fr> In-Reply-To: <1238750250.1711857.1541671514743.JavaMail.zimbra@univ-lille.fr> From: Gabriel Scherer Date: Thu, 8 Nov 2018 11:32:32 +0100 Message-ID: To: frederic.fort@univ-lille.fr Cc: caml users Content-Type: multipart/alternative; boundary="0000000000001123c4057a249f6d" Subject: Re: [Caml-list] Dynlink plugin reevaluates modules of main program Reply-To: Gabriel Scherer X-Loop: caml-list@inria.fr X-Sequence: 17123 Errors-to: caml-list-owner@inria.fr Precedence: list Precedence: bulk Sender: caml-list-request@inria.fr X-no-archive: yes List-Id: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --0000000000001123c4057a249f6d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Ocamlbuild knows of two ways to build .cmxs files: - from a .cmxa file, repackaged for dynamic loading - from a .mldylib, listing the modules to be included (like .mllib for .cm{x,}a) (See "ocamlbuild -documentation | grep cmxs" to check this) Your build uses the first approach, and this results in d *and its dependencies* being packaged in d.cmxa and then d.cmxs. (See the log, or use -classic-display to see the commands). The behavior you expect requires the second approach. You can obtain it by adding d.mldylib: D On Thu, Nov 8, 2018 at 11:06 AM Fr=C3=A9d=C3=A9ric Fort wrote: > Hello, > > 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: > - a.ml : "main module" of the program > - b.ml : additional definitions used in a.ml > - c.ml : interface for plugins (a collection of function refs) > - d.ml : plugin I would like to load > > Now, d.ml uses values defined in b.ml. Some of them are of type string ref > and it seems that the code of b.ml 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=C3=A9d=C3=A9ric 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 > > a.ml: > open Format > > let _ =3D > B.str :=3D "abc"; > printf "%s\n" !B.str; > begin > try > 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 -> () > > b.ml: > let str =3D ref "" > > c.ml: > let f : (int -> string) option ref =3D ref None > > d.ml: > let _ =3D > C.f :=3D Some((fun x -> !B.str^(string_of_int x))) > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > https://inbox.ocaml.org/caml-list > Forum: https://discuss.ocaml.org/ > Bug reports: http://caml.inria.fr/bin/caml-bugs --=20 Caml-list mailing list. Subscription management and archives: https://sympa.inria.fr/sympa/arc/caml-list https://inbox.ocaml.org/caml-list Forum: https://discuss.ocaml.org/ Bug reports: http://caml.inria.fr/bin/caml-bugs= --0000000000001123c4057a249f6d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Ocamlbuild knows of two ways to build .cmxs files:
- from a .cmxa file, repackaged for dynamic loading
-= from a .mldylib, listing the modules to be included (like .mllib for .cm{x= ,}a)

(See "ocamlbuild -documentation | grep c= mxs" to check this)

Your build uses the first= approach, and this results in d *and its dependencies* being packaged in d= .cmxa and then d.cmxs. (See the log, or use -classic-display to see the com= mands). The behavior you expect requires the second approach. You can obtai= n it by adding

d.mldylib:
=C2=A0 D

On Thu, Nov 8, 20= 18 at 11:06 AM Fr=C3=A9d=C3=A9ric Fort <frederic.fort@univ-lille.fr> wrote:
Hello,

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

Now,
d.ml = uses values defined in b.ml. Some of them are of type string ref
and it seems that the code of b.ml 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 woul= d each reevaluate C
and undo each others modifications.

Yours sincerely,
Fr=C3=A9d=C3=A9ric 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

a.ml:
open Format

let _ =3D
=C2=A0 B.str :=3D "abc";
=C2=A0 printf "%s\n" !B.str;
=C2=A0 begin
=C2=A0 =C2=A0 try
=C2=A0 =C2=A0 =C2=A0 Dynlink.loadfile "./_build/d.cmxs"
=C2=A0 =C2=A0 with Dynlink.Error err ->
=C2=A0 =C2=A0 =C2=A0 failwith (Dynlink.error_message err) end;
=C2=A0 printf "%s\n" !B.str;
=C2=A0 match !C.f with
=C2=A0 | Some(f) -> printf "%s\n" (f 0)
=C2=A0 | None -> ()

b.ml:
let str =3D ref ""

c.ml:
let f : (int -> string) option ref =3D ref None

d.ml:
let _ =3D
=C2=A0 C.f :=3D Some((fun x -> !B.str^(string_of_int x)))

--
Caml-list mailing list.=C2=A0 Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list htt= ps://inbox.ocaml.org/caml-list
Forum: https://discuss.ocaml.org/
Bug reports: http://caml.inria.fr/bin/caml-bugs --0000000000001123c4057a249f6d--