From patchwork Tue Jun 16 21:59:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1310730 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=xyo0jgsK; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49mhwG5lGZz9sRk for ; Wed, 17 Jun 2020 08:00:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 364F9388B018; Tue, 16 Jun 2020 22:00:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 364F9388B018 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592344828; bh=JAwGjRoGAJFldYKeGNWJF7ztTswWePlIFDw/2InqWgs=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=xyo0jgsKxZfcTtVGl+dJxvmKM7I95s8uHgPDXXID87v2/1QuwH67BiaU4FMBtFINe X6yydg7GLlN07UcEmuJv94Tuiq3ytQpLFPfwjDAOSUAZyF0XappZLuRSpVKjihnz77 BJSUYDAohrPc4EfsLdFwc77ccZy/XqQFabc59GqY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by sourceware.org (Postfix) with ESMTPS id 542B3386F447 for ; Tue, 16 Jun 2020 22:00:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 542B3386F447 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 49mhvq3YhpzKmt7; Wed, 17 Jun 2020 00:00:23 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id A44q_rTeNyxi; Wed, 17 Jun 2020 00:00:17 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Remove dependency on front-end File type for json and deps file generation. Date: Tue, 16 Jun 2020 23:59:26 +0200 Message-Id: <20200616215933.3858164-3-ibuclaw@gdcproject.org> In-Reply-To: <20200616215933.3858164-1-ibuclaw@gdcproject.org> References: <20200616215933.3858164-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: B720D1778 X-Rspamd-Score: 0.56 / 15.00 / 15.00 X-Spam-Status: No, score=-17.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch replaces some uses of File with FILE. Memory allocated by the DMD front-end is never freed due to the bump pointer allocator used internally. Bootstrapped and regression tested on x86_64-linux-gnu, and committed to master. Regards Iain gcc/d/ChangeLog: * d-lang.cc (d_parse_file): Replace uses of File with FILE. --- gcc/d/d-lang.cc | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc index 085d8393b5a..fe59abe93a8 100644 --- a/gcc/d/d-lang.cc +++ b/gcc/d/d-lang.cc @@ -1271,6 +1271,7 @@ d_parse_file (void) if (d_option.deps) { OutBuffer buf; + FILE *deps_stream; for (size_t i = 0; i < modules.length; i++) deps_write (modules[i], &buf); @@ -1281,13 +1282,25 @@ d_parse_file (void) if (d_option.deps_filename) { - File *fdeps = File::create (d_option.deps_filename); - fdeps->setbuffer ((void *) buf.data, buf.offset); - fdeps->ref = 1; - writeFile (Loc (), fdeps); + deps_stream = fopen (d_option.deps_filename, "w"); + if (!deps_stream) + { + fatal_error (input_location, "opening dependency file %s: %m", + d_option.deps_filename); + goto had_errors; + } } else - message ("%.*s", (int) buf.offset, (char *) buf.data); + deps_stream = stdout; + + fprintf (deps_stream, "%s", buf.peekChars ()); + + if (deps_stream != stdout + && (ferror (deps_stream) || fclose (deps_stream))) + { + fatal_error (input_location, "closing dependency file %s: %m", + d_option.deps_filename); + } } /* Generate JSON files. */ @@ -1297,18 +1310,27 @@ d_parse_file (void) json_generate (&buf, &modules); const char *name = global.params.jsonfilename.ptr; + FILE *json_stream; if (name && (name[0] != '-' || name[1] != '\0')) { const char *nameext = FileName::defaultExt (name, global.json_ext.ptr); - File *fjson = File::create (nameext); - fjson->setbuffer ((void *) buf.data, buf.offset); - fjson->ref = 1; - writeFile (Loc (), fjson); + json_stream = fopen (nameext, "w"); + if (!json_stream) + { + fatal_error (input_location, "opening json file %s: %m", nameext); + goto had_errors; + } } else - message ("%.*s", (int) buf.offset, (char *) buf.data); + json_stream = stdout; + + fprintf (json_stream, "%s", buf.peekChars ()); + + if (json_stream != stdout + && (ferror (json_stream) || fclose (json_stream))) + fatal_error (input_location, "closing json file %s: %m", name); } /* Generate Ddoc files. */