lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Introduce a maximum depth for markup evaluation (issue 5032041)


From: reinhold . kainhofer
Subject: Introduce a maximum depth for markup evaluation (issue 5032041)
Date: Thu, 15 Sep 2011 13:47:07 +0000

Reviewers: ,

Message:
Please review!

Description:
Introduce a maximum depth for markup evaluation

This will fix cases where a markup function calls itself (or other
functions) recursively with different arguments.

Please review this at http://codereview.appspot.com/5032041/

Affected files:
  A input/regression/markup-depth-non-terminating.ly
  M lily/text-interface.cc
  M scm/lily.scm


Index: input/regression/markup-depth-non-terminating.ly
diff --git a/input/regression/markup-depth-non-terminating.ly b/input/regression/markup-depth-non-terminating.ly
new file mode 100644
index 0000000000000000000000000000000000000000..52e0f70ee02aa78a80614c3f8d7a6b73628be09b
--- /dev/null
+++ b/input/regression/markup-depth-non-terminating.ly
@@ -0,0 +1,15 @@
+\version "2.15.12"
+#(ly:set-option 'warning-as-error #f)
+
+\header {
+  texidoc = "Markups have a maximum depth to prevent non-termination."
+
+}
+
+% A simple markup function that calls itself and increases its argument, so
+% it will grow forever, unless we terminate it.
+#(define-markup-command (recursive-explosion layout props nr)
+  (number?)
+ (interpret-markup layout props (make-recursive-explosion-markup (+ nr 1))))
+
+\markup { Test: \recursive-explosion #1 }
Index: lily/text-interface.cc
diff --git a/lily/text-interface.cc b/lily/text-interface.cc
index 7c9e8f26bbc975136acecfd730b01793c01c960a..92a3c9d8d7cd347649c5f26947aa6cac4865dc7e 100644
--- a/lily/text-interface.cc
+++ b/lily/text-interface.cc
@@ -28,6 +28,7 @@
 #include "modified-font-metric.hh"
 #include "output-def.hh"
 #include "pango-font.hh"
+#include "program-option.hh"
 #include "international.hh"
 #include "warn.hh"

@@ -119,6 +120,20 @@ Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup)
             }
         }

+      /* Check for non-terminating markups, e.g. recursive calls with
+       * changing arguments */
+      SCM opt_depth = ly_get_option (ly_symbol2scm ("max-markup-depth"));
+      size_t max_depth = robust_scm2int(opt_depth, 1024);
+      if (depth > max_depth)
+        {
+          string name = ly_symbol2string (scm_procedure_name (func));
+          string argstring = "TODO";
+          non_fatal_error (_f("Markup depth exceeds maximal value of %d; "
+                              "Markup: %s, arguments: %s",
+ max_depth, name.c_str (), argstring.c_str ()));
+          return Stencil().smobbed_copy ();
+        }
+
       encountered_markups.push_back (markup);
       SCM retval = scm_apply_2 (func, layout_smob, props, args);
       encountered_markups.pop_back ();
Index: scm/lily.scm
diff --git a/scm/lily.scm b/scm/lily.scm
index bbea5afab996462f9eedb9a6ee3613f65581ce5a..105a8b3b670156fc41cab3199db6a13c887045d0 100644
--- a/scm/lily.scm
+++ b/scm/lily.scm
@@ -120,6 +120,9 @@ jobs.")
     (log-file #f
 "If string FOO is given as argument, redirect
 output to log file `FOO.log'.")
+    (max-markup-depth 1024
+"Maximum depth for the markup tree. If a markup has more levels, assume that +it will not terminate at all and print out a warning, but continue processing.")
     (midi-extension ,(if (eq? PLATFORM 'windows)
                          "mid"
                          "midi")





reply via email to

[Prev in Thread] Current Thread [Next in Thread]