From owner-svn-src-all@FreeBSD.ORG Mon Feb 16 16:25:02 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0642EC02; Mon, 16 Feb 2015 16:25:02 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D0B34DCC; Mon, 16 Feb 2015 16:25:01 +0000 (UTC) Received: from ralph.baldwin.cx (pool-173-54-116-245.nwrknj.fios.verizon.net [173.54.116.245]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 28DE4B926; Mon, 16 Feb 2015 11:25:00 -0500 (EST) From: John Baldwin To: Pedro Giffuni Subject: Re: svn commit: r278737 - head/usr.sbin/flowctl Date: Mon, 16 Feb 2015 11:20:46 -0500 Message-ID: <2515976.62jDXqymxG@ralph.baldwin.cx> User-Agent: KMail/4.14.2 (FreeBSD/10.1-STABLE; KDE/4.14.2; amd64; ; ) In-Reply-To: <54DFA7CC.20305@FreeBSD.org> References: <201502132357.t1DNvKda075915@svn.freebsd.org> <1423938828.80968.148.camel@freebsd.org> <54DFA7CC.20305@FreeBSD.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Mon, 16 Feb 2015 11:25:00 -0500 (EST) Cc: src-committers@freebsd.org, Ian Lepore , svn-src-all@freebsd.org, Gleb Smirnoff , Bruce Evans , svn-src-head@freebsd.org 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: Mon, 16 Feb 2015 16:25:02 -0000 On Saturday, February 14, 2015 02:53:48 PM Pedro Giffuni wrote: > On 02/14/15 13:33, Ian Lepore wrote: > > 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. > > Because it's non-standard and the alloca(3) man page discourages it: > _____ > ... > BUGS > The alloca() function is machine and compiler dependent; its use is dis- > couraged. > > ____ > > It is not disappearing anytime soon though, some even say the man > page is wrong. Given all the alternative implementations and concerns, it seems like alloca() is a lot simpler to use. I suspect it isn't going away anytime soon, either. -- John Baldwin