changeset 1275:b01d3537960d

Limit the recursion depth.
author Marcel Keller <mkeller@cs.au.dk>
date Fri, 09 Oct 2009 16:27:59 +0200
parents 31da6944a413
children f9ab0f24979d
files viff/runtime.py
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/viff/runtime.py	Fri Oct 09 11:02:05 2009 +0200
+++ b/viff/runtime.py	Fri Oct 09 16:27:59 2009 +0200
@@ -38,6 +38,7 @@
 from optparse import OptionParser, OptionGroup
 from collections import deque
 import os
+import sys
 
 from viff.field import GF256, FieldElement
 from viff.util import wrapper, rand, deep_wait, track_memory_usage, begin, end
@@ -605,6 +606,8 @@
         #: Record the recursion depth.
         self.depth_counter = 0
         self.max_depth = 0
+        #: Recursion depth limit by experiment, including security margin.
+        self.depth_limit = int(sys.getrecursionlimit() / 50)
         #: Use deferred queues only if the ViffReactor is running.
         self.using_viff_reactor = isinstance(reactor, viff.reactor.ViffReactor)
 
@@ -921,8 +924,11 @@
             if self.depth_counter > self.max_depth:
                 # Record the maximal depth reached.
                 self.max_depth = self.depth_counter
+                if self.depth_counter >= self.depth_limit:
+                    print "Recursion depth limit reached."
 
-            reactor.doIteration(0)
+            if self.depth_counter < self.depth_limit:
+                reactor.doIteration(0)
 
             self.depth_counter -= 1
             self.activation_counter = 0