This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC] Make getenv O(1)
- From: Alexander Monakov <amonakov at ispras dot ru>
- To: Ondřej Bílka <neleai at seznam dot cz>
- Cc: Rich Felker <dalias at aerifal dot cx>, Florian Weimer <fweimer at redhat dot com>, libc-alpha at sourceware dot org
- Date: Mon, 21 Oct 2013 21:26:32 +0400 (MSK)
- Subject: Re: [RFC] Make getenv O(1)
- Authentication-results: sourceware.org; auth=none
- References: <20131014172852 dot GA26005 at domone dot podge> <52611F60 dot 3080700 at redhat dot com> <20131018124013 dot GA15803 at domone dot podge> <alpine dot LNX dot 2 dot 00 dot 1310181656380 dot 3212 at monopod dot intra dot ispras dot ru> <20131018132604 dot GA16445 at domone dot podge> <alpine dot LNX dot 2 dot 00 dot 1310181744060 dot 3212 at monopod dot intra dot ispras dot ru> <20131018140705 dot GA18542 at domone dot podge> <20131021152356 dot GQ20515 at brightrain dot aerifal dot cx> <20131021161938 dot GA26730 at domone dot podge> <alpine dot LNX dot 2 dot 00 dot 1310212054470 dot 3212 at monopod dot intra dot ispras dot ru> <20131021170934 dot GA26031 at domone dot podge>
On Mon, 21 Oct 2013, OndÅej BÃlka wrote:
> On Mon, Oct 21, 2013 at 08:55:37PM +0400, Alexander Monakov wrote:
> > On Mon, 21 Oct 2013, OndÅej BÃlka wrote:
> > > Why, following does not need synchronization.
> > >
> > > #define GETENV(x) ({ \
> > > static char *__ret = NULL; \
> > > if (__builtin_constant_p (x) && !__cached) \
> > > __ret = getenv (x) + 1; \
> > > __builtin_constant_p (x) ? __ret - 1: getenv (x);})
> >
> > This wouldn't compile as __cached is not defined (and I'll admit I don't see
> > what approach you're trying to convey).
> >
> s/__cached/__ret/
Ah, my bad. While this would be ok in practice, I think incrementing a
pointer containing a NULL value invokes undefined behavior, doesn't it?
Alexander