1*129fa3d1SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*129fa3d1SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*129fa3d1SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*129fa3d1SAndrew Rist * distributed with this work for additional information 6*129fa3d1SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*129fa3d1SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*129fa3d1SAndrew Rist * "License"); you may not use this file except in compliance 9*129fa3d1SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*129fa3d1SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*129fa3d1SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*129fa3d1SAndrew Rist * software distributed under the License is distributed on an 15*129fa3d1SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*129fa3d1SAndrew Rist * KIND, either express or implied. See the License for the 17*129fa3d1SAndrew Rist * specific language governing permissions and limitations 18*129fa3d1SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*129fa3d1SAndrew Rist *************************************************************/ 21*129fa3d1SAndrew Rist 22*129fa3d1SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_cppu.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <cstddef> 28cdf0e10cSrcweir #include <stdio.h> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include "cppu/macros.hxx" 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include "osl/mutex.hxx" 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include "constr.hxx" 35cdf0e10cSrcweir #include "destr.hxx" 36cdf0e10cSrcweir #include "copy.hxx" 37cdf0e10cSrcweir #include "assign.hxx" 38cdf0e10cSrcweir #include "eq.hxx" 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include "boost/static_assert.hpp" 41cdf0e10cSrcweir 42cdf0e10cSrcweir 43cdf0e10cSrcweir using namespace ::cppu; 44cdf0e10cSrcweir using namespace ::rtl; 45cdf0e10cSrcweir using namespace ::osl; 46cdf0e10cSrcweir 47cdf0e10cSrcweir 48cdf0e10cSrcweir namespace cppu 49cdf0e10cSrcweir { 50cdf0e10cSrcweir 51cdf0e10cSrcweir // Sequence<>() (default ctor) relies on this being static: 52cdf0e10cSrcweir uno_Sequence g_emptySeq = { 1, 0, { 0 } }; 53cdf0e10cSrcweir typelib_TypeDescriptionReference * g_pVoidType = 0; 54cdf0e10cSrcweir 55cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 56cdf0e10cSrcweir void * binuno_queryInterface( void * pUnoI, typelib_TypeDescriptionReference * pDestType ) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir // init queryInterface() td 59cdf0e10cSrcweir static typelib_TypeDescription * g_pQITD = 0; 60cdf0e10cSrcweir if (0 == g_pQITD) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() ); 63cdf0e10cSrcweir if (0 == g_pQITD) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir typelib_TypeDescriptionReference * type_XInterface = 66cdf0e10cSrcweir * typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE ); 67cdf0e10cSrcweir typelib_InterfaceTypeDescription * pTXInterfaceDescr = 0; 68cdf0e10cSrcweir TYPELIB_DANGER_GET( (typelib_TypeDescription **) &pTXInterfaceDescr, type_XInterface ); 69cdf0e10cSrcweir OSL_ASSERT( pTXInterfaceDescr->ppAllMembers ); 70cdf0e10cSrcweir typelib_typedescriptionreference_getDescription( 71cdf0e10cSrcweir &g_pQITD, pTXInterfaceDescr->ppAllMembers[ 0 ] ); 72cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( (typelib_TypeDescription *) pTXInterfaceDescr ); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir uno_Any aRet, aExc; 77cdf0e10cSrcweir uno_Any * pExc = &aExc; 78cdf0e10cSrcweir void * aArgs[ 1 ]; 79cdf0e10cSrcweir aArgs[ 0 ] = &pDestType; 80cdf0e10cSrcweir (*((uno_Interface *) pUnoI)->pDispatcher)( 81cdf0e10cSrcweir (uno_Interface *) pUnoI, g_pQITD, &aRet, aArgs, &pExc ); 82cdf0e10cSrcweir 83cdf0e10cSrcweir uno_Interface * ret = 0; 84cdf0e10cSrcweir if (0 == pExc) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir typelib_TypeDescriptionReference * ret_type = aRet.pType; 87cdf0e10cSrcweir switch (ret_type->eTypeClass) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir case typelib_TypeClass_VOID: // common case 90cdf0e10cSrcweir typelib_typedescriptionreference_release( ret_type ); 91cdf0e10cSrcweir break; 92cdf0e10cSrcweir case typelib_TypeClass_INTERFACE: 93cdf0e10cSrcweir // tweaky... avoiding acquire/ release pair 94cdf0e10cSrcweir typelib_typedescriptionreference_release( ret_type ); 95cdf0e10cSrcweir ret = (uno_Interface *) aRet.pReserved; // serving acquired interface 96cdf0e10cSrcweir break; 97cdf0e10cSrcweir default: 98cdf0e10cSrcweir _destructAny( &aRet, 0 ); 99cdf0e10cSrcweir break; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir } 102cdf0e10cSrcweir else 103cdf0e10cSrcweir { 104cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 105cdf0e10cSrcweir OUStringBuffer buf( 128 ); 106cdf0e10cSrcweir buf.appendAscii( 107cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("### exception occured querying for interface ") ); 108cdf0e10cSrcweir buf.append( * reinterpret_cast< OUString const * >( &pDestType->pTypeName ) ); 109cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(": [") ); 110cdf0e10cSrcweir buf.append( * reinterpret_cast< OUString const * >( &pExc->pType->pTypeName ) ); 111cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] ") ); 112cdf0e10cSrcweir // Message is very first member 113cdf0e10cSrcweir buf.append( * reinterpret_cast< OUString const * >( pExc->pData ) ); 114cdf0e10cSrcweir OString cstr( 115cdf0e10cSrcweir OUStringToOString( buf.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US ) ); 116cdf0e10cSrcweir OSL_ENSURE( 0, cstr.getStr() ); 117cdf0e10cSrcweir #endif 118cdf0e10cSrcweir uno_any_destruct( pExc, 0 ); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir return ret; 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir //================================================================================================== 124cdf0e10cSrcweir void defaultConstructStruct( 125cdf0e10cSrcweir void * pMem, 126cdf0e10cSrcweir typelib_CompoundTypeDescription * pCompType ) 127cdf0e10cSrcweir SAL_THROW( () ) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir _defaultConstructStruct( pMem, pCompType ); 130cdf0e10cSrcweir } 131cdf0e10cSrcweir //================================================================================================== 132cdf0e10cSrcweir void copyConstructStruct( 133cdf0e10cSrcweir void * pDest, void * pSource, 134cdf0e10cSrcweir typelib_CompoundTypeDescription * pTypeDescr, 135cdf0e10cSrcweir uno_AcquireFunc acquire, uno_Mapping * mapping ) 136cdf0e10cSrcweir SAL_THROW( () ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir _copyConstructStruct( pDest, pSource, pTypeDescr, acquire, mapping ); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir //================================================================================================== 141cdf0e10cSrcweir void destructStruct( 142cdf0e10cSrcweir void * pValue, 143cdf0e10cSrcweir typelib_CompoundTypeDescription * pTypeDescr, 144cdf0e10cSrcweir uno_ReleaseFunc release ) 145cdf0e10cSrcweir SAL_THROW( () ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir _destructStruct( pValue, pTypeDescr, release ); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir //================================================================================================== 150cdf0e10cSrcweir sal_Bool equalStruct( 151cdf0e10cSrcweir void * pDest, void *pSource, 152cdf0e10cSrcweir typelib_CompoundTypeDescription * pTypeDescr, 153cdf0e10cSrcweir uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) 154cdf0e10cSrcweir SAL_THROW( () ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir return _equalStruct( pDest, pSource, pTypeDescr, queryInterface, release ); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir //================================================================================================== 159cdf0e10cSrcweir sal_Bool assignStruct( 160cdf0e10cSrcweir void * pDest, void * pSource, 161cdf0e10cSrcweir typelib_CompoundTypeDescription * pTypeDescr, 162cdf0e10cSrcweir uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) 163cdf0e10cSrcweir SAL_THROW( () ) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir return _assignStruct( pDest, pSource, pTypeDescr, queryInterface, acquire, release ); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir //============================================================================== 169cdf0e10cSrcweir uno_Sequence * copyConstructSequence( 170cdf0e10cSrcweir uno_Sequence * pSource, 171cdf0e10cSrcweir typelib_TypeDescriptionReference * pElementType, 172cdf0e10cSrcweir uno_AcquireFunc acquire, uno_Mapping * mapping ) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir return icopyConstructSequence( pSource, pElementType, acquire, mapping ); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir //============================================================================== 178cdf0e10cSrcweir void destructSequence( 179cdf0e10cSrcweir uno_Sequence * pSequence, 180cdf0e10cSrcweir typelib_TypeDescriptionReference * pType, 181cdf0e10cSrcweir typelib_TypeDescription * pTypeDescr, 182cdf0e10cSrcweir uno_ReleaseFunc release ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir idestructSequence( pSequence, pType, pTypeDescr, release ); 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187cdf0e10cSrcweir //================================================================================================== 188cdf0e10cSrcweir sal_Bool equalSequence( 189cdf0e10cSrcweir uno_Sequence * pDest, uno_Sequence * pSource, 190cdf0e10cSrcweir typelib_TypeDescriptionReference * pElementType, 191cdf0e10cSrcweir uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) 192cdf0e10cSrcweir SAL_THROW( () ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir return _equalSequence( pDest, pSource, pElementType, queryInterface, release ); 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir extern "C" 198cdf0e10cSrcweir { 199cdf0e10cSrcweir //################################################################################################## 200cdf0e10cSrcweir void SAL_CALL uno_type_constructData( 201cdf0e10cSrcweir void * pMem, typelib_TypeDescriptionReference * pType ) 202cdf0e10cSrcweir SAL_THROW_EXTERN_C() 203cdf0e10cSrcweir { 204cdf0e10cSrcweir _defaultConstructData( pMem, pType, 0 ); 205cdf0e10cSrcweir } 206cdf0e10cSrcweir //################################################################################################## 207cdf0e10cSrcweir void SAL_CALL uno_constructData( 208cdf0e10cSrcweir void * pMem, typelib_TypeDescription * pTypeDescr ) 209cdf0e10cSrcweir SAL_THROW_EXTERN_C() 210cdf0e10cSrcweir { 211cdf0e10cSrcweir _defaultConstructData( pMem, pTypeDescr->pWeakRef, pTypeDescr ); 212cdf0e10cSrcweir } 213cdf0e10cSrcweir //################################################################################################## 214cdf0e10cSrcweir void SAL_CALL uno_type_destructData( 215cdf0e10cSrcweir void * pValue, typelib_TypeDescriptionReference * pType, 216cdf0e10cSrcweir uno_ReleaseFunc release ) 217cdf0e10cSrcweir SAL_THROW_EXTERN_C() 218cdf0e10cSrcweir { 219cdf0e10cSrcweir _destructData( pValue, pType, 0, release ); 220cdf0e10cSrcweir } 221cdf0e10cSrcweir //################################################################################################## 222cdf0e10cSrcweir void SAL_CALL uno_destructData( 223cdf0e10cSrcweir void * pValue, 224cdf0e10cSrcweir typelib_TypeDescription * pTypeDescr, 225cdf0e10cSrcweir uno_ReleaseFunc release ) 226cdf0e10cSrcweir SAL_THROW_EXTERN_C() 227cdf0e10cSrcweir { 228cdf0e10cSrcweir _destructData( pValue, pTypeDescr->pWeakRef, pTypeDescr, release ); 229cdf0e10cSrcweir } 230cdf0e10cSrcweir //################################################################################################## 231cdf0e10cSrcweir void SAL_CALL uno_type_copyData( 232cdf0e10cSrcweir void * pDest, void * pSource, 233cdf0e10cSrcweir typelib_TypeDescriptionReference * pType, 234cdf0e10cSrcweir uno_AcquireFunc acquire ) 235cdf0e10cSrcweir SAL_THROW_EXTERN_C() 236cdf0e10cSrcweir { 237cdf0e10cSrcweir _copyConstructData( pDest, pSource, pType, 0, acquire, 0 ); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir //################################################################################################## 240cdf0e10cSrcweir void SAL_CALL uno_copyData( 241cdf0e10cSrcweir void * pDest, void * pSource, 242cdf0e10cSrcweir typelib_TypeDescription * pTypeDescr, 243cdf0e10cSrcweir uno_AcquireFunc acquire ) 244cdf0e10cSrcweir SAL_THROW_EXTERN_C() 245cdf0e10cSrcweir { 246cdf0e10cSrcweir _copyConstructData( pDest, pSource, pTypeDescr->pWeakRef, pTypeDescr, acquire, 0 ); 247cdf0e10cSrcweir } 248cdf0e10cSrcweir //################################################################################################## 249cdf0e10cSrcweir void SAL_CALL uno_type_copyAndConvertData( 250cdf0e10cSrcweir void * pDest, void * pSource, 251cdf0e10cSrcweir typelib_TypeDescriptionReference * pType, 252cdf0e10cSrcweir uno_Mapping * mapping ) 253cdf0e10cSrcweir SAL_THROW_EXTERN_C() 254cdf0e10cSrcweir { 255cdf0e10cSrcweir _copyConstructData( pDest, pSource, pType, 0, 0, mapping ); 256cdf0e10cSrcweir } 257cdf0e10cSrcweir //################################################################################################## 258cdf0e10cSrcweir void SAL_CALL uno_copyAndConvertData( 259cdf0e10cSrcweir void * pDest, void * pSource, 260cdf0e10cSrcweir typelib_TypeDescription * pTypeDescr, 261cdf0e10cSrcweir uno_Mapping * mapping ) 262cdf0e10cSrcweir SAL_THROW_EXTERN_C() 263cdf0e10cSrcweir { 264cdf0e10cSrcweir _copyConstructData( pDest, pSource, pTypeDescr->pWeakRef, pTypeDescr, 0, mapping ); 265cdf0e10cSrcweir } 266cdf0e10cSrcweir //################################################################################################## 267cdf0e10cSrcweir sal_Bool SAL_CALL uno_type_equalData( 268cdf0e10cSrcweir void * pVal1, typelib_TypeDescriptionReference * pVal1Type, 269cdf0e10cSrcweir void * pVal2, typelib_TypeDescriptionReference * pVal2Type, 270cdf0e10cSrcweir uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) 271cdf0e10cSrcweir SAL_THROW_EXTERN_C() 272cdf0e10cSrcweir { 273cdf0e10cSrcweir return _equalData( 274cdf0e10cSrcweir pVal1, pVal1Type, 0, 275cdf0e10cSrcweir pVal2, pVal2Type, 0, 276cdf0e10cSrcweir queryInterface, release ); 277cdf0e10cSrcweir } 278cdf0e10cSrcweir //################################################################################################## 279cdf0e10cSrcweir sal_Bool SAL_CALL uno_equalData( 280cdf0e10cSrcweir void * pVal1, typelib_TypeDescription * pVal1TD, 281cdf0e10cSrcweir void * pVal2, typelib_TypeDescription * pVal2TD, 282cdf0e10cSrcweir uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) 283cdf0e10cSrcweir SAL_THROW_EXTERN_C() 284cdf0e10cSrcweir { 285cdf0e10cSrcweir return _equalData( 286cdf0e10cSrcweir pVal1, pVal1TD->pWeakRef, pVal1TD, 287cdf0e10cSrcweir pVal2, pVal2TD->pWeakRef, pVal2TD, 288cdf0e10cSrcweir queryInterface, release ); 289cdf0e10cSrcweir } 290cdf0e10cSrcweir //################################################################################################## 291cdf0e10cSrcweir sal_Bool SAL_CALL uno_type_assignData( 292cdf0e10cSrcweir void * pDest, typelib_TypeDescriptionReference * pDestType, 293cdf0e10cSrcweir void * pSource, typelib_TypeDescriptionReference * pSourceType, 294cdf0e10cSrcweir uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) 295cdf0e10cSrcweir SAL_THROW_EXTERN_C() 296cdf0e10cSrcweir { 297cdf0e10cSrcweir return _assignData( 298cdf0e10cSrcweir pDest, pDestType, 0, 299cdf0e10cSrcweir pSource, pSourceType, 0, 300cdf0e10cSrcweir queryInterface, acquire, release ); 301cdf0e10cSrcweir } 302cdf0e10cSrcweir //################################################################################################## 303cdf0e10cSrcweir sal_Bool SAL_CALL uno_assignData( 304cdf0e10cSrcweir void * pDest, typelib_TypeDescription * pDestTD, 305cdf0e10cSrcweir void * pSource, typelib_TypeDescription * pSourceTD, 306cdf0e10cSrcweir uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) 307cdf0e10cSrcweir SAL_THROW_EXTERN_C() 308cdf0e10cSrcweir { 309cdf0e10cSrcweir return _assignData( 310cdf0e10cSrcweir pDest, pDestTD->pWeakRef, pDestTD, 311cdf0e10cSrcweir pSource, pSourceTD->pWeakRef, pSourceTD, 312cdf0e10cSrcweir queryInterface, acquire, release ); 313cdf0e10cSrcweir } 314cdf0e10cSrcweir //################################################################################################## 315cdf0e10cSrcweir sal_Bool SAL_CALL uno_type_isAssignableFromData( 316cdf0e10cSrcweir typelib_TypeDescriptionReference * pAssignable, 317cdf0e10cSrcweir void * pFrom, typelib_TypeDescriptionReference * pFromType, 318cdf0e10cSrcweir uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) 319cdf0e10cSrcweir SAL_THROW_EXTERN_C() 320cdf0e10cSrcweir { 321cdf0e10cSrcweir if (::typelib_typedescriptionreference_isAssignableFrom( pAssignable, pFromType )) 322cdf0e10cSrcweir return sal_True; 323cdf0e10cSrcweir if (typelib_TypeClass_INTERFACE != pFromType->eTypeClass || 324cdf0e10cSrcweir typelib_TypeClass_INTERFACE != pAssignable->eTypeClass) 325cdf0e10cSrcweir { 326cdf0e10cSrcweir return sal_False; 327cdf0e10cSrcweir } 328cdf0e10cSrcweir 329cdf0e10cSrcweir // query 330cdf0e10cSrcweir if (0 == pFrom) 331cdf0e10cSrcweir return sal_False; 332cdf0e10cSrcweir void * pInterface = *(void **)pFrom; 333cdf0e10cSrcweir if (0 == pInterface) 334cdf0e10cSrcweir return sal_False; 335cdf0e10cSrcweir 336cdf0e10cSrcweir if (0 == queryInterface) 337cdf0e10cSrcweir queryInterface = binuno_queryInterface; 338cdf0e10cSrcweir void * p = (*queryInterface)( pInterface, pAssignable ); 339cdf0e10cSrcweir _release( p, release ); 340cdf0e10cSrcweir return (0 != p); 341cdf0e10cSrcweir } 342cdf0e10cSrcweir } 343cdf0e10cSrcweir 344cdf0e10cSrcweir 345cdf0e10cSrcweir //################################################################################################## 346cdf0e10cSrcweir //################################################################################################## 347cdf0e10cSrcweir //################################################################################################## 348cdf0e10cSrcweir 349cdf0e10cSrcweir 350cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 351cdf0e10cSrcweir 352cdf0e10cSrcweir #if defined( SAL_W32) 353cdf0e10cSrcweir #pragma pack(push, 8) 354cdf0e10cSrcweir #elif defined(SAL_OS2) 355cdf0e10cSrcweir #pragma pack(push, 4) 356cdf0e10cSrcweir #endif 357cdf0e10cSrcweir 358cdf0e10cSrcweir #if defined(INTEL) \ 359cdf0e10cSrcweir && (defined(__GNUC__) && (defined(LINUX) || defined(FREEBSD) || defined(OS2)) || defined(MACOSX) \ 360cdf0e10cSrcweir || defined(__SUNPRO_CC) && defined(SOLARIS)) 361cdf0e10cSrcweir #define MAX_ALIGNMENT_4 362cdf0e10cSrcweir #endif 363cdf0e10cSrcweir 364cdf0e10cSrcweir #define OFFSET_OF( s, m ) reinterpret_cast< std::size_t >((char *)&((s *)16)->m -16) 365cdf0e10cSrcweir 366cdf0e10cSrcweir #define BINTEST_VERIFY( c ) \ 367cdf0e10cSrcweir if (! (c)) { fprintf( stderr, "### binary compatibility test failed: %s [line %d]!!!\n", #c, __LINE__ ); abort(); } 368cdf0e10cSrcweir #define BINTEST_VERIFYOFFSET( s, m, n ) \ 369cdf0e10cSrcweir if (OFFSET_OF(s, m) != n) { fprintf( stderr, "### OFFSET_OF(" #s ", " #m ") = %" SAL_PRI_SIZET "u instead of expected %d!!!\n", OFFSET_OF(s, m), n ); abort(); } 370cdf0e10cSrcweir 371cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 372cdf0e10cSrcweir #if defined(__GNUC__) && (defined(LINUX) || defined(FREEBSD)) && (defined(INTEL) || defined(POWERPC) || defined(X86_64) || defined(S390)) 373cdf0e10cSrcweir #define BINTEST_VERIFYSIZE( s, n ) \ 374cdf0e10cSrcweir fprintf( stderr, "> sizeof(" #s ") = %d; __alignof__ (" #s ") = %d\n", sizeof(s), __alignof__ (s) ); \ 375cdf0e10cSrcweir if (sizeof(s) != n) { fprintf( stderr, "### sizeof(" #s ") = %d instead of expected %d!!!\n", sizeof(s), n ); abort(); } 376cdf0e10cSrcweir #else // ! GNUC 377cdf0e10cSrcweir #define BINTEST_VERIFYSIZE( s, n ) \ 378cdf0e10cSrcweir fprintf( stderr, "> sizeof(" #s ") = %d\n", sizeof(s) ); \ 379cdf0e10cSrcweir if (sizeof(s) != n) { fprintf( stderr, "### sizeof(" #s ") = %d instead of expected %d!!!\n", sizeof(s), n ); abort(); } 380cdf0e10cSrcweir #endif 381cdf0e10cSrcweir #else // ! OSL_DEBUG_LEVEL 382cdf0e10cSrcweir #define BINTEST_VERIFYSIZE( s, n ) \ 383cdf0e10cSrcweir if (sizeof(s) != n) { fprintf( stderr, "### sizeof(" #s ") = %d instead of expected %d!!!\n", sizeof(s), n ); abort(); } 384cdf0e10cSrcweir #endif 385cdf0e10cSrcweir 386cdf0e10cSrcweir struct C1 387cdf0e10cSrcweir { 388cdf0e10cSrcweir sal_Int16 n1; 389cdf0e10cSrcweir }; 390cdf0e10cSrcweir struct C2 : public C1 391cdf0e10cSrcweir { 392cdf0e10cSrcweir sal_Int32 n2 CPPU_GCC3_ALIGN( C1 ); 393cdf0e10cSrcweir }; 394cdf0e10cSrcweir struct C3 : public C2 395cdf0e10cSrcweir { 396cdf0e10cSrcweir double d3; 397cdf0e10cSrcweir sal_Int32 n3; 398cdf0e10cSrcweir }; 399cdf0e10cSrcweir struct C4 : public C3 400cdf0e10cSrcweir { 401cdf0e10cSrcweir sal_Int32 n4 CPPU_GCC3_ALIGN( C3 ); 402cdf0e10cSrcweir double d4; 403cdf0e10cSrcweir }; 404cdf0e10cSrcweir struct C5 : public C4 405cdf0e10cSrcweir { 406cdf0e10cSrcweir sal_Int64 n5; 407cdf0e10cSrcweir sal_Bool b5; 408cdf0e10cSrcweir }; 409cdf0e10cSrcweir struct C6 : public C1 410cdf0e10cSrcweir { 411cdf0e10cSrcweir C5 c6 CPPU_GCC3_ALIGN( C1 ); 412cdf0e10cSrcweir sal_Bool b6; 413cdf0e10cSrcweir }; 414cdf0e10cSrcweir 415cdf0e10cSrcweir struct D 416cdf0e10cSrcweir { 417cdf0e10cSrcweir sal_Int16 d; 418cdf0e10cSrcweir sal_Int32 e; 419cdf0e10cSrcweir }; 420cdf0e10cSrcweir struct E 421cdf0e10cSrcweir { 422cdf0e10cSrcweir sal_Bool a; 423cdf0e10cSrcweir sal_Bool b; 424cdf0e10cSrcweir sal_Bool c; 425cdf0e10cSrcweir sal_Int16 d; 426cdf0e10cSrcweir sal_Int32 e; 427cdf0e10cSrcweir }; 428cdf0e10cSrcweir 429cdf0e10cSrcweir struct M 430cdf0e10cSrcweir { 431cdf0e10cSrcweir sal_Int32 n; 432cdf0e10cSrcweir sal_Int16 o; 433cdf0e10cSrcweir }; 434cdf0e10cSrcweir 435cdf0e10cSrcweir struct N : public M 436cdf0e10cSrcweir { 437cdf0e10cSrcweir sal_Int16 p CPPU_GCC3_ALIGN( M ); 438cdf0e10cSrcweir }; 439cdf0e10cSrcweir struct N2 440cdf0e10cSrcweir { 441cdf0e10cSrcweir M m; 442cdf0e10cSrcweir sal_Int16 p; 443cdf0e10cSrcweir }; 444cdf0e10cSrcweir 445cdf0e10cSrcweir struct O : public M 446cdf0e10cSrcweir { 447cdf0e10cSrcweir double p; 448cdf0e10cSrcweir sal_Int16 q; 449cdf0e10cSrcweir }; 450cdf0e10cSrcweir struct O2 : public O 451cdf0e10cSrcweir { 452cdf0e10cSrcweir sal_Int16 p2 CPPU_GCC3_ALIGN( O ); 453cdf0e10cSrcweir }; 454cdf0e10cSrcweir 455cdf0e10cSrcweir struct P : public N 456cdf0e10cSrcweir { 457cdf0e10cSrcweir double p2; 458cdf0e10cSrcweir }; 459cdf0e10cSrcweir 460cdf0e10cSrcweir struct empty 461cdf0e10cSrcweir { 462cdf0e10cSrcweir }; 463cdf0e10cSrcweir struct second : public empty 464cdf0e10cSrcweir { 465cdf0e10cSrcweir int a; 466cdf0e10cSrcweir }; 467cdf0e10cSrcweir 468cdf0e10cSrcweir struct AlignSize_Impl 469cdf0e10cSrcweir { 470cdf0e10cSrcweir sal_Int16 nInt16; 471cdf0e10cSrcweir double dDouble; 472cdf0e10cSrcweir }; 473cdf0e10cSrcweir 474cdf0e10cSrcweir struct Char1 475cdf0e10cSrcweir { 476cdf0e10cSrcweir char c1; 477cdf0e10cSrcweir }; 478cdf0e10cSrcweir struct Char2 : public Char1 479cdf0e10cSrcweir { 480cdf0e10cSrcweir char c2 CPPU_GCC3_ALIGN( Char1 ); 481cdf0e10cSrcweir }; 482cdf0e10cSrcweir struct Char3 : public Char2 483cdf0e10cSrcweir { 484cdf0e10cSrcweir char c3 CPPU_GCC3_ALIGN( Char2 ); 485cdf0e10cSrcweir }; 486cdf0e10cSrcweir struct Char4 487cdf0e10cSrcweir { 488cdf0e10cSrcweir Char3 chars; 489cdf0e10cSrcweir char c; 490cdf0e10cSrcweir }; 491cdf0e10cSrcweir class Ref 492cdf0e10cSrcweir { 493cdf0e10cSrcweir void * p; 494cdf0e10cSrcweir }; 495cdf0e10cSrcweir enum Enum 496cdf0e10cSrcweir { 497cdf0e10cSrcweir v = SAL_MAX_ENUM 498cdf0e10cSrcweir }; 499cdf0e10cSrcweir 500cdf0e10cSrcweir 501cdf0e10cSrcweir class BinaryCompatible_Impl 502cdf0e10cSrcweir { 503cdf0e10cSrcweir public: 504cdf0e10cSrcweir BinaryCompatible_Impl(); 505cdf0e10cSrcweir }; 506cdf0e10cSrcweir BinaryCompatible_Impl::BinaryCompatible_Impl() 507cdf0e10cSrcweir { 508cdf0e10cSrcweir BOOST_STATIC_ASSERT( ((sal_Bool) true) == sal_True && 509cdf0e10cSrcweir (1 != 0) == sal_True ); 510cdf0e10cSrcweir BOOST_STATIC_ASSERT( ((sal_Bool) false) == sal_False && 511cdf0e10cSrcweir (1 == 0) == sal_False ); 512cdf0e10cSrcweir #ifdef MAX_ALIGNMENT_4 513cdf0e10cSrcweir // max alignment is 4 514cdf0e10cSrcweir BINTEST_VERIFYOFFSET( AlignSize_Impl, dDouble, 4 ); 515cdf0e10cSrcweir BINTEST_VERIFYSIZE( AlignSize_Impl, 12 ); 516cdf0e10cSrcweir #else 517cdf0e10cSrcweir // max alignment is 8 518cdf0e10cSrcweir BINTEST_VERIFYOFFSET( AlignSize_Impl, dDouble, 8 ); 519cdf0e10cSrcweir BINTEST_VERIFYSIZE( AlignSize_Impl, 16 ); 520cdf0e10cSrcweir #endif 521cdf0e10cSrcweir 522cdf0e10cSrcweir // sequence 523cdf0e10cSrcweir BINTEST_VERIFY( (SAL_SEQUENCE_HEADER_SIZE % 8) == 0 ); 524cdf0e10cSrcweir // enum 525cdf0e10cSrcweir BINTEST_VERIFY( sizeof( Enum ) == sizeof( sal_Int32 ) ); 526cdf0e10cSrcweir // any 527cdf0e10cSrcweir BINTEST_VERIFY( sizeof(void *) >= sizeof(sal_Int32) ); 528cdf0e10cSrcweir BINTEST_VERIFY( sizeof( uno_Any ) == sizeof( void * ) * 3 ); 529cdf0e10cSrcweir BINTEST_VERIFYOFFSET( uno_Any, pType, 0 ); 530cdf0e10cSrcweir BINTEST_VERIFYOFFSET( uno_Any, pData, 1 * sizeof (void *) ); 531cdf0e10cSrcweir BINTEST_VERIFYOFFSET( uno_Any, pReserved, 2 * sizeof (void *) ); 532cdf0e10cSrcweir // interface 533cdf0e10cSrcweir BINTEST_VERIFY( sizeof( Ref ) == sizeof( void * ) ); 534cdf0e10cSrcweir // string 535cdf0e10cSrcweir BINTEST_VERIFY( sizeof( OUString ) == sizeof( rtl_uString * ) ); 536cdf0e10cSrcweir // struct 537cdf0e10cSrcweir BINTEST_VERIFYSIZE( M, 8 ); 538cdf0e10cSrcweir BINTEST_VERIFYOFFSET( M, o, 4 ); 539cdf0e10cSrcweir BINTEST_VERIFYSIZE( N, 12 ); 540cdf0e10cSrcweir BINTEST_VERIFYOFFSET( N, p, 8 ); 541cdf0e10cSrcweir BINTEST_VERIFYSIZE( N2, 12 ); 542cdf0e10cSrcweir BINTEST_VERIFYOFFSET( N2, p, 8 ); 543cdf0e10cSrcweir #ifdef MAX_ALIGNMENT_4 544cdf0e10cSrcweir BINTEST_VERIFYSIZE( O, 20 ); 545cdf0e10cSrcweir #else 546cdf0e10cSrcweir BINTEST_VERIFYSIZE( O, 24 ); 547cdf0e10cSrcweir #endif 548cdf0e10cSrcweir BINTEST_VERIFYSIZE( D, 8 ); 549cdf0e10cSrcweir BINTEST_VERIFYOFFSET( D, e, 4 ); 550cdf0e10cSrcweir BINTEST_VERIFYOFFSET( E, d, 4 ); 551cdf0e10cSrcweir BINTEST_VERIFYOFFSET( E, e, 8 ); 552cdf0e10cSrcweir 553cdf0e10cSrcweir BINTEST_VERIFYSIZE( C1, 2 ); 554cdf0e10cSrcweir BINTEST_VERIFYSIZE( C2, 8 ); 555cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C2, n2, 4 ); 556cdf0e10cSrcweir 557cdf0e10cSrcweir #ifdef MAX_ALIGNMENT_4 558cdf0e10cSrcweir BINTEST_VERIFYSIZE( C3, 20 ); 559cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C3, d3, 8 ); 560cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C3, n3, 16 ); 561cdf0e10cSrcweir BINTEST_VERIFYSIZE( C4, 32 ); 562cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C4, n4, 20 ); 563cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C4, d4, 24 ); 564cdf0e10cSrcweir BINTEST_VERIFYSIZE( C5, 44 ); 565cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C5, n5, 32 ); 566cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C5, b5, 40 ); 567cdf0e10cSrcweir BINTEST_VERIFYSIZE( C6, 52 ); 568cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C6, c6, 4 ); 569cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C6, b6, 48 ); 570cdf0e10cSrcweir 571cdf0e10cSrcweir BINTEST_VERIFYSIZE( O2, 24 ); 572cdf0e10cSrcweir BINTEST_VERIFYOFFSET( O2, p2, 20 ); 573cdf0e10cSrcweir #else 574cdf0e10cSrcweir BINTEST_VERIFYSIZE( C3, 24 ); 575cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C3, d3, 8 ); 576cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C3, n3, 16 ); 577cdf0e10cSrcweir BINTEST_VERIFYSIZE( C4, 40 ); 578cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C4, n4, 24 ); 579cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C4, d4, 32 ); 580cdf0e10cSrcweir BINTEST_VERIFYSIZE( C5, 56 ); 581cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C5, n5, 40 ); 582cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C5, b5, 48 ); 583cdf0e10cSrcweir BINTEST_VERIFYSIZE( C6, 72 ); 584cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C6, c6, 8 ); 585cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C6, b6, 64 ); 586cdf0e10cSrcweir 587cdf0e10cSrcweir BINTEST_VERIFYSIZE( O2, 32 ); 588cdf0e10cSrcweir BINTEST_VERIFYOFFSET( O2, p2, 24 ); 589cdf0e10cSrcweir #endif 590cdf0e10cSrcweir 591cdf0e10cSrcweir BINTEST_VERIFYSIZE( Char3, 3 ); 592cdf0e10cSrcweir BINTEST_VERIFYOFFSET( Char4, c, 3 ); 593cdf0e10cSrcweir 594cdf0e10cSrcweir #ifdef MAX_ALIGNMENT_4 595cdf0e10cSrcweir // max alignment is 4 596cdf0e10cSrcweir BINTEST_VERIFYSIZE( P, 20 ); 597cdf0e10cSrcweir #else 598cdf0e10cSrcweir // alignment of P is 8, because of P[] ... 599cdf0e10cSrcweir BINTEST_VERIFYSIZE( P, 24 ); 600cdf0e10cSrcweir BINTEST_VERIFYSIZE( second, sizeof( int ) ); 601cdf0e10cSrcweir #endif 602cdf0e10cSrcweir } 603cdf0e10cSrcweir 604cdf0e10cSrcweir #ifdef SAL_W32 605cdf0e10cSrcweir # pragma pack(pop) 606cdf0e10cSrcweir #elif defined(SAL_OS2) 607cdf0e10cSrcweir # pragma pack() 608cdf0e10cSrcweir #endif 609cdf0e10cSrcweir 610cdf0e10cSrcweir static BinaryCompatible_Impl aTest; 611cdf0e10cSrcweir 612cdf0e10cSrcweir #endif 613cdf0e10cSrcweir 614cdf0e10cSrcweir } 615