]> git.donarmstrong.com Git - lilypond.git/commitdiff
* scm/define-event-classes.scm (lambda): use ly:is-listened-event-class
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 8 Aug 2006 19:56:54 +0000 (19:56 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 8 Aug 2006 19:56:54 +0000 (19:56 +0000)
* lily/ly-module.cc (ly_module_symbols): use ly_hash_table_keys

* lily/translator.cc (LY_DEFINE): ly:is-listened-event-class: new
function. Use hash tables to check membership.

* lily/general-scheme.cc (LY_DEFINE): new function.

* lily/piano-pedal-engraver.cc (struct Pedal_type_info): idem

* lily/include/translator.hh (struct Acknowledge_information): add Protected_scm

ChangeLog
lily/general-scheme.cc
lily/include/lily-guile.hh
lily/include/translator.hh
lily/lily-guile.cc
lily/ly-module.cc
lily/piano-pedal-engraver.cc
lily/translator.cc
scm/define-event-classes.scm

index 92dd64b541435339bcf7f0275882f1fa378d296d..6620907913e71ba27cd317544cbcd47027a1f2a0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2006-08-08  Han-Wen Nienhuys  <hanwen@lilypond.org>
 
+       * scm/define-event-classes.scm (lambda): use ly:is-listened-event-class
+
+       * lily/ly-module.cc (ly_module_symbols): use ly_hash_table_keys
+
+       * lily/translator.cc (LY_DEFINE): ly:is-listened-event-class: new
+       function. Use hash tables to check membership.
+
+       * lily/general-scheme.cc (LY_DEFINE): new function.
+
+       * lily/piano-pedal-engraver.cc (struct Pedal_type_info): idem
+
+       * lily/include/translator.hh (struct Acknowledge_information): add Protected_scm
+
        * ly/music-functions-init.ly: change name to BreathingEvent
 
        * input/regression/*.ly: apply it.
index 558d111f8617b7b61147504ec8dbf658446b76ed..5beda8355e9f5ec2940e8cbd0e5ecdc59b68bca4 100644 (file)
@@ -307,3 +307,19 @@ LY_DEFINE (ly_stderr_redirect, "ly:stderr-redirect",
   freopen (ly_scm2newstr (file_name, 0), m, stderr);
   return SCM_UNSPECIFIED;
 }
+
+static SCM
+accumulate_symbol (void *closure, SCM key, SCM val, SCM result)
+{
+  (void) closure;
+  (void) val;
+  return scm_cons (key, result);
+}
+
+LY_DEFINE(ly_hash_table_keys, "ly:hash-table-keys",
+         1,0,0, (SCM tab),
+         "return a list of keys in @var{tab}")
+{
+  return scm_internal_hash_fold ((Hash_closure_function) & accumulate_symbol,
+                                NULL, SCM_EOL, tab);
+}
index 98e7ceadcf5e1098d599e919e7d0aa3ef5ab5f42..23b3c64785edef95c978f2553d734da4a394f8a3 100644 (file)
@@ -76,7 +76,7 @@ SCM alist_to_hashq (SCM);
 
 SCM ly_alist_vals (SCM alist);
 SCM ly_hash2alist (SCM tab);
-
+SCM ly_hash_table_keys (SCM tab);
 int procedure_arity (SCM);
 
 /* inserts at front, removing dublicates */
index f39b122d8b83c91f9eb48d04517ec84a0a0b08f1..575a3fc792051ba5af3367590e3bc3209484433a 100644 (file)
 #include "input.hh"
 #include "smobs.hh"
 #include "std-vector.hh"
+#include "protected-scm.hh"
 
 struct Acknowledge_information
 {
-  SCM symbol_;
+  Protected_scm symbol_;
   Engraver_void_function_engraver_grob_info function_;
 };
 
index e44e47f4be27f6f30b64817b760191a678e4441f..26d2d30ac8400e46e55fdb4da9adfd51494e6820 100644 (file)
@@ -742,3 +742,4 @@ mangle_cxx_identifier (string cxx_id)
   cxx_id = replace_all (cxx_id, '_', '-');
   return cxx_id;
 }
+
index 45db747819a97ff1a58beb522566d7d8513c5673..740f9e4e521ceda5fb92eb6d417a2b9648dbe75c 100644 (file)
@@ -85,13 +85,7 @@ ly_use_module (SCM mod, SCM used)
 
 #define FUNC_NAME __FUNCTION__
 
-static SCM
-accumulate_symbol (void *closure, SCM key, SCM val, SCM result)
-{
-  (void) closure;
-  (void) val;
-  return scm_cons (key, result);
-}
+
 
 SCM
 ly_module_symbols (SCM mod)
@@ -99,8 +93,7 @@ ly_module_symbols (SCM mod)
   SCM_VALIDATE_MODULE (1, mod);
 
   SCM obarr = SCM_MODULE_OBARRAY (mod);
-  return scm_internal_hash_fold ((Hash_closure_function) & accumulate_symbol,
-                                NULL, SCM_EOL, obarr);
+  return ly_hash_table_keys (obarr);
 }
 
 static SCM
index afdcb741bb9288f29083abd931076157536ed67c..8e9b9252f0e0f4c2831c0a3019e7347296d1935a 100644 (file)
@@ -23,7 +23,7 @@
 #include "stream-event.hh"
 #include "string-convert.hh"
 #include "warn.hh"
-
+#include "protected-scm.hh"
 #include "translator.icc"
 
 /*
@@ -40,9 +40,10 @@ typedef enum Pedal_type {SOSTENUTO, SUSTAIN, UNA_CORDA, NUM_PEDAL_TYPES};
 struct Pedal_type_info
 {
   string base_name_;
-  SCM event_class_sym_;
-  SCM style_sym_;
-  SCM strings_sym_;
+  Protected_scm event_class_sym_;
+  Protected_scm style_sym_;
+  Protected_scm strings_sym_;
+  
   const char *pedal_line_spanner_c_str_;
   const char *pedal_c_str_;
 };
@@ -139,11 +140,10 @@ init_pedal_types ()
 
       Pedal_type_info *tbl = &pedal_types_[i];
       tbl->base_name_ = name;
-      /* These symbols are static and need to be protected */
-      tbl->event_class_sym_ = scm_gc_protect_object (scm_str2symbol ((base_ident + "-event").c_str ()));
+      tbl->event_class_sym_ = scm_str2symbol ((base_ident + "-event").c_str ());
       tbl->pedal_line_spanner_c_str_ = strdup ((base_name + "PedalLineSpanner").c_str ());
-      tbl->style_sym_ = scm_gc_protect_object (scm_str2symbol (("pedal" + base_name + "Style").c_str ()));
-      tbl->strings_sym_ = scm_gc_protect_object (scm_str2symbol (("pedal" + base_name + "Strings").c_str ()));
+      tbl->style_sym_ = scm_str2symbol (("pedal" + base_name + "Style").c_str ());
+      tbl->strings_sym_ = scm_str2symbol (("pedal" + base_name + "Strings").c_str ());
       tbl->pedal_c_str_ = strdup ((base_name + "Pedal").c_str ());
     }
 }
index cf07d527e8e956be25dd589bfa701fb2b5289b7c..3bb01cac65f62131fcd9a4b5e7089701dc76dad6 100644 (file)
@@ -130,17 +130,42 @@ Translator::disconnect_from_context (Context *c)
     c->events_below ()->remove_listener (r->get_listener_ (this), r->event_class_);
 }
 
-static SCM listened_event_classes = SCM_EOL;
+static SCM listened_event_class_table;
+void
+ensure_listened_hash ()
+{
+  if (!listened_event_class_table)
+    listened_event_class_table = scm_permanent_object (scm_c_make_hash_table (61));
+}
+
 
 LY_DEFINE (ly_get_listened_event_classes, "ly:get-listened-event-classes",
           0, 0, 0, (),
           "Returns a list of all event classes that some translator listens to.")
 {
-  return listened_event_classes;
+  ensure_listened_hash ();
+  return ly_hash_table_keys (listened_event_class_table);
+}
+
+LY_DEFINE (ly_is_listened_event_class, "ly:is-listened-event-class",
+          1, 0, 0, (SCM sym),
+          "Is @var{sym} a listened event class?")
+{
+  ensure_listened_hash ();
+  return scm_hashq_ref (listened_event_class_table, sym, SCM_BOOL_F);
 }
 
+void
+add_listened_event_class (SCM sym)
+{
+  ensure_listened_hash ();
+
+  scm_hashq_set_x (listened_event_class_table, sym, SCM_BOOL_T);
+}
+
+
 /*
-  Internally called once, statically, for each translator
+  internally called once, statically, for each translator
   listener. Connects the name of an event class with a procedure that
   fetches the corresponding listener.
 
@@ -149,18 +174,21 @@ LY_DEFINE (ly_get_listened_event_classes, "ly:get-listened-event-classes",
  */
 void
 Translator::add_translator_listener (translator_listener_record **listener_list,
-                        translator_listener_record *r,
-                        Listener (*get_listener) (void *), 
-                        const char *ev_class)
+                                    translator_listener_record *r,
+                                    Listener (*get_listener) (void *), 
+                                    const char *ev_class)
 {
   /* ev_class is the C++ identifier name. Convert to scm symbol */
   string name = string (ev_class);
   name = replace_all (name, '_', '-');
-  name = name + "-event";
+  name += "-event";
+  
   /* It's OK to use scm_gc_protect_object for protection, because r is
      statically allocated. */
-  SCM class_sym = scm_gc_protect_object (scm_str2symbol (name.c_str ()));
-  listened_event_classes = scm_gc_protect_object (scm_cons (class_sym, listened_event_classes));
+  // NO it's damn not !!!! --hwn
+  SCM class_sym = scm_str2symbol (name.c_str ());
+  
+  add_listened_event_class (class_sym);
   r->event_class_ = class_sym;
   r->get_listener_ = get_listener;
   r->next_ = *listener_list;
@@ -228,7 +256,7 @@ add_acknowledger (Engraver_void_function_engraver_grob_info ptr,
   interface_name = replace_all (interface_name, '_', '-');
   interface_name += "-interface";
 
-  inf.symbol_ = scm_gc_protect_object (ly_symbol2scm (interface_name.c_str ()));
+  inf.symbol_ = ly_symbol2scm (interface_name.c_str ());
   ack_array->push_back (inf);
 }
 
index 3bb654ada06ef58d2368bda69161d480650f7ccb..c98d603cf646ccbde41ae09a230e3dcc7064bd0b 100644 (file)
 ;; available translators; print warnings otherwise.
 (map-tree (lambda (sym) 
            (if (and (symbol? sym)
-                    (not (memq sym (ly:get-listened-event-classes)))
+                    (not (ly:is-listened-event-class sym))
                     (not (assq sym event-classes))
                     (not (memq sym unlistened-music-event-classes)))
                (ly:programming-error (_ "event class ~A seems to be unused") sym)))      
          music-event-tree)
+
 (map (lambda (sym)
        (if (not (pair? (ly:make-event-class sym)))
           ;; should be programming-error