From patchwork Thu Mar 28 10:21:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 231968 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 99E792C008C for ; Thu, 28 Mar 2013 21:22:03 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=jt9LKKIpearBRqYsY lfBZ9EgC9nmIaaY9xsAy4OUmrb8RagYiYLB3kY4JCfP/HZuPQlCzGDbkI0j0gmqu 1m7ryVFj4GPs3dIo8BwdLB3fbK2hsDayBOtkyZDloPwz8FF0vIVKtlpr3E07m5zZ BnJiOP3rl3OZQqtHfWI7wWU4cc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=ar9soeU4q0J3c20R7qE1HtV n1AY=; b=okh+vwxxhkFrcd5DZVZNX8KCqmg/BCvNt7rUQJUAjU6xSJM1EEE1igl HoxOLNFZAAuq9kDQqeEWZ/X5jcmVIvpcoVM5OtsCxEF2T5gdR4jt1ZE5KK22x5yG sZ7Ct4EZKffgUhJqViIyNw9Pzg3CWaTxZalm8CN5w7iqGursvUjU= Received: (qmail 5351 invoked by alias); 28 Mar 2013 10:21:50 -0000 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 Received: (qmail 5322 invoked by uid 89); 28 Mar 2013 10:21:43 -0000 X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 28 Mar 2013 10:21:40 +0000 Received: from archimedes.net-b.de (port-92-195-88-1.dynamic.qsc.de [92.195.88.1]) by mx02.qsc.de (Postfix) with ESMTP id 040682763E; Thu, 28 Mar 2013 11:21:37 +0100 (CET) Message-ID: <515419B1.5060102@net-b.de> Date: Thu, 28 Mar 2013 11:21:37 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 MIME-Version: 1.0 To: gcc patches , gfortran Subject: Re: [Patch, Fortran] PR56737 - Fixing a bug in the I/O format cache handling References: <51541271.4060707@net-b.de> In-Reply-To: <51541271.4060707@net-b.de> X-Virus-Found: No Tobias Burnus wrote: > b) To copy the format string > > The attached patch does the latter. The current hashing algorithm > avoids hash collisions by checking whether the value is exactly the > same - and the value is given by the format string. Thus, instead of > copying the string when storing the format in the cache, the patch > copies it now before calling parse_format_list. Re-reading what Jerry wrote, I realized that the current code disables format caching for strings (but not for Holleriths). With my patch, that's no longer required. Attached is a missed-optimization patch. > Bootstrapped and regtested on x86-64-gnu-linux. > OK for the trunk and the 4.6/4.7/4.8 branches? (Or should the follow-up patch only applied to the trunk?) BTW: Without the follow up patch, the following is a memory leak as parse_format_list might set format_cache_ok to false: > if (fmt->error) > { > format_error (dtp, NULL, fmt->error); > + if (format_cache_ok) > + free (dtp->format); Thus, if the follow-up patch is not backported, it should be changed to "!is_internal_unit (dtp)", which is the initial condition for format_cache_ok. Tobias 2012-03-28 Tobias Burnus PR fortran/56737 * io/format.c (parse_format_list): Also cache FMT_STRING. (parse_format): Update call. diff --git a/libgfortran/io/format.c b/libgfortran/io/format.c index db95e49..d5a3548 100644 --- a/libgfortran/io/format.c +++ b/libgfortran/io/format.c @@ -586,16 +586,15 @@ format_lex (format_data *fmt) * parenthesis node which contains the rest of the list. */ static fnode * -parse_format_list (st_parameter_dt *dtp, bool *save_ok, bool *seen_dd) +parse_format_list (st_parameter_dt *dtp, bool *seen_dd) { fnode *head, *tail; format_token t, u, t2; int repeat; format_data *fmt = dtp->u.p.fmt; - bool saveit, seen_data_desc = false; + bool seen_data_desc = false; head = tail = NULL; - saveit = *save_ok; /* Get the next format item */ format_item: @@ -612,7 +611,7 @@ parse_format_list (st_parameter_dt *dtp, bool *save_ok, bool *seen_dd) } get_fnode (fmt, &head, &tail, FMT_LPAREN); tail->repeat = -2; /* Signifies unlimited format. */ - tail->u.child = parse_format_list (dtp, &saveit, &seen_data_desc); + tail->u.child = parse_format_list (dtp, &seen_data_desc); if (fmt->error != NULL) goto finished; if (!seen_data_desc) @@ -631,7 +630,7 @@ parse_format_list (st_parameter_dt *dtp, bool *save_ok, bool *seen_dd) case FMT_LPAREN: get_fnode (fmt, &head, &tail, FMT_LPAREN); tail->repeat = repeat; - tail->u.child = parse_format_list (dtp, &saveit, &seen_data_desc); + tail->u.child = parse_format_list (dtp, &seen_data_desc); *seen_dd = seen_data_desc; if (fmt->error != NULL) goto finished; @@ -659,7 +658,7 @@ parse_format_list (st_parameter_dt *dtp, bool *save_ok, bool *seen_dd) case FMT_LPAREN: get_fnode (fmt, &head, &tail, FMT_LPAREN); tail->repeat = 1; - tail->u.child = parse_format_list (dtp, &saveit, &seen_data_desc); + tail->u.child = parse_format_list (dtp, &seen_data_desc); *seen_dd = seen_data_desc; if (fmt->error != NULL) goto finished; @@ -723,8 +722,6 @@ parse_format_list (st_parameter_dt *dtp, bool *save_ok, bool *seen_dd) goto between_desc; case FMT_STRING: - /* TODO: Find out why it is necessary to turn off format caching. */ - saveit = false; get_fnode (fmt, &head, &tail, FMT_STRING); tail->u.string.p = fmt->string; tail->u.string.length = fmt->value; @@ -1104,8 +1101,6 @@ parse_format_list (st_parameter_dt *dtp, bool *save_ok, bool *seen_dd) finished: - *save_ok = saveit; - return head; } @@ -1255,8 +1250,7 @@ parse_format (st_parameter_dt *dtp) fmt->avail++; if (format_lex (fmt) == FMT_LPAREN) - fmt->array.array[0].u.child = parse_format_list (dtp, &format_cache_ok, - &seen_data_desc); + fmt->array.array[0].u.child = parse_format_list (dtp, &seen_data_desc); else fmt->error = "Missing initial left parenthesis in format";