From owner-freebsd-arch Sat Jan 26 21:13:25 2002 Delivered-To: freebsd-arch@freebsd.org Received: from mail.acns.ab.ca (mail.acns.ab.ca [142.179.151.95]) by hub.freebsd.org (Postfix) with ESMTP id 2C25A37B404; Sat, 26 Jan 2002 21:13:22 -0800 (PST) Received: from colnta.acns.ab.ca (colnta.acns.ab.ca [192.168.1.2]) by mail.acns.ab.ca (8.11.6/8.11.3) with ESMTP id g0R5DBV12319; Sat, 26 Jan 2002 22:13:11 -0700 (MST) (envelope-from davidc@colnta.acns.ab.ca) Received: (from davidc@localhost) by colnta.acns.ab.ca (8.11.6/8.11.3) id g0R5DBf18715; Sat, 26 Jan 2002 22:13:11 -0700 (MST) (envelope-from davidc) Date: Sat, 26 Jan 2002 22:13:11 -0700 From: Chad David To: "Brian F. Feldman" Cc: Bruce Evans , arch@FreeBSD.ORG Subject: Re: strtod() Message-ID: <20020126221311.A18683@colnta.acns.ab.ca> Mail-Followup-To: "Brian F. Feldman" , Bruce Evans , arch@FreeBSD.ORG References: <200201270453.g0R4rwi92912@green.bikeshed.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200201270453.g0R4rwi92912@green.bikeshed.org>; from green@FreeBSD.ORG on Sat, Jan 26, 2002 at 11:53:58PM -0500 Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Sat, Jan 26, 2002 at 11:53:58PM -0500, Brian F. Feldman wrote: > Chad David wrote: > > > > Code like this is what I'm dealing with. My point is that if you set > > > > errno == 0, and then after the function it is != 0, an error DID occur, > > > > as long as the return value == 0.0 or HUGE_VAL I guess. > > > > > > > > Am I making any sense? > > > > > > Not "as long as the return value" is anything! Why should the function be > > > changing errno if it hasn't generated an error? These are particularly > > > difficult functions to use in the first place, and they really shouldn't be > > > made more-so by gratuitously changing errno. It's not hard to save errno, > > > either, in the library call... > > > > I'm not sure if you are agreeing with me, or disagreeing with me :). > > > > When 0.0 is returned and errno == EINVAL a lot of code assumes there was > > an error, but current always returns with errno == EINVAL, which breaks > > this code when "0.0" is converted.. > > The problem is that 0.0 could be the right return value, but if errno was > EINVAL before calling strtod(), the caller makes a mistake in assuming > "retval == 0.0 && errno == EINVAL means failure". That is true, but as I believe I stated at the beginning of this thread the Solaris strtod() man pages says: "Because 0 is returned on error and is also a valid return on success, an application wishing to check for error situa- tions should set errno to 0, then call strtod(), then check errno and if it is non-zero, assume an error has occurred." On FreeBSD current any code that does this (ie code written for Solaris) will fail everytime... but I think we are agreeing that this is wrong. I don't believe in trying to save code from itself, I just want things to work as expected. > > > If you are suggesting that strtod() etc. should save errno on entry and > > then reset it on return (unless it wants to return its own error) then I > > think I agree with that. > > If strtod() wants to use errno internally, that's fine, but I personally > really expect it to not modify errno without also intending to return an > error; that's why saving at entry and restoring at exit is my preference for > these functions. Agreed, so is there consensus enough on this for me to offer a patch that basically does this? I also want to see where this makes the most sense to do, in strtod.c or perhaps in the locale code (which is probably called by at least everything looking for a decimal point)? -- 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