1129fa3d1SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3129fa3d1SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4129fa3d1SAndrew Rist * or more contributor license agreements. See the NOTICE file
5129fa3d1SAndrew Rist * distributed with this work for additional information
6129fa3d1SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7129fa3d1SAndrew Rist * to you under the Apache License, Version 2.0 (the
8129fa3d1SAndrew Rist * "License"); you may not use this file except in compliance
9129fa3d1SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11129fa3d1SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13129fa3d1SAndrew Rist * Unless required by applicable law or agreed to in writing,
14129fa3d1SAndrew Rist * software distributed under the License is distributed on an
15129fa3d1SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16129fa3d1SAndrew Rist * KIND, either express or implied. See the License for the
17129fa3d1SAndrew Rist * specific language governing permissions and limitations
18129fa3d1SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20129fa3d1SAndrew Rist *************************************************************/
21129fa3d1SAndrew Rist
22129fa3d1SAndrew 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 //--------------------------------------------------------------------------------------------------
binuno_queryInterface(void * pUnoI,typelib_TypeDescriptionReference * pDestType)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 //==================================================================================================
defaultConstructStruct(void * pMem,typelib_CompoundTypeDescription * pCompType)124cdf0e10cSrcweir void defaultConstructStruct(
125cdf0e10cSrcweir void * pMem,
126cdf0e10cSrcweir typelib_CompoundTypeDescription * pCompType )
127cdf0e10cSrcweir SAL_THROW( () )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir _defaultConstructStruct( pMem, pCompType );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir //==================================================================================================
copyConstructStruct(void * pDest,void * pSource,typelib_CompoundTypeDescription * pTypeDescr,uno_AcquireFunc acquire,uno_Mapping * mapping)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 //==================================================================================================
destructStruct(void * pValue,typelib_CompoundTypeDescription * pTypeDescr,uno_ReleaseFunc release)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 //==================================================================================================
equalStruct(void * pDest,void * pSource,typelib_CompoundTypeDescription * pTypeDescr,uno_QueryInterfaceFunc queryInterface,uno_ReleaseFunc release)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 //==================================================================================================
assignStruct(void * pDest,void * pSource,typelib_CompoundTypeDescription * pTypeDescr,uno_QueryInterfaceFunc queryInterface,uno_AcquireFunc acquire,uno_ReleaseFunc release)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 //==============================================================================
copyConstructSequence(uno_Sequence * pSource,typelib_TypeDescriptionReference * pElementType,uno_AcquireFunc acquire,uno_Mapping * mapping)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 //==============================================================================
destructSequence(uno_Sequence * pSequence,typelib_TypeDescriptionReference * pType,typelib_TypeDescription * pTypeDescr,uno_ReleaseFunc release)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 //==================================================================================================
equalSequence(uno_Sequence * pDest,uno_Sequence * pSource,typelib_TypeDescriptionReference * pElementType,uno_QueryInterfaceFunc queryInterface,uno_ReleaseFunc release)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 //##################################################################################################
uno_type_constructData(void * pMem,typelib_TypeDescriptionReference * pType)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 //##################################################################################################
uno_constructData(void * pMem,typelib_TypeDescription * pTypeDescr)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 //##################################################################################################
uno_type_destructData(void * pValue,typelib_TypeDescriptionReference * pType,uno_ReleaseFunc release)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 //##################################################################################################
uno_destructData(void * pValue,typelib_TypeDescription * pTypeDescr,uno_ReleaseFunc release)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 //##################################################################################################
uno_type_copyData(void * pDest,void * pSource,typelib_TypeDescriptionReference * pType,uno_AcquireFunc acquire)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 //##################################################################################################
uno_copyData(void * pDest,void * pSource,typelib_TypeDescription * pTypeDescr,uno_AcquireFunc acquire)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 //##################################################################################################
uno_type_copyAndConvertData(void * pDest,void * pSource,typelib_TypeDescriptionReference * pType,uno_Mapping * mapping)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 //##################################################################################################
uno_copyAndConvertData(void * pDest,void * pSource,typelib_TypeDescription * pTypeDescr,uno_Mapping * mapping)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 //##################################################################################################
uno_type_equalData(void * pVal1,typelib_TypeDescriptionReference * pVal1Type,void * pVal2,typelib_TypeDescriptionReference * pVal2Type,uno_QueryInterfaceFunc queryInterface,uno_ReleaseFunc release)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 //##################################################################################################
uno_equalData(void * pVal1,typelib_TypeDescription * pVal1TD,void * pVal2,typelib_TypeDescription * pVal2TD,uno_QueryInterfaceFunc queryInterface,uno_ReleaseFunc release)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 //##################################################################################################
uno_type_assignData(void * pDest,typelib_TypeDescriptionReference * pDestType,void * pSource,typelib_TypeDescriptionReference * pSourceType,uno_QueryInterfaceFunc queryInterface,uno_AcquireFunc acquire,uno_ReleaseFunc release)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 //##################################################################################################
uno_assignData(void * pDest,typelib_TypeDescription * pDestTD,void * pSource,typelib_TypeDescription * pSourceTD,uno_QueryInterfaceFunc queryInterface,uno_AcquireFunc acquire,uno_ReleaseFunc release)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 //##################################################################################################
uno_type_isAssignableFromData(typelib_TypeDescriptionReference * pAssignable,void * pFrom,typelib_TypeDescriptionReference * pFromType,uno_QueryInterfaceFunc queryInterface,uno_ReleaseFunc release)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 ) \
369278534e3SPavel Janík 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), static_cast<int>(n) ); abort(); }
370cdf0e10cSrcweir
371cdf0e10cSrcweir #define BINTEST_VERIFYSIZE( s, n ) \
372*a40b38b0SHerbert Dürr if (sizeof(s) != n) { fprintf( stderr, "### sizeof(" #s ") = %d instead of expected %d!!!\n", (int)sizeof(s), n ); abort(); }
373cdf0e10cSrcweir
374cdf0e10cSrcweir struct C1
375cdf0e10cSrcweir {
376cdf0e10cSrcweir sal_Int16 n1;
377cdf0e10cSrcweir };
378cdf0e10cSrcweir struct C2 : public C1
379cdf0e10cSrcweir {
380cdf0e10cSrcweir sal_Int32 n2 CPPU_GCC3_ALIGN( C1 );
381cdf0e10cSrcweir };
382cdf0e10cSrcweir struct C3 : public C2
383cdf0e10cSrcweir {
384cdf0e10cSrcweir double d3;
385cdf0e10cSrcweir sal_Int32 n3;
386cdf0e10cSrcweir };
387cdf0e10cSrcweir struct C4 : public C3
388cdf0e10cSrcweir {
389cdf0e10cSrcweir sal_Int32 n4 CPPU_GCC3_ALIGN( C3 );
390cdf0e10cSrcweir double d4;
391cdf0e10cSrcweir };
392cdf0e10cSrcweir struct C5 : public C4
393cdf0e10cSrcweir {
394cdf0e10cSrcweir sal_Int64 n5;
395cdf0e10cSrcweir sal_Bool b5;
396cdf0e10cSrcweir };
397cdf0e10cSrcweir struct C6 : public C1
398cdf0e10cSrcweir {
399cdf0e10cSrcweir C5 c6 CPPU_GCC3_ALIGN( C1 );
400cdf0e10cSrcweir sal_Bool b6;
401cdf0e10cSrcweir };
402cdf0e10cSrcweir
403cdf0e10cSrcweir struct D
404cdf0e10cSrcweir {
405cdf0e10cSrcweir sal_Int16 d;
406cdf0e10cSrcweir sal_Int32 e;
407cdf0e10cSrcweir };
408cdf0e10cSrcweir struct E
409cdf0e10cSrcweir {
410cdf0e10cSrcweir sal_Bool a;
411cdf0e10cSrcweir sal_Bool b;
412cdf0e10cSrcweir sal_Bool c;
413cdf0e10cSrcweir sal_Int16 d;
414cdf0e10cSrcweir sal_Int32 e;
415cdf0e10cSrcweir };
416cdf0e10cSrcweir
417cdf0e10cSrcweir struct M
418cdf0e10cSrcweir {
419cdf0e10cSrcweir sal_Int32 n;
420cdf0e10cSrcweir sal_Int16 o;
421cdf0e10cSrcweir };
422cdf0e10cSrcweir
423cdf0e10cSrcweir struct N : public M
424cdf0e10cSrcweir {
425cdf0e10cSrcweir sal_Int16 p CPPU_GCC3_ALIGN( M );
426cdf0e10cSrcweir };
427cdf0e10cSrcweir struct N2
428cdf0e10cSrcweir {
429cdf0e10cSrcweir M m;
430cdf0e10cSrcweir sal_Int16 p;
431cdf0e10cSrcweir };
432cdf0e10cSrcweir
433cdf0e10cSrcweir struct O : public M
434cdf0e10cSrcweir {
435cdf0e10cSrcweir double p;
436cdf0e10cSrcweir sal_Int16 q;
437cdf0e10cSrcweir };
438cdf0e10cSrcweir struct O2 : public O
439cdf0e10cSrcweir {
440cdf0e10cSrcweir sal_Int16 p2 CPPU_GCC3_ALIGN( O );
441cdf0e10cSrcweir };
442cdf0e10cSrcweir
443cdf0e10cSrcweir struct P : public N
444cdf0e10cSrcweir {
445cdf0e10cSrcweir double p2;
446cdf0e10cSrcweir };
447cdf0e10cSrcweir
448cdf0e10cSrcweir struct empty
449cdf0e10cSrcweir {
450cdf0e10cSrcweir };
451cdf0e10cSrcweir struct second : public empty
452cdf0e10cSrcweir {
453cdf0e10cSrcweir int a;
454cdf0e10cSrcweir };
455cdf0e10cSrcweir
456cdf0e10cSrcweir struct AlignSize_Impl
457cdf0e10cSrcweir {
458cdf0e10cSrcweir sal_Int16 nInt16;
459cdf0e10cSrcweir double dDouble;
460cdf0e10cSrcweir };
461cdf0e10cSrcweir
462cdf0e10cSrcweir struct Char1
463cdf0e10cSrcweir {
464cdf0e10cSrcweir char c1;
465cdf0e10cSrcweir };
466cdf0e10cSrcweir struct Char2 : public Char1
467cdf0e10cSrcweir {
468cdf0e10cSrcweir char c2 CPPU_GCC3_ALIGN( Char1 );
469cdf0e10cSrcweir };
470cdf0e10cSrcweir struct Char3 : public Char2
471cdf0e10cSrcweir {
472cdf0e10cSrcweir char c3 CPPU_GCC3_ALIGN( Char2 );
473cdf0e10cSrcweir };
474cdf0e10cSrcweir struct Char4
475cdf0e10cSrcweir {
476cdf0e10cSrcweir Char3 chars;
477cdf0e10cSrcweir char c;
478cdf0e10cSrcweir };
479cdf0e10cSrcweir class Ref
480cdf0e10cSrcweir {
481cdf0e10cSrcweir void * p;
482cdf0e10cSrcweir };
483cdf0e10cSrcweir enum Enum
484cdf0e10cSrcweir {
485cdf0e10cSrcweir v = SAL_MAX_ENUM
486cdf0e10cSrcweir };
487cdf0e10cSrcweir
488cdf0e10cSrcweir
489cdf0e10cSrcweir class BinaryCompatible_Impl
490cdf0e10cSrcweir {
491cdf0e10cSrcweir public:
492cdf0e10cSrcweir BinaryCompatible_Impl();
493cdf0e10cSrcweir };
BinaryCompatible_Impl()494cdf0e10cSrcweir BinaryCompatible_Impl::BinaryCompatible_Impl()
495cdf0e10cSrcweir {
496cdf0e10cSrcweir BOOST_STATIC_ASSERT( ((sal_Bool) true) == sal_True &&
497cdf0e10cSrcweir (1 != 0) == sal_True );
498cdf0e10cSrcweir BOOST_STATIC_ASSERT( ((sal_Bool) false) == sal_False &&
499cdf0e10cSrcweir (1 == 0) == sal_False );
500cdf0e10cSrcweir #ifdef MAX_ALIGNMENT_4
501cdf0e10cSrcweir // max alignment is 4
502cdf0e10cSrcweir BINTEST_VERIFYOFFSET( AlignSize_Impl, dDouble, 4 );
503cdf0e10cSrcweir BINTEST_VERIFYSIZE( AlignSize_Impl, 12 );
504cdf0e10cSrcweir #else
505cdf0e10cSrcweir // max alignment is 8
506cdf0e10cSrcweir BINTEST_VERIFYOFFSET( AlignSize_Impl, dDouble, 8 );
507cdf0e10cSrcweir BINTEST_VERIFYSIZE( AlignSize_Impl, 16 );
508cdf0e10cSrcweir #endif
509cdf0e10cSrcweir
510cdf0e10cSrcweir // sequence
511cdf0e10cSrcweir BINTEST_VERIFY( (SAL_SEQUENCE_HEADER_SIZE % 8) == 0 );
512cdf0e10cSrcweir // enum
513cdf0e10cSrcweir BINTEST_VERIFY( sizeof( Enum ) == sizeof( sal_Int32 ) );
514cdf0e10cSrcweir // any
515cdf0e10cSrcweir BINTEST_VERIFY( sizeof(void *) >= sizeof(sal_Int32) );
516cdf0e10cSrcweir BINTEST_VERIFY( sizeof( uno_Any ) == sizeof( void * ) * 3 );
517cdf0e10cSrcweir BINTEST_VERIFYOFFSET( uno_Any, pType, 0 );
518cdf0e10cSrcweir BINTEST_VERIFYOFFSET( uno_Any, pData, 1 * sizeof (void *) );
519cdf0e10cSrcweir BINTEST_VERIFYOFFSET( uno_Any, pReserved, 2 * sizeof (void *) );
520cdf0e10cSrcweir // interface
521cdf0e10cSrcweir BINTEST_VERIFY( sizeof( Ref ) == sizeof( void * ) );
522cdf0e10cSrcweir // string
523cdf0e10cSrcweir BINTEST_VERIFY( sizeof( OUString ) == sizeof( rtl_uString * ) );
524cdf0e10cSrcweir // struct
525cdf0e10cSrcweir BINTEST_VERIFYSIZE( M, 8 );
526cdf0e10cSrcweir BINTEST_VERIFYOFFSET( M, o, 4 );
527cdf0e10cSrcweir BINTEST_VERIFYSIZE( N, 12 );
528cdf0e10cSrcweir BINTEST_VERIFYOFFSET( N, p, 8 );
529cdf0e10cSrcweir BINTEST_VERIFYSIZE( N2, 12 );
530cdf0e10cSrcweir BINTEST_VERIFYOFFSET( N2, p, 8 );
531cdf0e10cSrcweir #ifdef MAX_ALIGNMENT_4
532cdf0e10cSrcweir BINTEST_VERIFYSIZE( O, 20 );
533cdf0e10cSrcweir #else
534cdf0e10cSrcweir BINTEST_VERIFYSIZE( O, 24 );
535cdf0e10cSrcweir #endif
536cdf0e10cSrcweir BINTEST_VERIFYSIZE( D, 8 );
537cdf0e10cSrcweir BINTEST_VERIFYOFFSET( D, e, 4 );
538cdf0e10cSrcweir BINTEST_VERIFYOFFSET( E, d, 4 );
539cdf0e10cSrcweir BINTEST_VERIFYOFFSET( E, e, 8 );
540cdf0e10cSrcweir
541cdf0e10cSrcweir BINTEST_VERIFYSIZE( C1, 2 );
542cdf0e10cSrcweir BINTEST_VERIFYSIZE( C2, 8 );
543cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C2, n2, 4 );
544cdf0e10cSrcweir
545cdf0e10cSrcweir #ifdef MAX_ALIGNMENT_4
546cdf0e10cSrcweir BINTEST_VERIFYSIZE( C3, 20 );
547cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C3, d3, 8 );
548cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C3, n3, 16 );
549cdf0e10cSrcweir BINTEST_VERIFYSIZE( C4, 32 );
550cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C4, n4, 20 );
551cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C4, d4, 24 );
552cdf0e10cSrcweir BINTEST_VERIFYSIZE( C5, 44 );
553cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C5, n5, 32 );
554cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C5, b5, 40 );
555cdf0e10cSrcweir BINTEST_VERIFYSIZE( C6, 52 );
556cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C6, c6, 4 );
557cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C6, b6, 48 );
558cdf0e10cSrcweir
559cdf0e10cSrcweir BINTEST_VERIFYSIZE( O2, 24 );
560cdf0e10cSrcweir BINTEST_VERIFYOFFSET( O2, p2, 20 );
561cdf0e10cSrcweir #else
562cdf0e10cSrcweir BINTEST_VERIFYSIZE( C3, 24 );
563cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C3, d3, 8 );
564cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C3, n3, 16 );
565cdf0e10cSrcweir BINTEST_VERIFYSIZE( C4, 40 );
566cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C4, n4, 24 );
567cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C4, d4, 32 );
568cdf0e10cSrcweir BINTEST_VERIFYSIZE( C5, 56 );
569cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C5, n5, 40 );
570cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C5, b5, 48 );
571cdf0e10cSrcweir BINTEST_VERIFYSIZE( C6, 72 );
572cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C6, c6, 8 );
573cdf0e10cSrcweir BINTEST_VERIFYOFFSET( C6, b6, 64 );
574cdf0e10cSrcweir
575cdf0e10cSrcweir BINTEST_VERIFYSIZE( O2, 32 );
576cdf0e10cSrcweir BINTEST_VERIFYOFFSET( O2, p2, 24 );
577cdf0e10cSrcweir #endif
578cdf0e10cSrcweir
579cdf0e10cSrcweir BINTEST_VERIFYSIZE( Char3, 3 );
580cdf0e10cSrcweir BINTEST_VERIFYOFFSET( Char4, c, 3 );
581cdf0e10cSrcweir
582cdf0e10cSrcweir #ifdef MAX_ALIGNMENT_4
583cdf0e10cSrcweir // max alignment is 4
584cdf0e10cSrcweir BINTEST_VERIFYSIZE( P, 20 );
585cdf0e10cSrcweir #else
586cdf0e10cSrcweir // alignment of P is 8, because of P[] ...
587cdf0e10cSrcweir BINTEST_VERIFYSIZE( P, 24 );
588cdf0e10cSrcweir BINTEST_VERIFYSIZE( second, sizeof( int ) );
589cdf0e10cSrcweir #endif
590cdf0e10cSrcweir }
591cdf0e10cSrcweir
592cdf0e10cSrcweir #ifdef SAL_W32
593cdf0e10cSrcweir # pragma pack(pop)
594cdf0e10cSrcweir #elif defined(SAL_OS2)
595cdf0e10cSrcweir # pragma pack()
596cdf0e10cSrcweir #endif
597cdf0e10cSrcweir
598cdf0e10cSrcweir static BinaryCompatible_Impl aTest;
599cdf0e10cSrcweir
600cdf0e10cSrcweir #endif
601cdf0e10cSrcweir
602cdf0e10cSrcweir }
603