From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 103987 invoked by alias); 26 Oct 2015 16:22:27 -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 103976 invoked by uid 89); 26 Oct 2015 16:22:26 -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-f43.google.com Received: from mail-pa0-f43.google.com (HELO mail-pa0-f43.google.com) (209.85.220.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 26 Oct 2015 16:22:25 +0000 Received: by pacfa8 with SMTP id fa8so13624251pac.0 for ; Mon, 26 Oct 2015 09:22:23 -0700 (PDT) X-Received: by 10.66.152.44 with SMTP id uv12mr28499694pab.110.1445876543720; Mon, 26 Oct 2015 09:22:23 -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 w9sm34796592pbt.29.2015.10.26.09.22.23 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Oct 2015 09:22:23 -0700 (PDT) From: Doug Evans To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCH c++ 05/12] guile: Constify gdbscm_with_guile return value References: <1445831204-16588-1-git-send-email-simon.marchi@polymtl.ca> <1445831204-16588-5-git-send-email-simon.marchi@polymtl.ca> Date: Mon, 26 Oct 2015 20:34:00 -0000 In-Reply-To: (Simon Marchi's message of "Mon, 26 Oct 2015 11:09:08 -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/msg00571.txt.bz2 Simon Marchi writes: > On 26 October 2015 at 01:22, Doug Evans wrote: >> Hi. >> >> How about instead having gdbscm_with_guile return a const char *. >> That should, for example, remove the need for any cast here in >> gdbscm_safe_source_script (and presumably elsewhere): >> >> if (result != NULL) > > > Hmmm, looking more at the issue, I see that we happen to call > gdbscm_with_guile only with functions that return const char *. But > it doesn't mean we should make gdbscm_with_guile return const char * > ncecessarily. It (and scm_with_guile) takes a void* and returns a > void* in order to be generic, just like in the pthread_create/join > API. The caller is responsible to cast the void* to the right type. > In C++, we could always get fancy and make it a templated function to > get type-safety. > > So in retrospect, I think we should leave the original return type > (non-const void*) and just add the appropriate casts. > > Does that make sense? The function comment for gdbscm_with_guile says: /* A wrapper around scm_with_guile that prints backtraces and exceptions according to "set guile print-stack". The result if NULL if no exception occurred, otherwise it is a statically allocated error message (caller must *not* free). */ If we're going to return an error message, why make it a void * and not a char * (const as appropriate)? The lower level guile API uses a void * because it doesn't specify what the result is. But in this use of it we do specify what the result is.