+ return (handle == SCM_BOOL_F) ? SCM_EOL : scm_cdr (handle);
+}
+
+SCM
+Grob::internal_get_property (SCM sym) const
+{
+ SCM val = get_property_data (sym);
+
+#ifndef NDEBUG
+ if (val == ly_symbol2scm ("calculation-in-progress"))
+ {
+ programming_error (to_string ("cyclic dependency: calculation-in-progress encountered for #'%s (%s)",
+ ly_symbol2string (sym).c_str (),
+ name ().c_str ()));
+ if (debug_property_callbacks)
+ {
+ message ("backtrace: ");
+ print_property_callback_stack ();
+ }
+ }
+#endif
+
+ if (is_unpure_pure_container (val))
+ val = unpure_pure_container_unpure_part (val);
+ if (ly_is_procedure (val)
+ || is_simple_closure (val))
+ {
+ Grob *me = ((Grob *)this);
+ val = me->try_callback_on_alist (&me->mutable_property_alist_, sym, val);
+ }
+
+ return val;
+}
+
+/* Unlike internal_get_property, this function does no caching. Use it, therefore, with caution. */
+SCM
+Grob::internal_get_pure_property (SCM sym, int start, int end) const
+{
+ SCM val = internal_get_property_data (sym);
+ if (ly_is_procedure (val) || is_unpure_pure_container (val))
+ return call_pure_function (val, scm_list_1 (self_scm ()), start, end);
+ if (is_simple_closure (val))
+ return evaluate_with_simple_closure (self_scm (),
+ simple_closure_expression (val),
+ true, start, end);
+ return val;
+}
+
+SCM
+Grob::internal_get_maybe_pure_property (SCM sym, bool pure, int start, int end) const
+{
+ return pure ? internal_get_pure_property (sym, start, end) : internal_get_property (sym);
+}
+
+SCM
+Grob::try_callback_on_alist (SCM *alist, SCM sym, SCM proc)
+{
+ SCM marker = ly_symbol2scm ("calculation-in-progress");
+ /*
+ need to put a value in SYM to ensure that we don't get a
+ cyclic call chain.
+ */
+ *alist = scm_assq_set_x (*alist, sym, marker);
+
+#ifndef NDEBUG
+ if (debug_property_callbacks)
+ grob_property_callback_stack = scm_cons (scm_list_3 (self_scm (), sym, proc), grob_property_callback_stack);
+#endif
+
+ SCM value = SCM_EOL;
+ if (ly_is_procedure (proc))
+ value = scm_call_1 (proc, self_scm ());
+ else if (is_simple_closure (proc))
+ {
+ value = evaluate_with_simple_closure (self_scm (),
+ simple_closure_expression (proc),
+ false, 0, 0);
+ }
+
+#ifndef NDEBUG
+ if (debug_property_callbacks)
+ grob_property_callback_stack = scm_cdr (grob_property_callback_stack);
+#endif
+
+ /*
+ If the function returns SCM_UNSPECIFIED, we assume the
+ property has been set with an explicit set_property ()
+ call.
+ */
+ if (value == SCM_UNSPECIFIED)
+ {
+ value = get_property_data (sym);
+ assert (value == SCM_EOL || value == marker);
+ if (value == marker)
+ *alist = scm_assq_remove_x (*alist, marker);
+ }
+ else
+ {
+#ifndef NDEBUG
+ if (ly_is_procedure (cache_callback))
+ scm_apply_0 (cache_callback,
+ scm_list_n (self_scm (),
+ sym,
+ proc,
+ value,
+ SCM_UNDEFINED));
+#endif
+ internal_set_value_on_alist (alist, sym, value);
+ }
+
+ return value;