Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 27 Jan 2002 13:24:40 -0700
From:      Chad David <davidc@acns.ab.ca>
To:        Terry Lambert <tlambert2@mindspring.com>
Cc:        "Andrey A. Chernov" <ache@nagual.pp.ru>, "Brian F. Feldman" <green@FreeBSD.ORG>, Bruce Evans <bde@zeta.org.au>, arch@FreeBSD.ORG
Subject:   Re: strtod()
Message-ID:  <20020127132439.C42735@colnta.acns.ab.ca>
In-Reply-To: <3C53DB0B.6547EB76@mindspring.com>; from tlambert2@mindspring.com on Sun, Jan 27, 2002 at 02:48:43AM -0800
References:  <20020126162924.A7726@colnta.acns.ab.ca> <200201270453.g0R4rwi92912@green.bikeshed.org> <20020127070421.GA13415@nagual.pp.ru> <20020127003719.A38420@colnta.acns.ab.ca> <3C53DB0B.6547EB76@mindspring.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Jan 27, 2002 at 02:48:43AM -0800, Terry Lambert wrote:
> Chad David wrote:
> > I just noticed that if you call printf() (or anything that will call
> > localeconv()) before you call strtod() etc. it works as it should.  It
> > is the first call to localeconv() that causes errno to be updated when
> > it calls strtol().  After that localeconv() takes a short cut.  So it
> > isn't really strtod()'s problem, but localeconv()'s.
> 
> Good catch!
> 
> > The attached patch fixes this case, and probably others.  Comments?
> 
> Uh, working around the problem this way adds overhead to a
> lot of places where it wasn't before.  How about just
> initializing the shortcut completely?
> 
> Worse comes to worse, call localeconv() in a .init by abusing
> the G++ linker set that gets run to construct virtual base
> clases and template classes the first time.

This will not work, as somebody will eventually change the locale, which
could cause this to happen again (once) for some unlucky function.  Even
strtod() (which is where I first noticed this) will only fail the first
time.

Saving and restoring errno does seem like a hack to me, but I'm not sure
how to fix this so bad locales do not break functions (ie strtod()) in
none obvious ways.

-- 
Chad David        davidc@acns.ab.ca
www.FreeBSD.org   davidc@freebsd.org
ACNS Inc.         Calgary, Alberta Canada
Fourthly, The constant breeders, beside the gain of eight shillings
sterling per annum by the sale of their children, will be rid of the
charge of maintaining them after the first year. - Johnathan Swift

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




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