Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!eweka.nl!hq-usenetpeers.eweka.nl!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.115 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.78; '*S*': 0.01; 'fault': 0.07; 'function,': 0.09; 'thx': 0.09; 'python': 0.11; 'subject:python': 0.12; 'cc:addr:python-list': 0.15; '2.7.2': 0.16; 'funny,': 0.16; 'ubuntu,': 0.16; 'def': 0.20; 'wrote:': 0.21; 'header:In-Reply- To:1': 0.22; 'header:User-Agent:1': 0.23; '>>>': 0.24; 'cc:no real name:2**0': 0.26; 'cc:addr:python.org': 0.27; 'pm,': 0.28; 'equivalent.': 0.29; 'question': 0.30; 'raise': 0.30; 'cc:2**0': 0.31; 'hi,': 0.33; 'beginning': 0.35; 'why': 0.36; 'but': 0.36; 'michael': 0.38; 'received:192': 0.39; "can't": 0.39; 'large': 0.40; 'received:192.168': 0.40; 'steps': 0.61; 'skip:n 10': 0.62; 'real': 0.63; 'remove': 0.65; 'header:Reply-To:1': 0.66; 'bound': 0.72; 'reply-to:no real name:2**0': 0.72; 'limit': 0.73; 'size.': 0.79; 'davea': 0.84; 'received:74.208.4.194': 0.84; 'recursion': 0.84; 'true:': 0.84; 'explained': 0.91 Date: Tue, 27 Mar 2012 22:38:11 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.27) Gecko/20120216 Thunderbird/3.1.19 MIME-Version: 1.0 To: Michael Poeltl Subject: Re: python segfault References: <20120327222757.GA22125@terra.cms.at> In-Reply-To: <20120327222757.GA22125@terra.cms.at> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:zrfKCgS503YKCp5in1k2d5/o/Mp61P+rF95qPChVF7q mqnwuD7vOaN7WRw6yWnps5oBJpaTnHL7ZvWfQjPoYMtPRqqJMg J6JR0FpevhgKy9mc+UrLaPgI7c2AMwahYqMvuXuv52x0DkQ87r UiUOa7RqkMAK/SVRc9Dh5bVjpAygPZPLGDazVNUaGTPbAM48yx 5h0EfMloaTmid4rDm+zNU0FtT5JwZvwJsRZW911uw9VQgdnrTy +q6cxRyik6Qpn5TD/i2OB17SILISj9IAXFoKz1RnNyFoD6G4Ni xP58z6rtYfd9TuyyLb+WgNHK6D8tlLNuZ7/n5vTz4DJgWuyoUR Frbb3kgaQ67cM/36Dklg= Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332902301 news.xs4all.nl 6868 [2001:888:2000:d::a6]:49568 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22261 On 03/27/2012 06:27 PM, Michael Poeltl wrote: > hi, > > can anybody tell why this 'little stupid *thing* of code' let's python-3.2.2, 2.6.X or python 2.7.2 segfault? > >>> def get_steps2(pos=0, steps=0): > ... if steps == 0: > ... pos = random.randint(-1,1) > ... if pos == 0: > ... return steps > ... steps += 2 > ... pos += random.randint(-1,1) > ... return get_steps2(pos,steps) > ... > > 0 > 2 > 8 > 0 > Segmentation fault > ?> > > funny, isn't it? > I was able to reproduce this segfault on various machines (32bit 64bit), ubuntu, slackware, debian > python.X segfaults on all of them > > thx > Michael Others have explained why you can't just raise the recursion limit to arbitrarily large values, and why there's no particular bound on the possible recursion size. But the real question is why you don't do the completely trivial conversion to a non-recursive equivalent. All you need do is add a while True: to the beginning of the function, and remove the return statement. -- DaveA