[plt-scheme] Strange behaviour when loading modules
Folks,
I wonder if anyone has seen something like this before.
I have 2 extension modules (written with SWIG), which use what I
understand to be a fairly common approach to module extensions:
i.e. after all the extension functions have been declared, the module
definition is provided, as below:
-----------------------------------------------------------------------
Scheme_Object *scheme_reload(Scheme_Env *env) {
static int _swig_init = 0;
Scheme_Env *menv = env;
printf("module1: scheme_reload\n");
menv = scheme_primitive_module(scheme_intern_symbol("module1"), env);
if (!_swig_init) {
int i;
for (i = 0; swig_types_initial[i]; i++) {
swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);
}
_swig_init = 1;
}
SWIG_MzScheme_Init();
scheme_add_global("foo", scheme_make_prim_w_arity(_wrap_foof, "foo",
0, 1), menv);
[... repeat 250 odd times ...]
scheme_finish_primitive_module(menv);
return scheme_void;
}
Scheme_Object *scheme_initialize(Scheme_Env *env) {
printf("module1: scheme_initialize\n");
return scheme_reload(env);
}
Scheme_Object *scheme_module_name(void) {
printf("module1: scheme_module_name\n");
return scheme_intern_symbol((char*)"ccl_posix_utils");
}
-----------------------------------------------------------------------
The modules are built as .so, and installed in:
compiled/native/i386-solaris
I then try to load them up with:
(define (dnl . x)
(for-each (lambda (e) (display e) (display " ")) x) (newline))
(for-each
(lambda (name)
(dnl "first-load: " name)
(load/use-compiled (string-append name ".ss"))
)
'("module1" "module2")
)
(require module2)
This produces the following output:
first-load: module1
module1: scheme_initialize
module1: scheme_reload
first-load: module2
module2: scheme_initialize
require: unknown module: module2
Notice that scheme_reload was only called in the module1 initialize
If I load the modules twice -- i.e. with:
(lambda (name)
(dnl "first-load: " name)
(load/use-compiled (string-append name ".ss"))
(dnl "second-load: " name)
(load/use-compiled (string-append name ".ss"))
)
I get:
first-load: module1
module1: scheme_initialize
module1: scheme_reload
second-load: module1
module1: scheme_reload
first-load: module2
module2: scheme_initialize
second-load: module2
module2: scheme_reload
Actually, I have 4 modules, but the behaviour is reproducible for
just 2. And require recognises module2. AARGH.
So why does a simply C function call fail to call?
Has anyone seen anything like this before?
What am I missing?
Tim
--
Tim Brown <tim.brown at cityc.co.uk> | City Computing Limited |
T: +44 20 8770 2110 | City House, Sutton Park Road |
F: +44 20 8770 2130 | Sutton, Surrey, SM1 2AE, GB |
BEAUTY: What's in your eye when you have a bee in your hand.__________/