From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24877 invoked by alias); 26 Oct 2015 16:10:01 -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 24866 invoked by uid 89); 26 Oct 2015 16:10:00 -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,RP_MATCHES_RCVD,SPF_HELO_PASS,T_FILL_THIS_FORM_SHORT autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 26 Oct 2015 16:09:56 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id E0936461E2; Mon, 26 Oct 2015 16:09:54 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9QG9r69014309; Mon, 26 Oct 2015 12:09:54 -0400 Message-ID: <562E5050.6010909@redhat.com> Date: Mon, 26 Oct 2015 18:36:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Simon Marchi , 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> In-Reply-To: <1445831204-16588-6-git-send-email-simon.marchi@polymtl.ca> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-SW-Source: 2015-10/txt/msg00569.txt.bz2 On 10/26/2015 03:46 AM, Simon Marchi wrote: > 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'; > + } > + > + 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)); > Hmmm, I have the below on my branch, which seems clearer/straightforward to me. I don't think the cast in the scm_mode_bits call is problem. It's a deficiency of the scm_mode_bits api that it doesn't take a const pointer, and we actually already have this in ioscm_parse_mode_bits: /* Kinda awkward to convert the mode from SCM -> string only to have Guile convert it back to SCM, but that's the API we have to work with. */ mode_bits = scm_mode_bits ((char *) mode); WDYT? >From f1038881f2b79d26968f2552b86612324fdf72c3 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Thu, 22 Oct 2015 11:43:57 +0100 Subject: [PATCH] guile: 'const char *' -> 'char *' casts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /home/pedro/gdb/mygit/src/gdb/guile/scm-ports.c: In function ‘scm_unused_struct* ioscm_make_gdb_stdio_port(int)’: /home/pedro/gdb/mygit/src/gdb/guile/scm-ports.c:369:55: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive] mode_bits = scm_mode_bits (is_a_tty ? "r0" : "r"); ^ In file included from /usr/include/guile/2.0/libguile/fports.h:28:0, from /usr/include/guile/2.0/libguile.h:55, from /home/pedro/gdb/mygit/src/gdb/guile/guile-internal.h:29, from /home/pedro/gdb/mygit/src/gdb/guile/scm-ports.c:28: /usr/include/guile/2.0/libguile/ports.h:281:14: error: initializing argument 1 of ‘long int scm_mode_bits(char*)’ [-fpermissive] SCM_API long scm_mode_bits (char *modes); ^ /home/pedro/gdb/mygit/src/gdb/guile/scm-ports.c:373:55: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive] mode_bits = scm_mode_bits (is_a_tty ? "w0" : "w"); ^ In file included from /usr/include/guile/2.0/libguile/fports.h:28:0, from /usr/include/guile/2.0/libguile.h:55, from /home/pedro/gdb/mygit/src/gdb/guile/guile-internal.h:29, from /home/pedro/gdb/mygit/src/gdb/guile/scm-ports.c:28: /usr/include/guile/2.0/libguile/ports.h:281:14: error: initializing argument 1 of ‘long int scm_mode_bits(char*)’ [-fpermissive] SCM_API long scm_mode_bits (char *modes); ^ /home/pedro/gdb/mygit/src/gdb/guile/scm-ports.c:377:55: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive] mode_bits = scm_mode_bits (is_a_tty ? "w0" : "w"); ^ In file included from /usr/include/guile/2.0/libguile/fports.h:28:0, from /usr/include/guile/2.0/libguile.h:55, from /home/pedro/gdb/mygit/src/gdb/guile/guile-internal.h:29, from /home/pedro/gdb/mygit/src/gdb/guile/scm-ports.c:28: /usr/include/guile/2.0/libguile/ports.h:281:14: error: initializing argument 1 of ‘long int scm_mode_bits(char*)’ [-fpermissive] SCM_API long scm_mode_bits (char *modes); --- gdb/guile/scm-ports.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c index 90bdb39..d8ee70e 100644 --- a/gdb/guile/scm-ports.c +++ b/gdb/guile/scm-ports.c @@ -359,6 +359,7 @@ ioscm_make_gdb_stdio_port (int fd) { int is_a_tty = isatty (fd); const char *name; + const char *mode_str; long mode_bits; SCM port; @@ -366,20 +367,21 @@ ioscm_make_gdb_stdio_port (int fd) { case 0: name = input_port_name; - mode_bits = scm_mode_bits (is_a_tty ? "r0" : "r"); + mode_str = is_a_tty ? "r0" : "r"; break; case 1: name = output_port_name; - mode_bits = scm_mode_bits (is_a_tty ? "w0" : "w"); + mode_str = is_a_tty ? "w0" : "w"; break; case 2: name = error_port_name; - mode_bits = scm_mode_bits (is_a_tty ? "w0" : "w"); + mode_str = is_a_tty ? "w0" : "w"; break; default: gdb_assert_not_reached ("bad stdio file descriptor"); } + mode_bits = scm_mode_bits ((char *) mode_str); port = ioscm_open_port (stdio_port_desc, mode_bits); scm_set_port_filename_x (port, gdbscm_scm_from_c_string (name)); -- 1.9.3