From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 90336 invoked by alias); 24 Nov 2016 15:24:49 -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 90313 invoked by uid 89); 24 Nov 2016 15:24:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL,BAYES_00,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=Hx-spam-relays-external:sk:cable-1, H*RU:sk:cable-1, H*r:sk:cable-1, H*m:24725 X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 24 Nov 2016 15:24:39 +0000 X-ASG-Debug-ID: 1480001072-0c856e65d5b89ca0001-fS2M51 Received: from smtp.electronicbox.net (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id o1b1sG5k0nnYLbre (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 24 Nov 2016 10:24:32 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (cable-11.246.173-162.electronicbox.net [173.246.11.162]) by smtp.electronicbox.net (Postfix) with ESMTP id 63B71440E7F; Thu, 24 Nov 2016 10:24:32 -0500 (EST) From: Simon Marchi X-Barracuda-Effective-Source-IP: cable-11.246.173-162.electronicbox.net[173.246.11.162] X-Barracuda-Apparent-Source-IP: 173.246.11.162 X-Barracuda-RBL-IP: 173.246.11.162 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 09/22] Use std::vector for ui_out::levels Date: Thu, 24 Nov 2016 15:24:00 -0000 X-ASG-Orig-Subj: [PATCH 09/22] Use std::vector for ui_out::levels Message-Id: <20161124152428.24725-10-simon.marchi@polymtl.ca> In-Reply-To: <20161124152428.24725-1-simon.marchi@polymtl.ca> References: <20161124152428.24725-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1480001072 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 3641 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_SC0_MISMATCH_TO X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.34709 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 BSF_SC0_MISMATCH_TO Envelope rcpt doesn't match header X-IsSubscribed: yes X-SW-Source: 2016-11/txt/msg00746.txt.bz2 Convert the levels field of struct ui_out to be a vector of unique_ptr to ui_out_level. This way, the ownership of the ui_out_level objects by the ui_out instance is clear. gdb/ChangeLog: * ui-out.c (ui_out_level_p): Remove typedef. (DEF_VEC_P (ui_out_level_p)): Remove definition. (struct ui_out) : Change type to vector of unique_ptr of ui_out_level. (current_level): Update. (push_level): Update. (pop_level): Update, don't manually delete the ui_out_level instance. (ui_out_new): Update. --- gdb/ui-out.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/gdb/ui-out.c b/gdb/ui-out.c index bb37ece..1713183 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -25,6 +25,9 @@ #include "language.h" #include "ui-out.h" +#include +#include + /* table header structures */ struct ui_out_hdr @@ -45,9 +48,6 @@ struct ui_out_level enum ui_out_type type; }; -/* Define uiout->level vector types and operations. */ -typedef struct ui_out_level *ui_out_level_p; -DEF_VEC_P (ui_out_level_p); /* Tables are special. Maintain a separate structure that tracks their state. At present an output can only contain a single table @@ -99,7 +99,7 @@ struct ui_out int level; /* Vector to store and track the ui-out levels. */ - VEC (ui_out_level_p) *levels; + std::vector> levels; /* A table, if any. At present only a single table is supported. */ struct ui_out_table table; @@ -109,7 +109,7 @@ struct ui_out static struct ui_out_level * current_level (struct ui_out *uiout) { - return VEC_index (ui_out_level_p, uiout->levels, uiout->level); + return uiout->levels[uiout->level].get (); } /* Create a new level, of TYPE. Return the new level's index. */ @@ -117,13 +117,14 @@ static int push_level (struct ui_out *uiout, enum ui_out_type type) { - struct ui_out_level *current; + std::unique_ptr current (new ui_out_level ()); - uiout->level++; - current = new ui_out_level (); current->field_count = 0; current->type = type; - VEC_safe_push (ui_out_level_p, uiout->levels, current); + + uiout->level++; + uiout->levels.push_back (std::move (current)); + return uiout->level; } @@ -133,14 +134,13 @@ static int pop_level (struct ui_out *uiout, enum ui_out_type type) { - struct ui_out_level *current; - /* We had better not underflow the buffer. */ gdb_assert (uiout->level > 0); gdb_assert (current_level (uiout)->type == type); - current = VEC_pop (ui_out_level_p, uiout->levels); - delete current; + + uiout->levels.pop_back (); uiout->level--; + return uiout->level + 1; } @@ -861,7 +861,7 @@ ui_out_new (const struct ui_out_impl *impl, void *data, int flags) { struct ui_out *uiout = new ui_out (); - struct ui_out_level *current = new ui_out_level (); + std::unique_ptr current (new ui_out_level ()); uiout->data = data; uiout->impl = impl; @@ -869,12 +869,11 @@ ui_out_new (const struct ui_out_impl *impl, void *data, uiout->table.flag = 0; uiout->table.body_flag = 0; uiout->level = 0; - uiout->levels = NULL; /* Create uiout->level 0, the default level. */ current->type = ui_out_type_tuple; current->field_count = 0; - VEC_safe_push (ui_out_level_p, uiout->levels, current); + uiout->levels.push_back (std::move (current)); uiout->table.id = NULL; uiout->table.header_first = NULL; -- 2.10.0