diff src/pt-eval.cc @ 10578:cb0883127251

limit on recursion via calls to source function
author John W. Eaton <jwe@octave.org>
date Tue, 27 Apr 2010 12:07:04 -0400
parents 57a59eae83cc
children 6abf966379de
line wrap: on
line diff
--- a/src/pt-eval.cc	Tue Apr 27 00:52:28 2010 -0400
+++ b/src/pt-eval.cc	Tue Apr 27 12:07:04 2010 -0400
@@ -58,6 +58,10 @@
 
 bool tree_evaluator::in_loop_command = false;
 
+// Maximum nesting level for functions, scripts, or sourced files called
+// recursively.
+int Vmax_recursion_depth = 256;
+
 // If TRUE, turn off printing of results in functions (as if a
 // semicolon has been appended to each statement).
 static bool Vsilent_functions = false;
@@ -1168,6 +1172,18 @@
   return ::do_keyboard (args);
 }
 
+DEFUN (max_recursion_depth, args, nargout,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {@var{val} =} max_recursion_depth ()\n\
+@deftypefnx {Built-in Function} {@var{old_val} =} max_recursion_depth (@var{new_val})\n\
+Query or set the internal limit on the number of times a function may\n\
+be called recursively.  If the limit is exceeded, an error message is\n\
+printed and control returns to the top level.\n\
+@end deftypefn")
+{
+  return SET_INTERNAL_VARIABLE (max_recursion_depth);
+}
+
 DEFUN (silent_functions, args, nargout,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {@var{val} =} silent_functions ()\n\