From: Gabe Black Date: Wed, 3 Oct 2018 23:17:50 +0000 (-0700) Subject: systemc: Change how errors are handled in some constructors slightly. X-Git-Tag: v19.0.0.0~1536 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8946c9d52fc2d789844586867d047be69651ddd6;p=gem5.git systemc: Change how errors are handled in some constructors slightly. Because SC_REPORT_ERROR usually causes an exception to be thrown, it's easy to assume it will be the last thing executed in a function. It might, however, be set up to do nothing, in which case the function will continue to execute. This change makes sure sc_prim will be set up properly even if errors about the time a channel can be set up are ignored. Also, if an exception is thrown while sc_port is being set up, the corresponding Port object needs to be cleaned up. Rather than try to intercept exceptions in the constructor and clean up properly, we'll just make the allocation of the Port object be the last thing it does. If the function exits early, then the Port pointer will still be nullptr and nothing will need to be done. Change-Id: If8f6f6b7e6830235fee3cd75625240b99e87dfbe Reviewed-on: https://gem5-review.googlesource.com/c/13289 Reviewed-by: Gabe Black Maintainer: Gabe Black --- diff --git a/src/systemc/core/sc_port.cc b/src/systemc/core/sc_port.cc index 3a31e411d..50a67a3b6 100644 --- a/src/systemc/core/sc_port.cc +++ b/src/systemc/core/sc_port.cc @@ -56,7 +56,7 @@ reportError(const char *id, const char *add_msg, } sc_port_base::sc_port_base(const char *n, int max_size, sc_port_policy p) : - sc_object(n), _gem5Port(new ::sc_gem5::Port(this, max_size)) + sc_object(n), _gem5Port(nullptr) { if (sc_is_running()) { reportError("(E110) insert port failed", "simulation running", @@ -74,6 +74,7 @@ sc_port_base::sc_port_base(const char *n, int max_size, sc_port_policy p) : } else { m->ports.push_back(this); } + _gem5Port = new ::sc_gem5::Port(this, max_size); } sc_port_base::~sc_port_base() diff --git a/src/systemc/core/sc_prim.cc b/src/systemc/core/sc_prim.cc index 216bd78f9..099e5d8bf 100644 --- a/src/systemc/core/sc_prim.cc +++ b/src/systemc/core/sc_prim.cc @@ -48,12 +48,12 @@ sc_prim_channel::sc_prim_channel() : _gem5_channel(nullptr) if (sc_is_running()) { SC_REPORT_ERROR("(E113) insert primitive channel failed", "simulation running"); - } else if (::sc_gem5::scheduler.elaborationDone()) { + } + if (::sc_gem5::scheduler.elaborationDone()) { SC_REPORT_ERROR("(E113) insert primitive channel failed", "elaboration done"); - } else { - _gem5_channel = new sc_gem5::Channel(this); } + _gem5_channel = new sc_gem5::Channel(this); } sc_prim_channel::sc_prim_channel(const char *_name) : @@ -62,12 +62,12 @@ sc_prim_channel::sc_prim_channel(const char *_name) : if (sc_is_running()) { SC_REPORT_ERROR("(E113) insert primitive channel failed", "simulation running"); - } else if (::sc_gem5::scheduler.elaborationDone()) { + } + if (::sc_gem5::scheduler.elaborationDone()) { SC_REPORT_ERROR("(E113) insert primitive channel failed", "elaboration done"); - } else { - _gem5_channel = new sc_gem5::Channel(this); } + _gem5_channel = new sc_gem5::Channel(this); } sc_prim_channel::~sc_prim_channel() { delete _gem5_channel; }