caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] mixing dynlink & toplevel...
@ 2006-08-26 23:47 Jonathan Roewen
  2006-08-27 21:08 ` Jonathan Roewen
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Roewen @ 2006-08-26 23:47 UTC (permalink / raw)
  To: Caml Mailing List

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] mixing dynlink & toplevel...
  2006-08-26 23:47 [Caml-list] mixing dynlink & toplevel Jonathan Roewen
@ 2006-08-27 21:08 ` Jonathan Roewen
  2006-08-28  1:30   ` Jonathan Roewen
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Roewen @ 2006-08-27 21:08 UTC (permalink / raw)
  To: Caml Mailing List

> 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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] mixing dynlink & toplevel...
  2006-08-27 21:08 ` Jonathan Roewen
@ 2006-08-28  1:30   ` Jonathan Roewen
  2006-08-28  9:41     ` Vu Ngoc San
                       ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jonathan Roewen @ 2006-08-28  1:30 UTC (permalink / raw)
  To: Caml Mailing List

Well, I've solved my own problem. Mind you, I am known for doing
things that are not expected/thought of...

Turns out it was a double initialisation problem as dynlink &
toplevellib share some modules.

On 8/28/06, Jonathan Roewen <jonathan.roewen@gmail.com> wrote:
> > 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
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] mixing dynlink & toplevel...
  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
  2 siblings, 1 reply; 7+ messages in thread
From: Vu Ngoc San @ 2006-08-28  9:41 UTC (permalink / raw)
  To: Jonathan Roewen; +Cc: Caml Mailing List

By the way, is there somewhere a doc for toplevellib ? It is not in the
"official" ocaml manual, and, googgleing a little bit, I could not find
anything.

Best
San

Jonathan Roewen a écrit :
> Well, I've solved my own problem. Mind you, I am known for doing
> things that are not expected/thought of...
> 
> Turns out it was a double initialisation problem as dynlink &
> toplevellib share some modules.
> 
> On 8/28/06, Jonathan Roewen <jonathan.roewen@gmail.com> wrote:
>> > 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
>>
> 
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] mixing dynlink & toplevel...
  2006-08-28  9:41     ` Vu Ngoc San
@ 2006-08-28  9:49       ` Jonathan Roewen
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Roewen @ 2006-08-28  9:49 UTC (permalink / raw)
  To: Vu Ngoc San; +Cc: Caml Mailing List

> By the way, is there somewhere a doc for toplevellib ? It is not in the
> "official" ocaml manual, and, googgleing a little bit, I could not find
> anything.

None that I know of. An ocaml distribution puts a couple of the .cmi
files in the ocaml lib dir, so you could examine the interfaces via
the toplevel...

I remember a mailing post detailing how to implement something similar
to pythons eval using the toplevel.

http://alan.petitepomme.net/cwn/2004.04.13.html#2

Jonathan


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Caml-list] Re: mixing dynlink & toplevel...
  2006-08-28  1:30   ` Jonathan Roewen
  2006-08-28  9:41     ` Vu Ngoc San
@ 2012-07-10 11:22     ` Hongbo Zhang
  2012-07-10 11:32     ` [Caml-list] " Hongbo Zhang
  2 siblings, 0 replies; 7+ messages in thread
From: Hongbo Zhang @ 2012-07-10 11:22 UTC (permalink / raw)
  To: caml-list

Hi List,
   I tried to dynlink the toplevel. It works fine when I execute some 
simple phrase. "Format.eprintf "%d" 3 ;;" like this, but whenever I
execute some binding "let a = 3;;"
Error message is like this
 >> Reference to undefined global `Toploop'
I found this question raised in caml list years ago, did anyone find a 
solution for this?
   Many thanks
On 8/27/06 9:30 PM, Jonathan Roewen wrote:
> Well, I've solved my own problem. Mind you, I am known for doing
> things that are not expected/thought of...
>
> Turns out it was a double initialisation problem as dynlink &
> toplevellib share some modules.
>
> On 8/28/06, Jonathan Roewen <jonathan.roewen@gmail.com> wrote:
>> > 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
>>
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Caml-list] mixing dynlink & toplevel...
  2006-08-28  1:30   ` Jonathan Roewen
  2006-08-28  9:41     ` Vu Ngoc San
  2012-07-10 11:22     ` [Caml-list] " Hongbo Zhang
@ 2012-07-10 11:32     ` Hongbo Zhang
  2 siblings, 0 replies; 7+ messages in thread
From: Hongbo Zhang @ 2012-07-10 11:32 UTC (permalink / raw)
  To: Caml List

Hi List,
   (sorry if  I post here twice)
   I tried to dynlink the toplevel. It works fine when I execute some 
simple phrase. "Format.eprintf "%d" 3 ;;" like this, but whenever I
execute some binding "let a = 3;;"
Error message is like this
 >> Reference to undefined global `Toploop'
I found this question raised in caml list years ago, did anyone find a 
solution for this?
   Many thanks
On 8/27/06 9:30 PM, Jonathan Roewen wrote:
> Well, I've solved my own problem. Mind you, I am known for doing
> things that are not expected/thought of...
>
> Turns out it was a double initialisation problem as dynlink &
> toplevellib share some modules.
>
> On 8/28/06, Jonathan Roewen <jonathan.roewen@gmail.com> wrote:
>> > 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
>>
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-07-10 11:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-26 23:47 [Caml-list] mixing dynlink & toplevel Jonathan Roewen
2006-08-27 21:08 ` Jonathan Roewen
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

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).