Added a more comprehensive recursive location-loop checker that shouldn't be too expensive. Thanks to rcaskey for bouncing ideas in IRC!

This commit is contained in:
Griatch 2012-10-14 21:24:58 +02:00
parent 7de8e3fa82
commit 7997cf62e8

View file

@ -285,12 +285,18 @@ class ObjectDB(TypedObject):
loc = _GA(location, "dbobj") loc = _GA(location, "dbobj")
else: else:
loc = location loc = location
if loc == self:
# block 1st level recursion; best to defer having to do # recursive location check
# a full recursive check of location loops if possible - def is_loc_loop(loc, depth=0):
# (it's rather expensive) this could be checked higher up "Recursively traverse the target location to make sure we are not in it."
# if a problem. if depth > 10: return
raise RuntimeError elif loc == self: raise RuntimeError
elif loc == None: raise RuntimeWarning # just to quickly get out
return is_loc_loop(_GA(loc, "db_location"), depth+1)
# check so we don't create a location loop - if so, RuntimeError will be raised.
try: is_loc_loop(loc)
except RuntimeWarning: pass
# set the location # set the location
_set_cache(self, "location", loc) _set_cache(self, "location", loc)
# update the contents of each location # update the contents of each location