summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TAO/ChangeLog-98c44
-rw-r--r--TAO/TAO_IDL/be/be_visitor_exception.cpp9
-rw-r--r--TAO/TAO_IDL/be/be_visitor_interface.cpp7
-rw-r--r--TAO/TAO_IDL/be/be_visitor_sequence.cpp9
-rw-r--r--TAO/TAO_IDL/be/be_visitor_structure.cpp9
-rw-r--r--TAO/TAO_IDL/be/be_visitor_union.cpp9
-rw-r--r--TAO/tao/Any.cpp144
-rw-r--r--TAO/tao/Any.h3
-rw-r--r--TAO/tao/Typecode.cpp46
-rw-r--r--TAO/tao/decode.cpp10
10 files changed, 196 insertions, 94 deletions
diff --git a/TAO/ChangeLog-98c b/TAO/ChangeLog-98c
index 1a15ee0517f..3315b79c3d4 100644
--- a/TAO/ChangeLog-98c
+++ b/TAO/ChangeLog-98c
@@ -1,3 +1,47 @@
+Fri Apr 17 02:38:13 1998 Aniruddha Gokhale <gokhale@mambo.cs.wustl.edu>
+
+ * TAO_IDL/be/{be_visitor_exception, be_visitor_sequence,
+ be_visitor_structure, be_visitor_union}.cpp: We had a mismatch in
+ the signatures of operator <<= in the declaration and
+ implementation. In addition, we force the generated code for >>=
+ operator to own the allocated memory.
+
+ * TAO_IDL/be/be_visitor_interface.cpp: In the code that generates
+ >>= operator, we also generate code such that the allocated memory
+ is owned by the Any
+
+ * tao/Any.{h, cpp}: We now have two data members in class Any. We
+ keep the older semantics of the value_ field. In addition, we
+ maintain a ACE_Message_Block *cdr_ member. Originally we shared
+ the value_ variable to mean either a CDR stream or a pointer to
+ some data type. This was based on whether the Any owns the data or
+ not. However, this strategy does not work because in the >>=
+ operators for constructed types, we must hold on to the newly
+ allocated storage since we own it and we must free it.
+
+ * tao/TypeCode.cpp: In the constructor, we were initializing the
+ internal buffer to point to 4 bytes past the actual buffer that
+ was passed as a parameter. Things were fine as long as we were not
+ transmitting typecodes. However, once we started doing that, we
+ realized that somehow the buffers kept on reducing by 4 as we kept
+ transmitting typecodes over the wire. Thus, a typecode receive don
+ the other end had a smaller buffer (and hence different contents)
+ than the original. We fix this by making our internal buffer point
+ ot the start of the buffer that was passed as a parameter. The
+ side-effect of this is that whenever we have to initialize a
+ TAO_InputCDR with this internal buffer, we must do so by
+ explicitly skipping the first 4 bytes (which contains the byte
+ order flag) and indicating that the length is 4 less than the
+ actual.
+
+ * tao/decode.cpp: In TypeCode::decode, there was a very subtle
+ error. Whenever we were decoding a typecode and determining that
+ it was one of the ORB maintained constants, we were simply
+ pointing to it and passing it back. However, this is not correct
+ because the application can call "release" which was resulting in
+ "Freeing Non-Heap Memory" which is terrible. We now "_duplicate"
+ such typecodes and then pass them to the applications.
+
Thu Apr 16 20:34:40 1998 David L. Levine <levine@cs.wustl.edu>
* tao/ORB_Core.cpp (TAO_ORB_Core): reordered initializers to
diff --git a/TAO/TAO_IDL/be/be_visitor_exception.cpp b/TAO/TAO_IDL/be/be_visitor_exception.cpp
index b0dfc14eada..5caa004b73b 100644
--- a/TAO/TAO_IDL/be/be_visitor_exception.cpp
+++ b/TAO/TAO_IDL/be/be_visitor_exception.cpp
@@ -192,7 +192,7 @@ int be_visitor_exception_ch::visit_exception (be_exception *node)
if (node->is_nested ())
*os << "friend ";
*os << "void operator<<= (CORBA::Any &, " << node->local_name ()
- << "); // noncopying version" << be_nl;
+ << "*); // noncopying version" << be_nl;
if (node->is_nested ())
*os << "friend ";
*os << "CORBA::Boolean operator>>= (const CORBA::Any &, "
@@ -441,7 +441,12 @@ int be_visitor_exception_cs::visit_exception (be_exception *node)
<< "if (stream.decode (" << node->tc_name ()
<< ", &_tao_elem, 0, _tao_env)" << be_nl
<< " == CORBA::TypeCode::TRAVERSE_CONTINUE)" << be_nl
- << " return 1;" << be_nl
+ << "{" << be_idt_nl
+ << "((CORBA::Any *)&_tao_any)->replace (_tao_any.type (), "
+ << "_tao_elem, 1, _tao_env);"
+ << be_nl
+ << " return 1;" << be_uidt_nl
+ << "}" << be_nl
<< "else" << be_nl
<< " return 0;" << be_uidt_nl
<< "}\n\n";
diff --git a/TAO/TAO_IDL/be/be_visitor_interface.cpp b/TAO/TAO_IDL/be/be_visitor_interface.cpp
index 30cf2b5caae..668ba528ae3 100644
--- a/TAO/TAO_IDL/be/be_visitor_interface.cpp
+++ b/TAO/TAO_IDL/be/be_visitor_interface.cpp
@@ -1016,6 +1016,9 @@ be_visitor_interface_cs::visit_interface (be_interface *node)
<< "*_tao_elem = " << node->name () << "::_narrow (_tao_obj, _tao_env);"
<< be_nl
<< "CORBA::release (_tao_obj);" << be_nl
+ << "((CORBA::Any *)&_tao_any)->replace (_tao_any.type (), "
+ << "_tao_elem, 1, _tao_env);"
+ << be_nl
<< "if (_tao_env.exception ()) return 0; // narrow failed" << be_uidt_nl
<< "}" << be_nl
<< "return 1;" << be_uidt_nl
@@ -1759,7 +1762,7 @@ int be_visitor_interface_collocated_ss::visit_interface (be_interface *node)
if (node->defined_in ())
{
- be_decl* scope =
+ be_decl* scope =
be_scope::narrow_from_scope (node->defined_in())->decl ();
*os << ": ACE_NESTED_CLASS ("
@@ -1784,7 +1787,7 @@ int be_visitor_interface_collocated_ss::visit_interface (be_interface *node)
be_interface::narrow_from_decl (node->inherits()[i]);
if (parent->defined_in ())
{
- be_decl* scope =
+ be_decl* scope =
be_scope::narrow_from_scope (parent->defined_in())->decl ();
*os << " ACE_NESTED_CLASS ("
diff --git a/TAO/TAO_IDL/be/be_visitor_sequence.cpp b/TAO/TAO_IDL/be/be_visitor_sequence.cpp
index de4da91019b..7df6f018bd6 100644
--- a/TAO/TAO_IDL/be/be_visitor_sequence.cpp
+++ b/TAO/TAO_IDL/be/be_visitor_sequence.cpp
@@ -218,7 +218,7 @@ int be_visitor_sequence_ch::visit_sequence (be_sequence *node)
if (node->is_nested ())
*os << "friend ";
*os << "void operator<<= (CORBA::Any &, " << node->local_name ()
- << "); // noncopying version" << be_nl;
+ << "*); // noncopying version" << be_nl;
if (node->is_nested ())
*os << "friend ";
*os << "CORBA::Boolean operator>>= (const CORBA::Any &, "
@@ -1171,7 +1171,12 @@ int be_visitor_sequence_cs::visit_sequence (be_sequence *node)
<< "if (stream.decode (" << node->tc_name ()
<< ", &_tao_elem, 0, _tao_env)" << be_nl
<< " == CORBA::TypeCode::TRAVERSE_CONTINUE)" << be_nl
- << " return 1;" << be_nl
+ << "{" << be_idt_nl
+ << "((CORBA::Any *)&_tao_any)->replace (_tao_any.type (), "
+ << "_tao_elem, 1, _tao_env);"
+ << be_nl
+ << " return 1;" << be_uidt_nl
+ << "}" << be_nl
<< "else" << be_nl
<< " return 0;" << be_uidt_nl
<< "}\n\n";
diff --git a/TAO/TAO_IDL/be/be_visitor_structure.cpp b/TAO/TAO_IDL/be/be_visitor_structure.cpp
index ae39d5d9e36..85d12c4eb92 100644
--- a/TAO/TAO_IDL/be/be_visitor_structure.cpp
+++ b/TAO/TAO_IDL/be/be_visitor_structure.cpp
@@ -173,7 +173,7 @@ int be_visitor_structure_ch::visit_structure (be_structure *node)
if (node->is_nested ())
*os << "friend ";
*os << "void operator<<= (CORBA::Any &, " << node->local_name ()
- << "); // noncopying version" << be_nl;
+ << "*); // noncopying version" << be_nl;
if (node->is_nested ())
*os << "friend ";
*os << "CORBA::Boolean operator>>= (const CORBA::Any &, "
@@ -316,7 +316,12 @@ int be_visitor_structure_cs::visit_structure (be_structure *node)
<< "if (stream.decode (" << node->tc_name ()
<< ", &_tao_elem, 0, _tao_env)" << be_nl
<< " == CORBA::TypeCode::TRAVERSE_CONTINUE)" << be_nl
- << " return 1;" << be_nl
+ << "{" << be_idt_nl
+ << "((CORBA::Any *)&_tao_any)->replace (_tao_any.type (), "
+ << "_tao_elem, 1, _tao_env);"
+ << be_nl
+ << " return 1;" << be_uidt_nl
+ << "}" << be_nl
<< "else" << be_nl
<< " return 0;" << be_uidt_nl
<< "}\n\n";
diff --git a/TAO/TAO_IDL/be/be_visitor_union.cpp b/TAO/TAO_IDL/be/be_visitor_union.cpp
index c7c804e2741..c36f7ea199b 100644
--- a/TAO/TAO_IDL/be/be_visitor_union.cpp
+++ b/TAO/TAO_IDL/be/be_visitor_union.cpp
@@ -233,7 +233,7 @@ int be_visitor_union_ch::visit_union (be_union *node)
if (node->is_nested ())
*os << "friend ";
*os << "void operator<<= (CORBA::Any &, " << node->local_name ()
- << "); // noncopying version" << be_nl;
+ << "*); // noncopying version" << be_nl;
if (node->is_nested ())
*os << "friend ";
*os << "CORBA::Boolean operator>>= (const CORBA::Any &, "
@@ -577,7 +577,12 @@ int be_visitor_union_cs::visit_union (be_union *node)
<< "if (stream.decode (" << node->tc_name ()
<< ", &_tao_elem, 0, _tao_env)" << be_nl
<< " == CORBA::TypeCode::TRAVERSE_CONTINUE)" << be_nl
- << " return 1;" << be_nl
+ << "{" << be_idt_nl
+ << "((CORBA::Any *)&_tao_any)->replace (_tao_any.type (), "
+ << "_tao_elem, 1, _tao_env);"
+ << be_nl
+ << " return 1;" << be_uidt_nl
+ << "}" << be_nl
<< "else" << be_nl
<< " return 0;" << be_uidt_nl
<< "}\n\n";
diff --git a/TAO/tao/Any.cpp b/TAO/tao/Any.cpp
index e40adc54d3a..8a62dc2401f 100644
--- a/TAO/tao/Any.cpp
+++ b/TAO/tao/Any.cpp
@@ -44,6 +44,9 @@ CORBA_Any::type (void) const
return this->type_;
}
+// TAO doesn't give any guarantees if the value returned by value can be cast
+// to the desired type. This is a deprecated routine and its use must be
+// avoided. Use the >>= operators.
const void *
CORBA_Any::value (void) const
{
@@ -59,6 +62,7 @@ CORBA_Any::value (void) const
CORBA_Any::CORBA_Any (void)
: type_ (CORBA::_tc_null),
value_ (0),
+ cdr_ (0),
any_owns_data_ (CORBA::B_FALSE),
refcount_ (1)
{
@@ -72,6 +76,8 @@ CORBA_Any::CORBA_Any (CORBA::TypeCode_ptr tc,
void *value,
CORBA::Boolean any_owns_data)
: type_ (tc),
+ value_ (value),
+ cdr_ (0),
any_owns_data_ (any_owns_data),
refcount_ (1)
{
@@ -83,27 +89,20 @@ CORBA_Any::CORBA_Any (CORBA::TypeCode_ptr tc,
CORBA::Environment env;
TAO_OutputCDR stream;
- stream.encode (tc, value, 0, env);
- // retrieve the start of the message block chain and duplicate it
- this->value_ = ACE_Message_Block::duplicate ((ACE_Message_Block *)
- stream.start ());
-
- // we own the data. So first do a deep free and then deallocate it.
- DEEP_FREE (tc, value, 0, env);
- // @@ - address the following
- // delete this->value_;
+ // encode the value
+ stream.encode (this->type_, this->value_, 0, env);
- }
- else
- {
- // we don't own it. Maintain a pointer to the value
- this->value_ = value;
+ // retrieve the start of the message block chain and save it
+ this->cdr_ = ACE_Message_Block::duplicate ((ACE_Message_Block *)
+ stream.start ());
}
}
// Copy constructor for "Any".
CORBA_Any::CORBA_Any (const CORBA_Any &src)
: type_ (src.type_ != 0 ? src.type_ : CORBA::_tc_null),
+ value_ (0),
+ cdr_ (0),
any_owns_data_ (CORBA::B_TRUE),
refcount_ (1)
{
@@ -115,17 +114,20 @@ CORBA_Any::CORBA_Any (const CORBA_Any &src)
// form and must be encoded. Else we must simply duplicate the message block
if (src.any_owns_data_)
{
- this->value_ = ACE_Message_Block::duplicate ((ACE_Message_Block *)
- src.value_);
+ // the data was already encoded in "src". We simply duplicate it to avoid
+ // copies.
+ this->cdr_ = ACE_Message_Block::duplicate ((ACE_Message_Block *)
+ src.cdr_);
}
else
{
+ // "src" did not own the data. So we must do the encoding ourselves
TAO_OutputCDR stream;
stream.encode (this->type_, src.value_, 0, env);
// retrieve the start of the message block chain and duplicate it
- this->value_ = ACE_Message_Block::duplicate ((ACE_Message_Block *)
- stream.start ());
+ this->cdr_ = ACE_Message_Block::duplicate ((ACE_Message_Block *)
+ stream.start ());
}
}
@@ -134,7 +136,6 @@ CORBA_Any &
CORBA_Any::operator= (const CORBA_Any &src)
{
CORBA::Environment env;
- size_t size;
// check if it is a self assignment
if (this == &src)
@@ -147,13 +148,21 @@ CORBA_Any::operator= (const CORBA_Any &src)
if (this->any_owns_data_)
{
// decrement the refcount on the Message_Block we hold
- ACE_Message_Block::release ((ACE_Message_Block *) this->value_);
+ ACE_Message_Block::release ((ACE_Message_Block *) this->cdr_);
+
+ if (this->value_)
+ {
+ DEEP_FREE (this->type_, this->value_, 0, env);
+ }
+
if (this->type_)
this->type_->Release ();
}
// Now copy the contents of the source to ourselves.
this->type_ = (src.type_) != 0 ? src.type_ : CORBA::_tc_null;
+ this->type_->AddRef ();
+ this->value_ = 0;
this->any_owns_data_ = CORBA::B_TRUE;
this->refcount_ = 1;
this->type_->AddRef ();
@@ -162,7 +171,7 @@ CORBA_Any::operator= (const CORBA_Any &src)
// form and must be encoded. Else we must simply duplicate the message block
if (src.any_owns_data_)
{
- this->value_ = ACE_Message_Block::duplicate ((ACE_Message_Block *)
+ this->cdr_ = ACE_Message_Block::duplicate ((ACE_Message_Block *)
src.value_);
}
else
@@ -171,7 +180,7 @@ CORBA_Any::operator= (const CORBA_Any &src)
stream.encode (this->type_, src.value_, 0, env);
// retrieve the start of the message block chain and duplicate it
- this->value_ = ACE_Message_Block::duplicate ((ACE_Message_Block *)
+ this->cdr_ = ACE_Message_Block::duplicate ((ACE_Message_Block *)
stream.start ());
}
return *this;
@@ -188,19 +197,25 @@ CORBA_Any::operator= (const CORBA_Any &src)
CORBA_Any::~CORBA_Any (void)
{
- CORBA::Environment env;
-
// assert (this->refcount_ == 0);
-
+ CORBA::Environment env;
if (this->any_owns_data_)
{
// decrement the refcount on the Message_Block we hold
- ACE_Message_Block::release ((ACE_Message_Block *) this->value_);
- this->value_ = 0;
+ ACE_Message_Block::release ((ACE_Message_Block *) this->cdr_);
+ this->cdr_ = 0;
+
+ // free up the storage for the value
+ if (this->value_)
+ {
+ DEEP_FREE (this->type_, this->value_, 0, env);
+ this->value_ = 0;
+ }
}
if (this->type_)
this->type_->Release ();
+
}
// All-at-once replacement of the contents of an "Any."
@@ -211,17 +226,31 @@ CORBA_Any::replace (CORBA::TypeCode_ptr tc,
CORBA::Boolean any_owns_data,
CORBA::Environment &env)
{
+ // we may be replacing ourselves. So before releasing our typecode, we
+ // increment the refcount of the one that will be assigned to us.
+ tc->AddRef ();
+
if (this->any_owns_data_)
{
- // decrement the refcount on the Message_Block we hold
- ACE_Message_Block::release ((ACE_Message_Block *) this->value_);
+ // decrement the refcount on the Message_Block we currently hold
+ ACE_Message_Block::release ((ACE_Message_Block *) this->cdr_);
+
+ if (this->value_)
+ {
+ DEEP_FREE (this->type_, this->value_, 0, env);
+ }
}
+
+ // release our current typecode
if (this->type_ != 0)
this->type_->Release ();
+ // assign new typecode
this->type_ = tc;
- tc->AddRef ();
+ this->value_ = (void *) value;
this->any_owns_data_ = any_owns_data;
+ this->cdr_ = 0;
+
// if the Any owns the data, we encode the "value" into a CDR stream and
// store it. We also destroy the "value" since we own it.
if (this->any_owns_data_)
@@ -231,19 +260,8 @@ CORBA_Any::replace (CORBA::TypeCode_ptr tc,
stream.encode (tc, value, 0, env);
// retrieve the start of the message block chain and duplicate it
- this->value_ = ACE_Message_Block::duplicate ((ACE_Message_Block *)
- stream.start ());
-
- // we own the data. So first do a deep free and then deallocate it.
- DEEP_FREE (tc, value, 0, env);
- // @@ - address the following
- // delete this->value_;
-
- }
- else
- {
- // we don't own it. Maintain a pointer to the value
- this->value_ = (void *)value;
+ this->cdr_ = ACE_Message_Block::duplicate ((ACE_Message_Block *)
+ stream.start ());
}
}
@@ -253,7 +271,8 @@ CORBA_Any::operator<<= (from_string s)
{
// If the inserted string is bounded, we create a typecode.
static CORBA::Long _oc_string [] =
- { // CDR typecode octets
+ {
+ // CDR typecode octets
TAO_ENCAP_BYTE_ORDER, // native endian + padding; "tricky"
0 // ... unbounded string to start with
};
@@ -273,8 +292,9 @@ CORBA_Any::operator<<= (from_string s)
CORBA::Environment env;
if (s.nocopy_)
- this->replace (tc, new char* (s.val_), CORBA::B_TRUE, env);
- else // copying
+ this->replace (tc, new char* (s.val_), CORBA::B_TRUE, env);
+ else
+ // copying
this->replace (tc, new char* (CORBA::string_dup (s.val_)),
CORBA::B_TRUE, env);
}
@@ -292,7 +312,7 @@ CORBA_Any::operator>>= (CORBA::Short &s) const
{
if (this->any_owns_data_)
{
- TAO_InputCDR stream ((ACE_Message_Block *) this->value_);
+ TAO_InputCDR stream (this->cdr_);
return stream.read_short (s);
}
else
@@ -314,7 +334,7 @@ CORBA_Any::operator>>= (CORBA::UShort &s) const
{
if (this->any_owns_data_)
{
- TAO_InputCDR stream ((ACE_Message_Block *) this->value_);
+ TAO_InputCDR stream (this->cdr_);
return stream.read_ushort (s);
}
else
@@ -336,7 +356,7 @@ CORBA_Any::operator>>= (CORBA::Long &l) const
{
if (this->any_owns_data_)
{
- TAO_InputCDR stream ((ACE_Message_Block *) this->value_);
+ TAO_InputCDR stream (this->cdr_);
return stream.read_long (l);
}
else
@@ -358,7 +378,7 @@ CORBA_Any::operator>>= (CORBA::ULong &l) const
{
if (this->any_owns_data_)
{
- TAO_InputCDR stream ((ACE_Message_Block *) this->value_);
+ TAO_InputCDR stream (this->cdr_);
return stream.read_ulong (l);
}
else
@@ -380,7 +400,7 @@ CORBA_Any::operator>>= (CORBA::Float &f) const
{
if (this->any_owns_data_)
{
- TAO_InputCDR stream ((ACE_Message_Block *) this->value_);
+ TAO_InputCDR stream (this->cdr_);
return stream.read_float (f);
}
else
@@ -402,7 +422,7 @@ CORBA_Any::operator>>= (CORBA::Double &d) const
{
if (this->any_owns_data_)
{
- TAO_InputCDR stream ((ACE_Message_Block *) this->value_);
+ TAO_InputCDR stream (this->cdr_);
return stream.read_double (d);
}
else
@@ -424,7 +444,8 @@ CORBA_Any::operator>>= (CORBA::Any &a) const
{
if (this->any_owns_data_)
{
- TAO_InputCDR stream ((ACE_Message_Block *) this->value_);
+ TAO_InputCDR stream (this->cdr_);
+ // decode the CDR
return (stream.decode (CORBA::_tc_any, &a, 0, env)
== CORBA::TypeCode::TRAVERSE_CONTINUE) ? 1 : 0;
}
@@ -447,7 +468,7 @@ CORBA_Any::operator>>= (char *&s) const
{
if (this->any_owns_data_)
{
- TAO_InputCDR stream ((ACE_Message_Block *) this->value_);
+ TAO_InputCDR stream (this->cdr_);
return stream.read_string (s);
}
else
@@ -543,8 +564,9 @@ CORBA_Any::operator>>= (to_string s) const
{
if (this->any_owns_data_)
{
- TAO_InputCDR stream ((ACE_Message_Block *) this->value_);
- return stream.read_string (s.val_);
+ TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_);
+ CORBA::Boolean flag = stream.read_string (s.val_);
+ return flag;
}
else
{
@@ -567,9 +589,13 @@ CORBA_Any::operator>>= (to_object obj) const
{
if (this->any_owns_data_)
{
- TAO_InputCDR stream ((ACE_Message_Block *) this->value_);
- return (stream.decode (CORBA::_tc_Object, &obj.ref_, 0, env)
- == CORBA::TypeCode::TRAVERSE_CONTINUE) ? 1 : 0;
+ TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_);
+ CORBA::Boolean flag = (stream.decode (CORBA::_tc_Object,
+ &obj.ref_, 0, env)
+ == CORBA::TypeCode::TRAVERSE_CONTINUE) ? 1:0;
+ // we own this allocated value
+ // this->value_ = obj.ref_;
+ return flag;
}
else
{
diff --git a/TAO/tao/Any.h b/TAO/tao/Any.h
index 99b6092f33c..989f64693ec 100644
--- a/TAO/tao/Any.h
+++ b/TAO/tao/Any.h
@@ -279,6 +279,9 @@ private:
void *value_;
// Value for the <Any>.
+ ACE_Message_Block *cdr_;
+ // encoded value.
+
CORBA::Boolean any_owns_data_;
// Flag that indicates the ORB is responsible for deleting the data.
diff --git a/TAO/tao/Typecode.cpp b/TAO/tao/Typecode.cpp
index 9cfdbc5489e..cbeb7c02104 100644
--- a/TAO/tao/Typecode.cpp
+++ b/TAO/tao/Typecode.cpp
@@ -68,7 +68,8 @@ CORBA_TypeCode::CORBA_TypeCode (CORBA::TCKind kind,
const char *buffer,
CORBA::Boolean orb_owns_tc,
CORBA::TypeCode_ptr parent)
- : length_ (length - 4),
+ // : length_ (length - 4),
+ : length_ (length),
kind_ (kind),
parent_ (parent),
refcount_ (1),
@@ -121,7 +122,7 @@ CORBA_TypeCode::CORBA_TypeCode (CORBA::TCKind kind,
char* start = ptr_align_binary (this->non_aligned_buffer_,
CDR::MAX_ALIGNMENT);
- (void) ACE_OS::memcpy (start, buffer + 4, this->length_);
+ (void) ACE_OS::memcpy (start, buffer, this->length_);
this->buffer_ = start;
// The ORB does not own this typecode.
@@ -136,7 +137,7 @@ CORBA_TypeCode::CORBA_TypeCode (CORBA::TCKind kind,
ACE_reinterpret_cast(const CORBA::Octet*,buffer);
this->byte_order_ = *ptr;
- this->buffer_ = buffer + 4;
+ this->buffer_ = buffer;
}
}
@@ -1195,7 +1196,8 @@ CORBA_TypeCode::private_name (CORBA::Environment &env) const
case CORBA::tk_alias:
case CORBA::tk_except:
{
- TAO_InputCDR stream (this->buffer_, this->length_,
+ // setup an encapsulation
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
// skip the typecode ID
@@ -1241,7 +1243,8 @@ CORBA_TypeCode::private_member_count (CORBA::Environment &env) const
case CORBA::tk_struct:
{
CORBA::ULong members;
- TAO_InputCDR stream (this->buffer_, this->length_,
+ // setup an encapsulation
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
// skip rest of header (type ID and name) and collect the
@@ -1261,7 +1264,8 @@ CORBA_TypeCode::private_member_count (CORBA::Environment &env) const
case CORBA::tk_union:
{
CORBA::ULong members;
- TAO_InputCDR stream (this->buffer_, this->length_,
+ // setup an encapsulation
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
// skip rest of header (type ID, name, etc...) and collect the
@@ -1305,7 +1309,7 @@ CORBA_TypeCode::private_member_type (CORBA::ULong index,
// Build the de-encapsulating CDR stream, bypassing the stringent
// alignment tests (we're a bit looser in what we need here, and we
// _know_ we're OK). Then skip the byte order code.
- TAO_InputCDR stream (this->buffer_, this->length_,
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
CORBA::TypeCode_ptr tc = 0;
@@ -1472,7 +1476,7 @@ CORBA_TypeCode::private_member_name (CORBA::ULong index,
// Build the de-encapsulating CDR stream, bypassing the stringent
// alignment tests (we're a bit looser in what we need here, and we
// _know_ we're OK). Then skip the byte order code.
- TAO_InputCDR stream (this->buffer_, this->length_,
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
CORBA::TypeCode_ptr tc = 0;
@@ -1683,7 +1687,7 @@ CORBA_TypeCode::private_member_label (CORBA::ULong n,
// this function is only applicable to the CORBA::tk_union TC
if (this->kind_ == CORBA::tk_union)
{
- TAO_InputCDR stream (this->buffer_, this->length_,
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
// skip ID and name, and then get the discriminant TC
@@ -1765,7 +1769,7 @@ CORBA_TypeCode::private_member_label (CORBA::ULong n,
CORBA::TypeCode_ptr
CORBA_TypeCode::private_discriminator_type (CORBA::Environment &env) const
{
- TAO_InputCDR stream (this->buffer_, this->length_,
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
// skip ID and name, and then get the discriminant TC
@@ -1789,7 +1793,7 @@ CORBA_TypeCode::private_discriminator_type (CORBA::Environment &env) const
CORBA::Long
CORBA_TypeCode::private_default_index (CORBA::Environment &env) const
{
- TAO_InputCDR stream (this->buffer_, this->length_,
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
// skip ID and name, and then get the discriminant TC
@@ -1812,7 +1816,7 @@ CORBA_TypeCode::private_default_index (CORBA::Environment &env) const
CORBA::Long
CORBA_TypeCode::private_length (CORBA::Environment &env) const
{
- TAO_InputCDR stream (this->buffer_, this->length_,
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
switch (this->kind_)
{
@@ -1855,7 +1859,7 @@ CORBA_TypeCode::private_length (CORBA::Environment &env) const
CORBA::TypeCode_ptr
CORBA_TypeCode::private_content_type (CORBA::Environment &env) const
{
- TAO_InputCDR stream (this->buffer_, this->length_,
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
switch (kind_)
@@ -1904,7 +1908,7 @@ CORBA_TypeCode::private_content_type (CORBA::Environment &env) const
CORBA::ULong
CORBA_TypeCode::private_discrim_pad_size (CORBA::Environment &env)
{
- TAO_InputCDR stream (this->buffer_, this->length_,
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
size_t discrim_size;
@@ -1959,7 +1963,7 @@ CORBA_TypeCode::param_count (CORBA::Environment &env) const
case CORBA::tk_struct:
{
CORBA::ULong members;
- TAO_InputCDR stream (this->buffer_, this->length_,
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
// skip rest of header (type ID and name) and collect the
@@ -1977,7 +1981,7 @@ CORBA_TypeCode::param_count (CORBA::Environment &env) const
case CORBA::tk_enum:
{
CORBA::ULong members;
- TAO_InputCDR stream (this->buffer_, this->length_,
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
// skip rest of header (type ID and name) and collect the
@@ -1995,7 +1999,7 @@ CORBA_TypeCode::param_count (CORBA::Environment &env) const
case CORBA::tk_union:
{
CORBA::ULong members;
- TAO_InputCDR stream (this->buffer_, this->length_,
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
// skip rest of header (type ID, name, etc...) and collect the
@@ -2052,7 +2056,7 @@ CORBA_TypeCode::ulong_param (CORBA::ULong n,
// Build CDR stream for encapsulated params, and skip the
// typecode up front.
- TAO_InputCDR stream (this->buffer_, this->length_,
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
if (!skip_typecode (stream))
@@ -2107,7 +2111,7 @@ CORBA_TypeCode::typecode_param (CORBA::ULong n,
// alignment tests (we're a bit looser in what we need here, and we
// _know_ we're OK). Then skip the byte order code.
- TAO_InputCDR stream (this->buffer_, this->length_,
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
CORBA::TypeCode_ptr tc = 0;
@@ -2276,7 +2280,7 @@ CORBA::TypeCode::private_size (CORBA::Environment &env)
}
size_t alignment;
- TAO_InputCDR stream (this->buffer_, this->length_,
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
private_state_->tc_size_known_ = CORBA::B_TRUE;
@@ -2308,7 +2312,7 @@ CORBA::TypeCode::private_alignment (CORBA::Environment &env)
}
size_t alignment;
- TAO_InputCDR stream (this->buffer_, this->length_,
+ TAO_InputCDR stream (this->buffer_+4, this->length_-4,
this->byte_order_);
(void) TAO_IIOP_Interpreter::table_[kind_].calc_ (&stream,
diff --git a/TAO/tao/decode.cpp b/TAO/tao/decode.cpp
index 459e8e4256e..20c1b29a537 100644
--- a/TAO/tao/decode.cpp
+++ b/TAO/tao/decode.cpp
@@ -222,7 +222,7 @@ TAO_Marshal_TypeCode::decode (CORBA::TypeCode_ptr,
// heap access ... also, to speed things up!
if (kind < CORBA::TC_KIND_COUNT
&& (*tcp = __tc_consts [(u_int) kind]) != 0)
- *tcp = __tc_consts [(u_int) kind];
+ *tcp = CORBA::TypeCode::_duplicate (__tc_consts [(u_int) kind]);
else if (kind == ~(CORBA::ULong)0 || kind < CORBA::TC_KIND_COUNT)
{
// Either a non-constant typecode or an indirected typecode.
@@ -248,13 +248,15 @@ TAO_Marshal_TypeCode::decode (CORBA::TypeCode_ptr,
if (bound == 0)
{
if (kind == CORBA::tk_string)
- *tcp = CORBA::_tc_string;
+ *tcp = CORBA::TypeCode::_duplicate
+ (CORBA::_tc_string);
else
- *tcp = CORBA::_tc_wstring;
+ *tcp = CORBA::TypeCode::_duplicate
+ (CORBA::_tc_wstring);
}
else
{
- CORBA::Long _oc_bounded_string [2] =
+ CORBA::Long _oc_bounded_string [] =
{TAO_ENCAP_BYTE_ORDER, 0};
_oc_bounded_string [1] = (CORBA::Long) bound;
// Bounded string. Save the bounds