]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4514/1: Pass setup function call into Scm_module::boot
authorDavid Kastrup <dak@gnu.org>
Tue, 21 Jul 2015 11:19:24 +0000 (13:19 +0200)
committerDavid Kastrup <dak@gnu.org>
Mon, 27 Jul 2015 08:13:20 +0000 (10:13 +0200)
lily/guile-init.cc
lily/include/lily-modules.hh
lily/lily-modules.cc

index b812402e0e3d85f0ee4c975a246882d6294c7906..4270aa01d6b9de89f093bad38df5f300b60545a0 100644 (file)
@@ -48,8 +48,8 @@ void add_scm_init_func (void (*f) ())
   scm_init_funcs_->push_back (f);
 }
 
-SCM
-ly_init_ly_module (void *)
+void
+ly_init_ly_module ()
 {
   // Start up type system first.
   Scm_init::init ();
@@ -65,15 +65,13 @@ ly_init_ly_module (void *)
     }
 
   scm_primitive_load_path (scm_from_ascii_string ("lily.scm"));
-  return SCM_UNDEFINED;
 }
 
 void
 ly_c_init_guile ()
 {
   Guile_user::module.import ();
-  Lily::module.boot ();
-  scm_c_call_with_current_module (Lily::module, ly_init_ly_module, 0);
+  Lily::module.boot (ly_init_ly_module);
   Syntax::module.import ();
   Display::module.import ();
   scm_c_use_module ("lily");
index 1eb7cf7354c78e0630f60f62518b35e3d298f3bb..3393fc2ae85cd0c7ca34e53b63ca42041b0b6327 100644 (file)
@@ -32,7 +32,7 @@ class Scm_module
   Variable_record *variables_;
   static void boot_init (void *);
 public:
-  void boot ();
+  void boot (void (*init)() = 0);
   void import ();
   void register_variable (const char *name, Scm_variable *var);
 
index be736615d6e25e1d3f24e64ed4761edbebf86a20..b75e0afc05f6db9e24ba76b17608e5ab2426fd75 100644 (file)
@@ -57,11 +57,24 @@ Scm_module::boot_init (void *arg)
   self->variables_ = 0;
 }
 
+static SCM
+call_trampoline (void *self)
+{
+  // One more indirection since void * can only be safely cast to
+  // pointers to data rather than pointers to function.
+  (*static_cast <void (**)()> (self)) ();
+  return SCM_UNDEFINED;
+}
+
 void
-Scm_module::boot ()
+Scm_module::boot (void (*init) ())
 {
   assert (SCM_UNBNDP (module_));
   module_ = scm_c_define_module (name_, boot_init, static_cast <void *> (this));
+  // Can't wrap the following in the scm_c_define_module call since
+  // the init code may need module_ operative.
+  if (init)
+    scm_c_call_with_current_module (module_, call_trampoline, static_cast <void *> (&init));
 }
 
 void