public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: David Carlton <carlton@math.stanford.edu>
To: Andrew Cagney <ac131313@redhat.com>
Cc: "Theodore A. Roth" <troth@openavr.org>, gdb@sources.redhat.com
Subject: Re: suggested compile warnings
Date: Fri, 23 May 2003 21:17:00 -0000	[thread overview]
Message-ID: <ro1d6i91hy4.fsf@jackfruit.Stanford.EDU> (raw)
In-Reply-To: <3ECE817C.1020900@redhat.com>

On Fri, 23 May 2003 16:15:56 -0400, Andrew Cagney <ac131313@redhat.com> said:

> -Wwrite-strings
> It's just hard and really messy.  People occasionally chip away at the
> edges.  Last time I tried, I came across what appeared to be an
> effective xfree("string"), outch!

I've looked at this one fairly seriously.  From my point of view, the
main root issue here is that decode_line_1 takes a char ** instead of
a const char **.  I plan/hope to fix this eventually; I won't get
around to it for a while.

The xfree issue is an interesting one, and I agree that it's another
root problem.  My attitude is actually that xfree should take a const
void * instead of just a void *.  Basically, it seems to me that being
writeable and beeing freeable are orthogonal; examples are:

* Not writeable or freeable: literal

* Writeable and freeable: memory allocated via xmalloc.

* Writeable but not freeable: memory allocated on an obstack.

* Not writeable but freeable: memory that was originally allocated via
  xmalloc but whose contents you don't want to change.  (E.g. a name
  shared among many users, or used as a search key, or something.)

You can argue about examples in the fourth category (maybe their
existence is less clear to C programmers than to C++ programmers,
because of the different idioms for using const in the two languages)
but the third category is real.

Anyways, we can argue about this more once I've fixed decode_line_1.
If anybody else wants to fix it, the easiest thing to do is to write a
wrapper for decode_line_1 whose first argument is "const char
**argptr"; then make a copy of *argptr via alloca, and pass its
address to decode_line_1; then, before returning whatever
decode_line_1 returns, make sure that you modify *argptr in the same
way that decode_line_1 modified *copy_of_argptr.  And then go and fix
all the callers of decode_line_1 to call this new wrapper instead,
passing it a const char **.  (You might get annoyed by the fact that C
doesn't let you automatically convert a char ** into a const char **.)

Once that's happened, then we can argue about xfree; and once _that's_
been changed, then just pick a random char * somewhere (my favorite
would be the 'name' member of struct generic_symbol_info), change it
to a const char *, and follow through a huge chain of updates.

David Carlton
carlton@math.stanford.edu

  parent reply	other threads:[~2003-05-23 21:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-23 19:09 Theodore A. Roth
2003-05-23 20:17 ` Andrew Cagney
2003-05-23 21:02   ` Theodore A. Roth
2003-05-23 21:17   ` David Carlton [this message]
2003-05-23 21:46     ` Andrew Cagney

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=ro1d6i91hy4.fsf@jackfruit.Stanford.EDU \
    --to=carlton@math.stanford.edu \
    --cc=ac131313@redhat.com \
    --cc=gdb@sources.redhat.com \
    --cc=troth@openavr.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).