From bdfea17ea9bbd9f92ad19a70d770af42473d9c07 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 5 Feb 2021 07:17:11 -0700 Subject: Return unique_ptr from language_defn::get_compile_context This changes language_defn::get_compile_context to return a unique_ptr. This makes the ownership transfer clear. gdb/ChangeLog 2021-02-05 Tom Tromey * compile/compile-c-support.c (get_compile_context) (c_get_compile_context, cplus_get_compile_context): Change return type. * language.c (language_defn::get_compile_instance): New method. * language.h (language_defn::get_compile_instance): Change return type. No longer inline. * c-lang.c (c_language::get_compile_instance): Change return type. (cplus_language::get_compile_instance): Change return type. * c-lang.h (c_get_compile_context, cplus_get_compile_context): Change return type. * compile/compile.c (compile_to_object): Update. --- gdb/compile/compile-c-support.c | 8 ++++---- gdb/compile/compile.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'gdb/compile') diff --git a/gdb/compile/compile-c-support.c b/gdb/compile/compile-c-support.c index 5f49a0a74f0..65f186763f7 100644 --- a/gdb/compile/compile-c-support.c +++ b/gdb/compile/compile-c-support.c @@ -99,7 +99,7 @@ load_libcompile (const char *fe_libcc, const char *fe_context) template -compile_instance * +std::unique_ptr get_compile_context (const char *fe_libcc, const char *fe_context, BASE_VERSION_TYPE base_version, API_VERSION_TYPE api_version) @@ -118,12 +118,12 @@ get_compile_context (const char *fe_libcc, const char *fe_context, error (_("The loaded version of GCC does not support the required version " "of the API.")); - return new INSTTYPE (context); + return std::unique_ptr (new INSTTYPE (context)); } /* A C-language implementation of get_compile_context. */ -compile_instance * +std::unique_ptr c_get_compile_context () { return get_compile_context @@ -135,7 +135,7 @@ c_get_compile_context () /* A C++-language implementation of get_compile_context. */ -compile_instance * +std::unique_ptr cplus_get_compile_context () { return get_compile_context diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 4e72adc943d..d9c99bf4328 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -649,8 +649,8 @@ compile_to_object (struct command_line *cmd, const char *cmd_string, expr_pc = get_frame_address_in_block (get_selected_frame (NULL)); /* Set up instance and context for the compiler. */ - std::unique_ptr compiler - (current_language->get_compile_instance ()); + std::unique_ptr compiler + = current_language->get_compile_instance (); if (compiler == nullptr) error (_("No compiler support for language %s."), current_language->name ()); -- cgit v1.2.1