mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: musl & strndupa?
Date: Wed, 1 Jan 2014 15:18:59 -0500	[thread overview]
Message-ID: <20140101201859.GQ24286@brightrain.aerifal.cx> (raw)
In-Reply-To: <CACCP0Go-9Nb9tak9hW4bmd_7hhtsPDSWm5nZobnmc2T-FYeiCQ@mail.gmail.com>

On Wed, Jan 01, 2014 at 08:07:07PM +0000, Raphael Cohn wrote:
> Rich,
> 
> Thank you for the extremely informative and quick response! I suspect in
> the small, understandable places that use this function in this package it
> should be possible to avoid multiple evaluations (well, at least for this
> version of the code; no g'tee that would hold).
> 
> Out of interest, I presume there's no guarantee that alloca is aligned?

You'd have to consult the compiler for a guarantee, but I think the
intent is that it's suitably aligned for any type, but perhaps not for
extended things like vector operations.

> It's not a feature I've ever used - it seems like a micro-optimisation for
> tight loops that should be made as part of a decision by a higher-level
> language (eg Vala, which, as I understand, doesn't).

The intent of alloca is to allow the programmer to be lazy about
obtaining temporary, "arbitrarily large" storage that will
automatically cease to exist when the caller returns. It's mostly
obsoleted by VLAs (but alloca can do things VLA can't, e.g. when used
in loops), but VLAs are also unsafe in the same way that there's no
way to check for allocation failures or handle them when they occur.
When you really need more than a small reasonable bounded-size buffer,
you need to be using malloc/free and dealing with the ugly failure
cases and cleanup on return...

Rich


      reply	other threads:[~2014-01-01 20:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-01 19:42 Raphael Cohn
2014-01-01 19:54 ` Rich Felker
2014-01-01 20:07   ` Raphael Cohn
2014-01-01 20:18     ` Rich Felker [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140101201859.GQ24286@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).