From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.1 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 70AB1BC29 for ; Sun, 27 Aug 2006 23:08:55 +0200 (CEST) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.235]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k7RL8sSg019169 for ; Sun, 27 Aug 2006 23:08:55 +0200 Received: by wx-out-0506.google.com with SMTP id s6so1539283wxc for ; Sun, 27 Aug 2006 14:08:54 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=jTk2kgQAkSltoGcuk/1ytChkDX2jIW2Eplng/YTWQSr08iorXT8KpNhg5wsNqO33IaZdTGZCbwUZ4DUcJJLb55koz5oXFYYjlxofGP0lFEVPpmo2OoNx6KtdHsUUk2dmjN94tax8DPnAMNWidV/AAEnv+AqA4R603bgIblq1qXE= Received: by 10.70.8.8 with SMTP id 8mr8089247wxh; Sun, 27 Aug 2006 14:08:54 -0700 (PDT) Received: by 10.70.84.13 with HTTP; Sun, 27 Aug 2006 14:08:53 -0700 (PDT) Message-ID: Date: Mon, 28 Aug 2006 09:08:53 +1200 From: "Jonathan Roewen" To: "Caml Mailing List" Subject: Re: [Caml-list] mixing dynlink & toplevel... In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-j-chkmail-Score: MSGID : 44F209E6.000 on nez-perce : j-chkmail score : X : 0/20 1 X-Miltered: at nez-perce with ID 44F209E6.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; dynlink:01 toplevel:01 dynlink:01 toplevellib:01 endline:01 endline:01 toplevellib:01 loadfile:01 usr:01 lib:01 ocaml:01 topstart:01 cmo:01 loadfile:01 usr:01 > 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