]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4851: Scheme_engraver::init_acknowledgers API change
authorDavid Kastrup <dak@gnu.org>
Tue, 10 May 2016 13:51:58 +0000 (15:51 +0200)
committerDavid Kastrup <dak@gnu.org>
Sat, 21 May 2016 09:22:02 +0000 (11:22 +0200)
Nicer to return the constructed hash rather than pass it by reference.

lily/include/scheme-engraver.hh
lily/scheme-engraver.cc

index 7fb829e3c4d2a2f7fc95eb39b02ae177ff413779..7ec28c4c9a6972249c703e4e3a23ad8ebf1c8b9a 100644 (file)
@@ -50,7 +50,7 @@ private:
     return generic_get_acknowledger (sym, interface_end_acknowledger_hash_);
   }
 
-  void init_acknowledgers (SCM alist, SCM *hash);
+  SCM init_acknowledgers (SCM alist);
   // For now no description.  In future, something derived from the
   // definition might make sense.
   SCM translator_description () const { return SCM_EOL; }
index f8a3afc57a1c99bee0ad628bc4ed6e39841c1966..fc51d439c0e90eed08dbaf4b89c06d1c2f04ca16 100644 (file)
@@ -82,15 +82,14 @@ Scheme_engraver::init_from_scheme (SCM definition)
   initialize_function_ = callable (ly_symbol2scm ("initialize"), definition);
   finalize_function_ = callable (ly_symbol2scm ("finalize"), definition);
 
-  SCM listeners = ly_assoc_get (ly_symbol2scm ("listeners"), definition, SCM_EOL);
-
-  per_instance_listeners_ = SCM_EOL;
+  SCM p = ly_assoc_get (ly_symbol2scm ("listeners"), definition, SCM_EOL);
+  SCM listeners = SCM_EOL;
 
   must_be_last_ = to_boolean (ly_assoc_get (ly_symbol2scm ("must-be-last"),
                                             definition,
                                             SCM_BOOL_F));
 
-  for (SCM p = listeners; scm_is_pair (p); p = scm_cdr (p))
+  for (; scm_is_pair (p); p = scm_cdr (p))
     {
       SCM event_class = scm_caar (p);
       SCM proc = scm_cdar (p);
@@ -101,26 +100,36 @@ Scheme_engraver::init_from_scheme (SCM definition)
       // We should check the arity of the function?
 
       // Record for later lookup.
-      per_instance_listeners_ = scm_acons (event_class, proc, per_instance_listeners_);
+      listeners = scm_acons (event_class, proc, listeners);
     }
 
-  init_acknowledgers (ly_assoc_get (ly_symbol2scm ("acknowledgers"),
-                                    definition, SCM_EOL),
-                      &interface_acknowledger_hash_);
+  SCM hash1 =
+    init_acknowledgers (ly_assoc_get (ly_symbol2scm ("acknowledgers"),
+                                      definition, SCM_EOL));
+  SCM hash2 =
+    init_acknowledgers (ly_assoc_get (ly_symbol2scm ("end-acknowledgers"),
+                                      definition, SCM_EOL));
+
+  per_instance_listeners_ = listeners;
+  interface_acknowledger_hash_ = hash1;
+  interface_end_acknowledger_hash_ = hash2;
 
-  init_acknowledgers (ly_assoc_get (ly_symbol2scm ("end-acknowledgers"),
-                                    definition, SCM_EOL),
-                      &interface_end_acknowledger_hash_);
+  // It's not defined whether Scheme_engraver::derived_mark is already
+  // active while the construction is underway, so we make sure we
+  // keep a version of everything on the stack that is not still
+  // covered by `definition'.
+
+  scm_remember_upto_here_2 (definition, listeners);
+  scm_remember_upto_here_2 (hash1, hash2);
 
   // TODO: hook up description, props read/written, grobs created
   // etc. to provide automatic documentation.
 }
 
-void
-Scheme_engraver::init_acknowledgers (SCM alist,
-                                     SCM *hash)
+SCM
+Scheme_engraver::init_acknowledgers (SCM alist)
 {
-  *hash = Scheme_hash_table::make_smob ();
+  SCM hash = Scheme_hash_table::make_smob ();
   for (SCM p = alist; scm_is_pair (p); p = scm_cdr (p))
     {
       SCM iface = scm_caar (p);
@@ -129,8 +138,9 @@ Scheme_engraver::init_acknowledgers (SCM alist,
       if (!(ly_is_procedure (proc) && ly_is_symbol (iface)))
         continue;
 
-      unsmob<Scheme_hash_table>(*hash)->set (iface, proc);
+      unsmob<Scheme_hash_table>(hash)->set (iface, proc);
     }
+  return hash;
 }
 
 SCM