caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nicolas Cannasse" <warplayer@free.fr>
To: "Pietro Abate" <Pietro.Abate@anu.edu.au>,
	"ocaml ml" <caml-list@inria.fr>
Subject: Re: [Caml-list] dynlink
Date: Tue, 6 Apr 2004 07:58:46 +0200	[thread overview]
Message-ID: <006301c41b9c$3d475670$19b0e152@warp> (raw)
In-Reply-To: <20040406025129.GA8845@pulp.anu.edu.au>

> Hi all,
> I'm using dynlink for my project and since now I always had really
> simple dependecies (each module dependes only to an other module).
>
> As things are getting more complicated I need to have one module
> that dependes by many others. My initial solution was to load the
> module, look at possible dependecies error and try to solve them. It
> works well for the simple case but it fails with multiple deps.
>
> Does anyone can show me how to get the list of (recursive) depcs given a
> module ? recursive as a module can depend by an other module that in
> turn dependes by many other ...
>
> something like
>
> let depslist = magicfunction filename in (* I get all recrusive deps or
fail *)
> List.iter (fun f -> Dynlink.loadfile f) (List.rev listdeps) (* I load
eveything in order *)

When loading failed because a dependency is missing , Dynlink is raising an
exception Unavailable_unit "xxx" or Linking_error (_,Undefined_global "xxx")
You can then try to load the corresponding module recursively :

(this should work, I have been using 2 years ago)

let rec load_module modname =
    try
        Hashtbl.find modules modname
    with
        Not_found ->
            try
                Hashtbl.add modules modname ();
                Hashtbl.add are_loading modname ();
                current_module := ("Loading "^modname);
                Dynlink.loadfile (modname^".cmo");
                Hashtbl.remove are_loading modname;
            with
                    Dynlink.Error(Dynlink.Unavailable_unit(depend)) |

Dynlink.Error(Dynlink.Linking_error(_,Dynlink.Undefined_global(depend))) as
e ->
                        if Hashtbl.mem are_loading depend then failwith
("Crossing with "^depend);
                        load_module depend;
                        Hashtbl.remove modules modname;
                        load_module modname

Regards,
Nicolas Cannasse

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2004-04-06  6:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-06  2:51 Pietro Abate
2004-04-06  5:58 ` Nicolas Cannasse [this message]
2004-04-06  7:46   ` Pietro Abate
  -- strict thread matches above, loose matches on Subject: below --
2015-09-09 13:09 [Caml-list] Dynlink Sébastien Hinderer
2015-09-09 13:19 ` Olivier Andrieu
2015-09-09 13:29   ` Sébastien Hinderer
2015-09-09 13:34     ` Xavier Leroy
2015-09-09 13:44       ` Sébastien Hinderer
2015-09-09 16:03         ` Gerd Stolpmann
2015-09-10 12:08           ` Sébastien Hinderer
2015-09-10 16:57             ` Gerd Stolpmann
2015-09-09 13:25 ` Gabriel Scherer
2002-01-07 20:49 Warp
2002-01-08 21:43 ` Warp

Reply instructions:

You may reply publicly 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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to='006301c41b9c$3d475670$19b0e152@warp' \
    --to=warplayer@free.fr \
    --cc=Pietro.Abate@anu.edu.au \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).