caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jonathan Roewen" <jonathan.roewen@gmail.com>
To: "Caml Mailing List" <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] mixing dynlink & toplevel...
Date: Mon, 28 Aug 2006 09:08:53 +1200	[thread overview]
Message-ID: <ad8cfe7e0608271408i2a43362bn3adc08f7f260f23a@mail.gmail.com> (raw)
In-Reply-To: <ad8cfe7e0608261647w195fe13eh1c1d90955b677073@mail.gmail.com>

> Hi,
>
> I dunno if this is possible, but: if I use Dynlink, can I later load
> toplevellib.cma, and use it like normal? At the moment I get undefined
> reference to global 'Toploop'.
>
> Jonathan

I've just made a small test case to demonstate:

test.ml:
open Dynlink

let () = try
  print_endline "init";
  Dynlink.init ();
  print_endline "allowing unsafe modules";
  Dynlink.allow_unsafe_modules true;
  print_endline "loading toplevellib.cma";
  Dynlink.loadfile "/usr/local/lib/ocaml/toplevellib.cma";
  print_endline "loading topstart.cmo";
  Dynlink.loadfile "/usr/local/lib/ocaml/topstart.cmo";
  (* now the ocaml toplevel should be running *)
with Dynlink.Error error -> print_endline (Dynlink.error_message error);;

To compile: ocamlc -o test -linkall dynlink.cma test.ml

Running:
colinux:~/test# ./test
init
allowing unsafe modules
loading toplevellib.cma
loading topstart.cmo (shouldn't return)
        Objective Caml version 3.09.2

# let s = "hello world";;
Reference to undefined global `Toploop'
# exit 0;;
colinu:~/test#

As you can see, it can run functions fine (e.g. calling
Pervasives.exit), but let bindings fail.

I know that a module loaded via Dynlink.loadfile can call functions
defined by other modules loaded by Dynlink.loadfile before it (I
actually do this), so why can't the toplevel access these? It can only
access those of the original program from my testing.

Jonathan


  reply	other threads:[~2006-08-27 21:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-26 23:47 Jonathan Roewen
2006-08-27 21:08 ` Jonathan Roewen [this message]
2006-08-28  1:30   ` Jonathan Roewen
2006-08-28  9:41     ` Vu Ngoc San
2006-08-28  9:49       ` Jonathan Roewen
2012-07-10 11:22     ` [Caml-list] " Hongbo Zhang
2012-07-10 11:32     ` [Caml-list] " Hongbo Zhang

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=ad8cfe7e0608271408i2a43362bn3adc08f7f260f23a@mail.gmail.com \
    --to=jonathan.roewen@gmail.com \
    --cc=caml-list@yquem.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).