From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simon.marchi@polymtl.ca>, gdb-patches@sourceware.org
Subject: Re: [PATCH c++ 06/12] Fix constness problem in ioscm_make_gdb_stdio_port
Date: Mon, 26 Oct 2015 18:36:00 -0000 [thread overview]
Message-ID: <562E5050.6010909@redhat.com> (raw)
In-Reply-To: <1445831204-16588-6-git-send-email-simon.marchi@polymtl.ca>
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 <palves@redhat.com>
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
next prev parent reply other threads:[~2015-10-26 16:10 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-26 3:49 [PATCH c++ 01/12] Introduce ax_raw_byte and use it Simon Marchi
2015-10-26 4:17 ` [PATCH c++ 03/12] ctf_xfer_partial: Return TARGET_XFER_E_IO instead of -1 on error Simon Marchi
2015-10-27 9:54 ` Simon Marchi
2015-10-26 5:24 ` [PATCH c++ 06/12] Fix constness problem in ioscm_make_gdb_stdio_port Simon Marchi
2015-10-26 12:40 ` Doug Evans
2015-10-26 18:36 ` Pedro Alves [this message]
2015-10-27 1:30 ` Simon Marchi
2015-10-27 1:55 ` Pedro Alves
2015-10-27 2:02 ` Doug Evans
2015-10-27 2:07 ` Simon Marchi
2015-10-26 5:27 ` [PATCH c++ 08/12] scm-symbol.c: Add (domain_enum) casts Simon Marchi
2015-10-26 12:55 ` Doug Evans
2015-10-26 5:29 ` [PATCH c++ 05/12] guile: Constify gdbscm_with_guile return value Simon Marchi
2015-10-26 11:45 ` Doug Evans
2015-10-26 17:39 ` Simon Marchi
2015-10-26 20:34 ` Doug Evans
2015-10-27 9:31 ` Simon Marchi
2015-10-27 17:35 ` Doug Evans
2015-10-28 14:59 ` Simon Marchi
2015-10-26 5:30 ` [PATCH c++ 09/12] stap-probe.c: Add casts Simon Marchi
2015-10-27 9:54 ` Simon Marchi
2015-10-26 5:32 ` [PATCH c++ 10/12] symtab.c: Add cast Simon Marchi
2015-10-26 12:55 ` Doug Evans
2015-10-26 7:53 ` [PATCH c++ 04/12] Add scm_t_dynwind_flags casts Simon Marchi
2015-10-27 14:59 ` Pedro Alves
2015-10-27 16:02 ` Simon Marchi
2015-10-26 8:17 ` [PATCH c++ 07/12] gdbscm_memory_port_write: use local variable to avoid adding casts Simon Marchi
2015-10-26 12:55 ` Doug Evans
2015-10-26 10:03 ` [PATCH c++ 02/12] ctf.c: Fix int/enum implicit cast Simon Marchi
2015-10-27 15:17 ` Pedro Alves
2015-10-27 17:11 ` Yao Qi
2015-10-27 17:14 ` Simon Marchi
2015-10-27 15:08 ` [PATCH c++ 01/12] Introduce ax_raw_byte and use it Pedro Alves
2015-10-27 16:55 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=562E5050.6010909@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox