Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 Jun 2012 23:41:02 +0400
From:      Andrey Chernov <ache@FreeBSD.ORG>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        svn-src-head@FreeBSD.ORG, svn-src-all@FreeBSD.ORG, src-committers@FreeBSD.ORG, Pawel Jakub Dawidek <pjd@FreeBSD.ORG>, freebsd-arch@FreeBSD.ORG
Subject:   Re: svn commit: r236582 - head/lib/libc/stdlib
Message-ID:  <20120605194102.GA21173@vniz.net>
In-Reply-To: <20120606043731.D1124@besplex.bde.org>
References:  <201206042134.q54LYoVJ067685@svn.freebsd.org> <20120605074741.GA1391@garage.freebsd.pl> <20120605130922.GE13306@vniz.net> <20120606043731.D1124@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Jun 06, 2012 at 04:57:29AM +1000, Bruce Evans wrote:
> POSIX may require errno to not be clobbered, especially for its functions.
> It probably shouldn't do this for Standard C library functions like free(),
> since this would be an extension and any use of the extension would give
> unnecessarily unportanle code.

POSIX feels itself like they own all Standard C functions now. See 
"Resolved state" text for upcoming standard there:

"At line 30583 [XSH free DESCRIPTION], add a paragraph with CX shading:

The free() function shall not modify errno if ptr is a null pointer
or a pointer previously returned as if by malloc() and not yet 
deallocated.

At line 30591 [APPLICATION USAGE], add a new paragraph:

Because the free() function does not modify errno for valid pointers, it
is safe to use it in cleanup code without corrupting earlier errors, ..."

> OTOH, the libary can assume anything that it wants and
> implements for itself, since it is the implementation so it can make
> free() easy to use for itself, with any extensions that aren't incompatible
> with Standard C.  Since free() is allowed to clobber errno, it is also
> allowed to do a null clobber as a compatible extension.

Yes, it is safe for free() itself to save errno and still stay compliant 
with both current and upcoming POSIX and with Standard C. But any code
which rely on that is compliant with upcoming POSIX only. Since people 
don't want mass changes in that area, this is some sort of compromise
acceptable for me (in case free() itself will save/restore errno, of 
course).

-- 
http://ache.vniz.net/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120605194102.GA21173>