[gambit-list] Re: loading modules multiple times

Christian christian at pflanze.mine.nu
Thu Aug 11 09:03:35 EDT 2005


Hello Adam

I'm wondering why you need that patch. I think it's a bad idea to 
suppress module load errors, since it then would silently do nothing 
where as the user expects load to do something, which is bad. Whereas 
you could simply catch the exception if you really want to try to 
load without the program terminating:

(define MODULE_ALREADY_LOADED
   ((c-lambda () int "___result=___FIX(___MODULE_ALREADY_LOADED)")))

(define (load* x)
   (with-exception-catcher
      (lambda(e)
        (or (and (os-exception? e)
                 (= (os-exception-code e) MODULE_ALREADY_LOADED)))
            (raise e)))
      (lambda()
        (load x))))

(untested)

Checking the exception code against a constant which is only defined 
in C might look a bit awkward, an exception subtype like one with 
predicate os-module-already-loaded-exception? might be cleaner, so I 
would suggest to change that instead.

Some words about the logic behind the error (from how I see it): load 
on source code can simply reload the source, there's no 
implementation problem with that. It does two things, reparse the 
source (which may have changed), and re-run it's body (which means, 
perform bindings, thus overwriting bindings which may have changed 
since after the first load).

Loading a binary however only loads the precompiled object, thus 
ignoring any possible changes in the source. It still performs 
initializations/bindings. A user loading that object again might 
expect it at least to do initializations/bindings again. But now 
there's the problem that loading (=linking) the same binary object 
file multiple times is not possible at all on some systems, and on 
those where it is (e.g. linux) it requires unloading it first (which 
may be problematic in the presence of threads, how do you know if 
some code is still executing in the old code?). Would it be 
worthwhile to implement such unloading on systems where that works? 
Might be for some other reasons (not increasing virtual memory with 
each load -- not that I think this is a real problem: it's basically 
just wasted disk space, that's all). But since it wouldn't recompile 
the sources anyway, another layer on top is what users will want 
anyway (-> see chjmodule). So the best thing it can do is raise an 
error.

Christian.


More information about the Gambit-list mailing list