1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: data.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppu.hxx"
34 #include "cppu/macros.hxx"
36 #include "osl/mutex.hxx"
44 #include "boost/static_assert.hpp"
47 using namespace ::cppu
;
48 using namespace ::rtl
;
49 using namespace ::osl
;
55 // Sequence<>() (default ctor) relies on this being static:
56 uno_Sequence g_emptySeq
= { 1, 0, { 0 } };
57 typelib_TypeDescriptionReference
* g_pVoidType
= 0;
59 //--------------------------------------------------------------------------------------------------
60 void * binuno_queryInterface( void * pUnoI
, typelib_TypeDescriptionReference
* pDestType
)
62 // init queryInterface() td
63 static typelib_TypeDescription
* g_pQITD
= 0;
66 MutexGuard
aGuard( Mutex::getGlobalMutex() );
69 typelib_TypeDescriptionReference
* type_XInterface
=
70 * typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE
);
71 typelib_InterfaceTypeDescription
* pTXInterfaceDescr
= 0;
72 TYPELIB_DANGER_GET( (typelib_TypeDescription
**) &pTXInterfaceDescr
, type_XInterface
);
73 OSL_ASSERT( pTXInterfaceDescr
->ppAllMembers
);
74 typelib_typedescriptionreference_getDescription(
75 &g_pQITD
, pTXInterfaceDescr
->ppAllMembers
[ 0 ] );
76 TYPELIB_DANGER_RELEASE( (typelib_TypeDescription
*) pTXInterfaceDescr
);
81 uno_Any
* pExc
= &aExc
;
83 aArgs
[ 0 ] = &pDestType
;
84 (*((uno_Interface
*) pUnoI
)->pDispatcher
)(
85 (uno_Interface
*) pUnoI
, g_pQITD
, &aRet
, aArgs
, &pExc
);
87 uno_Interface
* ret
= 0;
90 typelib_TypeDescriptionReference
* ret_type
= aRet
.pType
;
91 switch (ret_type
->eTypeClass
)
93 case typelib_TypeClass_VOID
: // common case
94 typelib_typedescriptionreference_release( ret_type
);
96 case typelib_TypeClass_INTERFACE
:
97 // tweaky... avoiding acquire/ release pair
98 typelib_typedescriptionreference_release( ret_type
);
99 ret
= (uno_Interface
*) aRet
.pReserved
; // serving acquired interface
102 _destructAny( &aRet
, 0 );
108 #if OSL_DEBUG_LEVEL > 1
109 OUStringBuffer
buf( 128 );
111 RTL_CONSTASCII_STRINGPARAM("### exception occured querying for interface ") );
112 buf
.append( * reinterpret_cast< OUString
const * >( &pDestType
->pTypeName
) );
113 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM(": [") );
114 buf
.append( * reinterpret_cast< OUString
const * >( &pExc
->pType
->pTypeName
) );
115 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("] ") );
116 // Message is very first member
117 buf
.append( * reinterpret_cast< OUString
const * >( pExc
->pData
) );
119 OUStringToOString( buf
.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US
) );
120 OSL_ENSURE( 0, cstr
.getStr() );
122 uno_any_destruct( pExc
, 0 );
127 //==================================================================================================
128 void defaultConstructStruct(
130 typelib_CompoundTypeDescription
* pCompType
)
133 _defaultConstructStruct( pMem
, pCompType
);
135 //==================================================================================================
136 void copyConstructStruct(
137 void * pDest
, void * pSource
,
138 typelib_CompoundTypeDescription
* pTypeDescr
,
139 uno_AcquireFunc acquire
, uno_Mapping
* mapping
)
142 _copyConstructStruct( pDest
, pSource
, pTypeDescr
, acquire
, mapping
);
144 //==================================================================================================
147 typelib_CompoundTypeDescription
* pTypeDescr
,
148 uno_ReleaseFunc release
)
151 _destructStruct( pValue
, pTypeDescr
, release
);
153 //==================================================================================================
154 sal_Bool
equalStruct(
155 void * pDest
, void *pSource
,
156 typelib_CompoundTypeDescription
* pTypeDescr
,
157 uno_QueryInterfaceFunc queryInterface
, uno_ReleaseFunc release
)
160 return _equalStruct( pDest
, pSource
, pTypeDescr
, queryInterface
, release
);
162 //==================================================================================================
163 sal_Bool
assignStruct(
164 void * pDest
, void * pSource
,
165 typelib_CompoundTypeDescription
* pTypeDescr
,
166 uno_QueryInterfaceFunc queryInterface
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
169 return _assignStruct( pDest
, pSource
, pTypeDescr
, queryInterface
, acquire
, release
);
172 //==============================================================================
173 uno_Sequence
* copyConstructSequence(
174 uno_Sequence
* pSource
,
175 typelib_TypeDescriptionReference
* pElementType
,
176 uno_AcquireFunc acquire
, uno_Mapping
* mapping
)
178 return icopyConstructSequence( pSource
, pElementType
, acquire
, mapping
);
181 //==============================================================================
182 void destructSequence(
183 uno_Sequence
* pSequence
,
184 typelib_TypeDescriptionReference
* pType
,
185 typelib_TypeDescription
* pTypeDescr
,
186 uno_ReleaseFunc release
)
188 idestructSequence( pSequence
, pType
, pTypeDescr
, release
);
191 //==================================================================================================
192 sal_Bool
equalSequence(
193 uno_Sequence
* pDest
, uno_Sequence
* pSource
,
194 typelib_TypeDescriptionReference
* pElementType
,
195 uno_QueryInterfaceFunc queryInterface
, uno_ReleaseFunc release
)
198 return _equalSequence( pDest
, pSource
, pElementType
, queryInterface
, release
);
203 //##################################################################################################
204 void SAL_CALL
uno_type_constructData(
205 void * pMem
, typelib_TypeDescriptionReference
* pType
)
208 _defaultConstructData( pMem
, pType
, 0 );
210 //##################################################################################################
211 void SAL_CALL
uno_constructData(
212 void * pMem
, typelib_TypeDescription
* pTypeDescr
)
215 _defaultConstructData( pMem
, pTypeDescr
->pWeakRef
, pTypeDescr
);
217 //##################################################################################################
218 void SAL_CALL
uno_type_destructData(
219 void * pValue
, typelib_TypeDescriptionReference
* pType
,
220 uno_ReleaseFunc release
)
223 _destructData( pValue
, pType
, 0, release
);
225 //##################################################################################################
226 void SAL_CALL
uno_destructData(
228 typelib_TypeDescription
* pTypeDescr
,
229 uno_ReleaseFunc release
)
232 _destructData( pValue
, pTypeDescr
->pWeakRef
, pTypeDescr
, release
);
234 //##################################################################################################
235 void SAL_CALL
uno_type_copyData(
236 void * pDest
, void * pSource
,
237 typelib_TypeDescriptionReference
* pType
,
238 uno_AcquireFunc acquire
)
241 _copyConstructData( pDest
, pSource
, pType
, 0, acquire
, 0 );
243 //##################################################################################################
244 void SAL_CALL
uno_copyData(
245 void * pDest
, void * pSource
,
246 typelib_TypeDescription
* pTypeDescr
,
247 uno_AcquireFunc acquire
)
250 _copyConstructData( pDest
, pSource
, pTypeDescr
->pWeakRef
, pTypeDescr
, acquire
, 0 );
252 //##################################################################################################
253 void SAL_CALL
uno_type_copyAndConvertData(
254 void * pDest
, void * pSource
,
255 typelib_TypeDescriptionReference
* pType
,
256 uno_Mapping
* mapping
)
259 _copyConstructData( pDest
, pSource
, pType
, 0, 0, mapping
);
261 //##################################################################################################
262 void SAL_CALL
uno_copyAndConvertData(
263 void * pDest
, void * pSource
,
264 typelib_TypeDescription
* pTypeDescr
,
265 uno_Mapping
* mapping
)
268 _copyConstructData( pDest
, pSource
, pTypeDescr
->pWeakRef
, pTypeDescr
, 0, mapping
);
270 //##################################################################################################
271 sal_Bool SAL_CALL
uno_type_equalData(
272 void * pVal1
, typelib_TypeDescriptionReference
* pVal1Type
,
273 void * pVal2
, typelib_TypeDescriptionReference
* pVal2Type
,
274 uno_QueryInterfaceFunc queryInterface
, uno_ReleaseFunc release
)
280 queryInterface
, release
);
282 //##################################################################################################
283 sal_Bool SAL_CALL
uno_equalData(
284 void * pVal1
, typelib_TypeDescription
* pVal1TD
,
285 void * pVal2
, typelib_TypeDescription
* pVal2TD
,
286 uno_QueryInterfaceFunc queryInterface
, uno_ReleaseFunc release
)
290 pVal1
, pVal1TD
->pWeakRef
, pVal1TD
,
291 pVal2
, pVal2TD
->pWeakRef
, pVal2TD
,
292 queryInterface
, release
);
294 //##################################################################################################
295 sal_Bool SAL_CALL
uno_type_assignData(
296 void * pDest
, typelib_TypeDescriptionReference
* pDestType
,
297 void * pSource
, typelib_TypeDescriptionReference
* pSourceType
,
298 uno_QueryInterfaceFunc queryInterface
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
303 pSource
, pSourceType
, 0,
304 queryInterface
, acquire
, release
);
306 //##################################################################################################
307 sal_Bool SAL_CALL
uno_assignData(
308 void * pDest
, typelib_TypeDescription
* pDestTD
,
309 void * pSource
, typelib_TypeDescription
* pSourceTD
,
310 uno_QueryInterfaceFunc queryInterface
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
314 pDest
, pDestTD
->pWeakRef
, pDestTD
,
315 pSource
, pSourceTD
->pWeakRef
, pSourceTD
,
316 queryInterface
, acquire
, release
);
318 //##################################################################################################
319 sal_Bool SAL_CALL
uno_type_isAssignableFromData(
320 typelib_TypeDescriptionReference
* pAssignable
,
321 void * pFrom
, typelib_TypeDescriptionReference
* pFromType
,
322 uno_QueryInterfaceFunc queryInterface
, uno_ReleaseFunc release
)
325 if (::typelib_typedescriptionreference_isAssignableFrom( pAssignable
, pFromType
))
327 if (typelib_TypeClass_INTERFACE
!= pFromType
->eTypeClass
||
328 typelib_TypeClass_INTERFACE
!= pAssignable
->eTypeClass
)
336 void * pInterface
= *(void **)pFrom
;
340 if (0 == queryInterface
)
341 queryInterface
= binuno_queryInterface
;
342 void * p
= (*queryInterface
)( pInterface
, pAssignable
);
343 _release( p
, release
);
349 //##################################################################################################
350 //##################################################################################################
351 //##################################################################################################
354 #if OSL_DEBUG_LEVEL > 1
358 #if defined( SAL_W32)
359 #pragma pack(push, 8)
360 #elif defined(SAL_OS2)
361 #pragma pack(push, 4)
365 && (defined(__GNUC__) && (defined(LINUX) || defined(FREEBSD) || defined(OS2)) || defined(MACOSX) \
366 || defined(__SUNPRO_CC) && defined(SOLARIS))
367 #define MAX_ALIGNMENT_4
370 #define OFFSET_OF( s, m ) ((sal_Size)((char *)&((s *)16)->m -16))
372 #define BINTEST_VERIFY( c ) \
373 if (! (c)) { fprintf( stderr, "### binary compatibility test failed: " #c " [line %d]!!!\n", __LINE__ ); abort(); }
374 #define BINTEST_VERIFYOFFSET( s, m, n ) \
375 if (OFFSET_OF(s, m) != n) { fprintf( stderr, "### OFFSET_OF(" #s ", " #m ") = %d instead of expected %d!!!\n", OFFSET_OF(s, m), n ); abort(); }
377 #if OSL_DEBUG_LEVEL > 1
378 #if defined(__GNUC__) && (defined(LINUX) || defined(FREEBSD)) && (defined(INTEL) || defined(POWERPC) || defined(X86_64) || defined(S390))
379 #define BINTEST_VERIFYSIZE( s, n ) \
380 fprintf( stderr, "> sizeof(" #s ") = %d; __alignof__ (" #s ") = %d\n", sizeof(s), __alignof__ (s) ); \
381 if (sizeof(s) != n) { fprintf( stderr, "### sizeof(" #s ") = %d instead of expected %d!!!\n", sizeof(s), n ); abort(); }
383 #define BINTEST_VERIFYSIZE( s, n ) \
384 fprintf( stderr, "> sizeof(" #s ") = %d\n", sizeof(s) ); \
385 if (sizeof(s) != n) { fprintf( stderr, "### sizeof(" #s ") = %d instead of expected %d!!!\n", sizeof(s), n ); abort(); }
387 #else // ! OSL_DEBUG_LEVEL
388 #define BINTEST_VERIFYSIZE( s, n ) \
389 if (sizeof(s) != n) { fprintf( stderr, "### sizeof(" #s ") = %d instead of expected %d!!!\n", sizeof(s), n ); abort(); }
396 struct C2
: public C1
398 sal_Int32 n2
CPPU_GCC3_ALIGN( C1
);
400 struct C3
: public C2
405 struct C4
: public C3
407 sal_Int32 n4
CPPU_GCC3_ALIGN( C3
);
410 struct C5
: public C4
415 struct C6
: public C1
417 C5 c6
CPPU_GCC3_ALIGN( C1
);
443 sal_Int16 p
CPPU_GCC3_ALIGN( M
);
458 sal_Int16 p2
CPPU_GCC3_ALIGN( O
);
469 struct second
: public empty
474 struct AlignSize_Impl
484 struct Char2
: public Char1
486 char c2
CPPU_GCC3_ALIGN( Char1
);
488 struct Char3
: public Char2
490 char c3
CPPU_GCC3_ALIGN( Char2
);
507 class BinaryCompatible_Impl
510 BinaryCompatible_Impl();
512 BinaryCompatible_Impl::BinaryCompatible_Impl()
514 BOOST_STATIC_ASSERT( ((sal_Bool
) true) == sal_True
&&
515 (1 != 0) == sal_True
);
516 BOOST_STATIC_ASSERT( ((sal_Bool
) false) == sal_False
&&
517 (1 == 0) == sal_False
);
518 #ifdef MAX_ALIGNMENT_4
519 // max alignment is 4
520 BINTEST_VERIFYOFFSET( AlignSize_Impl
, dDouble
, 4 );
521 BINTEST_VERIFYSIZE( AlignSize_Impl
, 12 );
523 // max alignment is 8
524 BINTEST_VERIFYOFFSET( AlignSize_Impl
, dDouble
, 8 );
525 BINTEST_VERIFYSIZE( AlignSize_Impl
, 16 );
529 BINTEST_VERIFY( (SAL_SEQUENCE_HEADER_SIZE
% 8) == 0 );
531 BINTEST_VERIFY( sizeof( Enum
) == sizeof( sal_Int32
) );
533 BINTEST_VERIFY( sizeof(void *) >= sizeof(sal_Int32
) );
534 BINTEST_VERIFY( sizeof( uno_Any
) == sizeof( void * ) * 3 );
535 BINTEST_VERIFYOFFSET( uno_Any
, pType
, 0 );
536 BINTEST_VERIFYOFFSET( uno_Any
, pData
, 1 * sizeof (void *) );
537 BINTEST_VERIFYOFFSET( uno_Any
, pReserved
, 2 * sizeof (void *) );
539 BINTEST_VERIFY( sizeof( Ref
) == sizeof( void * ) );
541 BINTEST_VERIFY( sizeof( OUString
) == sizeof( rtl_uString
* ) );
543 BINTEST_VERIFYSIZE( M
, 8 );
544 BINTEST_VERIFYOFFSET( M
, o
, 4 );
545 BINTEST_VERIFYSIZE( N
, 12 );
546 BINTEST_VERIFYOFFSET( N
, p
, 8 );
547 BINTEST_VERIFYSIZE( N2
, 12 );
548 BINTEST_VERIFYOFFSET( N2
, p
, 8 );
549 #ifdef MAX_ALIGNMENT_4
550 BINTEST_VERIFYSIZE( O
, 20 );
552 BINTEST_VERIFYSIZE( O
, 24 );
554 BINTEST_VERIFYSIZE( D
, 8 );
555 BINTEST_VERIFYOFFSET( D
, e
, 4 );
556 BINTEST_VERIFYOFFSET( E
, d
, 4 );
557 BINTEST_VERIFYOFFSET( E
, e
, 8 );
559 BINTEST_VERIFYSIZE( C1
, 2 );
560 BINTEST_VERIFYSIZE( C2
, 8 );
561 BINTEST_VERIFYOFFSET( C2
, n2
, 4 );
563 #ifdef MAX_ALIGNMENT_4
564 BINTEST_VERIFYSIZE( C3
, 20 );
565 BINTEST_VERIFYOFFSET( C3
, d3
, 8 );
566 BINTEST_VERIFYOFFSET( C3
, n3
, 16 );
567 BINTEST_VERIFYSIZE( C4
, 32 );
568 BINTEST_VERIFYOFFSET( C4
, n4
, 20 );
569 BINTEST_VERIFYOFFSET( C4
, d4
, 24 );
570 BINTEST_VERIFYSIZE( C5
, 44 );
571 BINTEST_VERIFYOFFSET( C5
, n5
, 32 );
572 BINTEST_VERIFYOFFSET( C5
, b5
, 40 );
573 BINTEST_VERIFYSIZE( C6
, 52 );
574 BINTEST_VERIFYOFFSET( C6
, c6
, 4 );
575 BINTEST_VERIFYOFFSET( C6
, b6
, 48 );
577 BINTEST_VERIFYSIZE( O2
, 24 );
578 BINTEST_VERIFYOFFSET( O2
, p2
, 20 );
580 BINTEST_VERIFYSIZE( C3
, 24 );
581 BINTEST_VERIFYOFFSET( C3
, d3
, 8 );
582 BINTEST_VERIFYOFFSET( C3
, n3
, 16 );
583 BINTEST_VERIFYSIZE( C4
, 40 );
584 BINTEST_VERIFYOFFSET( C4
, n4
, 24 );
585 BINTEST_VERIFYOFFSET( C4
, d4
, 32 );
586 BINTEST_VERIFYSIZE( C5
, 56 );
587 BINTEST_VERIFYOFFSET( C5
, n5
, 40 );
588 BINTEST_VERIFYOFFSET( C5
, b5
, 48 );
589 BINTEST_VERIFYSIZE( C6
, 72 );
590 BINTEST_VERIFYOFFSET( C6
, c6
, 8 );
591 BINTEST_VERIFYOFFSET( C6
, b6
, 64 );
593 BINTEST_VERIFYSIZE( O2
, 32 );
594 BINTEST_VERIFYOFFSET( O2
, p2
, 24 );
597 BINTEST_VERIFYSIZE( Char3
, 3 );
598 BINTEST_VERIFYOFFSET( Char4
, c
, 3 );
600 #ifdef MAX_ALIGNMENT_4
601 // max alignment is 4
602 BINTEST_VERIFYSIZE( P
, 20 );
604 // alignment of P is 8, because of P[] ...
605 BINTEST_VERIFYSIZE( P
, 24 );
606 BINTEST_VERIFYSIZE( second
, sizeof( int ) );
612 #elif defined(SAL_OS2)
616 static BinaryCompatible_Impl aTest
;