[m-dev.] special module initialisation code

Zoltan Somogyi zs at cs.mu.OZ.AU
Tue Mar 21 16:33:46 AEDT 2000


On 21-Mar-2000, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> You'd need to add extra support in util/mkinit.c.
> Also it might increase build times a bit.
> 
> However, if you are going to add such an automatic initialization
> feature, then you need to consider the order-of-initialization
> problem.  What happens if the initialization code for one module
> depends on the initialization code for some other module already
> having been run?  This is a fairly common situation, so if you
> are going to add such a feature, then IMHO it really ought to
> address that issue.  This of course will further complicate the
> implementation...

A simple near-term approach would be to add to mkinit.c an option
that gives a list of C functions to call before invoking main/2.
This avoids the problem of paging in hundreds of initialization functions
(since usually there will be zero or one such functions), and throws the
problem of determining the proper order back to the programmer (who has
to give the functions in their order of invocation).

Note that the invoked C functions may call back to Mercury code, so
they would need to be called after the Mercury environment has been set up.

This scheme is not ideal, since the designer of a library may now have to tell
the users of the library to give some flags to c2init to pass on to mkinit,
but I think it gets 90% of the benefit for 10% of the cost.

Zoltan.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list