Skip to content

Commit

Permalink
Reimplement TAO_Stub_Auto_Ptr with a std::unique_ptr with a custom de…
Browse files Browse the repository at this point in the history
…leter, reduces our code, also simplified the _this, no magic ACE macros anymore

    * TAO/TAO_IDL/be/be_visitor_interface/amh_ss.cpp:
    * TAO/TAO_IDL/be/be_visitor_interface/interface_ss.cpp:
    * TAO/tao/ORB_Core.h:
    * TAO/tao/Stub.h:
    * TAO/tao/Stub.inl:
  • Loading branch information
jwillemsen committed Sep 4, 2023
1 parent 806844f commit da22574
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 145 deletions.
33 changes: 13 additions & 20 deletions TAO/TAO_IDL/be/be_visitor_interface/amh_ss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<STUB_SCOPED_NAME>::unchecked_narrow (";
*os << "return TAO::Narrow_Utils<::" << node->name () << ">::unchecked_narrow (";
}
else
{
*os << "TAO::AbstractBase_Narrow_Utils<STUB_SCOPED_NAME>::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
Expand Down
37 changes: 14 additions & 23 deletions TAO/TAO_IDL/be/be_visitor_interface/interface_ss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions TAO/tao/ORB_Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down Expand Up @@ -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
Expand Down
31 changes: 9 additions & 22 deletions TAO/tao/Stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ class TAO_Export TAO_Stub
*
* This <B>must</B> be the first field of the class, otherwise the
* TAO_ORB_Core is destroyed too early!
*
*/
TAO_ORB_Core_Auto_Ptr orb_core_;

Expand Down Expand Up @@ -405,32 +404,20 @@ class TAO_Export TAO_Stub
std::atomic<bool> 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_Stub, TAO_Stub_Decr_Refcnt>;

TAO_END_VERSIONED_NAMESPACE_DECL

#if defined (__ACE_INLINE__)
Expand Down
77 changes: 0 additions & 77 deletions TAO/tao/Stub.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit da22574

Please sign in to comment.