From ab2bc55207d99ddd49ea35d3409a73c4b7fd5448 Mon Sep 17 00:00:00 2001 From: parsons Date: Sat, 11 Jan 2003 00:59:45 +0000 Subject: ChangeLogTag: Fri Jan 10 18:57:58 2003 Jeff Parsons --- TAO/ChangeLog | 13 +++++++++ TAO/tao/Any.cpp | 28 ++++++++++++++++++ TAO/tao/Any.h | 37 +++++++++--------------- TAO/tao/CDR_Encaps_Codec.cpp | 68 +++++++++++++++++++++++++++++--------------- TAO/tao/NVList.cpp | 36 ++++++++++------------- TAO/tao/RequestInfo_Util.cpp | 15 ++-------- TAO/tao/append.cpp | 18 ++++++------ TAO/tao/skip.cpp | 15 ++++------ 8 files changed, 130 insertions(+), 100 deletions(-) diff --git a/TAO/ChangeLog b/TAO/ChangeLog index 5bc0c86c1db..0be32960736 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,3 +1,16 @@ +Fri Jan 10 18:57:58 2003 Jeff Parsons + + * tao/Any.cpp: + * tao/Any.h: + * tao/CDR_Encaps_Codec.cpp: + * tao/NVList.cpp: + * tao/RequestInfo_Util.cpp: + * tao/append.cpp: + * tao/skip.cpp: + + Some cleanup of internal incompatibilities with the new + Any implementation. + Fri Jan 10 11:30:08 2003 Jeff Parsons * tao/Any_T.inl: diff --git a/TAO/tao/Any.cpp b/TAO/tao/Any.cpp index f6e023ca0bd..3ab0aba7ef8 100644 --- a/TAO/tao/Any.cpp +++ b/TAO/tao/Any.cpp @@ -24,6 +24,19 @@ CORBA::Any::Any (const CORBA::Any &rhs) } } +CORBA::Any::Any (CORBA::TypeCode_ptr tc, + void *value, + CORBA::Boolean release) +{ + ACE_Message_Block *mb = ACE_reinterpret_cast (ACE_Message_Block *, + value); + ACE_NEW (this->impl_, + TAO::Unknown_IDL_Type (tc, + mb, + tc->byte_order_, + release)); +} + CORBA::Any::~Any (void) { if (this->impl_ != 0) @@ -53,6 +66,21 @@ CORBA::Any::operator= (const CORBA::Any &rhs) return *this; } +void +CORBA::Any::replace (CORBA::TypeCode_ptr tc, + void *value, + CORBA::Boolean release) +{ + ACE_Message_Block *mb = ACE_reinterpret_cast (ACE_Message_Block *, + value); + TAO::Unknown_IDL_Type *unk = 0; + ACE_NEW (unk, + TAO::Unknown_IDL_Type (tc, + mb, + release)); + this->replace (unk); +} + void CORBA::Any::replace (TAO::Any_Impl *new_impl) { diff --git a/TAO/tao/Any.h b/TAO/tao/Any.h index 0443a1dfbda..a17eb282fdf 100644 --- a/TAO/tao/Any.h +++ b/TAO/tao/Any.h @@ -45,33 +45,11 @@ namespace CORBA public: // ********** TEMPORARY ********************* -// typedef void (*_tao_destructor)(void *); - void _tao_replace (CORBA::TypeCode_ptr, - int byte_order, - const ACE_Message_Block *mb) {} -/* - void _tao_replace (CORBA::TypeCode_ptr type, - int byte_order, - const ACE_Message_Block *mb, - CORBA::Boolean any_owns_data, - void* value, - CORBA::Any::_tao_destructor destructor) {} - void _tao_replace (CORBA::TypeCode_ptr type, - CORBA::Boolean any_owns_data, - void* value, - CORBA::Any::_tao_destructor destructor) {} -*/ -// CORBA::Boolean any_owns_data (void) const { return 0; } CORBA::TypeCode_ptr type_; ACE_Message_Block *cdr_; void _tao_encode (TAO_OutputCDR &cdr, TAO_ORB_Core *orb_core ACE_ENV_ARG_DECL) {} - Any (CORBA::TypeCode_ptr) {} - Any (CORBA::TypeCode_ptr, - CORBA::UShort, - int, - const ACE_Message_Block*) {} void _tao_decode (TAO_InputCDR &cdr ACE_ENV_ARG_DECL) {} // ****************************************** @@ -81,6 +59,17 @@ namespace CORBA Any (void); Any (const Any &); + + /// This signature is required by the C++ mapping, but allows + /// obvious type safety dangers. TAO's implementation will + /// accept an ACE_Message_Block passed in as a void*. This is + /// also useful for interceptors, where an Any may need to be + /// created that contains a void type. In that case, we can + /// pass in a void* value of 0. + Any (TypeCode_ptr, + void *value, + Boolean release = 0); + ~Any (void); Any &operator= (const Any &); @@ -153,12 +142,12 @@ namespace CORBA Boolean operator>>= (to_object) const; Boolean operator>>= (to_abstract_base) const; Boolean operator>>= (to_value) const; -/* + /// Spec-defined signature. void replace (TypeCode_ptr, void *value, Boolean release = 0); -*/ + /// TAO-specific signature. void replace (TAO::Any_Impl *); diff --git a/TAO/tao/CDR_Encaps_Codec.cpp b/TAO/tao/CDR_Encaps_Codec.cpp index 7118e6e4aa0..f131cd47770 100644 --- a/TAO/tao/CDR_Encaps_Codec.cpp +++ b/TAO/tao/CDR_Encaps_Codec.cpp @@ -135,7 +135,8 @@ TAO_CDR_Encaps_Codec::decode (const CORBA::OctetSeq & data return safe_any._retn (); } - ACE_THROW_RETURN (IOP::Codec::FormatMismatch (), 0); + ACE_THROW_RETURN (IOP::Codec::FormatMismatch (), + 0); } CORBA::OctetSeq * @@ -145,7 +146,7 @@ TAO_CDR_Encaps_Codec::encode_value (const CORBA::Any & data IOP::Codec::InvalidTypeForEncoding)) { this->check_type_for_encoding (data - ACE_ENV_ARG_PARAMETER); + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (0); // ---------------------------------------------------------------- @@ -181,10 +182,12 @@ TAO_CDR_Encaps_Codec::encode_value (const CORBA::Any & data ACE_NEW_THROW_EX (octet_seq, CORBA::OctetSeq, CORBA::NO_MEMORY ( - CORBA_SystemException::_tao_minor_code ( - TAO_DEFAULT_MINOR_CODE, - ENOMEM), - CORBA::COMPLETED_NO)); + CORBA_SystemException::_tao_minor_code ( + TAO_DEFAULT_MINOR_CODE, + ENOMEM + ), + CORBA::COMPLETED_NO + )); ACE_CHECK_RETURN (0); CORBA::OctetSeq_var safe_octet_seq = octet_seq; @@ -197,14 +200,17 @@ TAO_CDR_Encaps_Codec::encode_value (const CORBA::Any & data i = i->cont ()) { size_t len = i->length (); - ACE_OS_String::memcpy (buf, i->rd_ptr (), len); + ACE_OS_String::memcpy (buf, + i->rd_ptr (), + len); buf += len; } return safe_octet_seq._retn (); } - ACE_THROW_RETURN (CORBA::MARSHAL (), 0); + ACE_THROW_RETURN (CORBA::MARSHAL (), + 0); } CORBA::Any * @@ -224,7 +230,9 @@ TAO_CDR_Encaps_Codec::decode_value (const CORBA::OctetSeq & data, ACE_Message_Block mb (data.length () + 2 * ACE_CDR::MAX_ALIGNMENT); ACE_CDR::mb_align (&mb); - ACE_OS::memcpy (mb.rd_ptr (), data.get_buffer (), data.length ()); + ACE_OS::memcpy (mb.rd_ptr (), + data.get_buffer (), + data.length ()); // @todo How do we check for a type mismatch so that we can // throw a IOP::Codec::TypeMismatch exception? @@ -254,6 +262,7 @@ TAO_CDR_Encaps_Codec::decode_value (const CORBA::OctetSeq & data, this->orb_core_); CORBA::Boolean byte_order; + if (cdr >> TAO_InputCDR::to_boolean (byte_order)) { cdr.reset_byte_order (ACE_static_cast (int, byte_order)); @@ -279,7 +288,6 @@ TAO_CDR_Encaps_Codec::decode_value (const CORBA::OctetSeq & data, { // This will be the end of the new message block. char *end = cdr.rd_ptr (); - size_t size = end - begin; // @@ I added the following check, but I'm not sure if it is @@ -295,7 +303,10 @@ TAO_CDR_Encaps_Codec::decode_value (const CORBA::OctetSeq & data, // possible to determine if the TypeCode does *not* match // the data, not if it does match. if (size != sequence_length - 1) - ACE_THROW_RETURN (IOP::Codec::TypeMismatch (), 0); + { + ACE_THROW_RETURN (IOP::Codec::TypeMismatch (), + 0); + } ptr_arith_t offset = ptr_arith_t (begin) % ACE_CDR::MAX_ALIGNMENT; @@ -306,31 +317,42 @@ TAO_CDR_Encaps_Codec::decode_value (const CORBA::OctetSeq & data, ACE_NEW_THROW_EX (any, CORBA::Any, CORBA::NO_MEMORY ( - CORBA_SystemException::_tao_minor_code ( - TAO_DEFAULT_MINOR_CODE, - ENOMEM), - CORBA::COMPLETED_NO)); + CORBA_SystemException::_tao_minor_code ( + TAO_DEFAULT_MINOR_CODE, + ENOMEM + ), + CORBA::COMPLETED_NO + )); ACE_CHECK_RETURN (0); CORBA::Any_var safe_any = any; - // Stick it into the Any. It gets duplicated there. - any->_tao_replace (tc, - cdr.byte_order (), - &mb); + // Stick it into the Any. + TAO::Unknown_IDL_Type *unk = 0; + ACE_NEW_RETURN (unk, + TAO::Unknown_IDL_Type (tc, + &mb, + cdr.byte_order ()), + 0); + any->replace (unk); return safe_any._retn (); } else - ACE_THROW_RETURN (IOP::Codec::TypeMismatch (), 0); + { + ACE_THROW_RETURN (IOP::Codec::TypeMismatch (), + 0); + } } - ACE_THROW_RETURN (IOP::Codec::FormatMismatch (), 0); + ACE_THROW_RETURN (IOP::Codec::FormatMismatch (), + 0); } void TAO_CDR_Encaps_Codec::check_type_for_encoding ( - const CORBA::Any & data - ACE_ENV_ARG_DECL) + const CORBA::Any & data + ACE_ENV_ARG_DECL + ) { // @@ TODO: Are there any other conditions we need to check? diff --git a/TAO/tao/NVList.cpp b/TAO/tao/NVList.cpp index 7a1681f0334..bec12ddcdf8 100644 --- a/TAO/tao/NVList.cpp +++ b/TAO/tao/NVList.cpp @@ -129,34 +129,28 @@ CORBA_NVList::add_value (const char *name, CORBA::Flags flags ACE_ENV_ARG_DECL) { - // call the helper to allocate a NamedValue element - CORBA::NamedValue_ptr nv = this->add_element (flags ACE_ENV_ARG_PARAMETER); + // Call the helper to allocate a NamedValue element. + CORBA::NamedValue_ptr nv = this->add_element (flags + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (0); + if (nv) { - // now initialize the fields nv->name_ = CORBA::string_dup (name); - if (ACE_BIT_ENABLED (flags, CORBA::IN_COPY_VALUE)) - // IN_COPY_VALUE means that the parameter is not "borrowed" by - // the ORB, but rather that the ORB copies its value. - // - // Initialize the newly allocated memory using a copy - // constructor that places the new "Any" value at just the right - // place, and makes a "deep copy" of the data. - nv->any_ = value; - else - { - // The normal behaviour for parameters is that the ORB "borrows" - // their memory for the duration of calls. - // - nv->any_._tao_replace (value.type_, - value._tao_byte_order (), - value.cdr_); - } + + // With the original Any implementation, we had alternate + // paths for the assignment based on the IN_COPY_VALUE flag. + // Now that the Any's contained Any_Impl is refcounted, the + // distinction between the ORB "copying" or "borrowing" the + // memory is irrelevant. The IN_COPY_VALUE flag was not + // checked anywhere else in the ORB anyway. + nv->any_ = value; return nv; } else - return 0; + { + return 0; + } } // add an element and just initialize its flags and name diff --git a/TAO/tao/RequestInfo_Util.cpp b/TAO/tao/RequestInfo_Util.cpp index 28c042faedb..945e02ee32f 100644 --- a/TAO/tao/RequestInfo_Util.cpp +++ b/TAO/tao/RequestInfo_Util.cpp @@ -84,20 +84,9 @@ TAO_RequestInfo_Util::make_any (CORBA::Boolean tk_void_any if (tk_void_any) { - CORBA::TypeCode *tc = 0; - ACE_NEW_THROW_EX (tc, - CORBA::TypeCode (CORBA::tk_void), - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - TAO_DEFAULT_MINOR_CODE, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK_RETURN (0); - - CORBA::TypeCode_var safe_tc = tc; - ACE_NEW_THROW_EX (any, - CORBA::Any (tc), + CORBA::Any (CORBA::_tc_void, + 0), CORBA::NO_MEMORY ( CORBA::SystemException::_tao_minor_code ( TAO_DEFAULT_MINOR_CODE, diff --git a/TAO/tao/append.cpp b/TAO/tao/append.cpp index cefbf980b50..da8f45226a0 100644 --- a/TAO/tao/append.cpp +++ b/TAO/tao/append.cpp @@ -482,10 +482,11 @@ TAO_Marshal_Union::append (CORBA::TypeCode_ptr tc, ++i) { CORBA::Any_var any = tc->member_label (i - ACE_ENV_ARG_PARAMETER); + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); CORBA::Octet o; + if ((any >>= CORBA::Any::to_octet (o)) && o == 0) { CORBA::ULong default_index = @@ -537,15 +538,12 @@ TAO_Marshal_Union::append (CORBA::TypeCode_ptr tc, case CORBA::tk_enum: { - CORBA::ULong d; - - // Create an special Any to handle this case. - CORBA::Any tmp; - tmp._tao_replace (CORBA::_tc_ulong, - any->_tao_byte_order (), - any->_tao_get_cdr ()); - if ((tmp >>= d) && d == enum_v) - current_member = i; + CORBA::ULong *d = ACE_reinterpret_cast (CORBA::ULong *, + any->value ()); + if (*d == enum_v) + { + current_member = i; + } } break; diff --git a/TAO/tao/skip.cpp b/TAO/tao/skip.cpp index d10a9f4526e..ae7beac0ee4 100644 --- a/TAO/tao/skip.cpp +++ b/TAO/tao/skip.cpp @@ -487,15 +487,12 @@ TAO_Marshal_Union::skip (CORBA::TypeCode_ptr tc, case CORBA::tk_enum: { - CORBA::ULong d; - - // Create an special Any to handle this case. - CORBA::Any tmp; - tmp._tao_replace (CORBA::_tc_ulong, - any->_tao_byte_order (), - any->_tao_get_cdr ()); - if ((tmp >>= d) && d == enum_v) - current_member = i; + CORBA::ULong *d = ACE_reinterpret_cast (CORBA::ULong *, + any->value ()); + if (*d == enum_v) + { + current_member = i; + } } break; -- cgit v1.2.1