caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Controlling module loading order.
@ 2010-01-08 20:54 Guillaume Yziquel
  2010-01-09  8:22 ` [Caml-list] " Stéphane Glondu
  2010-01-11 11:59 ` Gerd Stolpmann
  0 siblings, 2 replies; 5+ messages in thread
From: Guillaume Yziquel @ 2010-01-08 20:54 UTC (permalink / raw)
  To: OCaml List

Hi.

I've been reimpleminting the OCaml-R binding, and implemented a simple 
wrapper around the Quantmod package in R:

http://yziquel.homelinux.org/gitweb/?p=ocaml-r.git;a=tree
http://yziquel.homelinux.org/gitweb/?p=ocamlr-quantmod.git;a=tree

Testing these modules from the toplevel is quite fine. However, when 
compiling stuff using these pieces of code, I have issues with the way 
the modules are loaded, since the order in which they are loaded has 
side-effects: Initialisation of the R interpreter in the good case, 
segfaults in the bad case...

For instance, the META file of OCaml-R:

>    1 name = "R"
>    2 version = "0.2"
>    3 description = "R bindings for OCaml"
>    4 requires = "unix"
>    5 archive(byte) = "r.cma"
>    6 archive(native) = "r.cmxa"
>    7 
>    8 package "interpreter" (
>    9   version = "0.2"
>   10   description = "Embedded R interpreter"
>   11   requires = "R"
>   12   archive(byte) = "oCamlR.cma"
>   13   archive(native) = "oCamlR.cmxa"
>   14 )

The stub functions are in package "R", and package "R.interpreter" 
contains a module with and empty signature, whose side-effects are to 
initialise the R interpreter through an application of the functor

>   19 module Interpreter (Env : Environment) : Interpreter = struct
>   20 
>   21   let () = init ~name: Env.name
>   22                 ~argv: Env.options
>   23                 ~env:  Env.env
>   24                 ~sigs: Env.signal_handlers
>   25                 ()
>   26 
>   27 end

My issue concerns the Quantmod wrapper: How can I make sure that when 
the Quantmod module is loaded, the OCamlR module of the "R.interpreter" 
findlib package gets loaded before?

Currently the ocamlbuild _tags file for ocamlr-quantmod is

>    1 <quantmod.ml>: pkg_R.interpreter, pkg_CRAN-zoo

But that doesn't seem to do the trick...

My question is: do I have to put a line like "module X = OCamlR" in 
quantmod.ml, or is there a way to load OCamlR beforehand just by 
tweaking the build process, order of modules when linking, etc...

All the best,

-- 
      Guillaume Yziquel
http://yziquel.homelinux.org/


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

* Re: [Caml-list] Controlling module loading order.
  2010-01-08 20:54 Controlling module loading order Guillaume Yziquel
@ 2010-01-09  8:22 ` Stéphane Glondu
  2010-01-11 11:59 ` Gerd Stolpmann
  1 sibling, 0 replies; 5+ messages in thread
From: Stéphane Glondu @ 2010-01-09  8:22 UTC (permalink / raw)
  To: guillaume.yziquel; +Cc: OCaml List

Guillaume Yziquel a écrit :
> My question is: do I have to put a line like "module X = OCamlR" in
> quantmod.ml, [...]

Sounds good. But in case the compiler is too smart and discards this,
I'd rather export explicitly an initialization function (or some dummy
value to force the dependency order) in OCamlR and call it when needed.

> [...] is there a way to load OCamlR beforehand just by
> tweaking the build process, order of modules when linking, etc...

I wouldn't rely on this.


Cheers,

-- 
Stéphane


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

* Re: [Caml-list] Controlling module loading order.
  2010-01-08 20:54 Controlling module loading order Guillaume Yziquel
  2010-01-09  8:22 ` [Caml-list] " Stéphane Glondu
@ 2010-01-11 11:59 ` Gerd Stolpmann
  2010-01-11 17:49   ` Guillaume Yziquel
  1 sibling, 1 reply; 5+ messages in thread
From: Gerd Stolpmann @ 2010-01-11 11:59 UTC (permalink / raw)
  To: guillaume.yziquel; +Cc: OCaml List

Hi Guillaume,

if you want to control from findlib that a certain function is invoked,
the usual way to do it is to put a .cmo/.cmx file into the "archive"
variables. The problem is that the linker drops all unused modules
from .cma/.cmxa archives, and as a consequence the initialization code
of these modules is not executed. So you could make R.interpreter
a .cmo/.cmx - in this case the module is always initialized.

The other workaround is to provide an init function in R.interpreter
like

let init() = ()

By calling this function the user references the interpreter, and all
the initialization code is executed.

Gerd

Am Freitag, den 08.01.2010, 21:54 +0100 schrieb Guillaume Yziquel:
> Hi.
> 
> I've been reimpleminting the OCaml-R binding, and implemented a simple 
> wrapper around the Quantmod package in R:
> 
> http://yziquel.homelinux.org/gitweb/?p=ocaml-r.git;a=tree
> http://yziquel.homelinux.org/gitweb/?p=ocamlr-quantmod.git;a=tree
> 
> Testing these modules from the toplevel is quite fine. However, when 
> compiling stuff using these pieces of code, I have issues with the way 
> the modules are loaded, since the order in which they are loaded has 
> side-effects: Initialisation of the R interpreter in the good case, 
> segfaults in the bad case...
> 
> For instance, the META file of OCaml-R:
> 
> >    1 name = "R"
> >    2 version = "0.2"
> >    3 description = "R bindings for OCaml"
> >    4 requires = "unix"
> >    5 archive(byte) = "r.cma"
> >    6 archive(native) = "r.cmxa"
> >    7 
> >    8 package "interpreter" (
> >    9   version = "0.2"
> >   10   description = "Embedded R interpreter"
> >   11   requires = "R"
> >   12   archive(byte) = "oCamlR.cma"
> >   13   archive(native) = "oCamlR.cmxa"
> >   14 )
> 
> The stub functions are in package "R", and package "R.interpreter" 
> contains a module with and empty signature, whose side-effects are to 
> initialise the R interpreter through an application of the functor
> 
> >   19 module Interpreter (Env : Environment) : Interpreter = struct
> >   20 
> >   21   let () = init ~name: Env.name
> >   22                 ~argv: Env.options
> >   23                 ~env:  Env.env
> >   24                 ~sigs: Env.signal_handlers
> >   25                 ()
> >   26 
> >   27 end
> 
> My issue concerns the Quantmod wrapper: How can I make sure that when 
> the Quantmod module is loaded, the OCamlR module of the "R.interpreter" 
> findlib package gets loaded before?
> 
> Currently the ocamlbuild _tags file for ocamlr-quantmod is
> 
> >    1 <quantmod.ml>: pkg_R.interpreter, pkg_CRAN-zoo
> 
> But that doesn't seem to do the trick...
> 
> My question is: do I have to put a line like "module X = OCamlR" in 
> quantmod.ml, or is there a way to load OCamlR beforehand just by 
> tweaking the build process, order of modules when linking, etc...
> 
> All the best,
> 
-- 
------------------------------------------------------------
Gerd Stolpmann, Bad Nauheimer Str.3, 64289 Darmstadt,Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
Phone: +49-6151-153855                  Fax: +49-6151-997714
------------------------------------------------------------


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

* Re: [Caml-list] Controlling module loading order.
  2010-01-11 11:59 ` Gerd Stolpmann
@ 2010-01-11 17:49   ` Guillaume Yziquel
  2010-01-15 17:31     ` Guillaume Yziquel
  0 siblings, 1 reply; 5+ messages in thread
From: Guillaume Yziquel @ 2010-01-11 17:49 UTC (permalink / raw)
  To: Gerd Stolpmann; +Cc: OCaml List

Gerd Stolpmann a écrit :
> Hi Guillaume,
> 
> if you want to control from findlib that a certain function is invoked,
> the usual way to do it is to put a .cmo/.cmx file into the "archive"
> variables. The problem is that the linker drops all unused modules
> from .cma/.cmxa archives, and as a consequence the initialization code
> of these modules is not executed. So you could make R.interpreter
> a .cmo/.cmx - in this case the module is always initialized.

Thank you so much!

> The other workaround is to provide an init function in R.interpreter
> like
> 
> let init() = ()
> 
> By calling this function the user references the interpreter, and all
> the initialization code is executed.

That's exactly what I want to avoid.

-- 
      Guillaume Yziquel
http://yziquel.homelinux.org/


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

* Re: [Caml-list] Controlling module loading order.
  2010-01-11 17:49   ` Guillaume Yziquel
@ 2010-01-15 17:31     ` Guillaume Yziquel
  0 siblings, 0 replies; 5+ messages in thread
From: Guillaume Yziquel @ 2010-01-15 17:31 UTC (permalink / raw)
  Cc: Gerd Stolpmann, OCaml List

Guillaume Yziquel a écrit :
> Gerd Stolpmann a écrit :
>> Hi Guillaume,
>>
>> if you want to control from findlib that a certain function is invoked,
>> the usual way to do it is to put a .cmo/.cmx file into the "archive"
>> variables. The problem is that the linker drops all unused modules
>> from .cma/.cmxa archives, and as a consequence the initialization code
>> of these modules is not executed. So you could make R.interpreter
>> a .cmo/.cmx - in this case the module is always initialized.
> 
> Thank you so much!

Just a complementary remark: when using a .cmo instead of a .cma, one 
should ship a .o file in place of the .a file. For the sake of exhaustivity.

-- 
      Guillaume Yziquel
http://yziquel.homelinux.org/


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

end of thread, other threads:[~2010-01-15 17:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-08 20:54 Controlling module loading order Guillaume Yziquel
2010-01-09  8:22 ` [Caml-list] " Stéphane Glondu
2010-01-11 11:59 ` Gerd Stolpmann
2010-01-11 17:49   ` Guillaume Yziquel
2010-01-15 17:31     ` Guillaume Yziquel

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