From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juanma Barranquero Newsgroups: gmane.emacs.devel Subject: Re: Inconsistency in `string-to-number' Date: Fri, 4 Dec 2009 04:21:27 +0100 Message-ID: References: <47083.128.165.123.18.1240532205.squirrel@webmail.lanl.gov> <833abygwxo.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1259896929 18347 80.91.229.12 (4 Dec 2009 03:22:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 4 Dec 2009 03:22:09 +0000 (UTC) Cc: Eli Zaretskii , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Dec 04 04:22:02 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NGOk6-0006vS-62 for ged-emacs-devel@m.gmane.org; Fri, 04 Dec 2009 04:22:02 +0100 Original-Received: from localhost ([127.0.0.1]:56119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NGOk5-000470-9M for ged-emacs-devel@m.gmane.org; Thu, 03 Dec 2009 22:22:01 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NGOjy-000453-SL for emacs-devel@gnu.org; Thu, 03 Dec 2009 22:21:54 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NGOju-00042p-C3 for emacs-devel@gnu.org; Thu, 03 Dec 2009 22:21:54 -0500 Original-Received: from [199.232.76.173] (port=57508 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NGOju-00042m-5U for emacs-devel@gnu.org; Thu, 03 Dec 2009 22:21:50 -0500 Original-Received: from mail-bw0-f215.google.com ([209.85.218.215]:43639) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NGOjs-000089-EQ; Thu, 03 Dec 2009 22:21:48 -0500 Original-Received: by bwz7 with SMTP id 7so1811815bwz.26 for ; Thu, 03 Dec 2009 19:21:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=D1ObISjEADyTxYS2eOImdo6J6boRqXhCQYNUpYYIo6Y=; b=Se/e7QU2ZimKglIT89ljW6cU/UZe+Yl07WWTrXhNv0RVbIVaob/C6rUE9ow27tVdEB EHvSZag6JfuyNA2TE5EUIhT1Ccfh7K/Cf/6cbIefXAfEBAptMic6vy940QMQd38j/c29 Xe/mPJ8cBmwNDqQZAc+m+TGM7HmGic09syApQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=LF3c41KX1S6xA7tsPUOA4IZT9nK2bSXC0k/X3dnTkxpJ3/43aBhfiqmpUZ09B2/KXD RVsPXDcr44dC38rAhGH7Yqw6s6Lb6FUs7r4GwXEXeuBdg1mz+u7nrsk+XWPw79o1ylQN tCUCI5g55NnKiwAQ832+kUQ2BrejrQIJs68tI= Original-Received: by 10.204.10.152 with SMTP id p24mr2565352bkp.111.1259896907141; Thu, 03 Dec 2009 19:21:47 -0800 (PST) In-Reply-To: X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:118228 Archived-At: On Tue, Dec 1, 2009 at 21:15, Stefan Monnier wro= te: > Sorry, your email got misfiled. No problem. >> =C2=A03) Allow any trailing char. >> =C2=A0 =C2=A0 =C2=A0Pro: forgiving. >> =C2=A0 =C2=A0 =C2=A0Cons: (unlikely) incompatibility with uses of undocu= mented "1.2:" =3D> 1 > > That would be my choice. =C2=A0The behavior is still fairly regular, so t= he > doc shouldn't be too scary, and it works about as well as now. OK. > I'd need to see the patch to pronouce myself on the uncleanliness. Attached. Juanma diff --git a/src/lisp.h b/src/lisp.h index 2052dfa..3bdecc5 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -2795,7 +2795,7 @@ extern Lisp_Object Vcurrent_load_list; extern Lisp_Object Vload_history, Vload_suffixes, Vload_file_rep_suffixes; extern int openp P_ ((Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object *, Lisp_Object)); -extern int isfloat_string P_ ((char *)); +extern int isfloat_string P_ ((char *, int)); extern void map_obarray P_ ((Lisp_Object, void (*) (Lisp_Object, Lisp_Obje= ct), Lisp_Object)); extern void dir_warning P_ ((char *, Lisp_Object)); diff --git a/src/lread.c b/src/lread.c index 97b9410..f9b51a8 100644 --- a/src/lread.c +++ b/src/lread.c @@ -3026,7 +3026,7 @@ read1 (readcharfun, pch, first_in_list) } } } - if (isfloat_string (read_buffer)) + if (isfloat_string (read_buffer, 0)) { /* Compute NaN and infinities using 0.0 in a variable, to cope with compilers that think they are smarter @@ -3244,8 +3244,9 @@ substitute_in_interval (interval, arg) #define EXP_INT 16 int -isfloat_string (cp) +isfloat_string (cp, ignore_trailing) register char *cp; + int ignore_trailing; { register int state; @@ -3299,7 +3300,8 @@ isfloat_string (cp) cp +=3D 3; } - return (((*cp =3D=3D 0) || (*cp =3D=3D ' ') || (*cp =3D=3D '\t') || (*cp= =3D=3D '\n') || (*cp =3D=3D '\r') || (*cp =3D=3D '\f')) + return ((ignore_trailing + || (*cp =3D=3D 0) || (*cp =3D=3D ' ') || (*cp =3D=3D '\t') || (= *cp =3D=3D '\n') || (*cp =3D=3D '\r') || (*cp =3D=3D '\f')) && (state =3D=3D (LEAD_INT|DOT_CHAR|TRAIL_INT) || state =3D=3D (DOT_CHAR|TRAIL_INT) || state =3D=3D (LEAD_INT|E_CHAR|EXP_INT) diff --git a/src/data.c b/src/data.c index ce2d842..0f47556 100644 --- a/src/data.c +++ b/src/data.c @@ -2353,11 +2353,11 @@ digit_to_number (character, base) DEFUN ("string-to-number", Fstring_to_number, Sstring_to_number, 1, 2, 0, doc: /* Parse STRING as a decimal number and return the number. This parses both integers and floating point numbers. -It ignores leading spaces and tabs. +It ignores leading spaces and tabs, and all trailing chars. If BASE, interpret STRING as a number in that base. If BASE isn't present, base 10 is used. BASE must be between 2 and 16 (inclusive). -If the base used is not 10, floating point is not recognized. */) +If the base used is not 10, STRING is always parsed as integer. */) (string, base) register Lisp_Object string, base; { @@ -2392,7 +2392,7 @@ If the base used is not 10, floating point is not recognized. */) else if (*p =3D=3D '+') p++; - if (isfloat_string (p) && b =3D=3D 10) + if (isfloat_string (p, 1) && b =3D=3D 10) val =3D make_float (sign * atof (p)); else {