From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 85964 invoked by alias); 11 Aug 2015 21:49:45 -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 85954 invoked by uid 89); 11 Aug 2015 21:49:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 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-pd0-f170.google.com Received: from mail-pd0-f170.google.com (HELO mail-pd0-f170.google.com) (209.85.192.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 11 Aug 2015 21:49:43 +0000 Received: by pdbfa8 with SMTP id fa8so47606001pdb.1 for ; Tue, 11 Aug 2015 14:49:41 -0700 (PDT) X-Received: by 10.70.42.110 with SMTP id n14mr26485979pdl.133.1439329781790; Tue, 11 Aug 2015 14:49:41 -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 is3sm3838437pbc.53.2015.08.11.14.49.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Aug 2015 14:49:40 -0700 (PDT) From: Doug Evans To: Keith Seitz Cc: gdb-patches@sourceware.org Subject: Re: [PATCH v6 2/9] Explicit locations: introduce new struct event_locations-based API References: <1439325925-4652-1-git-send-email-keiths@redhat.com> Date: Tue, 11 Aug 2015 21:49:00 -0000 In-Reply-To: <1439325925-4652-1-git-send-email-keiths@redhat.com> (Keith Seitz's message of "Tue, 11 Aug 2015 13:45:25 -0700") 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-08/txt/msg00255.txt.bz2 Keith Seitz writes: > Doug Evans writes: > >> As for reposting, in this particular case (2/9) I suppose you should, >> but only for informational sake. No need for waiting for another review. > > For the record, this is the version I plan to commit/push. The only change > is the removal of event_location_to_string_cosnt, which was not being used > anymore. > > gdb/ChangeLog: > > * Makefile.in (SFILES): Add location.c. > (HFILES_NO_SRCDIR): Add location.h. > (COMMON_OBS): Add location.o. > * linespec.c (linespec_lex_to_end): New function. > * linespec.h (linespec_lex_to_end): Declare. > * location.c: New file. > * location.h: New file. Alas the removal of event_location_to_string_const isn't quite right. > +/* See description in location.h. */ > + > +const char * > +event_location_to_string (struct event_location *location) > +{ > + char *result = NULL; > + > + if (EL_STRING (location) != NULL) > + return xstrdup (EL_STRING (location)); > + > + switch (EL_TYPE (location)) > + { > + case LINESPEC_LOCATION: > + if (EL_LINESPEC (location) != NULL) > + result = xstrdup (EL_LINESPEC (location)); > + break; > + > + default: > + gdb_assert_not_reached ("unknown event location type"); > + } > + > + return result; > +} The caching done by the previous version is lost: +/* See description in location.h. */ + +const char * +event_location_to_string (struct event_location *location) +{ + /* Cache a copy of the string representation. */ + if (EL_STRING (location) == NULL) + EL_STRING (location) = event_location_to_string_const (location); + + return EL_STRING (location); +} The result is still owned by the location so we don't want to return an xstrdup'd copy. How about: const char * event_location_to_string (const struct event_location *location) { if (EL_STRING (location) == NULL) { switch (EL_TYPE (location)) { case LINESPEC_LOCATION: if (EL_LINESPEC (location) != NULL) EL_STRING (location) = xstrdup (EL_LINESPEC (location)); break; default: gdb_assert_not_reached ("unknown event location type"); } } return EL_STRING (location); }