From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24478 invoked by alias); 23 May 2003 21:17:32 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 24418 invoked from network); 23 May 2003 21:17:30 -0000 Received: from unknown (HELO jackfruit.Stanford.EDU) (171.64.38.136) by sources.redhat.com with SMTP; 23 May 2003 21:17:30 -0000 Received: (from carlton@localhost) by jackfruit.Stanford.EDU (8.11.6/8.11.6) id h4NLHNk05359; Fri, 23 May 2003 14:17:23 -0700 X-Authentication-Warning: jackfruit.Stanford.EDU: carlton set sender to carlton@math.stanford.edu using -f To: Andrew Cagney Cc: "Theodore A. Roth" , gdb@sources.redhat.com Subject: Re: suggested compile warnings References: <3ECE817C.1020900@redhat.com> From: David Carlton Date: Fri, 23 May 2003 21:17:00 -0000 In-Reply-To: <3ECE817C.1020900@redhat.com> Message-ID: User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2003-05/txt/msg00327.txt.bz2 On Fri, 23 May 2003 16:15:56 -0400, Andrew Cagney 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