From e78d2f32579091e9bc0408f6c28d5165b0d50942 Mon Sep 17 00:00:00 2001 From: parsons Date: Thu, 2 Sep 1999 12:52:57 +0000 Subject: Alignment fix for Borland Builder. --- TAO/tao/decode.cpp | 41 ++++++++++++++++------------------------- TAO/tao/deep_free.cpp | 14 ++++++++++++++ TAO/tao/encode.cpp | 14 ++++++++++++++ 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/TAO/tao/decode.cpp b/TAO/tao/decode.cpp index 2635ddea42c..1ff0746023a 100644 --- a/TAO/tao/decode.cpp +++ b/TAO/tao/decode.cpp @@ -344,9 +344,9 @@ TAO_Marshal_TypeCode::decode (CORBA::TypeCode_ptr, // have a parent, then the application must free it. // allocate a new TypeCode -#if 1 + // This may produce a memory leak, because - // callers are sloppy about removing this + // callers are sloppy about removing these // objects. CORBA::Long _oc_bounded_string [] = {TAO_ENCAP_BYTE_ORDER, 0}; @@ -357,29 +357,6 @@ TAO_Marshal_TypeCode::decode (CORBA::TypeCode_ptr, ACE_reinterpret_cast(char*,_oc_bounded_string), 0, sizeof (CORBA::String_var), 0); -#elif 0 - // This one fails because we are passing the - // parent but the buffer (_oc_bounded_string) is - // not pointing to the parent CDR stream - // (hence no sharing) and the length is wrong - // (should be 8 not bounds). - CORBA::Long _oc_bounded_string [] = - {TAO_ENCAP_BYTE_ORDER, 0}; - // Bounded string. Save the bounds - _oc_bounded_string [1] = (CORBA::Long) bound; - *tcp = new CORBA::TypeCode ((CORBA::TCKind) kind, - bound, (char *) &_oc_bounded_string, - 0, sizeof - (CORBA::String_var), parent); -#else - // This depends on the fact that is - // actually pointing to the parent CDR stream, - // it is untested. - *tcp = new CORBA::TypeCode ((CORBA::TCKind) kind, - 8, - stream->rd_ptr () - 8, - 0, 0, parent); -#endif } } } @@ -623,11 +600,25 @@ TAO_Marshal_Struct::decode (CORBA::TypeCode_ptr tc, alignment = param->alignment (ACE_TRY_ENV); ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); + // MSVC built code works with either of these, but Borland + // Builder needs the first one, whereas Sun compilers + // need the second one. +#if defined (WIN32) + align_offset = + (ptr_arith_t) ptr_align_binary (data, alignment) + - (ptr_arith_t) data + - (ptr_arith_t) ptr_align_binary (start_addr, alignment) + - (ptr_arith_t) start_addr; + if (align_offset < 0) + align_offset += alignment; +#else align_offset = (ptr_arith_t) ptr_align_binary (data, alignment) - (ptr_arith_t) data + (ptr_arith_t) ptr_align_binary (start_addr, alignment) - (ptr_arith_t) start_addr; +#endif + // if both the start_addr and data are not aligned as per // the alignment, we do not add the offset data = (const void *) ((ptr_arith_t) data + diff --git a/TAO/tao/deep_free.cpp b/TAO/tao/deep_free.cpp index b3cb907dfc1..fcf04851858 100644 --- a/TAO/tao/deep_free.cpp +++ b/TAO/tao/deep_free.cpp @@ -211,11 +211,25 @@ TAO_Marshal_Struct::deep_free (CORBA::TypeCode_ptr tc, alignment = param->alignment (ACE_TRY_ENV); ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); + // MSVC built code works with either of these, but Borland + // Builder needs the first one, whereas Sun compilers + // need the second one. +#if defined (WIN32) + align_offset = + (ptr_arith_t) ptr_align_binary (source, alignment) + - (ptr_arith_t) source + - (ptr_arith_t) ptr_align_binary (start_addr, alignment) + - (ptr_arith_t) start_addr; + if (align_offset < 0) + align_offset += alignment; +#else align_offset = (ptr_arith_t) ptr_align_binary (source, alignment) - (ptr_arith_t) source + (ptr_arith_t) ptr_align_binary (start_addr, alignment) - (ptr_arith_t) start_addr; +#endif + // if both the start_addr and data are not aligned as per // the alignment, we do not add the offset source = (const void *) ((ptr_arith_t) source + diff --git a/TAO/tao/encode.cpp b/TAO/tao/encode.cpp index 1676ee0183d..a1f825e3a37 100644 --- a/TAO/tao/encode.cpp +++ b/TAO/tao/encode.cpp @@ -316,11 +316,25 @@ TAO_Marshal_Struct::encode (CORBA::TypeCode_ptr tc, alignment = param->alignment (ACE_TRY_ENV); ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); + // MSVC built code works with either of these, but Borland + // Builder needs the first one, whereas Sun compilers + // need the second one. +#if defined (WIN32) + align_offset = + (ptr_arith_t) ptr_align_binary (data, alignment) + - (ptr_arith_t) data + - (ptr_arith_t) ptr_align_binary (start_addr, alignment) + - (ptr_arith_t) start_addr; + if (align_offset < 0) + align_offset += alignment; +#else align_offset = (ptr_arith_t) ptr_align_binary (data, alignment) - (ptr_arith_t) data + (ptr_arith_t) ptr_align_binary (start_addr, alignment) - (ptr_arith_t) start_addr; +#endif + // if both the start_addr and data are not aligned as per // the alignment, we do not add the offset data = (const void *) ((ptr_arith_t) data + -- cgit v1.2.1