From patchwork Thu Apr 26 12:00:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 905034 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-476846-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="EZSklm7g"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40WwdS3LBFz9rxs for ; Thu, 26 Apr 2018 22:01:15 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=kPp1TmDoqH6T4ut54MXVXii75+roaPA61Qn+zY7itXCo7Y6ZHC 09YZjkTsxLlQ/cf0jQqxhJIKnPA2DrlpY7YFtKU0iYUx6XDkc+c59Rlb0TAu1HK2 niV6ky8V+XoY+16S7TbjI+1MZxmb1Hp95iDBNxHJhR6Vcm5PyDlTXL2IY= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=FaHrmgcBtcpClTUKeV46PVSTN9U=; b=EZSklm7guasxSChqyVgp wMMRsFMPPCibqD80Y8/aqBR5ItqGzMeq0gddPKUm48X7HscuO+EEof/ELBBFZeBG L7m2Rl9gy+uw8bzi0mZJrzWZjdfnhfWzC6ni1ElDfWMfK80uynL5vYkV4uaNddBI WlS0QFlIU2ceNG3/72kLKHc= Received: (qmail 25496 invoked by alias); 26 Apr 2018 12:01:05 -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 25358 invoked by uid 89); 26 Apr 2018 12:01:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=forwards, H*r:181 X-HELO: mail-qt0-f172.google.com Received: from mail-qt0-f172.google.com (HELO mail-qt0-f172.google.com) (209.85.216.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 26 Apr 2018 12:00:58 +0000 Received: by mail-qt0-f172.google.com with SMTP id w12-v6so31051205qti.4 for ; Thu, 26 Apr 2018 05:00:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=UxaPOwW7Ow51W9LAwbUz7o8ZJ9VUKiaVMQKDt8wpGk4=; b=Xt+fhYvx2GQ8sTl6VEmsGUo3OYyhMJNQV6GJgZVyJlrLBJ6wzGqaS8A7iqeTMsZiAE RtsHqjQTKpLZrPKiQfxZkgAFlJ1f83cB6W8Ao+v726fAQwGl/Mc3O4roMtFgWgyu6Yr5 IvR+sRyvV1vSeFgSToHAykA2QTuyxxJmCX+TKc7Ivz5xJupaA4Qebceq8y0gSx9Aqfvp DaptxSU4oa8BU3Hm9UR7YGKzle7LL03kWICCRREGbbFkJQvpww43yL6MOJohBiK6N+JA WhjvI+ClYuiTHPbC8HgjUJ5MOE04VuCQ1P+qpe6vdTlPG5vVzdS6iUN5yNlSJmN1LzMU ywtA== X-Gm-Message-State: ALQs6tCKubQprkC2t14955Sbm40MZGuozVkzDho29UTc7biKCluXvYSd oVf4gTfYK5FQARTo3KEJajg= X-Google-Smtp-Source: AB8JxZqbAfD7WeH+JTFiMFssCGAnzYrldrcGG3/nPDkTk+wrm41q2odtJOsCQaWL2pp0ZxUQ4BCD2Q== X-Received: by 2002:ac8:2f44:: with SMTP id k4-v6mr36144867qta.151.1524744052376; Thu, 26 Apr 2018 05:00:52 -0700 (PDT) Received: from ?IPv6:2601:181:c480:b5c0::93f8? ([2601:181:c480:b5c0::93f8]) by smtp.googlemail.com with ESMTPSA id w22-v6sm15930090qtg.60.2018.04.26.05.00.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Apr 2018 05:00:51 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: dumpfile cleanup Message-ID: Date: Thu, 26 Apr 2018 08:00:49 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 I wanted to add '-' as a synonym for stdout in the dumping machinery. But this bit of cleanup's needed first. We check the special stdout/stderr names in 3 different places -- that's crying out for a worker function. We also check those streams by name before determining whether to fclose. It seems more straight forwards to just compare to stdin & stdout themselves. This patch does that cleanup, and the next patch will add the '-' functionality. I've been using this on the modules branch for some time now. ok for trunk? nathan 2018-04-26 Nathan Sidwell * dumpfile.c (dump_open): New. (dump_open_alternate_stream, dump_start, dump_begin): Call it. (dump_finish): Detect stdio/stderr by value not name. Index: dumpfile.c =================================================================== --- dumpfile.c (revision 259657) +++ dumpfile.c (working copy) @@ -312,6 +312,27 @@ get_dump_file_name (struct dump_file_inf return concat (dump_base_name, dump_id, dfi->suffix, NULL); } +/* Open a dump file called FILENAME. Some filenames are special and + refer to the standard streams. TRUNC indicates whether this is the + first open (so the file should be truncated, rather than appended). + An error message is emitted in the event of failure. */ + +static FILE * +dump_open (const char *filename, bool trunc) +{ + if (strcmp ("stderr", filename) == 0) + return stderr; + + if (strcmp ("stdout", filename) == 0) + return stdout; + + FILE *stream = fopen (filename, trunc ? "w" : "a"); + + if (!stream) + error ("could not open dump file %qs: %m", filename); + return stream; +} + /* For a given DFI, open an alternate dump filename (which could also be a standard stream such as stdout/stderr). If the alternate dump file cannot be opened, return NULL. */ @@ -319,22 +340,15 @@ get_dump_file_name (struct dump_file_inf static FILE * dump_open_alternate_stream (struct dump_file_info *dfi) { - FILE *stream ; if (!dfi->alt_filename) return NULL; if (dfi->alt_stream) return dfi->alt_stream; - stream = strcmp ("stderr", dfi->alt_filename) == 0 - ? stderr - : strcmp ("stdout", dfi->alt_filename) == 0 - ? stdout - : fopen (dfi->alt_filename, dfi->alt_state < 0 ? "w" : "a"); + FILE *stream = dump_open (dfi->alt_filename, dfi->alt_state < 0); - if (!stream) - error ("could not open dump file %qs: %m", dfi->alt_filename); - else + if (stream) dfi->alt_state = 1; return stream; @@ -515,14 +529,8 @@ dump_start (int phase, dump_flags_t *fla name = get_dump_file_name (phase); if (name) { - stream = strcmp ("stderr", name) == 0 - ? stderr - : strcmp ("stdout", name) == 0 - ? stdout - : fopen (name, dfi->pstate < 0 ? "w" : "a"); - if (!stream) - error ("could not open dump file %qs: %m", name); - else + stream = dump_open (name, dfi->pstate < 0); + if (stream) { dfi->pstate = 1; count++; @@ -562,13 +570,10 @@ dump_finish (int phase) if (phase < 0) return; dfi = get_dump_file_info (phase); - if (dfi->pstream && (!dfi->pfilename - || (strcmp ("stderr", dfi->pfilename) != 0 - && strcmp ("stdout", dfi->pfilename) != 0))) + if (dfi->pstream && dfi->pstream != stdout && dfi->pstream != stderr) fclose (dfi->pstream); - if (dfi->alt_stream && strcmp ("stderr", dfi->alt_filename) != 0 - && strcmp ("stdout", dfi->alt_filename) != 0) + if (dfi->alt_stream && dfi->alt_stream != stdout && dfi->alt_stream != stderr) fclose (dfi->alt_stream); dfi->alt_stream = NULL; @@ -607,15 +612,8 @@ dump_begin (int phase, dump_flags_t *fla return NULL; dfi = get_dump_file_info (phase); - stream = strcmp ("stderr", name) == 0 - ? stderr - : strcmp ("stdout", name) == 0 - ? stdout - : fopen (name, dfi->pstate < 0 ? "w" : "a"); - - if (!stream) - error ("could not open dump file %qs: %m", name); - else + stream = dump_open (name, dfi->pstate < 0); + if (stream) dfi->pstate = 1; free (name);