Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.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.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'overflow': 0.07; 'cc:addr :python-list': 0.09; '"run': 0.09; 'underlying': 0.09; 'stack': 0.13; 'ignore': 0.14; 'interpreter': 0.15; 'accordingly': 0.16; 'adjusted': 0.16; 'buggy': 0.16; 'cc:name:python': 0.16; 'joonas': 0.16; 'liik': 0.16; 'limit,': 0.16; 'program"': 0.16; 'safely.': 0.16; 'to:addr:pearwood.info': 0.16; "to:name:steven d'aprano": 0.16; 'wrote:': 0.16; 'memory': 0.17; 'programmer': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'code.': 0.23; 'defined': 0.23; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'least': 0.27; 'message-id:@mail.gmail.com': 0.27; 'executing': 0.27; 'specify': 0.27; 'function': 0.28; 'crash': 0.29; 'depth': 0.29; 'idea,': 0.29; 'system?': 0.29; 'subject:/': 0.30; 'code': 0.30; 'extend': 0.31; 'possibly': 0.32; 'url:python': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'received:google.com': 0.35; 'but': 0.36; 'too': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; 'possible': 0.36; 'url:library': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'mean': 0.38; 'means': 0.39; 'why': 0.39; 'system.': 0.39; 'takes': 0.39; 'your': 0.60; 'maximum': 0.61; 'hope': 0.61; 'real': 0.62; 'per': 0.62; 'times': 0.63; 'between': 0.65; 'limit': 0.65; 'manner': 0.69; 'duty': 0.72; 'jul': 0.72; 'treat': 0.72; '"can': 0.84; 'blow': 0.84; 'prolly': 0.84; 'safeguard': 0.84; 'have.': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=z3iJoeCGM3ATt3NsEVYnbnCtEzblKw9ZuFwL38HXdwg=; b=0pCdG06YOBCSZywpBqIUk84CHHabPP1lmz3ArQ96v16gCCrPJpiTRjY4HUPTteYWZo 56ITLPuKRucxZ5S2JQmF/CrrIdOdJROw3C6c4k8THFvneflKZLO6R/n/gARlM5GtSLT8 +mcB3hMWciwLXrFL0Mt27bss350RdkmY2hJHgRcprTU8dm7nqJg2hZ4yRFbu9+F0OEoZ DnwPuPYeE3HzaEg5mG72KH42GfLD5HAQfHXdL8E4X+hW0naX5pyId2gz4tD1WmoQtExV vIQfiBRIoVrCmyOPzGh1ltOCmvL/VNcgai0/cZyDu5hjXVn5Q1ma+tQ2qFeUkONHfKHR 0Jiw== MIME-Version: 1.0 X-Received: by 10.50.129.101 with SMTP id nv5mr5141302igb.31.1437074056267; Thu, 16 Jul 2015 12:14:16 -0700 (PDT) In-Reply-To: <55a7feed$0$1674$c3e8da3$5496439d@news.astraweb.com> References: <87d1zunctp.fsf@elektro.pacujo.net> <87k2u2eu67.fsf@elektro.pacujo.net> <55A51662.4090007@rece.vub.ac.be> <55A75DE0.1070101@rece.vub.ac.be> <55A7B80B.6090905@rece.vub.ac.be> <55A7C094.7060604@rece.vub.ac.be> <55a7feed$0$1674$c3e8da3$5496439d@news.astraweb.com> Date: Thu, 16 Jul 2015 22:14:15 +0300 Subject: Re: Possibly Pythonic Tail Call Optimization (TCO/TRE) From: Joonas Liik To: "Steven D'Aprano" Cc: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1437074064 news.xs4all.nl 2901 [2001:888:2000:d::a6]:36946 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93953 On 16 July 2015 at 21:58, Steven D'Aprano wrote: > On Fri, 17 Jul 2015 03:34 am, Joonas Liik wrote: > >> Now i admit that it is possible to have infinite recursion but it is >> also possiblew to have infinite loops. and we don't kill your code >> after 1000 iterations of a while loop so why should we treat recursion >> any differently? > > Because a while loop which repeats to many times is annoying but harmless, > but a function that recurses too many times will blow up the stack and > cause a seg fault, possibly executing arbitrary memory as code. You want > malware and viruses to take over your system? That's how you get malware > and viruses to take over your system. That's just a buggy implementation, there are ways to extend the stack that nears its capacity, safely. > >> Having a user defined maximum stack limit might be a good idea, eg if >> my stack takes up 100MB its prolly broke, but it should be my duty as >> a programmer to specify such a limit, not have it inflicted upon me >> (worse, in a manner that cannot be changed!). > > You mean sys.getrecursionlimit() and sys.setrecursionlimit()? > ... and that buggy implementation means that when you sys.setrecursionlimit() you will overflow the stack and crash because the recursion limit is an aritificial safeguard and the underlying c buffer is not adjusted accordingly or at least so it would seem. https://docs.python.org/2/library/sys.html#sys.setrecursionlimit so as per the docs the programmer has no real control over how much stack his program can have. all you can say is "let me ignore the safeguard a little longer, i hope i wont crash the program" that is not the same as "can i please have a stack depth of 20000.. You are giving the programmer a choice between "run out of stack and crash" and "mutilate interpreter internals and crash or zero out the hard drive" this is not a real choice..