From owner-svn-src-all@FreeBSD.ORG Sat Feb 14 18:33:56 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9038FADB; Sat, 14 Feb 2015 18:33:56 +0000 (UTC) Received: from pmta2.delivery5.ore.mailhop.org (pmta2.delivery5.ore.mailhop.org [54.186.218.12]) by mx1.freebsd.org (Postfix) with ESMTP id 6CF7E60E; Sat, 14 Feb 2015 18:33:56 +0000 (UTC) Received: from smtp7.ore.mailhop.org (172.31.36.112) by pmta2.delivery1.ore.mailhop.org id hruahq20u50c; Sat, 14 Feb 2015 18:33:59 +0000 (envelope-from ) Received: from [73.34.117.227] (helo=ilsoft.org) by smtp7.ore.mailhop.org with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.82) (envelope-from ) id 1YMhXK-0001ut-SJ; Sat, 14 Feb 2015 18:33:50 +0000 Received: from revolution.hippie.lan (revolution.hippie.lan [172.22.42.240]) by ilsoft.org (8.14.9/8.14.9) with ESMTP id t1EIXm0H014934; Sat, 14 Feb 2015 11:33:48 -0700 (MST) (envelope-from ian@freebsd.org) X-Mail-Handler: DuoCircle Outbound SMTP X-Originating-IP: 73.34.117.227 X-Report-Abuse-To: abuse@duocircle.com (see https://support.duocircle.com/support/solutions/articles/5000540958-duocircle-standard-smtp-abuse-information for abuse reporting information) X-MHO-User: U2FsdGVkX1+xqzchXH8jXc+AH5A4KqYa Message-ID: <1423938828.80968.148.camel@freebsd.org> Subject: Re: svn commit: r278737 - head/usr.sbin/flowctl From: Ian Lepore To: Gleb Smirnoff Date: Sat, 14 Feb 2015 11:33:48 -0700 In-Reply-To: <20150214181508.GL15484@FreeBSD.org> References: <201502132357.t1DNvKda075915@svn.freebsd.org> <20150214193210.N945@besplex.bde.org> <20150214181508.GL15484@FreeBSD.org> Content-Type: text/plain; charset="us-ascii" X-Mailer: Evolution 3.12.8 FreeBSD GNOME Team Port Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Bruce Evans X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Feb 2015 18:33:56 -0000 On Sat, 2015-02-14 at 21:15 +0300, Gleb Smirnoff wrote: > Bruce, > > On Sat, Feb 14, 2015 at 08:46:58PM +1100, Bruce Evans wrote: > B> Using VLAs and also the C99 feature of declarations anwhere, and extensions > B> like __aligned(), we can almost implement a full alloca() using the fixed > B> version of this change: > B> > B> /* > B> * XXX need extended statement-expression so that __buf doesn't go out > B> * of scope after the right brace. > B> */ > B> #define my_alloca(n) __extension__ ({ > B> /* XXX need unique name. */ \ > B> char __buf[__roundup2((n), MUMBLE)] __aligned(MUMBLE); \ > B> \ > B> (void *)__buf; \ > B> }) > > I like this idea. But would this exact code work? The life of > __buf is limited by the code block, and we exit the block > immediately. Wouldn't the allocation be overwritten if we > enter any function or block later? > Why put any effort into avoiding alloca() in the first place? Is it inefficient on some platforms? On arm it's like 5 instructions, it just adjusts the size to keep the stack dword-aligned and subtracts the result from sp, done. -- Ian