summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-03-10 17:55:56 +0000
committercoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-03-10 17:55:56 +0000
commite3e9c942051125fa5b2ccb3bf542725ce013a9a6 (patch)
tree0a9c36539eae81498a75f711074846b789addd6e
parent628c7c2c4d97b583281514f8ad849e5beb5a9360 (diff)
downloadATCD-e3e9c942051125fa5b2ccb3bf542725ce013a9a6.tar.gz
ChangeLogTag:Fri Mar 10 09:49:40 2000 Carlos O'Ryan <coryan@uci.edu>
-rw-r--r--TAO/ChangeLogs/ChangeLog-02a19
-rw-r--r--TAO/tao/Any.cpp44
-rw-r--r--TAO/tao/Any.h3
-rw-r--r--TAO/tao/DomainC.cpp148
-rw-r--r--TAO/tao/DomainC.h3
-rw-r--r--TAO/tao/DynAny_i.cpp16
-rw-r--r--TAO/tao/Object.cpp8
-rw-r--r--TAO/tao/Object.h3
8 files changed, 102 insertions, 142 deletions
diff --git a/TAO/ChangeLogs/ChangeLog-02a b/TAO/ChangeLogs/ChangeLog-02a
index 4ad6d340655..4cd0c2303be 100644
--- a/TAO/ChangeLogs/ChangeLog-02a
+++ b/TAO/ChangeLogs/ChangeLog-02a
@@ -1,3 +1,22 @@
+Fri Mar 10 09:49:40 2000 Carlos O'Ryan <coryan@uci.edu>
+
+ * tao/Any.h:
+ * tao/Any.cpp:
+ More memory management fixes for the >>= and <<= operators.
+ Moved some static _tao_any_destructor functions to the Any
+ class, it is easier to maintain it that way.
+
+ * tao/Object.h:
+ * tao/Object.cpp:
+ Add the _tao_any_destructor helper function.
+
+ * tao/DomainC.h:
+ * tao/DomainC.cpp:
+ Changed to use the new _tao_any_destructors in the right places.
+
+ * tao/DynAny_i.cpp:
+ It is better just to return 0 than to cast away const.
+
Fri Mar 10 11:28:15 2000 Jeff Parsons <parsons@cs.wustl.edu>
* tao/TAO.dsp:
diff --git a/TAO/tao/Any.cpp b/TAO/tao/Any.cpp
index 5f900811457..6cf993c58d1 100644
--- a/TAO/tao/Any.cpp
+++ b/TAO/tao/Any.cpp
@@ -937,6 +937,7 @@ CORBA_Any::operator<<= (from_string s)
{
// Bounded string.
_oc_string [1] = s.bound_;
+ // @@ It seems like this could be leaked!
ACE_NEW (tc,
CORBA::TypeCode (CORBA::tk_string,
sizeof _oc_string,
@@ -949,18 +950,15 @@ CORBA_Any::operator<<= (from_string s)
tc = CORBA::_tc_string; // unbounded.
}
- char **tmp;
+ char *tmp;
// Non-copying.
if (s.nocopy_)
{
- ACE_NEW (tmp,
- char* (s.val_));
+ tmp = s.val_;
}
- // Copying.
else
{
- ACE_NEW (tmp,
- char* (CORBA::string_dup (s.val_)));
+ tmp = CORBA::string_dup (s.val_);
}
this->_tao_replace (tc,
@@ -968,6 +966,7 @@ CORBA_Any::operator<<= (from_string s)
stream.begin (),
1,
tmp,
+ CORBA::Any::_tao_any_string_destructor,
ACE_TRY_ENV);
ACE_TRY_CHECK;
}
@@ -1004,6 +1003,7 @@ CORBA_Any::operator<<= (from_wstring ws)
{
// Bounded string.
_oc_wstring [1] = ws.bound_;
+ // @@ TODO It seems like this is leaked!
ACE_NEW (tc,
CORBA::TypeCode (CORBA::tk_wstring,
sizeof _oc_wstring,
@@ -1016,18 +1016,15 @@ CORBA_Any::operator<<= (from_wstring ws)
tc = CORBA::_tc_wstring; // unbounded.
}
- CORBA::WChar **tmp;
+ CORBA::WChar *tmp;
// Non-copying.
if (ws.nocopy_)
{
- ACE_NEW (tmp,
- CORBA::WChar* (ws.val_));
+ tmp = ws.val_;
}
- // Copying.
else
{
- ACE_NEW (tmp,
- CORBA::WChar* (CORBA::wstring_dup (ws.val_)));
+ tmp = CORBA::wstring_dup (ws.val_);
}
this->_tao_replace (tc,
@@ -1035,6 +1032,7 @@ CORBA_Any::operator<<= (from_wstring ws)
stream.begin (),
1,
tmp,
+ CORBA::Any::_tao_any_wstring_destructor,
ACE_TRY_ENV);
ACE_TRY_CHECK;
}
@@ -1397,8 +1395,8 @@ CORBA_Any::operator>>= (const CORBA::Any *&a) const
return 0;
}
-static void
-_tao_any_string_destructor (void *x)
+void
+CORBA_Any::_tao_any_string_destructor (void *x)
{
char *tmp = ACE_static_cast (char*,x);
CORBA::string_free (tmp);
@@ -1437,7 +1435,7 @@ CORBA_Any::operator>>= (const char *&s) const
this)->_tao_replace (CORBA::_tc_string,
1,
tmp.inout (),
- _tao_any_string_destructor,
+ CORBA::Any::_tao_any_string_destructor,
ACE_TRY_ENV);
ACE_TRY_CHECK;
@@ -1454,8 +1452,8 @@ CORBA_Any::operator>>= (const char *&s) const
return 0;
}
-static void
-_tao_any_wstring_destructor (void *x)
+void
+CORBA::Any::_tao_any_wstring_destructor (void *x)
{
CORBA::WChar *tmp = ACE_static_cast (CORBA::WChar*,x);
CORBA::wstring_free (tmp);
@@ -1494,7 +1492,7 @@ CORBA_Any::operator>>= (const CORBA::WChar *&s) const
this)->_tao_replace (CORBA::_tc_wstring,
1,
tmp.inout (),
- _tao_any_wstring_destructor,
+ CORBA::Any::_tao_any_wstring_destructor,
ACE_TRY_ENV);
ACE_TRY_CHECK;
@@ -1511,8 +1509,8 @@ CORBA_Any::operator>>= (const CORBA::WChar *&s) const
return 0;
}
-static void
-_tao_any_tc_destructor (void *x)
+void
+CORBA::Any::_tao_any_tc_destructor (void *x)
{
CORBA::TypeCode_ptr tmp = ACE_static_cast (CORBA::TypeCode_ptr,x);
CORBA::release (tmp);
@@ -1550,7 +1548,7 @@ CORBA_Any::operator>>= (CORBA::TypeCode_ptr &tc) const
this)->_tao_replace (CORBA::_tc_TypeCode,
1,
tmp.in (),
- _tao_any_tc_destructor,
+ CORBA::Any::_tao_any_tc_destructor,
ACE_TRY_ENV);
ACE_TRY_CHECK;
@@ -1732,7 +1730,7 @@ CORBA_Any::operator>>= (to_string s) const
this)->_tao_replace (CORBA::_tc_string,
1,
ACE_static_cast(char*,tmp),
- _tao_any_string_destructor,
+ CORBA::Any::_tao_any_string_destructor,
ACE_TRY_ENV);
ACE_TRY_CHECK;
@@ -1796,7 +1794,7 @@ CORBA_Any::operator>>= (to_wstring ws) const
this)->_tao_replace (CORBA::_tc_string,
1,
ACE_static_cast(CORBA::WChar*,tmp),
- _tao_any_wstring_destructor,
+ CORBA::Any::_tao_any_wstring_destructor,
ACE_TRY_ENV);
ACE_TRY_CHECK;
diff --git a/TAO/tao/Any.h b/TAO/tao/Any.h
index d909aa0f21f..f0c403f0be3 100644
--- a/TAO/tao/Any.h
+++ b/TAO/tao/Any.h
@@ -382,6 +382,9 @@ public:
// Useful for template programming.
static void _tao_any_destructor (void*);
+ static void _tao_any_string_destructor (void*);
+ static void _tao_any_wstring_destructor (void*);
+ static void _tao_any_tc_destructor (void*);
// Used to release Anys contained into anys.
protected:
diff --git a/TAO/tao/DomainC.cpp b/TAO/tao/DomainC.cpp
index 4c0d5fbe556..037431430d9 100644
--- a/TAO/tao/DomainC.cpp
+++ b/TAO/tao/DomainC.cpp
@@ -338,52 +338,50 @@ CORBA_DomainManagerList::CORBA_DomainManagerList (const CORBA_DomainManagerList
CORBA_DomainManagerList::~CORBA_DomainManagerList (void) // dtor
{}
+void CORBA_DomainManager::_tao_any_destructor (void* x)
+{
+ CORBA_DomainManager_ptr tmp = ACE_static_cast (CORBA_DomainManager_ptr,x);
+ CORBA::release (tmp);
+}
+
void operator<<= (CORBA::Any &_tao_any, CORBA::DomainManager_ptr _tao_elem)
{
- CORBA::Object_ptr *_tao_obj_ptr = 0;
ACE_TRY_NEW_ENV
{
- ACE_NEW (_tao_obj_ptr, CORBA::Object_ptr);
- *_tao_obj_ptr = CORBA::DomainManager::_duplicate (_tao_elem);
TAO_OutputCDR stream;
- if (stream << *_tao_obj_ptr)
+ if (stream << _tao_elem)
{
_tao_any._tao_replace (
CORBA::_tc_DomainManager,
TAO_ENCAP_BYTE_ORDER,
stream.begin (),
- 1,
- _tao_obj_ptr,
ACE_TRY_ENV
);
ACE_TRY_CHECK;
}
- else
- {
- delete _tao_obj_ptr;
- }
}
ACE_CATCHANY
{
- delete _tao_obj_ptr;
}
ACE_ENDTRY;
}
CORBA::Boolean operator>>= (const CORBA::Any &_tao_any, CORBA::DomainManager_ptr &_tao_elem)
{
- CORBA::Object_ptr *tmp = 0;
- ACE_NEW_RETURN (tmp, CORBA::Object_ptr, 0);
ACE_TRY_NEW_ENV
{
_tao_elem = CORBA::DomainManager::_nil ();
CORBA::TypeCode_var type = _tao_any.type ();
if (!type->equivalent (CORBA::_tc_DomainManager, ACE_TRY_ENV)) // not equal
{
- delete tmp;
return 0;
}
ACE_TRY_CHECK;
+ if (_tao_any.any_owns_data ())
+ {
+ _tao_elem = (CORBA::DomainManager_ptr)_tao_any.value ();
+ return 1;
+ }
TAO_InputCDR stream (
_tao_any._tao_get_cdr (),
_tao_any._tao_byte_order ()
@@ -393,29 +391,21 @@ CORBA::Boolean operator>>= (const CORBA::Any &_tao_any, CORBA::DomainManager_ptr
{
_tao_elem = CORBA::DomainManager::_narrow (_tao_obj_var.in (), ACE_TRY_ENV);
ACE_TRY_CHECK;
- *tmp = (CORBA::Object_ptr) _tao_elem; // any owns the object
((CORBA::Any *)&_tao_any)->_tao_replace (
CORBA::_tc_DomainManager,
1,
- tmp,
+ _tao_elem,
+ CORBA::DomainManager::_tao_any_destructor,
ACE_TRY_ENV
);
ACE_TRY_CHECK;
return 1;
}
- else // failure
- {
- delete tmp;
- }
}
ACE_CATCHANY
{
- delete tmp;
- _tao_elem = CORBA::DomainManager::_nil ();
- return 0;
}
ACE_ENDTRY;
- _tao_elem = CORBA::DomainManager::_nil ();
return 0;
}
@@ -431,52 +421,51 @@ CORBA::Boolean operator>>= (const CORBA::Any &_tao_any, CORBA::DomainManager_ptr
#if ! defined (TAO_HAS_MINIMUM_CORBA)
+void
+CORBA_ConstructionPolicy::_tao_any_destructor (void *x)
+{
+ CORBA_ConstructionPolicy_ptr tmp = ACE_static_cast(CORBA_ConstructionPolicy_ptr,x);
+ CORBA::release (tmp);
+}
+
void operator<<= (CORBA::Any &_tao_any, CORBA::ConstructionPolicy_ptr _tao_elem)
{
- CORBA::Object_ptr *_tao_obj_ptr = 0;
ACE_TRY_NEW_ENV
{
- ACE_NEW (_tao_obj_ptr, CORBA::Object_ptr);
- *_tao_obj_ptr = CORBA::ConstructionPolicy::_duplicate (_tao_elem);
TAO_OutputCDR stream;
- if (stream << *_tao_obj_ptr)
+ if (stream << _tao_elem)
{
_tao_any._tao_replace (
CORBA::_tc_ConstructionPolicy,
TAO_ENCAP_BYTE_ORDER,
stream.begin (),
- 1,
- _tao_obj_ptr,
ACE_TRY_ENV
);
ACE_TRY_CHECK;
}
- else
- {
- delete _tao_obj_ptr;
- }
}
ACE_CATCHANY
{
- delete _tao_obj_ptr;
}
ACE_ENDTRY;
}
CORBA::Boolean operator>>= (const CORBA::Any &_tao_any, CORBA::ConstructionPolicy_ptr &_tao_elem)
{
- CORBA::Object_ptr *tmp = 0;
- ACE_NEW_RETURN (tmp, CORBA::Object_ptr, 0);
ACE_TRY_NEW_ENV
{
_tao_elem = CORBA::ConstructionPolicy::_nil ();
CORBA::TypeCode_var type = _tao_any.type ();
if (!type->equivalent (CORBA::_tc_ConstructionPolicy, ACE_TRY_ENV)) // not equal
{
- delete tmp;
return 0;
}
ACE_TRY_CHECK;
+ if (_tao_any.any_owns_data ())
+ {
+ _tao_elem = (CORBA::ConstructionPolicy_ptr)_tao_any.value ();
+ return 1;
+ }
TAO_InputCDR stream (
_tao_any._tao_get_cdr (),
_tao_any._tao_byte_order ()
@@ -486,29 +475,21 @@ CORBA::Boolean operator>>= (const CORBA::Any &_tao_any, CORBA::ConstructionPolic
{
_tao_elem = CORBA::ConstructionPolicy::_narrow (_tao_obj_var.in (), ACE_TRY_ENV);
ACE_TRY_CHECK;
- *tmp = (CORBA::Object_ptr) _tao_elem; // any owns the object
((CORBA::Any *)&_tao_any)->_tao_replace (
CORBA::_tc_ConstructionPolicy,
1,
- tmp,
+ _tao_elem,
+ CORBA::ConstructionPolicy::_tao_any_destructor,
ACE_TRY_ENV
);
ACE_TRY_CHECK;
return 1;
}
- else // failure
- {
- delete tmp;
- }
}
ACE_CATCHANY
{
- delete tmp;
- _tao_elem = CORBA::ConstructionPolicy::_nil ();
- return 0;
}
ACE_ENDTRY;
- _tao_elem = CORBA::ConstructionPolicy::_nil ();
return 0;
}
@@ -521,37 +502,34 @@ CORBA::Boolean operator>>= (const CORBA::Any &_tao_any, CORBA::ConstructionPolic
#endif /* ! defined (TAO_HAS_MINIMUM_CORBA) */
+void
+CORBA_DomainManagerList::_tao_any_destructor (void *x)
+{
+ CORBA_DomainManagerList* tmp = ACE_static_cast (CORBA_DomainManagerList*,x);
+ delete tmp;
+}
+
void operator<<= (
CORBA::Any &_tao_any,
const CORBA::DomainManagerList &_tao_elem
) // copying
{
- CORBA::DomainManagerList *_tao_any_val;
- ACE_NEW (_tao_any_val, CORBA::DomainManagerList (_tao_elem));
- if (!_tao_any_val) return;
ACE_TRY_NEW_ENV
{
TAO_OutputCDR stream;
- if (stream << *_tao_any_val)
+ if (stream << _tao_elem)
{
_tao_any._tao_replace (
CORBA::_tc_DomainManagerList,
TAO_ENCAP_BYTE_ORDER,
stream.begin (),
- 1,
- _tao_any_val,
ACE_TRY_ENV
);
ACE_TRY_CHECK;
}
- else
- {
- delete _tao_any_val;
- }
}
ACE_CATCHANY
{
- delete _tao_any_val;
}
ACE_ENDTRY;
}
@@ -568,14 +546,13 @@ void operator<<= (CORBA::Any &_tao_any, CORBA::DomainManagerList *_tao_elem) //
stream.begin (),
1,
_tao_elem,
+ CORBA::DomainManagerList::_tao_any_destructor,
ACE_TRY_ENV
);
ACE_TRY_CHECK;
}
ACE_CATCHANY
{
- delete _tao_elem;
- _tao_elem = 0;
}
ACE_ENDTRY;
}
@@ -609,6 +586,7 @@ CORBA::Boolean operator>>= (const CORBA::Any &_tao_any, CORBA::DomainManagerList
CORBA::_tc_DomainManagerList,
1,
ACE_reinterpret_cast (void *, _tao_elem),
+ CORBA::DomainManagerList::_tao_any_destructor,
ACE_TRY_ENV
);
ACE_TRY_CHECK;
@@ -633,51 +611,5 @@ CORBA::Boolean operator>>= (const CORBA::Any &_tao_any, CORBA::DomainManagerList
CORBA::Boolean operator>>= (const CORBA::Any &_tao_any, const CORBA::DomainManagerList *&_tao_elem)
{
- ACE_TRY_NEW_ENV
- {
- CORBA::TypeCode_var type = _tao_any.type ();
- if (!type->equivalent (CORBA::_tc_DomainManagerList, ACE_TRY_ENV)) // not equal
- {
- _tao_elem = 0;
- return 0;
- }
- ACE_TRY_CHECK;
- if (_tao_any.any_owns_data ())
- {
- _tao_elem = (CORBA::DomainManagerList *)_tao_any.value ();
- return 1;
- }
- else
- {
- ACE_NEW_RETURN (_tao_elem, CORBA::DomainManagerList, 0);
- TAO_InputCDR stream (
- _tao_any._tao_get_cdr (),
- _tao_any._tao_byte_order ()
- );
- if (stream >> *(CORBA::DomainManagerList *)_tao_elem)
- {
- ((CORBA::Any *)&_tao_any)->_tao_replace (
- CORBA::_tc_DomainManagerList,
- 1,
- ACE_reinterpret_cast (void *, ACE_const_cast (CORBA::DomainManagerList *&, _tao_elem)),
- ACE_TRY_ENV
- );
- ACE_TRY_CHECK;
- return 1;
- }
- else
- {
- delete ACE_const_cast (CORBA::DomainManagerList *&, _tao_elem);
- _tao_elem = 0;
- }
- }
- }
- ACE_CATCHANY
- {
- delete ACE_const_cast (CORBA::DomainManagerList *&, _tao_elem);
- _tao_elem = 0;
- return 0;
- }
- ACE_ENDTRY;
- return 0;
+ return _tao_any >>= ACE_const_cast(CORBA::DomainManagerList*&,_tao_elem);
}
diff --git a/TAO/tao/DomainC.h b/TAO/tao/DomainC.h
index 0c92495996e..1f58c37b1f3 100644
--- a/TAO/tao/DomainC.h
+++ b/TAO/tao/DomainC.h
@@ -94,6 +94,7 @@ public:
TAO_default_environment ()
);
static CORBA_DomainManager_ptr _nil (void);
+ static void _tao_any_destructor (void*);
virtual CORBA::Policy_ptr get_domain_policy (
CORBA::PolicyType policy_type,
@@ -136,6 +137,7 @@ public:
);
CORBA_DomainManagerList (const CORBA_DomainManagerList &); // copy ctor
~CORBA_DomainManagerList (void); // dtor
+ static void _tao_any_destructor (void*);
};
typedef CORBA_DomainManagerList *CORBA_DomainManagerList_ptr;
@@ -257,6 +259,7 @@ public:
TAO_default_environment ()
);
static CORBA_ConstructionPolicy_ptr _nil (void);
+ static void _tao_any_destructor (void*);
virtual void make_domain_manager (
CORBA::InterfaceDef_ptr object_type,
diff --git a/TAO/tao/DynAny_i.cpp b/TAO/tao/DynAny_i.cpp
index a86667aaca4..d627f41fd85 100644
--- a/TAO/tao/DynAny_i.cpp
+++ b/TAO/tao/DynAny_i.cpp
@@ -424,20 +424,17 @@ TAO_DynAny_i::insert_reference (CORBA::Object_ptr value,
if (kind == CORBA::tk_objref)
{
- CORBA::Object_ptr *_tao_object_ptr;
-
- ACE_NEW (_tao_object_ptr,
- CORBA::Object_ptr);
-
- *_tao_object_ptr = CORBA::Object::_duplicate (value);
+ CORBA::Object_var obj = CORBA::Object::_duplicate (value);
TAO_OutputCDR stream;
- stream << *_tao_object_ptr;
+ if (!(stream << obj.in ()))
+ ACE_THROW (CORBA::MARSHAL ());
this->value_._tao_replace (this->value_.type (),
TAO_ENCAP_BYTE_ORDER,
stream.begin (),
1,
- (void*)_tao_object_ptr,
+ obj.in (),
+ CORBA::Object::_tao_any_destructor,
ACE_TRY_ENV);
ACE_CHECK;
}
@@ -676,8 +673,7 @@ TAO_DynAny_i::get_string (CORBA::Environment &ACE_TRY_ENV)
if (!(this->value_ >>= val))
{
- ACE_THROW_RETURN (CORBA_DynAny::TypeMismatch (),
- ACE_const_cast (char *, val));
+ ACE_THROW_RETURN (CORBA_DynAny::TypeMismatch (), 0);
}
return CORBA::string_dup (val);
diff --git a/TAO/tao/Object.cpp b/TAO/tao/Object.cpp
index 0b2f486eaee..d1e1ea7ce67 100644
--- a/TAO/tao/Object.cpp
+++ b/TAO/tao/Object.cpp
@@ -21,7 +21,6 @@
#include "tao/InterfaceC.h"
#endif /* TAO_HAS_INTERFACE_REPOSITORY == 1 */
-
#include "ace/Auto_Ptr.h"
#if !defined (__ACE_INLINE__)
@@ -50,6 +49,13 @@ CORBA_Object::CORBA_Object (TAO_Stub *protocol_proxy,
// implicitly takes a reference.
}
+void
+CORBA_Object::_tao_any_destructor (void *x)
+{
+ CORBA_Object_ptr tmp = ACE_static_cast(CORBA_Object_ptr,x);
+ CORBA::release (tmp);
+}
+
// IS_A ... ask the object if it's an instance of the type whose
// logical type ID is passed as a parameter.
diff --git a/TAO/tao/Object.h b/TAO/tao/Object.h
index fc175854a9e..58bacd8ca2a 100644
--- a/TAO/tao/Object.h
+++ b/TAO/tao/Object.h
@@ -54,6 +54,9 @@ public:
TAO_default_environment ());
// no-op it is just here to simplify some templates.
+ static void _tao_any_destructor (void*);
+ // Used in the implementation of CORBA::Any
+
// These calls correspond to over-the-wire operations, or at least
// do so in many common cases. The normal implementation assumes a
// particular simple, efficient, protocol-neutral interface for