From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 89274 invoked by alias); 24 Nov 2016 15:24:39 -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 89248 invoked by uid 89); 24 Nov 2016 15:24:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 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:37 +0000 X-ASG-Debug-ID: 1480001072-0c856e65d4b89580001-fS2M51 Received: from smtp.electronicbox.net (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id mlJFDAEcHjwCrfED (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 4FA57440E7D; 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 08/22] Use new/delete instead of malloc/free-based functions Date: Thu, 24 Nov 2016 15:24:00 -0000 X-ASG-Orig-Subj: [PATCH 08/22] Use new/delete instead of malloc/free-based functions Message-Id: <20161124152428.24725-9-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: 4561 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.60 X-Barracuda-Spam-Status: No, SCORE=0.60 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_SC0_MISMATCH_TO, MARKETING_SUBJECT X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.34709 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.60 MARKETING_SUBJECT Subject contains popular marketing words 0.00 BSF_SC0_MISMATCH_TO Envelope rcpt doesn't match header X-IsSubscribed: yes X-SW-Source: 2016-11/txt/msg00749.txt.bz2 The following patches introduce C++ vectors and strings as fields of the various ui_out structures. We therefore need to use new/delete so that their contructor/destructor is called. I find it simpler to change all the allocations in a separate preliminary patch, rather than in each individual patch. gdb/ChangeLog: * cli-out.c (cli_uiout_dtor): Use delete instead of xfree. (cli_out_new): Use new instead of XNEW. * mi/mi-out.c (mi_out_data_dtor): Use delete instead of xfree. (mi_out_new): Use new instead of XNEW. * tui/tui-out.c (tui_out_new): Likewise. * ui-out.c (push_level): Likewise. (pop_level): Use delete instead of xfree. (clear_header_list): Use delete instead of xfree. (append_header_to_list): Use new instead of XNEW. (ui_out_new): Likewise. --- gdb/cli-out.c | 4 ++-- gdb/mi/mi-out.c | 4 ++-- gdb/tui/tui-out.c | 2 +- gdb/ui-out.c | 13 +++++++------ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/gdb/cli-out.c b/gdb/cli-out.c index e882756..b98af4a 100644 --- a/gdb/cli-out.c +++ b/gdb/cli-out.c @@ -47,7 +47,7 @@ cli_uiout_dtor (struct ui_out *ui_out) cli_out_data *data = (cli_out_data *) ui_out_data (ui_out); VEC_free (ui_filep, data->streams); - xfree (data); + delete data; } /* These are the CLI output functions */ @@ -395,7 +395,7 @@ struct ui_out * cli_out_new (struct ui_file *stream) { int flags = ui_source_list; - cli_out_data *data = XNEW (cli_out_data); + cli_out_data *data = new cli_out_data (); cli_out_data_ctor (data, stream); return ui_out_new (&cli_ui_out_impl, data, flags); diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c index 44e28b1..2561f16 100644 --- a/gdb/mi/mi-out.c +++ b/gdb/mi/mi-out.c @@ -413,7 +413,7 @@ mi_out_data_dtor (struct ui_out *ui_out) mi_out_data *data = (mi_out_data *) ui_out_data (ui_out); VEC_free (ui_filep, data->streams); - xfree (data); + delete data; } /* Initialize private members at startup. */ @@ -422,7 +422,7 @@ struct ui_out * mi_out_new (int mi_version) { int flags = 0; - mi_out_data *data = XNEW (mi_out_data); + mi_out_data *data = new mi_out_data (); struct ui_file *stream = mem_fileopen (); mi_out_data_ctor (data, mi_version, stream); diff --git a/gdb/tui/tui-out.c b/gdb/tui/tui-out.c index 0232370..4856562 100644 --- a/gdb/tui/tui-out.c +++ b/gdb/tui/tui-out.c @@ -147,7 +147,7 @@ tui_out_new (struct ui_file *stream) { int flags = 0; - tui_out_data *data = XNEW (tui_out_data); + tui_out_data *data = new tui_out_data (); /* Initialize base "class". */ cli_out_data_ctor (&data->base, stream); diff --git a/gdb/ui-out.c b/gdb/ui-out.c index b8253c9..bb37ece 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -120,7 +120,7 @@ push_level (struct ui_out *uiout, struct ui_out_level *current; uiout->level++; - current = XNEW (struct ui_out_level); + current = new ui_out_level (); current->field_count = 0; current->type = type; VEC_safe_push (ui_out_level_p, uiout->levels, current); @@ -139,7 +139,7 @@ pop_level (struct ui_out *uiout, gdb_assert (uiout->level > 0); gdb_assert (current_level (uiout)->type == type); current = VEC_pop (ui_out_level_p, uiout->levels); - xfree (current); + delete current; uiout->level--; return uiout->level + 1; } @@ -708,8 +708,9 @@ clear_header_list (struct ui_out *uiout) uiout->table.header_first = uiout->table.header_first->next; xfree (uiout->table.header_next->colhdr); xfree (uiout->table.header_next->col_name); - xfree (uiout->table.header_next); + delete uiout->table.header_next; } + gdb_assert (uiout->table.header_first == NULL); uiout->table.header_last = NULL; uiout->table.header_next = NULL; @@ -724,7 +725,7 @@ append_header_to_list (struct ui_out *uiout, { struct ui_out_hdr *temphdr; - temphdr = XNEW (struct ui_out_hdr); + temphdr = new ui_out_hdr (); temphdr->width = width; temphdr->alignment = alignment; /* We have to copy the column title as the original may be an @@ -859,8 +860,8 @@ struct ui_out * ui_out_new (const struct ui_out_impl *impl, void *data, int flags) { - struct ui_out *uiout = XNEW (struct ui_out); - struct ui_out_level *current = XNEW (struct ui_out_level); + struct ui_out *uiout = new ui_out (); + struct ui_out_level *current = new ui_out_level (); uiout->data = data; uiout->impl = impl; -- 2.10.0