From patchwork Tue Jun 29 03:44:30 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry DeLisle X-Patchwork-Id: 57240 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 27805B6EED for ; Tue, 29 Jun 2010 13:44:58 +1000 (EST) Received: (qmail 13136 invoked by alias); 29 Jun 2010 03:44:53 -0000 Received: (qmail 13119 invoked by uid 22791); 29 Jun 2010 03:44:52 -0000 X-SWARE-Spam-Status: No, hits=3.7 required=5.0 tests=AWL, BAYES_05, BOTNET, RCVD_IN_DNSWL_NONE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from vms173019pub.verizon.net (HELO vms173019pub.verizon.net) (206.46.173.19) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 29 Jun 2010 03:44:47 +0000 Received: from [192.168.1.10] ([unknown] [64.234.92.14]) by vms173019.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0L4R001O3BQ7SZ50@vms173019.mailsrvcs.net>; Mon, 28 Jun 2010 22:44:32 -0500 (CDT) Message-id: <4C296C1E.4000702@verizon.net> Date: Mon, 28 Jun 2010 20:44:30 -0700 From: Jerry DeLisle User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4 MIME-version: 1.0 To: Tobias Burnus Cc: gfortran , gcc patches Subject: Re: [patch, libfortran] PR43298 Fortran library does not read in NaN -Inf or Inf References: <4C27A929.8010702@verizon.net> <4C27B771.2080801@net-b.de> In-reply-to: <4C27B771.2080801@net-b.de> Content-type: multipart/mixed; boundary=------------040500010005070901050403 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On 06/27/2010 01:41 PM, Tobias Burnus wrote: > Jerry DeLisle wrote: >> This attached patch adds code to read these special cases. The code is >> self explanatory. This added feature is for formatted READ. > The attached revised patch includes the updated test case. With this patch, signs are handled for inf and infinity, spaces are not allowed within parenthesis, and malformed parenthesis are checked. If OK, I can commit before freeze Tuesday evening (PST). Regression tested. Regards, Jerry 2010-06-28 Jerry DeLisle PR libfortran/43298 * io/read.c: Add code to parse and read Inf, Infinity, NaN, and Nan with optional parenthesis. Index: libgfortran/io/read.c =================================================================== --- libgfortran/io/read.c (revision 161521) +++ libgfortran/io/read.c (working copy) @@ -810,6 +810,66 @@ read_f (st_parameter_dt *dtp, const fnode *f, char if (w == 0) goto zero; + /* Check for Infinity or NaN. */ + if (unlikely ((w >= 3 && (*p == 'i' || *p == 'I' || *p == 'n' || *p == 'N')))) + { + int seen_paren = 0; + char *save = out; + + /* Scan through the buffer keeping track of spaces and parenthesis. We + null terminate the string as soon as we see a left paren or if we are + BLANK_NULL mode. Leading spaces have already been skipped above, + trailing spaces are ignored by converting to '\0'. A space + between "NaN" and the optional perenthesis is not permitted. */ + while (w > 0) + { + *out = tolower (*p); + switch (*p) + { + case ' ': + if (dtp->u.p.blank_status == BLANK_ZERO) + { + *out = '0'; + break; + } + *out = '\0'; + if (seen_paren == 1) + goto bad_float; + break; + case '(': + seen_paren++; + *out = '\0'; + break; + case ')': + if (seen_paren++ != 1) + goto bad_float; + break; + default: + if (!isalnum (*out)) + goto bad_float; + } + --w; + ++p; + ++out; + } + + *out = '\0'; + + if (seen_paren != 0 && seen_paren != 2) + goto bad_float; + + if ((strcmp (save, "inf") == 0) || (strcmp (save, "infinity") == 0)) + { + if (seen_paren) + goto bad_float; + } + else if (strcmp (save, "nan") != 0) + goto bad_float; + + convert_real (dtp, dest, buffer, length); + return; + } + /* Process the mantissa string. */ while (w > 0) {