diff --git a/TAO/TAO_IDL/be/be_visitor_interface/amh_ss.cpp b/TAO/TAO_IDL/be/be_visitor_interface/amh_ss.cpp index 6333aae01d4e1..87642de80f33d 100644 --- a/TAO/TAO_IDL/be/be_visitor_interface/amh_ss.cpp +++ b/TAO/TAO_IDL/be/be_visitor_interface/amh_ss.cpp @@ -67,38 +67,31 @@ be_visitor_amh_interface_ss::this_method (be_interface *node) << full_skel_name << "::_this ()" << be_nl << "{" << be_idt_nl - << "TAO_Stub *stub = this->_create_stub ();" << be_nl_2; + << "TAO_Stub_Auto_Ptr stub (this->_create_stub ());" << be_nl; - *os << "TAO_Stub_Auto_Ptr safe_stub (stub);" << be_nl - << "::CORBA::Object_ptr tmp {};" << be_nl - << be_nl - << "::CORBA::Boolean _tao_opt_colloc =" << be_idt_nl + *os << "::CORBA::Boolean _tao_opt_colloc = " << "stub->servant_orb_var ()->orb_core ()->" - << "optimize_collocation_objects ();" << be_uidt_nl << be_nl - << "ACE_NEW_RETURN (" << be_idt << be_idt_nl - << "tmp," << be_nl - << "::CORBA::Object (stub, _tao_opt_colloc, this)," << be_nl - << "nullptr" << be_uidt_nl - << ");" << be_uidt_nl << be_nl; + << "optimize_collocation_objects ();" << be_nl + << "::CORBA::Object_var obj = " + << "new (std::nothrow) ::CORBA::Object (stub.get (), _tao_opt_colloc, this);" << be_nl + << "if (obj.ptr ())" << be_idt_nl + << "{" << be_idt_nl; - *os << "::CORBA::Object_var obj = tmp;" << be_nl - << "(void) safe_stub.release ();" << be_nl_2; - - *os << "typedef ::" << node->name () << " STUB_SCOPED_NAME;" << be_nl - << "return" << be_idt_nl; + *os << "(void) stub.release ();" << be_nl; if (!node->is_abstract ()) { - *os << "TAO::Narrow_Utils::unchecked_narrow ("; + *os << "return TAO::Narrow_Utils<::" << node->name () << ">::unchecked_narrow ("; } else { - *os << "TAO::AbstractBase_Narrow_Utils::unchecked_narrow ("; + *os << "return TAO::AbstractBase_Narrow_Utils<::" << node->name () << ">::unchecked_narrow ("; } *os << "obj.in ());" << be_nl; - *os << be_uidt << be_uidt_nl - << "}"; + *os << be_uidt_nl + << "}" + << be_uidt_nl << "return {};" << be_uidt_nl << "}"; } void diff --git a/TAO/TAO_IDL/be/be_visitor_interface/interface_ss.cpp b/TAO/TAO_IDL/be/be_visitor_interface/interface_ss.cpp index 33c5ee3bdabed..d87a9d64457e7 100644 --- a/TAO/TAO_IDL/be/be_visitor_interface/interface_ss.cpp +++ b/TAO/TAO_IDL/be/be_visitor_interface/interface_ss.cpp @@ -360,37 +360,28 @@ be_visitor_interface_ss::this_method (be_interface *node) << node->full_skel_name () << "::_this ()" << be_nl << "{" << be_idt_nl - << "TAO_Stub *stub = this->_create_stub ();" - << be_nl_2 - << "TAO_Stub_Auto_Ptr safe_stub (stub);" << be_nl; - - /* Coverity whines about an unused return value from _nil() when - initializing tmp. Just use zero instead. */ - *os << "::CORBA::Object_ptr tmp {};" - << be_nl_2; + << "TAO_Stub_Auto_Ptr stub (this->_create_stub ());" + << be_nl; - *os << "::CORBA::Boolean const _tao_opt_colloc =" - << be_idt_nl + *os << "::CORBA::Boolean const _tao_opt_colloc = " << "stub->servant_orb_var ()->orb_core ()->" - << "optimize_collocation_objects ();" << be_uidt_nl << be_nl; + << "optimize_collocation_objects ();" << be_nl; - *os << "ACE_NEW_RETURN (" << be_idt << be_idt_nl - << "tmp," << be_nl - << "::CORBA::Object (stub, "; - - *os << "_tao_opt_colloc"; - - *os << ", this)," << be_nl - << "nullptr);" << be_uidt << be_uidt_nl << be_nl; + /* Coverity whines about an unused return value from _nil() when + initializing tmp. Just use zero instead. */ + *os << "::CORBA::Object_var obj = " + << "new (std::nothrow) ::CORBA::Object (stub.get (), _tao_opt_colloc, this);" << be_nl + << "if (obj.ptr ())" << be_idt_nl + << "{" << be_idt_nl; - *os << "::CORBA::Object_var obj = tmp;" << be_nl - << "(void) safe_stub.release ();" << be_nl_2 + *os << "(void) stub.release ();" << be_nl << "return " - << "TAO::Narrow_Utils< ::" << node->name () << ">::unchecked_narrow (" + << "TAO::Narrow_Utils<::" << node->name () << ">::unchecked_narrow (" << "obj.in ());"; *os << be_uidt_nl - << "}"; + << "}" + << be_uidt_nl << "return {};" << be_uidt_nl << "}"; } void diff --git a/TAO/tao/ORB_Core.h b/TAO/tao/ORB_Core.h index 84f2af9e92595..f0b82382f7a80 100644 --- a/TAO/tao/ORB_Core.h +++ b/TAO/tao/ORB_Core.h @@ -157,7 +157,7 @@ namespace PortableInterceptor */ class TAO_Export TAO_ORB_Core { - friend class TAO_ORB_Core_Auto_Ptr; + friend class TAO_ORB_Core_Decr_Refcnt; friend TAO_Export CORBA::ORB_ptr CORBA::ORB_init (int &, ACE_TCHAR *argv[], const char *); @@ -1362,8 +1362,7 @@ class TAO_Export TAO_ORB_Core_Static_Resources : public ACE_Service_Object //private: /// Constructor. TAO_ORB_Core_Static_Resources (); - TAO_ORB_Core_Static_Resources& operator= - (const TAO_ORB_Core_Static_Resources&); + TAO_ORB_Core_Static_Resources& operator= (const TAO_ORB_Core_Static_Resources&); private: /// Mostly unused variable whose sole purpose is to enforce diff --git a/TAO/tao/Stub.h b/TAO/tao/Stub.h index 153a3d8207d0c..a44c33af78e80 100644 --- a/TAO/tao/Stub.h +++ b/TAO/tao/Stub.h @@ -313,7 +313,6 @@ class TAO_Export TAO_Stub * * This must be the first field of the class, otherwise the * TAO_ORB_Core is destroyed too early! - * */ TAO_ORB_Core_Auto_Ptr orb_core_; @@ -405,32 +404,20 @@ class TAO_Export TAO_Stub std::atomic forwarded_on_exception_; }; -// Define a TAO_Stub auto_ptr class. /** - * @class TAO_Stub_Auto_Ptr - * - * @brief Implements the draft C++ standard auto_ptr abstraction. - * This class allows one to work Stub Objects *Only*! + * Custom deleter to decrement the refcount when called */ -class TAO_Export TAO_Stub_Auto_Ptr +struct TAO_Export TAO_Stub_Decr_Refcnt { -public: - explicit TAO_Stub_Auto_Ptr (TAO_Stub *p = nullptr); - TAO_Stub_Auto_Ptr (TAO_Stub_Auto_Ptr &ap); - TAO_Stub_Auto_Ptr &operator= (TAO_Stub_Auto_Ptr &rhs); - ~TAO_Stub_Auto_Ptr (); - - // = Accessor methods. - TAO_Stub &operator *() const; - TAO_Stub *get () const; - TAO_Stub *release (); - void reset (TAO_Stub *p = 0); - TAO_Stub *operator-> () const; - -protected: - TAO_Stub *p_; + void operator()(TAO_Stub* stub) const { if (stub) stub->_decr_refcnt(); } }; +/** + * TAO_Stub_Auto_Ptr will decrement the refcount when going our of scope + * using std::unique_ptr and a custom deleter + */ +using TAO_Stub_Auto_Ptr = std::unique_ptr; + TAO_END_VERSIONED_NAMESPACE_DECL #if defined (__ACE_INLINE__) diff --git a/TAO/tao/Stub.inl b/TAO/tao/Stub.inl index 30c4653160bed..02dc6e925830f 100644 --- a/TAO/tao/Stub.inl +++ b/TAO/tao/Stub.inl @@ -418,81 +418,4 @@ TAO_Stub::at_starting_profile () const return profile_in_use_ == base_profiles_.get_profile(0); } -// --------------------------------------------------------------- - -// Creator methods for TAO_Stub_Auto_Ptr (TAO_Stub Auto Pointer) -ACE_INLINE -TAO_Stub_Auto_Ptr::TAO_Stub_Auto_Ptr (TAO_Stub *p) - : p_ (p) -{ - ACE_TRACE ("TAO_Stub_Auto_Ptr::TAO_Stub_Auto_Ptr"); -} - -ACE_INLINE TAO_Stub * -TAO_Stub_Auto_Ptr::get () const -{ - ACE_TRACE ("TAO_Stub_Auto_Ptr::get"); - return this->p_; -} - -ACE_INLINE TAO_Stub * -TAO_Stub_Auto_Ptr::release () -{ - ACE_TRACE ("TAO_Stub_Auto_Ptr::release"); - TAO_Stub *old = this->p_; - this->p_ = nullptr; - return old; -} - -ACE_INLINE void -TAO_Stub_Auto_Ptr::reset (TAO_Stub *p) -{ - ACE_TRACE ("TAO_Stub_Auto_Ptr::reset"); - if (this->get () != p && this->get () != nullptr) - this->get ()->_decr_refcnt (); - this->p_ = p; -} - -ACE_INLINE TAO_Stub * -TAO_Stub_Auto_Ptr::operator-> () const -{ - ACE_TRACE ("TAO_Stub_Auto_Ptr::operator->"); - return this->get (); -} - -ACE_INLINE -TAO_Stub_Auto_Ptr::TAO_Stub_Auto_Ptr (TAO_Stub_Auto_Ptr &rhs) - : p_ (rhs.release ()) -{ - ACE_TRACE ("TAO_Stub_Auto_Ptr::TAO_Stub_Auto_Ptr"); -} - -ACE_INLINE TAO_Stub_Auto_Ptr & -TAO_Stub_Auto_Ptr::operator= (TAO_Stub_Auto_Ptr &rhs) -{ - ACE_TRACE ("TAO_Stub_Auto_Ptr::operator="); - if (this != &rhs) - { - this->reset (rhs.release ()); - } - return *this; -} - -ACE_INLINE -TAO_Stub_Auto_Ptr::~TAO_Stub_Auto_Ptr () -{ - ACE_TRACE ("TAO_Stub_Auto_Ptr::~TAO_Stub_Auto_Ptr"); - if (this->get() != nullptr) - this->get ()->_decr_refcnt (); -} - -// Accessor methods to the underlying Stub Object -ACE_INLINE TAO_Stub & -TAO_Stub_Auto_Ptr::operator *() const -{ - ACE_TRACE ("TAO_Stub_Auto_Ptr::operator *()"); - // @@ Potential problem if this->p_ is zero! - return *this->get (); -} - TAO_END_VERSIONED_NAMESPACE_DECL