summaryrefslogtreecommitdiff
path: root/libcc1/libcp1.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
commit30c9604c2c04587094207b3dc91f472acb6f331d (patch)
treeca7aab1ad8c8d17ffbdbbeeb1ce9d4d27729f448 /libcc1/libcp1.cc
parent0f237df286ecaf366e19601917bedaf6224929d0 (diff)
libcc1: use unique_ptr more
This changes libcc1 to use unique_ptr in a few more places, removing some manual memory management. libcc1 * libcp1.cc (struct libcp1) <connection, compilerp>: Use unique_ptr. (~libcp1): Remove. (libcp1_compile, libcp1_set_triplet_regexp) (libcp1_set_driver_filename): Update. * libcc1.cc (struct libcc1) <connection, compilerp>: Use unique_ptr. (~libcc1): Remove. (libcc1_set_triplet_regexp, libcc1_set_driver_filename) (libcc1_compile): Update.
Diffstat (limited to 'libcc1/libcp1.cc')
-rw-r--r--libcc1/libcp1.cc32
1 files changed, 13 insertions, 19 deletions
diff --git a/libcc1/libcp1.cc b/libcc1/libcp1.cc
index 4273f8d8382..4bd8c6b00b6 100644
--- a/libcc1/libcp1.cc
+++ b/libcc1/libcp1.cc
@@ -48,7 +48,6 @@ class libcp1_connection;
struct libcp1 : public gcc_cp_context
{
libcp1 (const gcc_base_vtable *, const gcc_cp_fe_vtable *);
- ~libcp1 ();
// A convenience function to print something.
void print (const char *str)
@@ -56,7 +55,7 @@ struct libcp1 : public gcc_cp_context
this->print_function (this->print_datum, str);
}
- libcp1_connection *connection;
+ std::unique_ptr<libcp1_connection> connection;
gcc_cp_oracle_function *binding_oracle;
gcc_cp_symbol_address_function *address_oracle;
@@ -86,7 +85,9 @@ struct libcp1 : public gcc_cp_context
virtual ~compiler ()
{
}
- } *compilerp;
+ };
+
+ std::unique_ptr<compiler> compilerp;
/* Compiler to set by set_triplet_regexp. */
class compiler_triplet_regexp : public compiler
@@ -143,8 +144,7 @@ public:
libcp1::libcp1 (const gcc_base_vtable *v,
const gcc_cp_fe_vtable *cv)
- : connection (NULL),
- binding_oracle (NULL),
+ : binding_oracle (NULL),
address_oracle (NULL),
oracle_datum (NULL),
print_function (NULL),
@@ -158,12 +158,6 @@ libcp1::libcp1 (const gcc_base_vtable *v,
cp_ops = cv;
}
-libcp1::~libcp1 ()
-{
- delete connection;
- delete compilerp;
-}
-
// Enclose these functions in an anonymous namespace because they
@@ -243,7 +237,7 @@ R rpc (struct gcc_cp_context *s, Arg... rest)
libcp1 *self = (libcp1 *) s;
R result;
- if (!cc1_plugin::call (self->connection, NAME, &result, rest...))
+ if (!cc1_plugin::call (self->connection.get (), NAME, &result, rest...))
return 0;
return result;
}
@@ -403,8 +397,8 @@ libcp1_set_triplet_regexp (struct gcc_base_context *s,
{
libcp1 *self = (libcp1 *) s;
- delete self->compilerp;
- self->compilerp = new libcp1::compiler_triplet_regexp (self, triplet_regexp);
+ self->compilerp.reset (new libcp1::compiler_triplet_regexp (self,
+ triplet_regexp));
return NULL;
}
@@ -414,9 +408,8 @@ libcp1_set_driver_filename (struct gcc_base_context *s,
{
libcp1 *self = (libcp1 *) s;
- delete self->compilerp;
- self->compilerp = new libcp1::compiler_driver_filename (self,
- driver_filename);
+ self->compilerp.reset (new libcp1::compiler_driver_filename (self,
+ driver_filename));
return NULL;
}
@@ -487,7 +480,8 @@ fork_exec (libcp1 *self, char **argv, int spair_fds[2], int stderr_fds[2])
cc1_plugin::status result = cc1_plugin::FAIL;
if (self->connection->send ('H')
- && ::cc1_plugin::marshall (self->connection, GCC_CP_FE_VERSION_0))
+ && ::cc1_plugin::marshall (self->connection.get (),
+ GCC_CP_FE_VERSION_0))
result = self->connection->wait_for_query ();
close (spair_fds[0]);
@@ -550,7 +544,7 @@ libcp1_compile (struct gcc_base_context *s,
if (self->verbose)
self->args.push_back ("-v");
- self->connection = new libcp1_connection (fds[0], stderr_fds[0], self);
+ self->connection.reset (new libcp1_connection (fds[0], stderr_fds[0], self));
cc1_plugin::callback_ftype *fun
= cc1_plugin::callback<int,