From patchwork Wed Aug 26 08:14:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1351700 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=2620:52:3:1:0:246e:9693:128c; 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=n2sc6P56; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4BbzDp01Gcz9sSJ for ; Wed, 26 Aug 2020 18:15:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DD63B386102C; Wed, 26 Aug 2020 08:15:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD63B386102C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598429703; bh=8aBQVLLjOcl1DnYW7qs1i85063rsdbrg6pK3D72TKtA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=n2sc6P56TMmJMIVtJ9qfLIxmkf9yW7087BUxrTSZzOzVI0M0b5fIACCaLRy2okW7R B9qEeuAYvrbxO4cZawjIIKpOVFgGAxNwef+qnHOSEvBQD0QDQ5H7JSzWJykkszHsKY GI7ohItXLCxCyIbj/hf1ZDe+SES3DSA1gQIBs9YI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [IPv6:2001:67c:2050::465:201]) by sourceware.org (Postfix) with ESMTPS id 337E53850409 for ; Wed, 26 Aug 2020 08:15:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 337E53850409 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4BbzDh0bpTzQlWb; Wed, 26 Aug 2020 10:15:00 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id k91iCaVSxHNr; Wed, 26 Aug 2020 10:14:56 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Use read() to load contents of stdin into memory. Date: Wed, 26 Aug 2020 10:14:55 +0200 Message-Id: <20200826081455.451145-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-MBO-SPAM-Probability: * X-Rspamd-Score: 1.26 / 15.00 / 15.00 X-Rspamd-Queue-Id: 056D468C X-Rspamd-UID: 5fb354 X-Spam-Status: No, score=-15.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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 getc() with read(), which would be an improvement over reading one character at a time. An ICE was also discovered when mixing reading from stdin with `-v', this has been fixed in upstream DMD and backported as well. Regstrapped on x86_64-linux-gnu/-m32/-mx32, committed to mainline and backported to releases/gcc-10 branch. Regards Iain --- gcc/d/ChangeLog: * d-lang.cc (d_parse_file): Use read() to load contents from stdin, allow the front-end to free the memory after parsing. * dmd/MERGE: Merge upstream dmd 2cc25c219. --- gcc/d/d-lang.cc | 43 +++++++++++++++++++++++++++---------------- gcc/d/dmd/MERGE | 2 +- gcc/d/dmd/func.c | 5 +++-- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc index 6183389007a..c5254a02446 100644 --- a/gcc/d/d-lang.cc +++ b/gcc/d/d-lang.cc @@ -906,32 +906,43 @@ d_parse_file (void) { if (strcmp (in_fnames[i], "-") == 0) { - /* Handling stdin, generate a unique name for the module. */ - obstack buffer; - gcc_obstack_init (&buffer); - int c; + /* Load the entire contents of stdin into memory. 8 kilobytes should + be a good enough initial size, but double on each iteration. + 16 bytes are added for the final '\n' and 15 bytes of padding. */ + ssize_t size = 8 * 1024; + uchar *buffer = XNEWVEC (uchar, size + 16); + ssize_t len = 0; + ssize_t count; + + while ((count = read (STDIN_FILENO, buffer + len, size - len)) > 0) + { + len += count; + if (len == size) + { + size *= 2; + buffer = XRESIZEVEC (uchar, buffer, size + 16); + } + } + if (count < 0) + { + error (Loc ("stdin", 0, 0), "%s", xstrerror (errno)); + free (buffer); + continue; + } + + /* Handling stdin, generate a unique name for the module. */ Module *m = Module::create (in_fnames[i], Identifier::generateId ("__stdin"), global.params.doDocComments, global.params.doHdrGeneration); modules.push (m); - /* Load the entire contents of stdin into memory. */ - while ((c = getc (stdin)) != EOF) - obstack_1grow (&buffer, c); - - if (!obstack_object_size (&buffer)) - obstack_1grow (&buffer, '\0'); - /* Overwrite the source file for the module, the one created by Module::create would have a forced a `.d' suffix. */ m->srcfile = File::create (""); - m->srcfile->len = obstack_object_size (&buffer); - m->srcfile->buffer = (unsigned char *) obstack_finish (&buffer); - - /* Tell the front-end not to free the buffer after parsing. */ - m->srcfile->ref = 1; + m->srcfile->len = len; + m->srcfile->buffer = buffer; } else { diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index d0e5f442247..8445bfaf343 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -1b5a53d01c465109ce47edf49ace6143b69b118b +2cc25c2191928f865e1b711f30b6a4268d6a0d9a The first line of this file holds the git revision number of the last merge done from the dlang/dmd repository. diff --git a/gcc/d/dmd/func.c b/gcc/d/dmd/func.c index b6849559bf6..30ba8dd93be 100644 --- a/gcc/d/dmd/func.c +++ b/gcc/d/dmd/func.c @@ -1212,8 +1212,9 @@ Ldone: if (type && mod) { printedMain = true; - const char *name = FileName::searchPath(global.path, mod->srcfile->toChars(), true); - message("entry %-10s\t%s", type, name); + const char *name = mod->srcfile->toChars(); + const char *path = FileName::searchPath(global.path, name, true); + message("entry %-10s\t%s", type, path ? path : name); } }