aboutsummaryrefslogtreecommitdiff
path: root/libcc1/marshall.cc
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-05-04 15:26:58 -0600
committerTom Tromey <tom@tromey.com>2021-05-05 00:06:17 -0600
commit0f237df286ecaf366e19601917bedaf6224929d0 (patch)
tree181d82fe9796bb364de8241a78e5a82c3782c260 /libcc1/marshall.cc
parent0d5a0b9af5b9c0f07eabcdb1a7a6454c06cdf8ae (diff)
downloadgcc-0f237df286ecaf366e19601917bedaf6224929d0.zip
gcc-0f237df286ecaf366e19601917bedaf6224929d0.tar.gz
gcc-0f237df286ecaf366e19601917bedaf6224929d0.tar.bz2
libcc1: add more uses of 'deleter'
This changes libcc1 to use the 'deleter' template in a few more places. The template and basic specializations are moved to a new header, then some unmarshall functions are changed to use this code. This change avoids the need to repeat cleanup code in the unmarshallers. libcc1 * rpc.hh (deleter): Move template and some specializations to deleter.hh. (argument_wrapper<const T *>): Use cc1_plugin::unique_ptr. * marshall.cc (cc1_plugin::unmarshall): Use cc1_plugin::unique_ptr. * marshall-cp.hh (deleter): New specializations. (unmarshall): Use cc1_plugin::unique_ptr. * deleter.hh: New file.
Diffstat (limited to 'libcc1/marshall.cc')
-rw-r--r--libcc1/marshall.cc11
1 files changed, 4 insertions, 7 deletions
diff --git a/libcc1/marshall.cc b/libcc1/marshall.cc
index aac077e..4a7a21f 100644
--- a/libcc1/marshall.cc
+++ b/libcc1/marshall.cc
@@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. If not see
#include <string.h>
#include "marshall.hh"
#include "connection.hh"
+#include "rpc.hh"
cc1_plugin::status
cc1_plugin::unmarshall_check (connection *conn, unsigned long long check)
@@ -175,7 +176,7 @@ cc1_plugin::unmarshall (connection *conn, gcc_type_array **result)
return OK;
}
- gcc_type_array *gta = new gcc_type_array;
+ cc1_plugin::unique_ptr<gcc_type_array> gta (new gcc_type_array {});
gta->n_elements = len;
gta->elements = new gcc_type[len];
@@ -183,13 +184,9 @@ cc1_plugin::unmarshall (connection *conn, gcc_type_array **result)
if (!unmarshall_array_elmts (conn,
len * sizeof (gta->elements[0]),
gta->elements))
- {
- delete[] gta->elements;
- delete *result;
- return FAIL;
- }
+ return FAIL;
- *result = gta;
+ *result = gta.release ();
return OK;
}