From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 58519 invoked by alias); 26 Oct 2015 05:27:53 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 58498 invoked by uid 89); 26 Oct 2015 05:27:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f50.google.com Received: from mail-pa0-f50.google.com (HELO mail-pa0-f50.google.com) (209.85.220.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 26 Oct 2015 05:27:51 +0000 Received: by padhk11 with SMTP id hk11so177099951pad.1 for ; Sun, 25 Oct 2015 22:27:49 -0700 (PDT) X-Received: by 10.68.189.3 with SMTP id ge3mr20295711pbc.30.1445837269778; Sun, 25 Oct 2015 22:27:49 -0700 (PDT) Received: from seba.sebabeach.org.gmail.com (173-13-178-53-sfba.hfc.comcastbusiness.net. [173.13.178.53]) by smtp.gmail.com with ESMTPSA id mk5sm31571490pab.44.2015.10.25.22.27.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Oct 2015 22:27:49 -0700 (PDT) From: Doug Evans To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCH c++ 06/12] Fix constness problem in ioscm_make_gdb_stdio_port References: <1445831204-16588-1-git-send-email-simon.marchi@polymtl.ca> <1445831204-16588-6-git-send-email-simon.marchi@polymtl.ca> Date: Mon, 26 Oct 2015 12:40:00 -0000 In-Reply-To: <1445831204-16588-6-git-send-email-simon.marchi@polymtl.ca> (Simon Marchi's message of "Sun, 25 Oct 2015 23:46:38 -0400") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg00545.txt.bz2 Simon Marchi writes: > ioscm_make_gdb_stdio_port passes const char pointers (literal strings) to > scm_mode_bits, which takes a non-const char pointer. Ideally, we would > change scm_mode_bits to take a const char pointer, but it's not part of > an API we control. > > Instead, it's easy enough to build the string to pass to scm_mode_bits in > a (non-const) char array and pass that. > > gdb/ChangeLog: > > * guile/scm-ports.c (ioscm_make_gdb_stdio_port): Pass non-const > char pointer to scm_mode_bits. > --- > gdb/guile/scm-ports.c | 17 +++++++++++++---- > 1 file changed, 13 insertions(+), 4 deletions(-) > > diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c > index 925f3b2..49e4fd6 100644 > --- a/gdb/guile/scm-ports.c > +++ b/gdb/guile/scm-ports.c > @@ -357,29 +357,38 @@ ioscm_init_stdio_buffers (SCM port, long mode_bits) > static SCM > ioscm_make_gdb_stdio_port (int fd) > { > - int is_a_tty = isatty (fd); > const char *name; > long mode_bits; > SCM port; > + char buf[3]; > + > + memset (buf, 0, sizeof (buf)); > > switch (fd) > { > case 0: > name = input_port_name; > - mode_bits = scm_mode_bits (is_a_tty ? "r0" : "r"); > + buf[0] = 'r'; > break; > case 1: > name = output_port_name; > - mode_bits = scm_mode_bits (is_a_tty ? "w0" : "w"); > + buf[0] = 'w'; > break; > case 2: > name = error_port_name; > - mode_bits = scm_mode_bits (is_a_tty ? "w0" : "w"); > + buf[0] = 'w'; > break; > default: > gdb_assert_not_reached ("bad stdio file descriptor"); > } > > + if (isatty (fd)) > + { > + buf[1] = '0'; > + } Community rules say to not use braces here. Ok with that change. > + > + mode_bits = scm_mode_bits (buf); > + > port = ioscm_open_port (stdio_port_desc, mode_bits); > > scm_set_port_filename_x (port, gdbscm_scm_from_c_string (name));