Bug Summary

File:cppu/source/typelib/typelib.cxx
Location:line 492, column 11
Description:Access to field 'bComplete' results in a dereference of a null pointer

Annotated Source Code

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
21#if OSL_DEBUG_LEVEL1 > 1
22#include <stdio.h>
23#endif
24
25#include <boost/unordered_map.hpp>
26#include <list>
27#include <set>
28#include <vector>
29
30#include <stdarg.h>
31#include <stdlib.h>
32#include <string.h>
33#include <sal/alloca.h>
34#include <new>
35#include <osl/interlck.h>
36#include <osl/mutex.hxx>
37#include <rtl/ustring.hxx>
38#include <rtl/ustrbuf.hxx>
39#include <rtl/alloc.h>
40#include <rtl/instance.hxx>
41#include <osl/diagnose.h>
42#include <typelib/typedescription.h>
43#include <uno/any2.h>
44
45using namespace std;
46using namespace osl;
47
48using ::rtl::OUString;
49using ::rtl::OUStringBuffer;
50using ::rtl::OString;
51
52#ifdef SAL_W32
53#pragma pack(push, 8)
54#endif
55
56/**
57 * The double member determin the alignment.
58 * Under Os2 and MS-Windows the Alignment is min( 8, sizeof( type ) ).
59 * The aligment of a strukture is min( 8, sizeof( max basic type ) ), the greatest basic type
60 * determine the aligment.
61 */
62struct AlignSize_Impl
63{
64 sal_Int16 nInt16;
65#ifdef AIX
66 //double: doubleword aligned if -qalign=natural/-malign=natural
67 //which isn't the default ABI. Otherwise word aligned, While a long long int
68 //is always doubleword aligned, so use that instead.
69 sal_Int64 dDouble;
70#else
71 double dDouble;
72#endif
73};
74
75#ifdef SAL_W32
76#pragma pack(pop)
77#endif
78
79// the value of the maximal alignment
80static sal_Int32 nMaxAlignment = (sal_Int32)( (sal_Size)(&((AlignSize_Impl *) 16)->dDouble) - 16);
81
82static inline sal_Int32 adjustAlignment( sal_Int32 nRequestedAlignment )
83 SAL_THROW(())
84{
85 if( nRequestedAlignment > nMaxAlignment )
86 nRequestedAlignment = nMaxAlignment;
87 return nRequestedAlignment;
88}
89
90/**
91 * Calculate the new size of the struktur.
92 */
93static inline sal_Int32 newAlignedSize(
94 sal_Int32 OldSize, sal_Int32 ElementSize, sal_Int32 NeededAlignment )
95 SAL_THROW(())
96{
97 NeededAlignment = adjustAlignment( NeededAlignment );
98 return (OldSize + NeededAlignment -1) / NeededAlignment * NeededAlignment + ElementSize;
99}
100
101static inline sal_Bool reallyWeak( typelib_TypeClass eTypeClass )
102 SAL_THROW(())
103{
104 return TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( eTypeClass )((eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (eTypeClass
) == typelib_TypeClass_INTERFACE_ATTRIBUTE)
;
105}
106
107static inline sal_Int32 getDescriptionSize( typelib_TypeClass eTypeClass )
108 SAL_THROW(())
109{
110 OSL_ASSERT( typelib_TypeClass_TYPEDEF != eTypeClass )do { if (true && (!(typelib_TypeClass_TYPEDEF != eTypeClass
))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "110" ": "), "OSL_ASSERT: %s", "typelib_TypeClass_TYPEDEF != eTypeClass"
); } } while (false)
;
111
112 sal_Int32 nSize;
113 // The reference is the description
114 // if the description is empty, than it must be filled with
115 // the new description
116 switch( eTypeClass )
117 {
118 case typelib_TypeClass_ARRAY:
119 nSize = (sal_Int32)sizeof( typelib_ArrayTypeDescription );
120 break;
121
122 case typelib_TypeClass_SEQUENCE:
123 nSize = (sal_Int32)sizeof( typelib_IndirectTypeDescription );
124 break;
125
126 case typelib_TypeClass_UNION:
127 nSize = (sal_Int32)sizeof( typelib_UnionTypeDescription );
128 break;
129
130 case typelib_TypeClass_STRUCT:
131 nSize = (sal_Int32)sizeof( typelib_StructTypeDescription );
132 break;
133
134 case typelib_TypeClass_EXCEPTION:
135 nSize = (sal_Int32)sizeof( typelib_CompoundTypeDescription );
136 break;
137
138 case typelib_TypeClass_ENUM:
139 nSize = (sal_Int32)sizeof( typelib_EnumTypeDescription );
140 break;
141
142 case typelib_TypeClass_INTERFACE:
143 nSize = (sal_Int32)sizeof( typelib_InterfaceTypeDescription );
144 break;
145
146 case typelib_TypeClass_INTERFACE_METHOD:
147 nSize = (sal_Int32)sizeof( typelib_InterfaceMethodTypeDescription );
148 break;
149
150 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
151 nSize = (sal_Int32)sizeof( typelib_InterfaceAttributeTypeDescription );
152 break;
153
154 default:
155 nSize = (sal_Int32)sizeof( typelib_TypeDescription );
156 }
157 return nSize;
158}
159
160
161//-----------------------------------------------------------------------------
162extern "C" void SAL_CALL typelib_typedescriptionreference_getByName(
163 typelib_TypeDescriptionReference ** ppRet, rtl_uString * pName )
164 SAL_THROW_EXTERN_C()throw ();
165
166//-----------------------------------------------------------------------------
167struct equalStr_Impl
168{
169 sal_Bool operator()(const sal_Unicode * const & s1, const sal_Unicode * const & s2) const SAL_THROW(())
170 { return 0 == rtl_ustr_compare( s1, s2 ); }
171};
172
173//-----------------------------------------------------------------------------
174struct hashStr_Impl
175{
176 size_t operator()(const sal_Unicode * const & s) const SAL_THROW(())
177 { return rtl_ustr_hashCode( s ); }
178};
179
180
181//-----------------------------------------------------------------------------
182// Heavy hack, the const sal_Unicode * is hold by the typedescription reference
183typedef boost::unordered_map< const sal_Unicode *, typelib_TypeDescriptionReference *,
184 hashStr_Impl, equalStr_Impl > WeakMap_Impl;
185
186typedef pair< void *, typelib_typedescription_Callback > CallbackEntry;
187typedef list< CallbackEntry > CallbackSet_Impl;
188typedef list< typelib_TypeDescription * > TypeDescriptionList_Impl;
189
190// # of cached elements
191static sal_Int32 nCacheSize = 256;
192
193struct TypeDescriptor_Init_Impl
194{
195 //sal_Bool bDesctructorCalled;
196 // all type description references
197 WeakMap_Impl * pWeakMap;
198 // all type description callbacks
199 CallbackSet_Impl * pCallbacks;
200 // A cache to hold descriptions
201 TypeDescriptionList_Impl * pCache;
202 // The mutex to guard all type library accesses
203 Mutex * pMutex;
204
205 inline Mutex & getMutex() SAL_THROW(());
206
207 inline void callChain( typelib_TypeDescription ** ppRet, rtl_uString * pName ) SAL_THROW(());
208
209#if OSL_DEBUG_LEVEL1 > 1
210 // only for debugging
211 sal_Int32 nTypeDescriptionCount;
212 sal_Int32 nCompoundTypeDescriptionCount;
213 sal_Int32 nUnionTypeDescriptionCount;
214 sal_Int32 nIndirectTypeDescriptionCount;
215 sal_Int32 nArrayTypeDescriptionCount;
216 sal_Int32 nEnumTypeDescriptionCount;
217 sal_Int32 nInterfaceMethodTypeDescriptionCount;
218 sal_Int32 nInterfaceAttributeTypeDescriptionCount;
219 sal_Int32 nInterfaceTypeDescriptionCount;
220 sal_Int32 nTypeDescriptionReferenceCount;
221#endif
222
223 TypeDescriptor_Init_Impl():
224 pWeakMap(0), pCallbacks(0), pCache(0), pMutex(0)
225#if OSL_DEBUG_LEVEL1 > 1
226 , nTypeDescriptionCount(0), nCompoundTypeDescriptionCount(0),
227 nUnionTypeDescriptionCount(0), nIndirectTypeDescriptionCount(0),
228 nArrayTypeDescriptionCount(0), nEnumTypeDescriptionCount(0),
229 nInterfaceMethodTypeDescriptionCount(0),
230 nInterfaceAttributeTypeDescriptionCount(0),
231 nInterfaceTypeDescriptionCount(0), nTypeDescriptionReferenceCount(0)
232#endif
233 {}
234
235 ~TypeDescriptor_Init_Impl() SAL_THROW(());
236};
237//__________________________________________________________________________________________________
238inline Mutex & TypeDescriptor_Init_Impl::getMutex() SAL_THROW(())
239{
240 if( !pMutex )
241 {
242 MutexGuard aGuard( Mutex::getGlobalMutex() );
243 if( !pMutex )
244 pMutex = new Mutex();
245 }
246 return * pMutex;
247}
248//__________________________________________________________________________________________________
249inline void TypeDescriptor_Init_Impl::callChain(
250 typelib_TypeDescription ** ppRet, rtl_uString * pName )
251 SAL_THROW(())
252{
253 if (pCallbacks)
254 {
255 CallbackSet_Impl::const_iterator aIt = pCallbacks->begin();
256 while( aIt != pCallbacks->end() )
257 {
258 const CallbackEntry & rEntry = *aIt;
259 (*rEntry.second)( rEntry.first, ppRet, pName );
260 if( *ppRet )
261 return;
262 ++aIt;
263 }
264 }
265 if (*ppRet)
266 {
267 typelib_typedescription_release( *ppRet );
268 *ppRet = 0;
269 }
270}
271
272//__________________________________________________________________________________________________
273TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl() SAL_THROW(())
274{
275 if( pCache )
276 {
277 TypeDescriptionList_Impl::const_iterator aIt = pCache->begin();
278 while( aIt != pCache->end() )
279 {
280 typelib_typedescription_release( (*aIt) );
281 ++aIt;
282 }
283 delete pCache;
284 pCache = 0;
285 }
286
287 if( pWeakMap )
288 {
289 std::vector< typelib_TypeDescriptionReference * > ppTDR;
290 // save al weak references
291 WeakMap_Impl::const_iterator aIt = pWeakMap->begin();
292 while( aIt != pWeakMap->end() )
293 {
294 ppTDR.push_back( (*aIt).second );
295 typelib_typedescriptionreference_acquire( ppTDR.back() );
296 ++aIt;
297 }
298
299 for( std::vector< typelib_TypeDescriptionReference * >::iterator i(
300 ppTDR.begin() );
301 i != ppTDR.end(); ++i )
302 {
303 typelib_TypeDescriptionReference * pTDR = *i;
304 OSL_ASSERT( pTDR->nRefCount > pTDR->nStaticRefCount )do { if (true && (!(pTDR->nRefCount > pTDR->
nStaticRefCount))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "304" ": "), "OSL_ASSERT: %s", "pTDR->nRefCount > pTDR->nStaticRefCount"
); } } while (false)
;
305 pTDR->nRefCount -= pTDR->nStaticRefCount;
306
307 if( pTDR->pType && !pTDR->pType->bOnDemand )
308 {
309 pTDR->pType->bOnDemand = sal_True((sal_Bool)1);
310 typelib_typedescription_release( pTDR->pType );
311 }
312 typelib_typedescriptionreference_release( pTDR );
313 }
314
315#if OSL_DEBUG_LEVEL1 > 1
316 aIt = pWeakMap->begin();
317 while( aIt != pWeakMap->end() )
318 {
319 typelib_TypeDescriptionReference * pTDR = (*aIt).second;
320 if (pTDR)
321 {
322 OString aTypeName( rtl::OUStringToOString( pTDR->pTypeName, RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11)) ) );
323 OSL_TRACE(do { if (true && (1 > 0)) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "324" ": "), "### remaining type: %s; ref count = %d", aTypeName
.getStr(), pTDR->nRefCount); } } while (false)
324 "### remaining type: %s; ref count = %d", aTypeName.getStr(), pTDR->nRefCount )do { if (true && (1 > 0)) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "324" ": "), "### remaining type: %s; ref count = %d", aTypeName
.getStr(), pTDR->nRefCount); } } while (false)
;
325 }
326 else
327 {
328 OSL_TRACE( "### remaining null type entry!?" )do { if (true && (1 > 0)) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "328" ": "), "### remaining null type entry!?"); } } while
(false)
;
329 }
330 ++aIt;
331 }
332#endif
333
334 delete pWeakMap;
335 pWeakMap = 0;
336 }
337#if OSL_DEBUG_LEVEL1 > 1
338 OSL_ENSURE( !nTypeDescriptionCount, "### nTypeDescriptionCount is not zero" )do { if (true && (!(!nTypeDescriptionCount))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "338" ": "), "%s", "### nTypeDescriptionCount is not zero"
); } } while (false)
;
339 OSL_ENSURE( !nCompoundTypeDescriptionCount, "### nCompoundTypeDescriptionCount is not zero" )do { if (true && (!(!nCompoundTypeDescriptionCount)))
{ sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "339" ": "), "%s", "### nCompoundTypeDescriptionCount is not zero"
); } } while (false)
;
340 OSL_ENSURE( !nUnionTypeDescriptionCount, "### nUnionTypeDescriptionCount is not zero" )do { if (true && (!(!nUnionTypeDescriptionCount))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "340" ": "), "%s", "### nUnionTypeDescriptionCount is not zero"
); } } while (false)
;
341 OSL_ENSURE( !nIndirectTypeDescriptionCount, "### nIndirectTypeDescriptionCount is not zero" )do { if (true && (!(!nIndirectTypeDescriptionCount)))
{ sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "341" ": "), "%s", "### nIndirectTypeDescriptionCount is not zero"
); } } while (false)
;
342 OSL_ENSURE( !nArrayTypeDescriptionCount, "### nArrayTypeDescriptionCount is not zero" )do { if (true && (!(!nArrayTypeDescriptionCount))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "342" ": "), "%s", "### nArrayTypeDescriptionCount is not zero"
); } } while (false)
;
343 OSL_ENSURE( !nEnumTypeDescriptionCount, "### nEnumTypeDescriptionCount is not zero" )do { if (true && (!(!nEnumTypeDescriptionCount))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "343" ": "), "%s", "### nEnumTypeDescriptionCount is not zero"
); } } while (false)
;
344 OSL_ENSURE( !nInterfaceMethodTypeDescriptionCount, "### nInterfaceMethodTypeDescriptionCount is not zero" )do { if (true && (!(!nInterfaceMethodTypeDescriptionCount
))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "344" ": "), "%s", "### nInterfaceMethodTypeDescriptionCount is not zero"
); } } while (false)
;
345 OSL_ENSURE( !nInterfaceAttributeTypeDescriptionCount, "### nInterfaceAttributeTypeDescriptionCount is not zero" )do { if (true && (!(!nInterfaceAttributeTypeDescriptionCount
))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "345" ": "), "%s", "### nInterfaceAttributeTypeDescriptionCount is not zero"
); } } while (false)
;
346 OSL_ENSURE( !nInterfaceTypeDescriptionCount, "### nInterfaceTypeDescriptionCount is not zero" )do { if (true && (!(!nInterfaceTypeDescriptionCount))
) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "346" ": "), "%s", "### nInterfaceTypeDescriptionCount is not zero"
); } } while (false)
;
347 OSL_ENSURE( !nTypeDescriptionReferenceCount, "### nTypeDescriptionReferenceCount is not zero" )do { if (true && (!(!nTypeDescriptionReferenceCount))
) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "347" ": "), "%s", "### nTypeDescriptionReferenceCount is not zero"
); } } while (false)
;
348
349 OSL_ENSURE( !pCallbacks || pCallbacks->empty(), "### pCallbacks is not NULL or empty" )do { if (true && (!(!pCallbacks || pCallbacks->empty
()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "349" ": "), "%s", "### pCallbacks is not NULL or empty"
); } } while (false)
;
350#endif
351
352 delete pCallbacks;
353 pCallbacks = 0;
354
355 if( pMutex )
356 {
357 delete pMutex;
358 pMutex = 0;
359 }
360};
361
362namespace { struct Init : public rtl::Static< TypeDescriptor_Init_Impl, Init > {}; }
363
364extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_registerCallback(
365 void * pContext, typelib_typedescription_Callback pCallback )
366 SAL_THROW_EXTERN_C()throw ()
367{
368 // todo mt safe: guard is no solution, can not acquire while calling callback!
369 TypeDescriptor_Init_Impl &rInit = Init::get();
370// OslGuard aGuard( rInit.getMutex() );
371 if( !rInit.pCallbacks )
372 rInit.pCallbacks = new CallbackSet_Impl;
373 rInit.pCallbacks->push_back( CallbackEntry( pContext, pCallback ) );
374}
375
376//------------------------------------------------------------------------
377extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_revokeCallback(
378 void * pContext, typelib_typedescription_Callback pCallback )
379 SAL_THROW_EXTERN_C()throw ()
380{
381 TypeDescriptor_Init_Impl &rInit = Init::get();
382 if( rInit.pCallbacks )
383 {
384 // todo mt safe: guard is no solution, can not acquire while calling callback!
385// OslGuard aGuard( rInit.getMutex() );
386 CallbackEntry aEntry( pContext, pCallback );
387 CallbackSet_Impl::iterator iPos( rInit.pCallbacks->begin() );
388 while (!(iPos == rInit.pCallbacks->end()))
389 {
390 if (*iPos == aEntry)
391 {
392 rInit.pCallbacks->erase( iPos );
393 iPos = rInit.pCallbacks->begin();
394 }
395 else
396 {
397 ++iPos;
398 }
399 }
400 }
401}
402
403extern "C" sal_Int32 SAL_CALL typelib_typedescription_getAlignedUnoSize(
404 const typelib_TypeDescription * pTypeDescription,
405 sal_Int32 nOffset, sal_Int32 & rMaxIntegralTypeSize )
406 SAL_THROW_EXTERN_C()throw ();
407
408//------------------------------------------------------------------------
409static inline void typelib_typedescription_initTables(
410 typelib_TypeDescription * pTD )
411 SAL_THROW(())
412{
413 typelib_InterfaceTypeDescription * pITD = (typelib_InterfaceTypeDescription *)pTD;
414
415 sal_Bool * pReadWriteAttributes = (sal_Bool *)alloca( pITD->nAllMembers )__builtin_alloca (pITD->nAllMembers);
416 for ( sal_Int32 i = pITD->nAllMembers; i--; )
417 {
418 pReadWriteAttributes[i] = sal_False((sal_Bool)0);
419 if( typelib_TypeClass_INTERFACE_ATTRIBUTE == pITD->ppAllMembers[i]->eTypeClass )
420 {
421 typelib_TypeDescription * pM = 0;
422 TYPELIB_DANGER_GET( &pM, pITD->ppAllMembers[i] ){ typelib_TypeDescriptionReference * pMacroTypeRef = (pITD->
ppAllMembers[i]); typelib_TypeDescription ** ppMacroTypeDescr
= (&pM); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr
, pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef
->pType->pWeakRef) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release
( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef
->pType; } }
;
423 OSL_ASSERT( pM )do { if (true && (!(pM))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "423" ": "), "OSL_ASSERT: %s", "pM"); } } while (false)
;
424 if (pM)
425 {
426 pReadWriteAttributes[i] = !((typelib_InterfaceAttributeTypeDescription *)pM)->bReadOnly;
427 TYPELIB_DANGER_RELEASE( pM ){ if ((((pM)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| ((pM)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) typelib_typedescription_release( pM ); }
;
428 }
429#if OSL_DEBUG_LEVEL1 > 1
430 else
431 {
432 OString aStr( rtl::OUStringToOString( pITD->ppAllMembers[i]->pTypeName, RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11)) ) );
433 OSL_TRACE( "\n### cannot get attribute type description: %s", aStr.getStr() )do { if (true && (1 > 0)) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "433" ": "), "\n### cannot get attribute type description: %s"
, aStr.getStr()); } } while (false)
;
434 }
435#endif
436 }
437 }
438
439 MutexGuard aGuard( Init::get().getMutex() );
440 if( !pTD->bComplete )
441 {
442 // create the index table from member to function table
443 pITD->pMapMemberIndexToFunctionIndex = new sal_Int32[ pITD->nAllMembers ];
444 sal_Int32 nAdditionalOffset = 0; // +1 for read/write attributes
445 sal_Int32 i;
446 for( i = 0; i < pITD->nAllMembers; i++ )
447 {
448 // index to the get method of the attribute
449 pITD->pMapMemberIndexToFunctionIndex[i] = i + nAdditionalOffset;
450 // extra offset if it is a read/write attribute?
451 if( pReadWriteAttributes[i] )
452 {
453 // a read/write attribute
454 nAdditionalOffset++;
455 }
456 }
457
458 // create the index table from function to member table
459 pITD->pMapFunctionIndexToMemberIndex = new sal_Int32[ pITD->nAllMembers + nAdditionalOffset ];
460 nAdditionalOffset = 0; // +1 for read/write attributes
461 for( i = 0; i < pITD->nAllMembers; i++ )
462 {
463 // index to the get method of the attribute
464 pITD->pMapFunctionIndexToMemberIndex[i + nAdditionalOffset] = i;
465 // extra offset if it is a read/write attribute?
466 if( pReadWriteAttributes[i] )
467 {
468 // a read/write attribute
469 pITD->pMapFunctionIndexToMemberIndex[i + ++nAdditionalOffset] = i;
470 }
471 }
472 // must be the last action after all initialization is done
473 pITD->nMapFunctionIndexToMemberIndex = pITD->nAllMembers + nAdditionalOffset;
474 pTD->bComplete = sal_True((sal_Bool)1);
475 }
476}
477
478namespace {
479
480// In some situations (notably typelib_typedescription_newInterfaceMethod and
481// typelib_typedescription_newInterfaceAttribute), only the members nMembers,
482// ppMembers, nAllMembers, and ppAllMembers of an incomplete interface type
483// description are necessary, but not the additional
484// pMapMemberIndexToFunctionIndex, nMapFunctionIndexToMemberIndex, and
485// pMapFunctionIndexToMemberIndex (which are computed by
486// typelib_typedescription_initTables). Furthermore, in those situations, it
487// might be illegal to compute those tables, as the creation of the interface
488// member type descriptions would recursively require a complete interface type
489// description. The parameter initTables controls whether or not to call
490// typelib_typedescription_initTables in those situations.
491bool complete(typelib_TypeDescription ** ppTypeDescr, bool initTables) {
492 if (! (*ppTypeDescr)->bComplete)
6
Access to field 'bComplete' results in a dereference of a null pointer
493 {
494 OSL_ASSERT( (typelib_TypeClass_STRUCT == (*ppTypeDescr)->eTypeClass ||do { if (true && (!((typelib_TypeClass_STRUCT == (*ppTypeDescr
)->eTypeClass || typelib_TypeClass_EXCEPTION == (*ppTypeDescr
)->eTypeClass || typelib_TypeClass_UNION == (*ppTypeDescr)
->eTypeClass || typelib_TypeClass_ENUM == (*ppTypeDescr)->
eTypeClass || typelib_TypeClass_INTERFACE == (*ppTypeDescr)->
eTypeClass) && !reallyWeak( (*ppTypeDescr)->eTypeClass
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "499" ": "), "OSL_ASSERT: %s", "(typelib_TypeClass_STRUCT == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_EXCEPTION == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_UNION == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_ENUM == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_INTERFACE == (*ppTypeDescr)->eTypeClass) && !reallyWeak( (*ppTypeDescr)->eTypeClass )"
); } } while (false)
495 typelib_TypeClass_EXCEPTION == (*ppTypeDescr)->eTypeClass ||do { if (true && (!((typelib_TypeClass_STRUCT == (*ppTypeDescr
)->eTypeClass || typelib_TypeClass_EXCEPTION == (*ppTypeDescr
)->eTypeClass || typelib_TypeClass_UNION == (*ppTypeDescr)
->eTypeClass || typelib_TypeClass_ENUM == (*ppTypeDescr)->
eTypeClass || typelib_TypeClass_INTERFACE == (*ppTypeDescr)->
eTypeClass) && !reallyWeak( (*ppTypeDescr)->eTypeClass
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "499" ": "), "OSL_ASSERT: %s", "(typelib_TypeClass_STRUCT == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_EXCEPTION == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_UNION == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_ENUM == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_INTERFACE == (*ppTypeDescr)->eTypeClass) && !reallyWeak( (*ppTypeDescr)->eTypeClass )"
); } } while (false)
496 typelib_TypeClass_UNION == (*ppTypeDescr)->eTypeClass ||do { if (true && (!((typelib_TypeClass_STRUCT == (*ppTypeDescr
)->eTypeClass || typelib_TypeClass_EXCEPTION == (*ppTypeDescr
)->eTypeClass || typelib_TypeClass_UNION == (*ppTypeDescr)
->eTypeClass || typelib_TypeClass_ENUM == (*ppTypeDescr)->
eTypeClass || typelib_TypeClass_INTERFACE == (*ppTypeDescr)->
eTypeClass) && !reallyWeak( (*ppTypeDescr)->eTypeClass
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "499" ": "), "OSL_ASSERT: %s", "(typelib_TypeClass_STRUCT == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_EXCEPTION == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_UNION == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_ENUM == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_INTERFACE == (*ppTypeDescr)->eTypeClass) && !reallyWeak( (*ppTypeDescr)->eTypeClass )"
); } } while (false)
497 typelib_TypeClass_ENUM == (*ppTypeDescr)->eTypeClass ||do { if (true && (!((typelib_TypeClass_STRUCT == (*ppTypeDescr
)->eTypeClass || typelib_TypeClass_EXCEPTION == (*ppTypeDescr
)->eTypeClass || typelib_TypeClass_UNION == (*ppTypeDescr)
->eTypeClass || typelib_TypeClass_ENUM == (*ppTypeDescr)->
eTypeClass || typelib_TypeClass_INTERFACE == (*ppTypeDescr)->
eTypeClass) && !reallyWeak( (*ppTypeDescr)->eTypeClass
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "499" ": "), "OSL_ASSERT: %s", "(typelib_TypeClass_STRUCT == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_EXCEPTION == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_UNION == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_ENUM == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_INTERFACE == (*ppTypeDescr)->eTypeClass) && !reallyWeak( (*ppTypeDescr)->eTypeClass )"
); } } while (false)
498 typelib_TypeClass_INTERFACE == (*ppTypeDescr)->eTypeClass) &&do { if (true && (!((typelib_TypeClass_STRUCT == (*ppTypeDescr
)->eTypeClass || typelib_TypeClass_EXCEPTION == (*ppTypeDescr
)->eTypeClass || typelib_TypeClass_UNION == (*ppTypeDescr)
->eTypeClass || typelib_TypeClass_ENUM == (*ppTypeDescr)->
eTypeClass || typelib_TypeClass_INTERFACE == (*ppTypeDescr)->
eTypeClass) && !reallyWeak( (*ppTypeDescr)->eTypeClass
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "499" ": "), "OSL_ASSERT: %s", "(typelib_TypeClass_STRUCT == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_EXCEPTION == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_UNION == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_ENUM == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_INTERFACE == (*ppTypeDescr)->eTypeClass) && !reallyWeak( (*ppTypeDescr)->eTypeClass )"
); } } while (false)
499 !reallyWeak( (*ppTypeDescr)->eTypeClass ) )do { if (true && (!((typelib_TypeClass_STRUCT == (*ppTypeDescr
)->eTypeClass || typelib_TypeClass_EXCEPTION == (*ppTypeDescr
)->eTypeClass || typelib_TypeClass_UNION == (*ppTypeDescr)
->eTypeClass || typelib_TypeClass_ENUM == (*ppTypeDescr)->
eTypeClass || typelib_TypeClass_INTERFACE == (*ppTypeDescr)->
eTypeClass) && !reallyWeak( (*ppTypeDescr)->eTypeClass
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "499" ": "), "OSL_ASSERT: %s", "(typelib_TypeClass_STRUCT == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_EXCEPTION == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_UNION == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_ENUM == (*ppTypeDescr)->eTypeClass || typelib_TypeClass_INTERFACE == (*ppTypeDescr)->eTypeClass) && !reallyWeak( (*ppTypeDescr)->eTypeClass )"
); } } while (false)
;
500
501 if (typelib_TypeClass_INTERFACE == (*ppTypeDescr)->eTypeClass &&
502 ((typelib_InterfaceTypeDescription *)*ppTypeDescr)->ppAllMembers)
503 {
504 if (initTables) {
505 typelib_typedescription_initTables( *ppTypeDescr );
506 }
507 return true;
508 }
509
510 typelib_TypeDescription * pTD = 0;
511 // on demand access of complete td
512 TypeDescriptor_Init_Impl &rInit = Init::get();
513 rInit.callChain( &pTD, (*ppTypeDescr)->pTypeName );
514 if (pTD)
515 {
516 if (typelib_TypeClass_TYPEDEF == pTD->eTypeClass)
517 {
518 typelib_typedescriptionreference_getDescription(
519 &pTD, ((typelib_IndirectTypeDescription *)pTD)->pType );
520 OSL_ASSERT( pTD )do { if (true && (!(pTD))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "520" ": "), "OSL_ASSERT: %s", "pTD"); } } while (false)
;
521 if (! pTD)
522 return false;
523 }
524
525 OSL_ASSERT( typelib_TypeClass_TYPEDEF != pTD->eTypeClass )do { if (true && (!(typelib_TypeClass_TYPEDEF != pTD->
eTypeClass))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "525" ": "), "OSL_ASSERT: %s", "typelib_TypeClass_TYPEDEF != pTD->eTypeClass"
); } } while (false)
;
526 // typedescription found
527 // set to on demand
528 pTD->bOnDemand = sal_True((sal_Bool)1);
529
530 if (pTD->eTypeClass == typelib_TypeClass_INTERFACE
531 && !pTD->bComplete && initTables)
532 {
533 // mandatory info from callback chain
534 OSL_ASSERT( ((typelib_InterfaceTypeDescription *)pTD)->ppAllMembers )do { if (true && (!(((typelib_InterfaceTypeDescription
*)pTD)->ppAllMembers))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "534" ": "), "OSL_ASSERT: %s", "((typelib_InterfaceTypeDescription *)pTD)->ppAllMembers"
); } } while (false)
;
535 // complete except of tables init
536 typelib_typedescription_initTables( pTD );
537 pTD->bComplete = sal_True((sal_Bool)1);
538 }
539
540 // The type description is hold by the reference until
541 // on demand is activated.
542 ::typelib_typedescription_register( &pTD ); // replaces incomplete one
543 OSL_ASSERT( pTD == *ppTypeDescr )do { if (true && (!(pTD == *ppTypeDescr))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "543" ": "), "OSL_ASSERT: %s", "pTD == *ppTypeDescr"); }
} while (false)
; // has to merge into existing one
544
545 // insert into the chache
546 MutexGuard aGuard( rInit.getMutex() );
547 if( !rInit.pCache )
548 rInit.pCache = new TypeDescriptionList_Impl;
549 if( (sal_Int32)rInit.pCache->size() >= nCacheSize )
550 {
551 typelib_typedescription_release( rInit.pCache->front() );
552 rInit.pCache->pop_front();
553 }
554 // descriptions in the cache must be acquired!
555 typelib_typedescription_acquire( pTD );
556 rInit.pCache->push_back( pTD );
557
558 OSL_ASSERT(do { if (true && (!(pTD->bComplete || (pTD->eTypeClass
== typelib_TypeClass_INTERFACE && !initTables)))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "561" ": "), "OSL_ASSERT: %s", "pTD->bComplete || (pTD->eTypeClass == typelib_TypeClass_INTERFACE && !initTables)"
); } } while (false)
559 pTD->bCompletedo { if (true && (!(pTD->bComplete || (pTD->eTypeClass
== typelib_TypeClass_INTERFACE && !initTables)))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "561" ": "), "OSL_ASSERT: %s", "pTD->bComplete || (pTD->eTypeClass == typelib_TypeClass_INTERFACE && !initTables)"
); } } while (false)
560 || (pTD->eTypeClass == typelib_TypeClass_INTERFACEdo { if (true && (!(pTD->bComplete || (pTD->eTypeClass
== typelib_TypeClass_INTERFACE && !initTables)))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "561" ": "), "OSL_ASSERT: %s", "pTD->bComplete || (pTD->eTypeClass == typelib_TypeClass_INTERFACE && !initTables)"
); } } while (false)
561 && !initTables))do { if (true && (!(pTD->bComplete || (pTD->eTypeClass
== typelib_TypeClass_INTERFACE && !initTables)))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "561" ": "), "OSL_ASSERT: %s", "pTD->bComplete || (pTD->eTypeClass == typelib_TypeClass_INTERFACE && !initTables)"
); } } while (false)
;
562
563 ::typelib_typedescription_release( *ppTypeDescr );
564 *ppTypeDescr = pTD;
565 }
566 else
567 {
568#if OSL_DEBUG_LEVEL1 > 1
569 OString aStr(
570 rtl::OUStringToOString( (*ppTypeDescr)->pTypeName, RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11)) ) );
571 OSL_TRACE( "\n### type cannot be completed: %s", aStr.getStr() )do { if (true && (1 > 0)) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "571" ": "), "\n### type cannot be completed: %s", aStr.
getStr()); } } while (false)
;
572#endif
573 return false;
574 }
575 }
576 return true;
577}
578
579}
580
581//------------------------------------------------------------------------
582extern "C" void SAL_CALL typelib_typedescription_newEmpty(
583 typelib_TypeDescription ** ppRet,
584 typelib_TypeClass eTypeClass, rtl_uString * pTypeName )
585 SAL_THROW_EXTERN_C()throw ()
586{
587 if( *ppRet )
588 {
589 typelib_typedescription_release( *ppRet );
590 *ppRet = 0;
591 }
592
593 OSL_ASSERT( typelib_TypeClass_TYPEDEF != eTypeClass )do { if (true && (!(typelib_TypeClass_TYPEDEF != eTypeClass
))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "593" ": "), "OSL_ASSERT: %s", "typelib_TypeClass_TYPEDEF != eTypeClass"
); } } while (false)
;
594
595 typelib_TypeDescription * pRet;
596 switch( eTypeClass )
597 {
598 case typelib_TypeClass_ARRAY:
599 {
600 typelib_ArrayTypeDescription * pTmp = new typelib_ArrayTypeDescription();
601 typelib_IndirectTypeDescription * pIndirect = (typelib_IndirectTypeDescription *)pTmp;
602 pRet = (typelib_TypeDescription *)pTmp;
603#if OSL_DEBUG_LEVEL1 > 1
604 osl_incrementInterlockedCount(
605 &Init::get().nArrayTypeDescriptionCount );
606#endif
607 pIndirect->pType = 0;
608 pTmp->nDimensions = 0;
609 pTmp->nTotalElements = 0;
610 pTmp->pDimensions = 0;
611 }
612 break;
613
614 case typelib_TypeClass_SEQUENCE:
615 {
616 typelib_IndirectTypeDescription * pTmp = new typelib_IndirectTypeDescription();
617 pRet = (typelib_TypeDescription *)pTmp;
618#if OSL_DEBUG_LEVEL1 > 1
619 osl_incrementInterlockedCount(
620 &Init::get().nIndirectTypeDescriptionCount );
621#endif
622 pTmp->pType = 0;
623 }
624 break;
625
626 case typelib_TypeClass_UNION:
627 {
628 typelib_UnionTypeDescription * pTmp;
629 pTmp = new typelib_UnionTypeDescription();
630 pRet = (typelib_TypeDescription *)pTmp;
631#if OSL_DEBUG_LEVEL1 > 1
632 osl_incrementInterlockedCount(
633 &Init::get().nUnionTypeDescriptionCount );
634#endif
635 pTmp->nMembers = 0;
636 pTmp->pDiscriminantTypeRef = 0;
637 pTmp->pDiscriminants = 0;
638 pTmp->ppTypeRefs = 0;
639 pTmp->ppMemberNames = 0;
640 pTmp->pDefaultTypeRef = 0;
641 }
642 break;
643
644 case typelib_TypeClass_STRUCT:
645 {
646 // FEATURE_EMPTYCLASS
647 typelib_StructTypeDescription * pTmp;
648 pTmp = new typelib_StructTypeDescription();
649 pRet = (typelib_TypeDescription *)pTmp;
650#if OSL_DEBUG_LEVEL1 > 1
651 osl_incrementInterlockedCount(
652 &Init::get().nCompoundTypeDescriptionCount );
653#endif
654 pTmp->aBase.pBaseTypeDescription = 0;
655 pTmp->aBase.nMembers = 0;
656 pTmp->aBase.pMemberOffsets = 0;
657 pTmp->aBase.ppTypeRefs = 0;
658 pTmp->aBase.ppMemberNames = 0;
659 pTmp->pParameterizedTypes = 0;
660 }
661 break;
662
663 case typelib_TypeClass_EXCEPTION:
664 {
665 // FEATURE_EMPTYCLASS
666 typelib_CompoundTypeDescription * pTmp;
667 pTmp = new typelib_CompoundTypeDescription();
668 pRet = (typelib_TypeDescription *)pTmp;
669#if OSL_DEBUG_LEVEL1 > 1
670 osl_incrementInterlockedCount(
671 &Init::get().nCompoundTypeDescriptionCount );
672#endif
673 pTmp->pBaseTypeDescription = 0;
674 pTmp->nMembers = 0;
675 pTmp->pMemberOffsets = 0;
676 pTmp->ppTypeRefs = 0;
677 pTmp->ppMemberNames = 0;
678 }
679 break;
680
681 case typelib_TypeClass_ENUM:
682 {
683 typelib_EnumTypeDescription * pTmp = new typelib_EnumTypeDescription();
684 pRet = (typelib_TypeDescription *)pTmp;
685#if OSL_DEBUG_LEVEL1 > 1
686 osl_incrementInterlockedCount(
687 &Init::get().nEnumTypeDescriptionCount );
688#endif
689 pTmp->nDefaultEnumValue = 0;
690 pTmp->nEnumValues = 0;
691 pTmp->ppEnumNames = 0;
692 pTmp->pEnumValues = 0;
693 }
694 break;
695
696 case typelib_TypeClass_INTERFACE:
697 {
698 typelib_InterfaceTypeDescription * pTmp = new typelib_InterfaceTypeDescription();
699 pRet = (typelib_TypeDescription *)pTmp;
700#if OSL_DEBUG_LEVEL1 > 1
701 osl_incrementInterlockedCount(
702 &Init::get().nInterfaceTypeDescriptionCount );
703#endif
704 pTmp->pBaseTypeDescription = 0;
705 pTmp->nMembers = 0;
706 pTmp->ppMembers = 0;
707 pTmp->nAllMembers = 0;
708 pTmp->ppAllMembers = 0;
709 pTmp->nMapFunctionIndexToMemberIndex = 0;
710 pTmp->pMapFunctionIndexToMemberIndex = 0;
711 pTmp->pMapMemberIndexToFunctionIndex= 0;
712 pTmp->nBaseTypes = 0;
713 pTmp->ppBaseTypes = 0;
714 }
715 break;
716
717 case typelib_TypeClass_INTERFACE_METHOD:
718 {
719 typelib_InterfaceMethodTypeDescription * pTmp = new typelib_InterfaceMethodTypeDescription();
720 pRet = (typelib_TypeDescription *)pTmp;
721#if OSL_DEBUG_LEVEL1 > 1
722 osl_incrementInterlockedCount(
723 &Init::get().nInterfaceMethodTypeDescriptionCount );
724#endif
725 pTmp->aBase.pMemberName = 0;
726 pTmp->pReturnTypeRef = 0;
727 pTmp->nParams = 0;
728 pTmp->pParams = 0;
729 pTmp->nExceptions = 0;
730 pTmp->ppExceptions = 0;
731 pTmp->pInterface = 0;
732 pTmp->pBaseRef = 0;
733 pTmp->nIndex = 0;
734 }
735 break;
736
737 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
738 {
739 typelib_InterfaceAttributeTypeDescription * pTmp = new typelib_InterfaceAttributeTypeDescription();
740 pRet = (typelib_TypeDescription *)pTmp;
741#if OSL_DEBUG_LEVEL1 > 1
742 osl_incrementInterlockedCount(
743 &Init::get().nInterfaceAttributeTypeDescriptionCount );
744#endif
745 pTmp->aBase.pMemberName = 0;
746 pTmp->pAttributeTypeRef = 0;
747 pTmp->pInterface = 0;
748 pTmp->pBaseRef = 0;
749 pTmp->nIndex = 0;
750 pTmp->nGetExceptions = 0;
751 pTmp->ppGetExceptions = 0;
752 pTmp->nSetExceptions = 0;
753 pTmp->ppSetExceptions = 0;
754 }
755 break;
756
757 default:
758 {
759 pRet = new typelib_TypeDescription();
760#if OSL_DEBUG_LEVEL1 > 1
761 osl_incrementInterlockedCount( &Init::get().nTypeDescriptionCount );
762#endif
763 }
764 }
765
766 pRet->nRefCount = 1; // reference count is initially 1
767 pRet->nStaticRefCount = 0;
768 pRet->eTypeClass = eTypeClass;
769 pRet->pTypeName = 0;
770 pRet->pUniqueIdentifier = 0;
771 pRet->pReserved = 0;
772 rtl_uString_acquire( pRet->pTypeName = pTypeName );
773 pRet->pSelf = pRet;
774 pRet->bComplete = sal_True((sal_Bool)1);
775 pRet->nSize = 0;
776 pRet->nAlignment = 0;
777 pRet->pWeakRef = 0;
778 pRet->bOnDemand = sal_False((sal_Bool)0);
779 *ppRet = pRet;
780}
781
782//------------------------------------------------------------------------
783namespace {
784
785void newTypeDescription(
786 typelib_TypeDescription ** ppRet, typelib_TypeClass eTypeClass,
787 rtl_uString * pTypeName, typelib_TypeDescriptionReference * pType,
788 sal_Int32 nMembers, typelib_CompoundMember_Init * pCompoundMembers,
789 typelib_StructMember_Init * pStructMembers)
790{
791 OSL_ASSERT(do { if (true && (!((pCompoundMembers == 0 || pStructMembers
== 0) && (pStructMembers == 0 || eTypeClass == typelib_TypeClass_STRUCT
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "793" ": "), "OSL_ASSERT: %s", "(pCompoundMembers == 0 || pStructMembers == 0) && (pStructMembers == 0 || eTypeClass == typelib_TypeClass_STRUCT)"
); } } while (false)
792 (pCompoundMembers == 0 || pStructMembers == 0)do { if (true && (!((pCompoundMembers == 0 || pStructMembers
== 0) && (pStructMembers == 0 || eTypeClass == typelib_TypeClass_STRUCT
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "793" ": "), "OSL_ASSERT: %s", "(pCompoundMembers == 0 || pStructMembers == 0) && (pStructMembers == 0 || eTypeClass == typelib_TypeClass_STRUCT)"
); } } while (false)
793 && (pStructMembers == 0 || eTypeClass == typelib_TypeClass_STRUCT))do { if (true && (!((pCompoundMembers == 0 || pStructMembers
== 0) && (pStructMembers == 0 || eTypeClass == typelib_TypeClass_STRUCT
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "793" ": "), "OSL_ASSERT: %s", "(pCompoundMembers == 0 || pStructMembers == 0) && (pStructMembers == 0 || eTypeClass == typelib_TypeClass_STRUCT)"
); } } while (false)
;
794 if (typelib_TypeClass_TYPEDEF == eTypeClass)
795 {
796 OSL_TRACE( "### unexpected typedef!" )do { if (true && (1 > 0)) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "796" ": "), "### unexpected typedef!"); } } while (false
)
;
797 typelib_typedescriptionreference_getDescription( ppRet, pType );
798 return;
799 }
800
801 typelib_typedescription_newEmpty( ppRet, eTypeClass, pTypeName );
802
803 switch( eTypeClass )
804 {
805 case typelib_TypeClass_SEQUENCE:
806 {
807 OSL_ASSERT( nMembers == 0 )do { if (true && (!(nMembers == 0))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "807" ": "), "OSL_ASSERT: %s", "nMembers == 0"); } } while
(false)
;
808 typelib_typedescriptionreference_acquire( pType );
809 ((typelib_IndirectTypeDescription *)*ppRet)->pType = pType;
810 }
811 break;
812
813 case typelib_TypeClass_EXCEPTION:
814 case typelib_TypeClass_STRUCT:
815 {
816 // FEATURE_EMPTYCLASS
817 typelib_CompoundTypeDescription * pTmp = (typelib_CompoundTypeDescription*)*ppRet;
818
819 sal_Int32 nOffset = 0;
820 if( pType )
821 {
822 typelib_typedescriptionreference_getDescription(
823 (typelib_TypeDescription **)&pTmp->pBaseTypeDescription, pType );
824 nOffset = ((typelib_TypeDescription *)pTmp->pBaseTypeDescription)->nSize;
825 OSL_ENSURE( newAlignedSize( 0, ((typelib_TypeDescription *)pTmp->pBaseTypeDescription)->nSize, ((typelib_TypeDescription *)pTmp->pBaseTypeDescription)->nAlignment ) == ((typelib_TypeDescription *)pTmp->pBaseTypeDescription)->nSize, "### unexpected offset!" )do { if (true && (!(newAlignedSize( 0, ((typelib_TypeDescription
*)pTmp->pBaseTypeDescription)->nSize, ((typelib_TypeDescription
*)pTmp->pBaseTypeDescription)->nAlignment ) == ((typelib_TypeDescription
*)pTmp->pBaseTypeDescription)->nSize))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "825" ": "), "%s", "### unexpected offset!"); } } while (
false)
;
826 }
827 if( nMembers )
828 {
829 pTmp->nMembers = nMembers;
830 pTmp->pMemberOffsets = new sal_Int32[ nMembers ];
831 pTmp->ppTypeRefs = new typelib_TypeDescriptionReference *[ nMembers ];
832 pTmp->ppMemberNames = new rtl_uString *[ nMembers ];
833 bool polymorphic = eTypeClass == typelib_TypeClass_STRUCT
834 && rtl::OUString::unacquired(&pTypeName).indexOf('<') >= 0;
835 OSL_ASSERT(!polymorphic || pStructMembers != 0)do { if (true && (!(!polymorphic || pStructMembers !=
0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "835" ": "), "OSL_ASSERT: %s", "!polymorphic || pStructMembers != 0"
); } } while (false)
;
836 if (polymorphic) {
837 reinterpret_cast< typelib_StructTypeDescription * >(pTmp)->
838 pParameterizedTypes = new sal_Bool[nMembers];
839 }
840 for( sal_Int32 i = 0 ; i < nMembers; i++ )
841 {
842 // read the type and member names
843 pTmp->ppTypeRefs[i] = 0;
844 if (pCompoundMembers != 0) {
845 typelib_typedescriptionreference_new(
846 pTmp->ppTypeRefs +i, pCompoundMembers[i].eTypeClass,
847 pCompoundMembers[i].pTypeName );
848 rtl_uString_acquire(
849 pTmp->ppMemberNames[i]
850 = pCompoundMembers[i].pMemberName );
851 } else {
852 typelib_typedescriptionreference_new(
853 pTmp->ppTypeRefs +i,
854 pStructMembers[i].aBase.eTypeClass,
855 pStructMembers[i].aBase.pTypeName );
856 rtl_uString_acquire(
857 pTmp->ppMemberNames[i]
858 = pStructMembers[i].aBase.pMemberName );
859 }
860 // write offset
861 sal_Int32 size;
862 sal_Int32 alignment;
863 if (pTmp->ppTypeRefs[i]->eTypeClass ==
864 typelib_TypeClass_SEQUENCE)
865 {
866 // Take care of recursion like
867 // struct S { sequence<S> x; };
868 size = sizeof(void *);
869 alignment = adjustAlignment(size);
870 } else {
871 typelib_TypeDescription * pTD = 0;
872 TYPELIB_DANGER_GET( &pTD, pTmp->ppTypeRefs[i] ){ typelib_TypeDescriptionReference * pMacroTypeRef = (pTmp->
ppTypeRefs[i]); typelib_TypeDescription ** ppMacroTypeDescr =
(&pTD); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr
, pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef
->pType->pWeakRef) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release
( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef
->pType; } }
;
873 OSL_ENSURE( pTD->nSize, "### void member?" )do { if (true && (!(pTD->nSize))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "873" ": "), "%s", "### void member?"); } } while (false
)
;
874 size = pTD->nSize;
875 alignment = pTD->nAlignment;
876 TYPELIB_DANGER_RELEASE( pTD ){ if ((((pTD)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| ((pTD)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) typelib_typedescription_release( pTD ); }
;
877 }
878 nOffset = newAlignedSize( nOffset, size, alignment );
879 pTmp->pMemberOffsets[i] = nOffset - size;
880
881 if (polymorphic) {
882 reinterpret_cast< typelib_StructTypeDescription * >(
883 pTmp)->pParameterizedTypes[i]
884 = pStructMembers[i].bParameterizedType;
885 }
886 }
887 }
888 }
889 break;
890
891 default:
892 break;
893 }
894
895 if( !reallyWeak( eTypeClass ) )
896 (*ppRet)->pWeakRef = (typelib_TypeDescriptionReference *)*ppRet;
897 if( eTypeClass != typelib_TypeClass_VOID )
898 {
899 // sizeof( void ) not allowed
900 (*ppRet)->nSize = typelib_typedescription_getAlignedUnoSize( (*ppRet), 0, (*ppRet)->nAlignment );
901 (*ppRet)->nAlignment = adjustAlignment( (*ppRet)->nAlignment );
902 }
903}
904
905}
906
907extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_new(
908 typelib_TypeDescription ** ppRet,
909 typelib_TypeClass eTypeClass,
910 rtl_uString * pTypeName,
911 typelib_TypeDescriptionReference * pType,
912 sal_Int32 nMembers,
913 typelib_CompoundMember_Init * pMembers )
914 SAL_THROW_EXTERN_C()throw ()
915{
916 newTypeDescription(
917 ppRet, eTypeClass, pTypeName, pType, nMembers, pMembers, 0);
918}
919
920extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_newStruct(
921 typelib_TypeDescription ** ppRet,
922 rtl_uString * pTypeName,
923 typelib_TypeDescriptionReference * pType,
924 sal_Int32 nMembers,
925 typelib_StructMember_Init * pMembers )
926 SAL_THROW_EXTERN_C()throw ()
927{
928 newTypeDescription(
929 ppRet, typelib_TypeClass_STRUCT, pTypeName, pType, nMembers, 0,
930 pMembers);
931}
932
933//------------------------------------------------------------------------
934extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_newUnion(
935 typelib_TypeDescription ** ppRet,
936 rtl_uString * pTypeName,
937 typelib_TypeDescriptionReference * pDiscriminantTypeRef,
938 sal_Int64 nDefaultDiscriminant,
939 typelib_TypeDescriptionReference * pDefaultTypeRef,
940 sal_Int32 nMembers,
941 typelib_Union_Init * pMembers )
942 SAL_THROW_EXTERN_C()throw ()
943{
944 typelib_typedescription_newEmpty( ppRet, typelib_TypeClass_UNION, pTypeName );
945 // discriminant type
946 typelib_UnionTypeDescription * pTmp = (typelib_UnionTypeDescription *)*ppRet;
947 typelib_typedescriptionreference_acquire( pTmp->pDiscriminantTypeRef = pDiscriminantTypeRef );
948
949 sal_Int32 nPos;
950
951 pTmp->nMembers = nMembers;
952 // default discriminant
953 if (nMembers)
954 {
955 pTmp->pDiscriminants = new sal_Int64[ nMembers ];
956 for ( nPos = nMembers; nPos--; )
957 {
958 pTmp->pDiscriminants[nPos] = pMembers[nPos].nDiscriminant;
959 }
960 }
961 // default default discriminant
962 pTmp->nDefaultDiscriminant = nDefaultDiscriminant;
963
964 // union member types
965 pTmp->ppTypeRefs = new typelib_TypeDescriptionReference *[ nMembers ];
966 for ( nPos = nMembers; nPos--; )
967 {
968 typelib_typedescriptionreference_acquire( pTmp->ppTypeRefs[nPos] = pMembers[nPos].pTypeRef );
969 }
970 // union member names
971 pTmp->ppMemberNames = new rtl_uString *[ nMembers ];
972 for ( nPos = nMembers; nPos--; )
973 {
974 rtl_uString_acquire( pTmp->ppMemberNames[nPos] = pMembers[nPos].pMemberName );
975 }
976
977 // default union type
978 typelib_typedescriptionreference_acquire( pTmp->pDefaultTypeRef = pDefaultTypeRef );
979
980 if (! reallyWeak( typelib_TypeClass_UNION ))
981 (*ppRet)->pWeakRef = (typelib_TypeDescriptionReference *)*ppRet;
982 (*ppRet)->nSize = typelib_typedescription_getAlignedUnoSize( (*ppRet), 0, (*ppRet)->nAlignment );
983 (*ppRet)->nAlignment = adjustAlignment( (*ppRet)->nAlignment );
984}
985
986//------------------------------------------------------------------------
987extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_newEnum(
988 typelib_TypeDescription ** ppRet,
989 rtl_uString * pTypeName,
990 sal_Int32 nDefaultValue,
991 sal_Int32 nEnumValues,
992 rtl_uString ** ppEnumNames,
993 sal_Int32 * pEnumValues )
994 SAL_THROW_EXTERN_C()throw ()
995{
996 typelib_typedescription_newEmpty( ppRet, typelib_TypeClass_ENUM, pTypeName );
997 typelib_EnumTypeDescription * pEnum = (typelib_EnumTypeDescription *)*ppRet;
998
999 pEnum->nDefaultEnumValue = nDefaultValue;
1000 pEnum->nEnumValues = nEnumValues;
1001 pEnum->ppEnumNames = new rtl_uString * [ nEnumValues ];
1002 for ( sal_Int32 nPos = nEnumValues; nPos--; )
1003 {
1004 rtl_uString_acquire( pEnum->ppEnumNames[nPos] = ppEnumNames[nPos] );
1005 }
1006 pEnum->pEnumValues = new sal_Int32[ nEnumValues ];
1007 ::memcpy( pEnum->pEnumValues, pEnumValues, nEnumValues * sizeof(sal_Int32) );
1008
1009 (*ppRet)->pWeakRef = (typelib_TypeDescriptionReference *)*ppRet;
1010 // sizeof( void ) not allowed
1011 (*ppRet)->nSize = typelib_typedescription_getAlignedUnoSize( (*ppRet), 0, (*ppRet)->nAlignment );
1012 (*ppRet)->nAlignment = adjustAlignment( (*ppRet)->nAlignment );
1013}
1014
1015//------------------------------------------------------------------------
1016extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_newArray(
1017 typelib_TypeDescription ** ppRet,
1018 typelib_TypeDescriptionReference * pElementTypeRef,
1019 sal_Int32 nDimensions,
1020 sal_Int32 * pDimensions )
1021 SAL_THROW_EXTERN_C ()throw ()
1022{
1023 OUStringBuffer aBuf( 32 );
1024 aBuf.append( pElementTypeRef->pTypeName );
1025 sal_Int32 nElements = 1;
1026 for (sal_Int32 i=0; i < nDimensions; i++)
1027 {
1028 aBuf.appendAscii("[");
1029 aBuf.append(pDimensions[i]);
1030 aBuf.appendAscii("]");
1031 nElements *= pDimensions[i];
1032 }
1033 OUString aTypeName( aBuf.makeStringAndClear() );
1034
1035
1036 typelib_typedescription_newEmpty( ppRet, typelib_TypeClass_ARRAY, aTypeName.pData );
1037 typelib_ArrayTypeDescription * pArray = (typelib_ArrayTypeDescription *)*ppRet;
1038
1039 pArray->nDimensions = nDimensions;
1040 pArray->nTotalElements = nElements;
1041 pArray->pDimensions = new sal_Int32[ nDimensions ];
1042 ::memcpy( pArray->pDimensions, pDimensions, nDimensions * sizeof(sal_Int32) );
1043
1044 typelib_typedescriptionreference_acquire(pElementTypeRef);
1045 ((typelib_IndirectTypeDescription*)pArray)->pType = pElementTypeRef;
1046
1047 (*ppRet)->pWeakRef = (typelib_TypeDescriptionReference *)*ppRet;
1048 // sizeof( void ) not allowed
1049 (*ppRet)->nSize = typelib_typedescription_getAlignedUnoSize( *ppRet, 0, (*ppRet)->nAlignment );
1050 (*ppRet)->nAlignment = adjustAlignment( (*ppRet)->nAlignment );
1051}
1052
1053//------------------------------------------------------------------------
1054extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_newInterface(
1055 typelib_InterfaceTypeDescription ** ppRet,
1056 rtl_uString * pTypeName,
1057 sal_uInt32 nUik1, sal_uInt16 nUik2, sal_uInt16 nUik3, sal_uInt32 nUik4, sal_uInt32 nUik5,
1058 typelib_TypeDescriptionReference * pBaseInterface,
1059 sal_Int32 nMembers,
1060 typelib_TypeDescriptionReference ** ppMembers )
1061 SAL_THROW_EXTERN_C()throw ()
1062{
1063 typelib_typedescription_newMIInterface(
2
Calling 'typelib_typedescription_newMIInterface'
1064 ppRet, pTypeName, nUik1, nUik2, nUik3, nUik4, nUik5,
1065 pBaseInterface == 0 ? 0 : 1, &pBaseInterface, nMembers, ppMembers);
1
'?' condition is false
1066}
1067
1068//------------------------------------------------------------------------
1069
1070namespace {
1071
1072class BaseList {
1073public:
1074 struct Entry {
1075 sal_Int32 memberOffset;
1076 sal_Int32 directBaseIndex;
1077 sal_Int32 directBaseMemberOffset;
1078 typelib_InterfaceTypeDescription const * base;
1079 };
1080
1081 typedef std::vector< Entry > List;
1082
1083 BaseList(typelib_InterfaceTypeDescription const * desc);
1084
1085 List const & getList() const { return list; }
1086
1087 sal_Int32 getBaseMembers() const { return members; }
1088
1089private:
1090 typedef std::set< rtl::OUString > Set;
1091
1092 void calculate(
1093 sal_Int32 directBaseIndex, Set & directBaseSet,
1094 sal_Int32 * directBaseMembers,
1095 typelib_InterfaceTypeDescription const * desc);
1096
1097 Set set;
1098 List list;
1099 sal_Int32 members;
1100};
1101
1102BaseList::BaseList(typelib_InterfaceTypeDescription const * desc) {
1103 members = 0;
1104 for (sal_Int32 i = 0; i < desc->nBaseTypes; ++i) {
1105 Set directBaseSet;
1106 sal_Int32 directBaseMembers = 0;
1107 calculate(i, directBaseSet, &directBaseMembers, desc->ppBaseTypes[i]);
1108 }
1109}
1110
1111void BaseList::calculate(
1112 sal_Int32 directBaseIndex, Set & directBaseSet,
1113 sal_Int32 * directBaseMembers,
1114 typelib_InterfaceTypeDescription const * desc)
1115{
1116 for (sal_Int32 i = 0; i < desc->nBaseTypes; ++i) {
1117 calculate(
1118 directBaseIndex, directBaseSet, directBaseMembers,
1119 desc->ppBaseTypes[i]);
1120 }
1121 if (set.insert(desc->aBase.pTypeName).second) {
1122 Entry e;
1123 e.memberOffset = members;
1124 e.directBaseIndex = directBaseIndex;
1125 e.directBaseMemberOffset = *directBaseMembers;
1126 e.base = desc;
1127 list.push_back(e);
1128 OSL_ASSERT(desc->ppAllMembers != 0)do { if (true && (!(desc->ppAllMembers != 0))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1128" ": "), "OSL_ASSERT: %s", "desc->ppAllMembers != 0"
); } } while (false)
;
1129 members += desc->nMembers;
1130 }
1131 if (directBaseSet.insert(desc->aBase.pTypeName).second) {
1132 OSL_ASSERT(desc->ppAllMembers != 0)do { if (true && (!(desc->ppAllMembers != 0))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1132" ": "), "OSL_ASSERT: %s", "desc->ppAllMembers != 0"
); } } while (false)
;
1133 *directBaseMembers += desc->nMembers;
1134 }
1135}
1136
1137}
1138
1139extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_newMIInterface(
1140 typelib_InterfaceTypeDescription ** ppRet,
1141 rtl_uString * pTypeName,
1142 sal_uInt32 nUik1, sal_uInt16 nUik2, sal_uInt16 nUik3, sal_uInt32 nUik4, sal_uInt32 nUik5,
1143 sal_Int32 nBaseInterfaces,
1144 typelib_TypeDescriptionReference ** ppBaseInterfaces,
1145 sal_Int32 nMembers,
1146 typelib_TypeDescriptionReference ** ppMembers )
1147 SAL_THROW_EXTERN_C()throw ()
1148{
1149 if (*ppRet != 0) {
3
Taking false branch
1150 typelib_typedescription_release(&(*ppRet)->aBase);
1151 *ppRet = 0;
1152 }
1153
1154 typelib_InterfaceTypeDescription * pITD = 0;
1155 typelib_typedescription_newEmpty(
1156 (typelib_TypeDescription **)&pITD, typelib_TypeClass_INTERFACE, pTypeName );
1157
1158 pITD->nBaseTypes = nBaseInterfaces;
1159 pITD->ppBaseTypes = new typelib_InterfaceTypeDescription *[nBaseInterfaces];
1160 for (sal_Int32 i = 0; i < nBaseInterfaces; ++i) {
4
Loop condition is true. Entering loop body
1161 pITD->ppBaseTypes[i] = 0;
1162 typelib_typedescriptionreference_getDescription(
1163 reinterpret_cast< typelib_TypeDescription ** >(
1164 &pITD->ppBaseTypes[i]),
1165 ppBaseInterfaces[i]);
1166 if (pITD->ppBaseTypes[i] == 0
1167 || !complete(
5
Calling 'complete'
1168 reinterpret_cast< typelib_TypeDescription ** >(
1169 &pITD->ppBaseTypes[i]),
1170 false))
1171 {
1172 OSL_ASSERT(false)do { if (true && (!(false))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1172" ": "), "OSL_ASSERT: %s", "false"); } } while (false
)
;
1173 return;
1174 }
1175 OSL_ASSERT(pITD->ppBaseTypes[i] != 0)do { if (true && (!(pITD->ppBaseTypes[i] != 0))) {
sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1175" ": "), "OSL_ASSERT: %s", "pITD->ppBaseTypes[i] != 0"
); } } while (false)
;
1176 }
1177 if (nBaseInterfaces > 0) {
1178 pITD->pBaseTypeDescription = pITD->ppBaseTypes[0];
1179 }
1180 // set the
1181 pITD->aUik.m_Data1 = nUik1;
1182 pITD->aUik.m_Data2 = nUik2;
1183 pITD->aUik.m_Data3 = nUik3;
1184 pITD->aUik.m_Data4 = nUik4;
1185 pITD->aUik.m_Data5 = nUik5;
1186
1187 BaseList aBaseList(pITD);
1188 pITD->nAllMembers = nMembers + aBaseList.getBaseMembers();
1189 pITD->nMembers = nMembers;
1190
1191 if( pITD->nAllMembers )
1192 {
1193 // at minimum one member exist, allocate the memory
1194 pITD->ppAllMembers = new typelib_TypeDescriptionReference *[ pITD->nAllMembers ];
1195 sal_Int32 n = 0;
1196
1197 BaseList::List const & rList = aBaseList.getList();
1198 {for (BaseList::List::const_iterator i(rList.begin()); i != rList.end();
1199 ++i)
1200 {
1201 typelib_InterfaceTypeDescription const * pBase = i->base;
1202 typelib_InterfaceTypeDescription const * pDirectBase
1203 = pITD->ppBaseTypes[i->directBaseIndex];
1204 OSL_ASSERT(pBase->ppAllMembers != 0)do { if (true && (!(pBase->ppAllMembers != 0))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1204" ": "), "OSL_ASSERT: %s", "pBase->ppAllMembers != 0"
); } } while (false)
;
1205 for (sal_Int32 j = 0; j < pBase->nMembers; ++j) {
1206 typelib_TypeDescriptionReference const * pDirectBaseMember
1207 = pDirectBase->ppAllMembers[i->directBaseMemberOffset + j];
1208 rtl::OUStringBuffer aBuf(pDirectBaseMember->pTypeName);
1209 aBuf.appendAscii(RTL_CONSTASCII_STRINGPARAM(":@")(&(":@")[0]), ((sal_Int32)(sizeof (":@") / sizeof ((":@")
[0]))-1)
);
1210 aBuf.append(i->directBaseIndex);
1211 aBuf.append(static_cast< sal_Unicode >(','));
1212 aBuf.append(i->memberOffset + j);
1213 aBuf.append(static_cast< sal_Unicode >(':'));
1214 aBuf.append(pITD->aBase.pTypeName);
1215 rtl::OUString aName(aBuf.makeStringAndClear());
1216 typelib_TypeDescriptionReference * pDerivedMember = 0;
1217 typelib_typedescriptionreference_new(
1218 &pDerivedMember, pDirectBaseMember->eTypeClass,
1219 aName.pData);
1220 pITD->ppAllMembers[n++] = pDerivedMember;
1221 }
1222 }}
1223
1224 if( nMembers )
1225 {
1226 pITD->ppMembers = pITD->ppAllMembers + aBaseList.getBaseMembers();
1227 }
1228
1229 // add own members
1230 {for( sal_Int32 i = 0; i < nMembers; i++ )
1231 {
1232 typelib_typedescriptionreference_acquire( ppMembers[i] );
1233 pITD->ppAllMembers[n++] = ppMembers[i];
1234 }}
1235 }
1236
1237 typelib_TypeDescription * pTmp = (typelib_TypeDescription *)pITD;
1238 if( !reallyWeak( typelib_TypeClass_INTERFACE ) )
1239 pTmp->pWeakRef = (typelib_TypeDescriptionReference *)pTmp;
1240 pTmp->nSize = typelib_typedescription_getAlignedUnoSize( pTmp, 0, pTmp->nAlignment );
1241 pTmp->nAlignment = adjustAlignment( pTmp->nAlignment );
1242 pTmp->bComplete = sal_False((sal_Bool)0);
1243
1244 *ppRet = pITD;
1245}
1246
1247//------------------------------------------------------------------------
1248
1249namespace {
1250
1251typelib_TypeDescriptionReference ** copyExceptions(
1252 sal_Int32 count, rtl_uString ** typeNames)
1253{
1254 OSL_ASSERT(count >= 0)do { if (true && (!(count >= 0))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1254" ": "), "OSL_ASSERT: %s", "count >= 0"); } } while
(false)
;
1255 if (count == 0) {
1256 return 0;
1257 }
1258 typelib_TypeDescriptionReference ** p
1259 = new typelib_TypeDescriptionReference *[count];
1260 for (sal_Int32 i = 0; i < count; ++i) {
1261 p[i] = 0;
1262 typelib_typedescriptionreference_new(
1263 p + i, typelib_TypeClass_EXCEPTION, typeNames[i]);
1264 }
1265 return p;
1266}
1267
1268}
1269
1270extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_newInterfaceMethod(
1271 typelib_InterfaceMethodTypeDescription ** ppRet,
1272 sal_Int32 nAbsolutePosition,
1273 sal_Bool bOneWay,
1274 rtl_uString * pTypeName,
1275 typelib_TypeClass eReturnTypeClass,
1276 rtl_uString * pReturnTypeName,
1277 sal_Int32 nParams,
1278 typelib_Parameter_Init * pParams,
1279 sal_Int32 nExceptions,
1280 rtl_uString ** ppExceptionNames )
1281 SAL_THROW_EXTERN_C()throw ()
1282{
1283 if (*ppRet != 0) {
1284 typelib_typedescription_release(&(*ppRet)->aBase.aBase);
1285 *ppRet = 0;
1286 }
1287 sal_Int32 nOffset = rtl_ustr_lastIndexOfChar_WithLength(
1288 pTypeName->buffer, pTypeName->length, ':');
1289 if (nOffset <= 0 || pTypeName->buffer[nOffset - 1] != ':') {
1290 OSL_FAIL("Bad interface method type name")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1290" ": "), "%s", "Bad interface method type name"); }
} while (false)
;
1291 return;
1292 }
1293 rtl::OUString aInterfaceTypeName(pTypeName->buffer, nOffset - 1);
1294 typelib_InterfaceTypeDescription * pInterface = 0;
1295 typelib_typedescription_getByName(
1296 reinterpret_cast< typelib_TypeDescription ** >(&pInterface),
1297 aInterfaceTypeName.pData);
1298 if (pInterface == 0
1299 || pInterface->aBase.eTypeClass != typelib_TypeClass_INTERFACE
1300 || !complete(
1301 reinterpret_cast< typelib_TypeDescription ** >(&pInterface), false))
1302 {
1303 OSL_FAIL("No interface corresponding to interface method")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1303" ": "), "%s", "No interface corresponding to interface method"
); } } while (false)
;
1304 return;
1305 }
1306
1307 typelib_typedescription_newEmpty(
1308 (typelib_TypeDescription **)ppRet, typelib_TypeClass_INTERFACE_METHOD, pTypeName );
1309 typelib_TypeDescription * pTmp = (typelib_TypeDescription *)*ppRet;
1310
1311 rtl_uString_newFromStr_WithLength( &(*ppRet)->aBase.pMemberName,
1312 pTypeName->buffer + nOffset +1,
1313 pTypeName->length - nOffset -1 );
1314 (*ppRet)->aBase.nPosition = nAbsolutePosition;
1315 (*ppRet)->bOneWay = bOneWay;
1316 typelib_typedescriptionreference_new( &(*ppRet)->pReturnTypeRef, eReturnTypeClass, pReturnTypeName );
1317 (*ppRet)->nParams = nParams;
1318 if( nParams )
1319 {
1320 (*ppRet)->pParams = new typelib_MethodParameter[ nParams ];
1321
1322 for( sal_Int32 i = 0; i < nParams; i++ )
1323 {
1324 // get the name of the parameter
1325 (*ppRet)->pParams[ i ].pName = 0;
1326 rtl_uString_acquire( (*ppRet)->pParams[ i ].pName = pParams[i].pParamName );
1327 (*ppRet)->pParams[ i ].pTypeRef = 0;
1328 // get the type name of the parameter and create the weak reference
1329 typelib_typedescriptionreference_new(
1330 &(*ppRet)->pParams[ i ].pTypeRef, pParams[i].eTypeClass, pParams[i].pTypeName );
1331 (*ppRet)->pParams[ i ].bIn = pParams[i].bIn;
1332 (*ppRet)->pParams[ i ].bOut = pParams[i].bOut;
1333 }
1334 }
1335 (*ppRet)->nExceptions = nExceptions;
1336 (*ppRet)->ppExceptions = copyExceptions(nExceptions, ppExceptionNames);
1337 (*ppRet)->pInterface = pInterface;
1338 (*ppRet)->pBaseRef = 0;
1339 OSL_ASSERT(do { if (true && (!((nAbsolutePosition >= pInterface
->nAllMembers - pInterface->nMembers) && nAbsolutePosition
< pInterface->nAllMembers))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1341" ": "), "OSL_ASSERT: %s", "(nAbsolutePosition >= pInterface->nAllMembers - pInterface->nMembers) && nAbsolutePosition < pInterface->nAllMembers"
); } } while (false)
1340 (nAbsolutePosition >= pInterface->nAllMembers - pInterface->nMembers)do { if (true && (!((nAbsolutePosition >= pInterface
->nAllMembers - pInterface->nMembers) && nAbsolutePosition
< pInterface->nAllMembers))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1341" ": "), "OSL_ASSERT: %s", "(nAbsolutePosition >= pInterface->nAllMembers - pInterface->nMembers) && nAbsolutePosition < pInterface->nAllMembers"
); } } while (false)
1341 && nAbsolutePosition < pInterface->nAllMembers)do { if (true && (!((nAbsolutePosition >= pInterface
->nAllMembers - pInterface->nMembers) && nAbsolutePosition
< pInterface->nAllMembers))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1341" ": "), "OSL_ASSERT: %s", "(nAbsolutePosition >= pInterface->nAllMembers - pInterface->nMembers) && nAbsolutePosition < pInterface->nAllMembers"
); } } while (false)
;
1342 (*ppRet)->nIndex = nAbsolutePosition
1343 - (pInterface->nAllMembers - pInterface->nMembers);
1344 if( !reallyWeak( typelib_TypeClass_INTERFACE_METHOD ) )
1345 pTmp->pWeakRef = (typelib_TypeDescriptionReference *)pTmp;
1346}
1347
1348
1349//------------------------------------------------------------------------
1350extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_newInterfaceAttribute(
1351 typelib_InterfaceAttributeTypeDescription ** ppRet,
1352 sal_Int32 nAbsolutePosition,
1353 rtl_uString * pTypeName,
1354 typelib_TypeClass eAttributeTypeClass,
1355 rtl_uString * pAttributeTypeName,
1356 sal_Bool bReadOnly )
1357 SAL_THROW_EXTERN_C()throw ()
1358{
1359 typelib_typedescription_newExtendedInterfaceAttribute(
1360 ppRet, nAbsolutePosition, pTypeName, eAttributeTypeClass,
1361 pAttributeTypeName, bReadOnly, 0, 0, 0, 0);
1362}
1363
1364//------------------------------------------------------------------------
1365extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_newExtendedInterfaceAttribute(
1366 typelib_InterfaceAttributeTypeDescription ** ppRet,
1367 sal_Int32 nAbsolutePosition,
1368 rtl_uString * pTypeName,
1369 typelib_TypeClass eAttributeTypeClass,
1370 rtl_uString * pAttributeTypeName,
1371 sal_Bool bReadOnly,
1372 sal_Int32 nGetExceptions, rtl_uString ** ppGetExceptionNames,
1373 sal_Int32 nSetExceptions, rtl_uString ** ppSetExceptionNames )
1374 SAL_THROW_EXTERN_C()throw ()
1375{
1376 if (*ppRet != 0) {
1377 typelib_typedescription_release(&(*ppRet)->aBase.aBase);
1378 *ppRet = 0;
1379 }
1380 sal_Int32 nOffset = rtl_ustr_lastIndexOfChar_WithLength(
1381 pTypeName->buffer, pTypeName->length, ':');
1382 if (nOffset <= 0 || pTypeName->buffer[nOffset - 1] != ':') {
1383 OSL_FAIL("Bad interface attribute type name")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1383" ": "), "%s", "Bad interface attribute type name")
; } } while (false)
;
1384 return;
1385 }
1386 rtl::OUString aInterfaceTypeName(pTypeName->buffer, nOffset - 1);
1387 typelib_InterfaceTypeDescription * pInterface = 0;
1388 typelib_typedescription_getByName(
1389 reinterpret_cast< typelib_TypeDescription ** >(&pInterface),
1390 aInterfaceTypeName.pData);
1391 if (pInterface == 0
1392 || pInterface->aBase.eTypeClass != typelib_TypeClass_INTERFACE
1393 || !complete(
1394 reinterpret_cast< typelib_TypeDescription ** >(&pInterface), false))
1395 {
1396 OSL_FAIL("No interface corresponding to interface attribute")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1396" ": "), "%s", "No interface corresponding to interface attribute"
); } } while (false)
;
1397 return;
1398 }
1399
1400 typelib_typedescription_newEmpty(
1401 (typelib_TypeDescription **)ppRet, typelib_TypeClass_INTERFACE_ATTRIBUTE, pTypeName );
1402 typelib_TypeDescription * pTmp = (typelib_TypeDescription *)*ppRet;
1403
1404 rtl_uString_newFromStr_WithLength( &(*ppRet)->aBase.pMemberName,
1405 pTypeName->buffer + nOffset +1,
1406 pTypeName->length - nOffset -1 );
1407 (*ppRet)->aBase.nPosition = nAbsolutePosition;
1408 typelib_typedescriptionreference_new( &(*ppRet)->pAttributeTypeRef, eAttributeTypeClass, pAttributeTypeName );
1409 (*ppRet)->bReadOnly = bReadOnly;
1410 (*ppRet)->pInterface = pInterface;
1411 (*ppRet)->pBaseRef = 0;
1412 OSL_ASSERT(do { if (true && (!((nAbsolutePosition >= pInterface
->nAllMembers - pInterface->nMembers) && nAbsolutePosition
< pInterface->nAllMembers))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1414" ": "), "OSL_ASSERT: %s", "(nAbsolutePosition >= pInterface->nAllMembers - pInterface->nMembers) && nAbsolutePosition < pInterface->nAllMembers"
); } } while (false)
1413 (nAbsolutePosition >= pInterface->nAllMembers - pInterface->nMembers)do { if (true && (!((nAbsolutePosition >= pInterface
->nAllMembers - pInterface->nMembers) && nAbsolutePosition
< pInterface->nAllMembers))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1414" ": "), "OSL_ASSERT: %s", "(nAbsolutePosition >= pInterface->nAllMembers - pInterface->nMembers) && nAbsolutePosition < pInterface->nAllMembers"
); } } while (false)
1414 && nAbsolutePosition < pInterface->nAllMembers)do { if (true && (!((nAbsolutePosition >= pInterface
->nAllMembers - pInterface->nMembers) && nAbsolutePosition
< pInterface->nAllMembers))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1414" ": "), "OSL_ASSERT: %s", "(nAbsolutePosition >= pInterface->nAllMembers - pInterface->nMembers) && nAbsolutePosition < pInterface->nAllMembers"
); } } while (false)
;
1415 (*ppRet)->nIndex = nAbsolutePosition
1416 - (pInterface->nAllMembers - pInterface->nMembers);
1417 (*ppRet)->nGetExceptions = nGetExceptions;
1418 (*ppRet)->ppGetExceptions = copyExceptions(
1419 nGetExceptions, ppGetExceptionNames);
1420 (*ppRet)->nSetExceptions = nSetExceptions;
1421 (*ppRet)->ppSetExceptions = copyExceptions(
1422 nSetExceptions, ppSetExceptionNames);
1423 if( !reallyWeak( typelib_TypeClass_INTERFACE_ATTRIBUTE ) )
1424 pTmp->pWeakRef = (typelib_TypeDescriptionReference *)pTmp;
1425}
1426
1427//------------------------------------------------------------------------
1428extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_acquire(
1429 typelib_TypeDescription * pTypeDescription )
1430 SAL_THROW_EXTERN_C()throw ()
1431{
1432 ::osl_incrementInterlockedCount( &pTypeDescription->nRefCount );
1433}
1434
1435//------------------------------------------------------------------------
1436
1437namespace {
1438
1439void deleteExceptions(
1440 sal_Int32 count, typelib_TypeDescriptionReference ** exceptions)
1441{
1442 for (sal_Int32 i = 0; i < count; ++i) {
1443 typelib_typedescriptionreference_release(exceptions[i]);
1444 }
1445 delete[] exceptions;
1446}
1447
1448}
1449
1450// frees anything except typelib_TypeDescription base!
1451static inline void typelib_typedescription_destructExtendedMembers(
1452 typelib_TypeDescription * pTD )
1453 SAL_THROW(())
1454{
1455 OSL_ASSERT( typelib_TypeClass_TYPEDEF != pTD->eTypeClass )do { if (true && (!(typelib_TypeClass_TYPEDEF != pTD->
eTypeClass))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1455" ": "), "OSL_ASSERT: %s", "typelib_TypeClass_TYPEDEF != pTD->eTypeClass"
); } } while (false)
;
1456
1457 switch( pTD->eTypeClass )
1458 {
1459 case typelib_TypeClass_ARRAY:
1460 if( ((typelib_IndirectTypeDescription*)pTD)->pType )
1461 typelib_typedescriptionreference_release( ((typelib_IndirectTypeDescription*)pTD)->pType );
1462 delete [] ((typelib_ArrayTypeDescription *)pTD)->pDimensions;
1463 break;
1464 case typelib_TypeClass_SEQUENCE:
1465 if( ((typelib_IndirectTypeDescription*)pTD)->pType )
1466 typelib_typedescriptionreference_release( ((typelib_IndirectTypeDescription*)pTD)->pType );
1467 break;
1468 case typelib_TypeClass_UNION:
1469 {
1470 typelib_UnionTypeDescription * pUnionTD = (typelib_UnionTypeDescription *)pTD;
1471 typelib_typedescriptionreference_release( pUnionTD->pDiscriminantTypeRef );
1472 typelib_typedescriptionreference_release( pUnionTD->pDefaultTypeRef );
1473
1474 sal_Int32 nPos;
1475 typelib_TypeDescriptionReference ** ppTypeRefs = pUnionTD->ppTypeRefs;
1476 for ( nPos = pUnionTD->nMembers; nPos--; )
1477 {
1478 typelib_typedescriptionreference_release( ppTypeRefs[nPos] );
1479 }
1480
1481 rtl_uString ** ppMemberNames = pUnionTD->ppMemberNames;
1482 for ( nPos = pUnionTD->nMembers; nPos--; )
1483 {
1484 rtl_uString_release( ppMemberNames[nPos] );
1485 }
1486 delete [] pUnionTD->ppMemberNames;
1487 delete [] pUnionTD->pDiscriminants;
1488 delete [] pUnionTD->ppTypeRefs;
1489 }
1490 break;
1491 case typelib_TypeClass_STRUCT:
1492 delete[] reinterpret_cast< typelib_StructTypeDescription * >(pTD)->
1493 pParameterizedTypes;
1494 case typelib_TypeClass_EXCEPTION:
1495 {
1496 typelib_CompoundTypeDescription * pCTD = (typelib_CompoundTypeDescription*)pTD;
1497 if( pCTD->pBaseTypeDescription )
1498 typelib_typedescription_release( (typelib_TypeDescription *)pCTD->pBaseTypeDescription );
1499 sal_Int32 i;
1500 for( i = 0; i < pCTD->nMembers; i++ )
1501 {
1502 typelib_typedescriptionreference_release( pCTD->ppTypeRefs[i] );
1503 }
1504 if (pCTD->ppMemberNames)
1505 {
1506 for ( i = 0; i < pCTD->nMembers; i++ )
1507 {
1508 rtl_uString_release( pCTD->ppMemberNames[i] );
1509 }
1510 delete [] pCTD->ppMemberNames;
1511 }
1512 delete [] pCTD->ppTypeRefs;
1513 delete [] pCTD->pMemberOffsets;
1514 }
1515 break;
1516 case typelib_TypeClass_INTERFACE:
1517 {
1518 typelib_InterfaceTypeDescription * pITD = (typelib_InterfaceTypeDescription*)pTD;
1519 {for( sal_Int32 i = 0; i < pITD->nAllMembers; i++ )
1520 {
1521 typelib_typedescriptionreference_release( pITD->ppAllMembers[i] );
1522 }}
1523 delete [] pITD->ppAllMembers;
1524 delete [] pITD->pMapMemberIndexToFunctionIndex;
1525 delete [] pITD->pMapFunctionIndexToMemberIndex;
1526 {for (sal_Int32 i = 0; i < pITD->nBaseTypes; ++i) {
1527 typelib_typedescription_release(
1528 reinterpret_cast< typelib_TypeDescription * >(
1529 pITD->ppBaseTypes[i]));
1530 }}
1531 delete[] pITD->ppBaseTypes;
1532 break;
1533 }
1534 case typelib_TypeClass_INTERFACE_METHOD:
1535 {
1536 typelib_InterfaceMethodTypeDescription * pIMTD = (typelib_InterfaceMethodTypeDescription*)pTD;
1537 if( pIMTD->pReturnTypeRef )
1538 typelib_typedescriptionreference_release( pIMTD->pReturnTypeRef );
1539 for( sal_Int32 i = 0; i < pIMTD->nParams; i++ )
1540 {
1541 rtl_uString_release( pIMTD->pParams[ i ].pName );
1542 typelib_typedescriptionreference_release( pIMTD->pParams[ i ].pTypeRef );
1543 }
1544 delete [] pIMTD->pParams;
1545 deleteExceptions(pIMTD->nExceptions, pIMTD->ppExceptions);
1546 rtl_uString_release( pIMTD->aBase.pMemberName );
1547 typelib_typedescription_release(&pIMTD->pInterface->aBase);
1548 if (pIMTD->pBaseRef != 0) {
1549 typelib_typedescriptionreference_release(pIMTD->pBaseRef);
1550 }
1551 }
1552 break;
1553 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
1554 {
1555 typelib_InterfaceAttributeTypeDescription * pIATD = (typelib_InterfaceAttributeTypeDescription*)pTD;
1556 deleteExceptions(pIATD->nGetExceptions, pIATD->ppGetExceptions);
1557 deleteExceptions(pIATD->nSetExceptions, pIATD->ppSetExceptions);
1558 if( pIATD->pAttributeTypeRef )
1559 typelib_typedescriptionreference_release( pIATD->pAttributeTypeRef );
1560 if( pIATD->aBase.pMemberName )
1561 rtl_uString_release( pIATD->aBase.pMemberName );
1562 typelib_typedescription_release(&pIATD->pInterface->aBase);
1563 if (pIATD->pBaseRef != 0) {
1564 typelib_typedescriptionreference_release(pIATD->pBaseRef);
1565 }
1566 }
1567 break;
1568 case typelib_TypeClass_ENUM:
1569 {
1570 typelib_EnumTypeDescription * pEnum = (typelib_EnumTypeDescription *)pTD;
1571 for ( sal_Int32 nPos = pEnum->nEnumValues; nPos--; )
1572 {
1573 rtl_uString_release( pEnum->ppEnumNames[nPos] );
1574 }
1575 delete [] pEnum->ppEnumNames;
1576 delete [] pEnum->pEnumValues;
1577 }
1578 break;
1579 default:
1580 break;
1581 }
1582}
1583
1584//------------------------------------------------------------------------
1585extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_release(
1586 typelib_TypeDescription * pTD )
1587 SAL_THROW_EXTERN_C()throw ()
1588{
1589 sal_Int32 ref = ::osl_decrementInterlockedCount( &pTD->nRefCount );
1590 OSL_ASSERT(ref >= 0)do { if (true && (!(ref >= 0))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1590" ": "), "OSL_ASSERT: %s", "ref >= 0"); } } while
(false)
;
1591 if (0 == ref)
1592 {
1593 TypeDescriptor_Init_Impl &rInit = Init::get();
1594 if( reallyWeak( pTD->eTypeClass ) )
1595 {
1596 if( pTD->pWeakRef )
1597 {
1598 {
1599 MutexGuard aGuard( rInit.getMutex() );
1600 // remove this description from the weak reference
1601 pTD->pWeakRef->pType = 0;
1602 }
1603 typelib_typedescriptionreference_release( pTD->pWeakRef );
1604 }
1605 }
1606 else
1607 {
1608 // this description is a reference too, so remove it from the hash table
1609 if( rInit.pWeakMap )
1610 {
1611 MutexGuard aGuard( rInit.getMutex() );
1612 WeakMap_Impl::iterator aIt = rInit.pWeakMap->find( (sal_Unicode*)pTD->pTypeName->buffer );
1613 if( aIt != rInit.pWeakMap->end() && (void *)(*aIt).second == (void *)pTD )
1614 {
1615 // remove only if it contains the same object
1616 rInit.pWeakMap->erase( aIt );
1617 }
1618 }
1619 }
1620
1621 typelib_typedescription_destructExtendedMembers( pTD );
1622 rtl_uString_release( pTD->pTypeName );
1623
1624#if OSL_DEBUG_LEVEL1 > 1
1625 switch( pTD->eTypeClass )
1626 {
1627 case typelib_TypeClass_ARRAY:
1628 osl_decrementInterlockedCount( &rInit.nArrayTypeDescriptionCount );
1629 break;
1630 case typelib_TypeClass_SEQUENCE:
1631 osl_decrementInterlockedCount( &rInit.nIndirectTypeDescriptionCount );
1632 break;
1633 case typelib_TypeClass_UNION:
1634 osl_decrementInterlockedCount( &rInit.nUnionTypeDescriptionCount );
1635 break;
1636 case typelib_TypeClass_STRUCT:
1637 case typelib_TypeClass_EXCEPTION:
1638 osl_decrementInterlockedCount( &rInit.nCompoundTypeDescriptionCount );
1639 break;
1640 case typelib_TypeClass_INTERFACE:
1641 osl_decrementInterlockedCount( &rInit.nInterfaceTypeDescriptionCount );
1642 break;
1643 case typelib_TypeClass_INTERFACE_METHOD:
1644 osl_decrementInterlockedCount( &rInit.nInterfaceMethodTypeDescriptionCount );
1645 break;
1646 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
1647 osl_decrementInterlockedCount( &rInit.nInterfaceAttributeTypeDescriptionCount );
1648 break;
1649 case typelib_TypeClass_ENUM:
1650 osl_decrementInterlockedCount( &rInit.nEnumTypeDescriptionCount );
1651 break;
1652 default:
1653 osl_decrementInterlockedCount( &rInit.nTypeDescriptionCount );
1654 }
1655#endif
1656
1657 delete pTD;
1658 }
1659}
1660
1661//------------------------------------------------------------------------
1662extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_register(
1663 typelib_TypeDescription ** ppNewDescription )
1664 SAL_THROW_EXTERN_C()throw ()
1665{
1666 // connect the description with the weak reference
1667 TypeDescriptor_Init_Impl &rInit = Init::get();
1668 ClearableMutexGuard aGuard( rInit.getMutex() );
1669
1670 typelib_TypeDescriptionReference * pTDR = 0;
1671 typelib_typedescriptionreference_getByName( &pTDR, (*ppNewDescription)->pTypeName );
1672
1673 OSL_ASSERT( (*ppNewDescription)->pWeakRef || reallyWeak( (*ppNewDescription)->eTypeClass ) )do { if (true && (!((*ppNewDescription)->pWeakRef ||
reallyWeak( (*ppNewDescription)->eTypeClass )))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1673" ": "), "OSL_ASSERT: %s", "(*ppNewDescription)->pWeakRef || reallyWeak( (*ppNewDescription)->eTypeClass )"
); } } while (false)
;
1674 if( pTDR )
1675 {
1676 OSL_ASSERT( (*ppNewDescription)->eTypeClass == pTDR->eTypeClass )do { if (true && (!((*ppNewDescription)->eTypeClass
== pTDR->eTypeClass))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1676" ": "), "OSL_ASSERT: %s", "(*ppNewDescription)->eTypeClass == pTDR->eTypeClass"
); } } while (false)
;
1677 if( pTDR->pType )
1678 {
1679 if (reallyWeak( pTDR->eTypeClass ))
1680 {
1681 // pRef->pType->pWeakRef == 0 means that the description is empty
1682 if (pTDR->pType->pWeakRef)
1683 {
1684 if (osl_incrementInterlockedCount( &pTDR->pType->nRefCount ) > 1)
1685 {
1686 // The refence is incremented. The object cannot be destroyed.
1687 // Release the guard at the earliest point.
1688 aGuard.clear();
1689 ::typelib_typedescription_release( *ppNewDescription );
1690 *ppNewDescription = pTDR->pType;
1691 ::typelib_typedescriptionreference_release( pTDR );
1692 return;
1693 }
1694 else
1695 {
1696 // destruction of this type in progress (another thread!)
1697 osl_decrementInterlockedCount( &pTDR->pType->nRefCount );
1698 }
1699 }
1700 // take new descr
1701 pTDR->pType = *ppNewDescription;
1702 OSL_ASSERT( ! (*ppNewDescription)->pWeakRef )do { if (true && (!(! (*ppNewDescription)->pWeakRef
))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1702" ": "), "OSL_ASSERT: %s", "! (*ppNewDescription)->pWeakRef"
); } } while (false)
;
1703 (*ppNewDescription)->pWeakRef = pTDR;
1704 return;
1705 }
1706 // !reallyWeak
1707
1708 if (((void *)pTDR != (void *)*ppNewDescription) && // if different
1709 (!pTDR->pType->pWeakRef || // uninit: ref data only set
1710 // new one is complete:
1711 (!pTDR->pType->bComplete && (*ppNewDescription)->bComplete) ||
1712 // new one may be partly initialized interface (except of tables):
1713 (typelib_TypeClass_INTERFACE == pTDR->pType->eTypeClass &&
1714 !((typelib_InterfaceTypeDescription *)pTDR->pType)->ppAllMembers &&
1715 (*(typelib_InterfaceTypeDescription **)ppNewDescription)->ppAllMembers)))
1716 {
1717 // uninitialized or incomplete
1718
1719 if (pTDR->pType->pWeakRef) // if init
1720 {
1721 typelib_typedescription_destructExtendedMembers( pTDR->pType );
1722 }
1723
1724 // pTDR->pType->pWeakRef == 0 means that the description is empty
1725 // description is not weak and the not the same
1726 sal_Int32 nSize = getDescriptionSize( (*ppNewDescription)->eTypeClass );
1727
1728 // copy all specific data for the descriptions
1729 memcpy(
1730 pTDR->pType +1,
1731 *ppNewDescription +1,
1732 nSize - sizeof(typelib_TypeDescription) );
1733
1734 pTDR->pType->bComplete = (*ppNewDescription)->bComplete;
1735 pTDR->pType->nSize = (*ppNewDescription)->nSize;
1736 pTDR->pType->nAlignment = (*ppNewDescription)->nAlignment;
1737
1738 memset(
1739 *ppNewDescription +1,
1740 0,
1741 nSize - sizeof( typelib_TypeDescription ) );
1742
1743 if( pTDR->pType->bOnDemand && !(*ppNewDescription)->bOnDemand )
1744 {
1745 // switch from OnDemand to !OnDemand, so the description must be acquired
1746 typelib_typedescription_acquire( pTDR->pType );
1747 }
1748 else if( !pTDR->pType->bOnDemand && (*ppNewDescription)->bOnDemand )
1749 {
1750 // switch from !OnDemand to OnDemand, so the description must be relesed
1751 typelib_typedescription_release( pTDR->pType );
1752 }
1753
1754 pTDR->pType->bOnDemand = (*ppNewDescription)->bOnDemand;
1755 // initialized
1756 pTDR->pType->pWeakRef = pTDR;
1757 }
1758
1759 typelib_typedescription_release( *ppNewDescription );
1760 // pTDR was acquired by getByName(), so it must not be acquired again
1761 *ppNewDescription = pTDR->pType;
1762 return;
1763 }
1764 }
1765 else if( reallyWeak( (*ppNewDescription)->eTypeClass) )
1766 {
1767 typelib_typedescriptionreference_new(
1768 &pTDR, (*ppNewDescription)->eTypeClass, (*ppNewDescription)->pTypeName );
1769 }
1770 else
1771 {
1772 pTDR = (typelib_TypeDescriptionReference *)*ppNewDescription;
1773 if( !rInit.pWeakMap )
1774 rInit.pWeakMap = new WeakMap_Impl;
1775
1776 // description is the weak itself, so register it
1777 (*rInit.pWeakMap)[pTDR->pTypeName->buffer] = pTDR;
1778 OSL_ASSERT( (void *)*ppNewDescription == (void *)pTDR )do { if (true && (!((void *)*ppNewDescription == (void
*)pTDR))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN)
, ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1778" ": "), "OSL_ASSERT: %s", "(void *)*ppNewDescription == (void *)pTDR"
); } } while (false)
;
1779 }
1780
1781 // By default this reference is not really weak. The reference hold the description
1782 // and the description hold the reference.
1783 if( !(*ppNewDescription)->bOnDemand )
1784 {
1785 // nor OnDemand so the description must be acquired if registered
1786 typelib_typedescription_acquire( *ppNewDescription );
1787 }
1788
1789 pTDR->pType = *ppNewDescription;
1790 (*ppNewDescription)->pWeakRef = pTDR;
1791 OSL_ASSERT( rtl_ustr_compare( pTDR->pTypeName->buffer, (*ppNewDescription)->pTypeName->buffer ) == 0 )do { if (true && (!(rtl_ustr_compare( pTDR->pTypeName
->buffer, (*ppNewDescription)->pTypeName->buffer ) ==
0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1791" ": "), "OSL_ASSERT: %s", "rtl_ustr_compare( pTDR->pTypeName->buffer, (*ppNewDescription)->pTypeName->buffer ) == 0"
); } } while (false)
;
1792 OSL_ASSERT( pTDR->eTypeClass == (*ppNewDescription)->eTypeClass )do { if (true && (!(pTDR->eTypeClass == (*ppNewDescription
)->eTypeClass))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1792" ": "), "OSL_ASSERT: %s", "pTDR->eTypeClass == (*ppNewDescription)->eTypeClass"
); } } while (false)
;
1793}
1794
1795//------------------------------------------------------------------------
1796static inline sal_Bool type_equals(
1797 typelib_TypeDescriptionReference * p1, typelib_TypeDescriptionReference * p2 )
1798 SAL_THROW(())
1799{
1800 return (p1 == p2 ||
1801 (p1->eTypeClass == p2->eTypeClass &&
1802 p1->pTypeName->length == p2->pTypeName->length &&
1803 rtl_ustr_compare( p1->pTypeName->buffer, p2->pTypeName->buffer ) == 0));
1804}
1805extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) sal_Bool SAL_CALL typelib_typedescription_equals(
1806 const typelib_TypeDescription * p1, const typelib_TypeDescription * p2 )
1807 SAL_THROW_EXTERN_C()throw ()
1808{
1809 return type_equals(
1810 (typelib_TypeDescriptionReference *)p1, (typelib_TypeDescriptionReference *)p2 );
1811}
1812
1813//------------------------------------------------------------------------
1814extern "C" sal_Int32 SAL_CALL typelib_typedescription_getAlignedUnoSize(
1815 const typelib_TypeDescription * pTypeDescription,
1816 sal_Int32 nOffset, sal_Int32 & rMaxIntegralTypeSize )
1817 SAL_THROW_EXTERN_C()throw ()
1818{
1819 sal_Int32 nSize;
1820 if( pTypeDescription->nSize )
1821 {
1822 // size and alignment are set
1823 rMaxIntegralTypeSize = pTypeDescription->nAlignment;
1824 nSize = pTypeDescription->nSize;
1825 }
1826 else
1827 {
1828 nSize = 0;
1829 rMaxIntegralTypeSize = 1;
1830
1831 OSL_ASSERT( typelib_TypeClass_TYPEDEF != pTypeDescription->eTypeClass )do { if (true && (!(typelib_TypeClass_TYPEDEF != pTypeDescription
->eTypeClass))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1831" ": "), "OSL_ASSERT: %s", "typelib_TypeClass_TYPEDEF != pTypeDescription->eTypeClass"
); } } while (false)
;
1832
1833 switch( pTypeDescription->eTypeClass )
1834 {
1835 case typelib_TypeClass_INTERFACE:
1836 // FEATURE_INTERFACE
1837 nSize = rMaxIntegralTypeSize = (sal_Int32)(sizeof( void * ));
1838 break;
1839 case typelib_TypeClass_UNION:
1840 {
1841 nSize = rMaxIntegralTypeSize = (sal_Int32)(sizeof(sal_Int64));
1842 for ( sal_Int32 nPos = ((typelib_UnionTypeDescription *)pTypeDescription)->nMembers; nPos--; )
1843 {
1844 typelib_TypeDescription * pTD = 0;
1845 TYPELIB_DANGER_GET( &pTD, ((typelib_UnionTypeDescription *)pTypeDescription)->ppTypeRefs[nPos] ){ typelib_TypeDescriptionReference * pMacroTypeRef = (((typelib_UnionTypeDescription
*)pTypeDescription)->ppTypeRefs[nPos]); typelib_TypeDescription
** ppMacroTypeDescr = (&pTD); if (((pMacroTypeRef->eTypeClass
) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef->
eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE)) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); } else if (!pMacroTypeRef
->pType || !pMacroTypeRef->pType->pWeakRef) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release
( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef
->pType; } }
;
1846 sal_Int32 nMaxIntegralTypeSize;
1847 sal_Int32 nMemberSize = typelib_typedescription_getAlignedUnoSize( pTD, (sal_Int32)(sizeof(sal_Int64)), nMaxIntegralTypeSize );
1848 TYPELIB_DANGER_RELEASE( pTD ){ if ((((pTD)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| ((pTD)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) typelib_typedescription_release( pTD ); }
;
1849 if (nSize < nMemberSize)
1850 nSize = nMemberSize;
1851 if (rMaxIntegralTypeSize < nMaxIntegralTypeSize)
1852 rMaxIntegralTypeSize = nMaxIntegralTypeSize;
1853 }
1854 ((typelib_UnionTypeDescription *)pTypeDescription)->nValueOffset = rMaxIntegralTypeSize;
1855 }
1856 break;
1857 case typelib_TypeClass_ENUM:
1858 nSize = rMaxIntegralTypeSize = (sal_Int32)(sizeof( typelib_TypeClass ));
1859 break;
1860 case typelib_TypeClass_STRUCT:
1861 case typelib_TypeClass_EXCEPTION:
1862 // FEATURE_EMPTYCLASS
1863 {
1864 typelib_CompoundTypeDescription * pTmp = (typelib_CompoundTypeDescription *)pTypeDescription;
1865 sal_Int32 nStructSize = 0;
1866 if( pTmp->pBaseTypeDescription )
1867 {
1868 // inherit structs extends the base struct.
1869 nStructSize = pTmp->pBaseTypeDescription->aBase.nSize;
1870 rMaxIntegralTypeSize = pTmp->pBaseTypeDescription->aBase.nAlignment;
1871 }
1872 for( sal_Int32 i = 0; i < pTmp->nMembers; i++ )
1873 {
1874 typelib_TypeDescription * pMemberType = 0;
1875 typelib_TypeDescriptionReference * pMemberRef = pTmp->ppTypeRefs[i];
1876
1877 sal_Int32 nMaxIntegral;
1878 if (pMemberRef->eTypeClass == typelib_TypeClass_INTERFACE
1879 || pMemberRef->eTypeClass == typelib_TypeClass_SEQUENCE)
1880 {
1881 nMaxIntegral = (sal_Int32)(sizeof(void *));
1882 nStructSize = newAlignedSize( nStructSize, nMaxIntegral, nMaxIntegral );
1883 }
1884 else
1885 {
1886 TYPELIB_DANGER_GET( &pMemberType, pMemberRef ){ typelib_TypeDescriptionReference * pMacroTypeRef = (pMemberRef
); typelib_TypeDescription ** ppMacroTypeDescr = (&pMemberType
); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr
, pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef
->pType->pWeakRef) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release
( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef
->pType; } }
;
1887 nStructSize = typelib_typedescription_getAlignedUnoSize(
1888 pMemberType, nStructSize, nMaxIntegral );
1889 TYPELIB_DANGER_RELEASE( pMemberType ){ if ((((pMemberType)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| ((pMemberType)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) typelib_typedescription_release( pMemberType ); }
;
1890 }
1891 if( nMaxIntegral > rMaxIntegralTypeSize )
1892 rMaxIntegralTypeSize = nMaxIntegral;
1893 }
1894#ifdef __m68k__
1895 // Anything that is at least 16 bits wide is aligned on a 16-bit
1896 // boundary on the m68k default abi
1897 sal_Int32 nMaxAlign = (rMaxIntegralTypeSize > 2) ? 2 : rMaxIntegralTypeSize;
1898 nStructSize = (nStructSize + nMaxAlign -1) / nMaxAlign * nMaxAlign;
1899#else
1900 // Example: A { double; int; } structure has a size of 16 instead of 10. The
1901 // compiler must follow this rule if it is possible to access members in arrays through:
1902 // (Element *)((char *)pArray + sizeof( Element ) * ElementPos)
1903 nStructSize = (nStructSize + rMaxIntegralTypeSize -1)
1904 / rMaxIntegralTypeSize * rMaxIntegralTypeSize;
1905#endif
1906 nSize += nStructSize;
1907 }
1908 break;
1909 case typelib_TypeClass_ARRAY:
1910 {
1911 typelib_TypeDescription * pTD = 0;
1912 TYPELIB_DANGER_GET( &pTD, ((typelib_IndirectTypeDescription *)pTypeDescription)->pType ){ typelib_TypeDescriptionReference * pMacroTypeRef = (((typelib_IndirectTypeDescription
*)pTypeDescription)->pType); typelib_TypeDescription ** ppMacroTypeDescr
= (&pTD); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr
, pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef
->pType->pWeakRef) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release
( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef
->pType; } }
;
1913 rMaxIntegralTypeSize = pTD->nSize;
1914 TYPELIB_DANGER_RELEASE( pTD ){ if ((((pTD)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| ((pTD)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) typelib_typedescription_release( pTD ); }
;
1915 nSize = ((typelib_ArrayTypeDescription *)pTypeDescription)->nTotalElements * rMaxIntegralTypeSize;
1916 }
1917 break;
1918 case typelib_TypeClass_SEQUENCE:
1919 nSize = rMaxIntegralTypeSize = (sal_Int32)(sizeof( void * ));
1920 break;
1921 case typelib_TypeClass_ANY:
1922 // FEATURE_ANY
1923 nSize = (sal_Int32)(sizeof( uno_Any ));
1924 rMaxIntegralTypeSize = (sal_Int32)(sizeof( void * ));
1925 break;
1926 case typelib_TypeClass_TYPE:
1927 nSize = rMaxIntegralTypeSize = (sal_Int32)(sizeof( typelib_TypeDescriptionReference * ));
1928 break;
1929 case typelib_TypeClass_BOOLEAN:
1930 nSize = rMaxIntegralTypeSize = (sal_Int32)(sizeof( sal_Bool ));
1931 break;
1932 case typelib_TypeClass_CHAR:
1933 nSize = rMaxIntegralTypeSize = (sal_Int32)(sizeof( sal_Unicode ));
1934 break;
1935 case typelib_TypeClass_STRING:
1936 // FEATURE_STRING
1937 nSize = rMaxIntegralTypeSize = (sal_Int32)(sizeof( rtl_uString * ));
1938 break;
1939 case typelib_TypeClass_FLOAT:
1940 nSize = rMaxIntegralTypeSize = (sal_Int32)(sizeof( float ));
1941 break;
1942 case typelib_TypeClass_DOUBLE:
1943#ifdef AIX
1944 //See previous AIX ifdef comment for an explanation
1945 nSize = (sal_Int32)(sizeof(double));
1946 rMaxIntegralTypeSize = (sal_Int32)(sizeof(void*));
1947#else
1948 nSize = rMaxIntegralTypeSize = (sal_Int32)(sizeof( double ));
1949#endif
1950 break;
1951 case typelib_TypeClass_BYTE:
1952 nSize = rMaxIntegralTypeSize = (sal_Int32)(sizeof( sal_Int8 ));
1953 break;
1954 case typelib_TypeClass_SHORT:
1955 case typelib_TypeClass_UNSIGNED_SHORT:
1956 nSize = rMaxIntegralTypeSize = (sal_Int32)(sizeof( sal_Int16 ));
1957 break;
1958 case typelib_TypeClass_LONG:
1959 case typelib_TypeClass_UNSIGNED_LONG:
1960 nSize = rMaxIntegralTypeSize = (sal_Int32)(sizeof( sal_Int32 ));
1961 break;
1962 case typelib_TypeClass_HYPER:
1963 case typelib_TypeClass_UNSIGNED_HYPER:
1964 nSize = rMaxIntegralTypeSize = (sal_Int32)(sizeof( sal_Int64 ));
1965 break;
1966 case typelib_TypeClass_UNKNOWN:
1967 case typelib_TypeClass_SERVICE:
1968 case typelib_TypeClass_MODULE:
1969 default:
1970 OSL_FAIL( "not convertable type" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "1970" ": "), "%s", "not convertable type"); } } while (
false)
;
1971 };
1972 }
1973
1974 return newAlignedSize( nOffset, nSize, rMaxIntegralTypeSize );
1975}
1976
1977//------------------------------------------------------------------------
1978
1979namespace {
1980
1981typelib_TypeDescriptionReference ** copyExceptions(
1982 sal_Int32 count, typelib_TypeDescriptionReference ** source)
1983{
1984 typelib_TypeDescriptionReference ** p
1985 = new typelib_TypeDescriptionReference *[count];
1986 for (sal_Int32 i = 0; i < count; ++i) {
1987 typelib_typedescriptionreference_acquire(p[i] = source[i]);
1988 }
1989 return p;
1990}
1991
1992bool createDerivedInterfaceMemberDescription(
1993 typelib_TypeDescription ** result, rtl::OUString const & name,
1994 typelib_TypeDescriptionReference * baseRef,
1995 typelib_TypeDescription const * base, typelib_TypeDescription * interface,
1996 sal_Int32 index, sal_Int32 position)
1997{
1998 if (baseRef != 0 && base != 0 && interface != 0) {
1999 switch (base->eTypeClass) {
2000 case typelib_TypeClass_INTERFACE_METHOD:
2001 {
2002 typelib_typedescription_newEmpty(
2003 result, typelib_TypeClass_INTERFACE_METHOD, name.pData);
2004 typelib_InterfaceMethodTypeDescription const * baseMethod
2005 = reinterpret_cast<
2006 typelib_InterfaceMethodTypeDescription const * >(base);
2007 typelib_InterfaceMethodTypeDescription * newMethod
2008 = reinterpret_cast<
2009 typelib_InterfaceMethodTypeDescription * >(*result);
2010 newMethod->aBase.nPosition = position;
2011 rtl_uString_acquire(
2012 newMethod->aBase.pMemberName
2013 = baseMethod->aBase.pMemberName);
2014 typelib_typedescriptionreference_acquire(
2015 newMethod->pReturnTypeRef = baseMethod->pReturnTypeRef);
2016 newMethod->nParams = baseMethod->nParams;
2017 newMethod->pParams = new typelib_MethodParameter[
2018 newMethod->nParams];
2019 for (sal_Int32 i = 0; i < newMethod->nParams; ++i) {
2020 rtl_uString_acquire(
2021 newMethod->pParams[i].pName
2022 = baseMethod->pParams[i].pName);
2023 typelib_typedescriptionreference_acquire(
2024 newMethod->pParams[i].pTypeRef
2025 = baseMethod->pParams[i].pTypeRef);
2026 newMethod->pParams[i].bIn = baseMethod->pParams[i].bIn;
2027 newMethod->pParams[i].bOut = baseMethod->pParams[i].bOut;
2028 }
2029 newMethod->nExceptions = baseMethod->nExceptions;
2030 newMethod->ppExceptions = copyExceptions(
2031 baseMethod->nExceptions, baseMethod->ppExceptions);
2032 newMethod->bOneWay = baseMethod->bOneWay;
2033 newMethod->pInterface
2034 = reinterpret_cast< typelib_InterfaceTypeDescription * >(
2035 interface);
2036 newMethod->pBaseRef = baseRef;
2037 newMethod->nIndex = index;
2038 return true;
2039 }
2040
2041 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
2042 {
2043 typelib_typedescription_newEmpty(
2044 result, typelib_TypeClass_INTERFACE_ATTRIBUTE, name.pData);
2045 typelib_InterfaceAttributeTypeDescription const * baseAttribute
2046 = reinterpret_cast<
2047 typelib_InterfaceAttributeTypeDescription const * >(base);
2048 typelib_InterfaceAttributeTypeDescription * newAttribute
2049 = reinterpret_cast<
2050 typelib_InterfaceAttributeTypeDescription * >(*result);
2051 newAttribute->aBase.nPosition = position;
2052 rtl_uString_acquire(
2053 newAttribute->aBase.pMemberName
2054 = baseAttribute->aBase.pMemberName);
2055 newAttribute->bReadOnly = baseAttribute->bReadOnly;
2056 typelib_typedescriptionreference_acquire(
2057 newAttribute->pAttributeTypeRef
2058 = baseAttribute->pAttributeTypeRef);
2059 newAttribute->pInterface
2060 = reinterpret_cast< typelib_InterfaceTypeDescription * >(
2061 interface);
2062 newAttribute->pBaseRef = baseRef;
2063 newAttribute->nIndex = index;
2064 newAttribute->nGetExceptions = baseAttribute->nGetExceptions;
2065 newAttribute->ppGetExceptions = copyExceptions(
2066 baseAttribute->nGetExceptions,
2067 baseAttribute->ppGetExceptions);
2068 newAttribute->nSetExceptions = baseAttribute->nSetExceptions;
2069 newAttribute->ppSetExceptions = copyExceptions(
2070 baseAttribute->nSetExceptions,
2071 baseAttribute->ppSetExceptions);
2072 return true;
2073 }
2074
2075 default:
2076 break;
2077 }
2078 }
2079 return false;
2080}
2081
2082}
2083
2084extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescription_getByName(
2085 typelib_TypeDescription ** ppRet, rtl_uString * pName )
2086 SAL_THROW_EXTERN_C()throw ()
2087{
2088 if( *ppRet )
2089 {
2090 typelib_typedescription_release( (*ppRet) );
2091 *ppRet = 0;
2092 }
2093
2094 static sal_Bool bInited = sal_False((sal_Bool)0);
2095 TypeDescriptor_Init_Impl &rInit = Init::get();
2096
2097 if( !bInited )
2098 {
2099 // guard against multi thread access
2100 MutexGuard aGuard( rInit.getMutex() );
2101 if( !bInited )
2102 {
2103 // avoid recursion during the next ...new calls
2104 bInited = sal_True((sal_Bool)1);
2105
2106 rtl_uString * pTypeName = 0;
2107 typelib_TypeDescription * pType = 0;
2108 rtl_uString_newFromAscii( &pTypeName, "type" );
2109 typelib_typedescription_new( &pType, typelib_TypeClass_TYPE, pTypeName, 0, 0, 0 );
2110 typelib_typedescription_register( &pType );
2111 rtl_uString_newFromAscii( &pTypeName, "void" );
2112 typelib_typedescription_new( &pType, typelib_TypeClass_VOID, pTypeName, 0, 0, 0 );
2113 typelib_typedescription_register( &pType );
2114 rtl_uString_newFromAscii( &pTypeName, "boolean" );
2115 typelib_typedescription_new( &pType, typelib_TypeClass_BOOLEAN, pTypeName, 0, 0, 0 );
2116 typelib_typedescription_register( &pType );
2117 rtl_uString_newFromAscii( &pTypeName, "char" );
2118 typelib_typedescription_new( &pType, typelib_TypeClass_CHAR, pTypeName, 0, 0, 0 );
2119 typelib_typedescription_register( &pType );
2120 rtl_uString_newFromAscii( &pTypeName, "byte" );
2121 typelib_typedescription_new( &pType, typelib_TypeClass_BYTE, pTypeName, 0, 0, 0 );
2122 typelib_typedescription_register( &pType );
2123 rtl_uString_newFromAscii( &pTypeName, "string" );
2124 typelib_typedescription_new( &pType, typelib_TypeClass_STRING, pTypeName, 0, 0, 0 );
2125 typelib_typedescription_register( &pType );
2126 rtl_uString_newFromAscii( &pTypeName, "short" );
2127 typelib_typedescription_new( &pType, typelib_TypeClass_SHORT, pTypeName, 0, 0, 0 );
2128 typelib_typedescription_register( &pType );
2129 rtl_uString_newFromAscii( &pTypeName, "unsigned short" );
2130 typelib_typedescription_new( &pType, typelib_TypeClass_UNSIGNED_SHORT, pTypeName, 0, 0, 0 );
2131 typelib_typedescription_register( &pType );
2132 rtl_uString_newFromAscii( &pTypeName, "long" );
2133 typelib_typedescription_new( &pType, typelib_TypeClass_LONG, pTypeName, 0, 0, 0 );
2134 typelib_typedescription_register( &pType );
2135 rtl_uString_newFromAscii( &pTypeName, "unsigned long" );
2136 typelib_typedescription_new( &pType, typelib_TypeClass_UNSIGNED_LONG, pTypeName, 0, 0, 0 );
2137 typelib_typedescription_register( &pType );
2138 rtl_uString_newFromAscii( &pTypeName, "hyper" );
2139 typelib_typedescription_new( &pType, typelib_TypeClass_HYPER, pTypeName, 0, 0, 0 );
2140 typelib_typedescription_register( &pType );
2141 rtl_uString_newFromAscii( &pTypeName, "unsigned hyper" );
2142 typelib_typedescription_new( &pType, typelib_TypeClass_UNSIGNED_HYPER, pTypeName, 0, 0, 0 );
2143 typelib_typedescription_register( &pType );
2144 rtl_uString_newFromAscii( &pTypeName, "float" );
2145 typelib_typedescription_new( &pType, typelib_TypeClass_FLOAT, pTypeName, 0, 0, 0 );
2146 typelib_typedescription_register( &pType );
2147 rtl_uString_newFromAscii( &pTypeName, "double" );
2148 typelib_typedescription_new( &pType, typelib_TypeClass_DOUBLE, pTypeName, 0, 0, 0 );
2149 typelib_typedescription_register( &pType );
2150 rtl_uString_newFromAscii( &pTypeName, "any" );
2151 typelib_typedescription_new( &pType, typelib_TypeClass_ANY, pTypeName, 0, 0, 0 );
2152 typelib_typedescription_register( &pType );
2153 typelib_typedescription_release( pType );
2154 rtl_uString_release( pTypeName );
2155 }
2156 }
2157
2158 typelib_TypeDescriptionReference * pTDR = 0;
2159 typelib_typedescriptionreference_getByName( &pTDR, pName );
2160 if( pTDR )
2161 {
2162 {
2163 // guard against multi thread access
2164 MutexGuard aGuard( rInit.getMutex() );
2165 // pTDR->pType->pWeakRef == 0 means that the description is empty
2166 if( pTDR->pType && pTDR->pType->pWeakRef )
2167 {
2168 typelib_typedescription_acquire( pTDR->pType );
2169 *ppRet = pTDR->pType;
2170 }
2171 }
2172 typelib_typedescriptionreference_release( pTDR );
2173 }
2174
2175 if (0 == *ppRet)
2176 {
2177 // check for sequence
2178 OUString const & name = *reinterpret_cast< OUString const * >( &pName );
2179 if (2 < name.getLength() && '[' == name[ 0 ])
2180 {
2181 OUString element_name( name.copy( 2 ) );
2182 typelib_TypeDescription * element_td = 0;
2183 typelib_typedescription_getByName( &element_td, element_name.pData );
2184 if (0 != element_td)
2185 {
2186 typelib_typedescription_new(
2187 ppRet, typelib_TypeClass_SEQUENCE, pName, element_td->pWeakRef, 0, 0 );
2188 // register?
2189 typelib_typedescription_release( element_td );
2190 }
2191 }
2192 if (0 == *ppRet)
2193 {
2194 // Check for derived interface member type:
2195 sal_Int32 i1 = name.lastIndexOf(
2196 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":@")(&(":@")[0]), ((sal_Int32)((sizeof (":@") / sizeof ((":@"
)[0]))-1)), (((rtl_TextEncoding) 11))
));
2197 if (i1 >= 0) {
2198 sal_Int32 i2 = i1 + RTL_CONSTASCII_LENGTH(":@")((sal_Int32)((sizeof (":@") / sizeof ((":@")[0]))-1));
2199 sal_Int32 i3 = name.indexOf(',', i2);
2200 if (i3 >= 0) {
2201 sal_Int32 i4 = name.indexOf(':', i3);
2202 if (i4 >= 0) {
2203 typelib_TypeDescriptionReference * pBaseRef = 0;
2204 typelib_TypeDescription * pBase = 0;
2205 typelib_TypeDescription * pInterface = 0;
2206 typelib_typedescriptionreference_getByName(
2207 &pBaseRef, name.copy(0, i1).pData);
2208 if (pBaseRef != 0) {
2209 typelib_typedescriptionreference_getDescription(
2210 &pBase, pBaseRef);
2211 }
2212 typelib_typedescription_getByName(
2213 &pInterface, name.copy(i4 + 1).pData);
2214 if (!createDerivedInterfaceMemberDescription(
2215 ppRet, name, pBaseRef, pBase, pInterface,
2216 name.copy(i2, i3 - i2).toInt32(),
2217 name.copy(i3 + 1, i4 - i3 - 1).toInt32()))
2218 {
2219 if (pInterface != 0) {
2220 typelib_typedescription_release(pInterface);
2221 }
2222 if (pBase != 0) {
2223 typelib_typedescription_release(pBase);
2224 }
2225 if (pBaseRef != 0) {
2226 typelib_typedescriptionreference_release(
2227 pBaseRef);
2228 }
2229 }
2230 }
2231 }
2232 }
2233 }
2234 if (0 == *ppRet)
2235 {
2236 // on demand access
2237 rInit.callChain( ppRet, pName );
2238 }
2239
2240 if( *ppRet )
2241 {
2242 // typedescription found
2243 if (typelib_TypeClass_TYPEDEF == (*ppRet)->eTypeClass)
2244 {
2245 typelib_TypeDescription * pTD = 0;
2246 typelib_typedescriptionreference_getDescription(
2247 &pTD, ((typelib_IndirectTypeDescription *)*ppRet)->pType );
2248 typelib_typedescription_release( *ppRet );
2249 *ppRet = pTD;
2250 }
2251 else
2252 {
2253 // set to on demand
2254 (*ppRet)->bOnDemand = sal_True((sal_Bool)1);
2255 // The type description is hold by the reference until
2256 // on demand is activated.
2257 typelib_typedescription_register( ppRet );
2258
2259 // insert into the chache
2260 MutexGuard aGuard( rInit.getMutex() );
2261 if( !rInit.pCache )
2262 rInit.pCache = new TypeDescriptionList_Impl;
2263 if( (sal_Int32)rInit.pCache->size() >= nCacheSize )
2264 {
2265 typelib_typedescription_release( rInit.pCache->front() );
2266 rInit.pCache->pop_front();
2267 }
2268 // descriptions in the cache must be acquired!
2269 typelib_typedescription_acquire( *ppRet );
2270 rInit.pCache->push_back( *ppRet );
2271 }
2272 }
2273 }
2274}
2275
2276extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescriptionreference_newByAsciiName(
2277 typelib_TypeDescriptionReference ** ppTDR,
2278 typelib_TypeClass eTypeClass,
2279 const sal_Char * pTypeName )
2280 SAL_THROW_EXTERN_C()throw ()
2281{
2282 OUString aTypeName( OUString::createFromAscii( pTypeName ) );
2283 typelib_typedescriptionreference_new( ppTDR, eTypeClass, aTypeName.pData );
2284}
2285//------------------------------------------------------------------------
2286extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescriptionreference_new(
2287 typelib_TypeDescriptionReference ** ppTDR,
2288 typelib_TypeClass eTypeClass, rtl_uString * pTypeName )
2289 SAL_THROW_EXTERN_C()throw ()
2290{
2291 TypeDescriptor_Init_Impl &rInit = Init::get();
2292 if( eTypeClass == typelib_TypeClass_TYPEDEF )
2293 {
2294 // on demand access
2295 typelib_TypeDescription * pRet = 0;
2296 rInit.callChain( &pRet, pTypeName );
2297 if( pRet )
2298 {
2299 // typedescription found
2300 if (typelib_TypeClass_TYPEDEF == pRet->eTypeClass)
2301 {
2302 typelib_typedescriptionreference_acquire(
2303 ((typelib_IndirectTypeDescription *)pRet)->pType );
2304 if (*ppTDR)
2305 typelib_typedescriptionreference_release( *ppTDR );
2306 *ppTDR = ((typelib_IndirectTypeDescription *)pRet)->pType;
2307 typelib_typedescription_release( pRet );
2308 }
2309 else
2310 {
2311 // set to on demand
2312 pRet->bOnDemand = sal_True((sal_Bool)1);
2313 // The type description is hold by the reference until
2314 // on demand is activated.
2315 typelib_typedescription_register( &pRet );
2316
2317 // insert into the chache
2318 MutexGuard aGuard( rInit.getMutex() );
2319 if( !rInit.pCache )
2320 rInit.pCache = new TypeDescriptionList_Impl;
2321 if( (sal_Int32)rInit.pCache->size() >= nCacheSize )
2322 {
2323 typelib_typedescription_release( rInit.pCache->front() );
2324 rInit.pCache->pop_front();
2325 }
2326 rInit.pCache->push_back( pRet );
2327 // pRet kept acquired for cache
2328
2329 typelib_typedescriptionreference_acquire( pRet->pWeakRef );
2330 if (*ppTDR)
2331 typelib_typedescriptionreference_release( *ppTDR );
2332 *ppTDR = pRet->pWeakRef;
2333 }
2334 }
2335 else if (*ppTDR)
2336 {
2337#if OSL_DEBUG_LEVEL1 > 1
2338 OString aStr( rtl::OUStringToOString( pTypeName, RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11)) ) );
2339 OSL_ENSURE( !"### typedef not found: ", aStr.getStr() )do { if (true && (!(!"### typedef not found: "))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "2339" ": "), "%s", aStr.getStr()); } } while (false)
;
2340#endif
2341 typelib_typedescriptionreference_release( *ppTDR );
2342 *ppTDR = 0;
2343 }
2344 return;
2345 }
2346
2347 MutexGuard aGuard( rInit.getMutex() );
2348 typelib_typedescriptionreference_getByName( ppTDR, pTypeName );
2349 if( *ppTDR )
2350 return;
2351
2352 if( reallyWeak( eTypeClass ) )
2353 {
2354 typelib_TypeDescriptionReference * pTDR = new typelib_TypeDescriptionReference();
2355#if OSL_DEBUG_LEVEL1 > 1
2356 osl_incrementInterlockedCount( &rInit.nTypeDescriptionReferenceCount );
2357#endif
2358 pTDR->nRefCount = 1;
2359 pTDR->nStaticRefCount = 0;
2360 pTDR->eTypeClass = eTypeClass;
2361 pTDR->pUniqueIdentifier = 0;
2362 pTDR->pReserved = 0;
2363 rtl_uString_acquire( pTDR->pTypeName = pTypeName );
2364 pTDR->pType = 0;
2365 *ppTDR = pTDR;
2366 }
2367 else
2368 {
2369 typelib_typedescription_newEmpty( (typelib_TypeDescription ** )ppTDR, eTypeClass, pTypeName );
2370 // description will be registered but not acquired
2371 (*(typelib_TypeDescription ** )ppTDR)->bOnDemand = sal_True((sal_Bool)1);
2372 (*(typelib_TypeDescription ** )ppTDR)->bComplete = sal_False((sal_Bool)0);
2373 }
2374
2375 if( !rInit.pWeakMap )
2376 rInit.pWeakMap = new WeakMap_Impl;
2377 // Heavy hack, the const sal_Unicode * is hold by the typedescription reference
2378 // not registered
2379 rInit.pWeakMap->operator[]( (*ppTDR)->pTypeName->buffer ) = *ppTDR;
2380}
2381
2382//------------------------------------------------------------------------
2383extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescriptionreference_acquire(
2384 typelib_TypeDescriptionReference * pRef )
2385 SAL_THROW_EXTERN_C()throw ()
2386{
2387 ::osl_incrementInterlockedCount( &pRef->nRefCount );
2388}
2389
2390//------------------------------------------------------------------------
2391extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescriptionreference_release(
2392 typelib_TypeDescriptionReference * pRef )
2393 SAL_THROW_EXTERN_C()throw ()
2394{
2395 // Is it a type description?
2396 if( reallyWeak( pRef->eTypeClass ) )
2397 {
2398 if( ! ::osl_decrementInterlockedCount( &pRef->nRefCount ) )
2399 {
2400 TypeDescriptor_Init_Impl &rInit = Init::get();
2401 if( rInit.pWeakMap )
2402 {
2403 MutexGuard aGuard( rInit.getMutex() );
2404 WeakMap_Impl::iterator aIt = rInit.pWeakMap->find( (sal_Unicode*)pRef->pTypeName->buffer );
2405 if( !(aIt == rInit.pWeakMap->end()) && (*aIt).second == pRef )
2406 {
2407 // remove only if it contains the same object
2408 rInit.pWeakMap->erase( aIt );
2409 }
2410 }
2411
2412 rtl_uString_release( pRef->pTypeName );
2413 OSL_ASSERT( pRef->pType == 0 )do { if (true && (!(pRef->pType == 0))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "2413" ": "), "OSL_ASSERT: %s", "pRef->pType == 0"); }
} while (false)
;
2414#if OSL_DEBUG_LEVEL1 > 1
2415 osl_decrementInterlockedCount( &rInit.nTypeDescriptionReferenceCount );
2416#endif
2417 delete pRef;
2418 }
2419 }
2420 else
2421 {
2422 typelib_typedescription_release( (typelib_TypeDescription *)pRef );
2423 }
2424}
2425
2426//------------------------------------------------------------------------
2427extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescriptionreference_getDescription(
2428 typelib_TypeDescription ** ppRet, typelib_TypeDescriptionReference * pRef )
2429 SAL_THROW_EXTERN_C()throw ()
2430{
2431 if( *ppRet )
2432 {
2433 typelib_typedescription_release( *ppRet );
2434 *ppRet = 0;
2435 }
2436
2437 if( !reallyWeak( pRef->eTypeClass ) && pRef->pType && pRef->pType->pWeakRef )
2438 {
2439 // reference is a description and initialized
2440 osl_incrementInterlockedCount( &((typelib_TypeDescription *)pRef)->nRefCount );
2441 *ppRet = (typelib_TypeDescription *)pRef;
2442 return;
2443 }
2444
2445 {
2446 MutexGuard aGuard( Init::get().getMutex() );
2447 // pRef->pType->pWeakRef == 0 means that the description is empty
2448 if( pRef->pType && pRef->pType->pWeakRef )
2449 {
2450 sal_Int32 n = ::osl_incrementInterlockedCount( &pRef->pType->nRefCount );
2451 if( n > 1 )
2452 {
2453 // The refence is incremented. The object cannot be destroyed.
2454 // Release the guard at the earliest point.
2455 *ppRet = pRef->pType;
2456 return;
2457 }
2458 else
2459 {
2460 ::osl_decrementInterlockedCount( &pRef->pType->nRefCount );
2461 // detruction of this type in progress (another thread!)
2462 // no acces through this weak reference
2463 pRef->pType = 0;
2464 }
2465 }
2466 }
2467
2468 typelib_typedescription_getByName( ppRet, pRef->pTypeName );
2469 OSL_ASSERT( !*ppRet || rtl_ustr_compare( pRef->pTypeName->buffer, (*ppRet)->pTypeName->buffer ) == 0 )do { if (true && (!(!*ppRet || rtl_ustr_compare( pRef
->pTypeName->buffer, (*ppRet)->pTypeName->buffer )
== 0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), (
"legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "2469" ": "), "OSL_ASSERT: %s", "!*ppRet || rtl_ustr_compare( pRef->pTypeName->buffer, (*ppRet)->pTypeName->buffer ) == 0"
); } } while (false)
;
2470 OSL_ASSERT( !*ppRet || pRef->eTypeClass == (*ppRet)->eTypeClass )do { if (true && (!(!*ppRet || pRef->eTypeClass ==
(*ppRet)->eTypeClass))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "2470" ": "), "OSL_ASSERT: %s", "!*ppRet || pRef->eTypeClass == (*ppRet)->eTypeClass"
); } } while (false)
;
2471 OSL_ASSERT( !*ppRet || pRef == (*ppRet)->pWeakRef )do { if (true && (!(!*ppRet || pRef == (*ppRet)->pWeakRef
))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "2471" ": "), "OSL_ASSERT: %s", "!*ppRet || pRef == (*ppRet)->pWeakRef"
); } } while (false)
;
2472 pRef->pType = *ppRet;
2473}
2474
2475//------------------------------------------------------------------------
2476extern "C" void SAL_CALL typelib_typedescriptionreference_getByName(
2477 typelib_TypeDescriptionReference ** ppRet, rtl_uString * pName )
2478 SAL_THROW_EXTERN_C()throw ()
2479{
2480 if( *ppRet )
2481 {
2482 typelib_typedescriptionreference_release( *ppRet );
2483 *ppRet = 0;
2484 }
2485 TypeDescriptor_Init_Impl &rInit = Init::get();
2486 if( rInit.pWeakMap )
2487 {
2488 MutexGuard aGuard( rInit.getMutex() );
2489 WeakMap_Impl::const_iterator aIt = rInit.pWeakMap->find( (sal_Unicode*)pName->buffer );
2490 if( !(aIt == rInit.pWeakMap->end()) ) // != failed on msc4.2
2491 {
2492 sal_Int32 n = ::osl_incrementInterlockedCount( &(*aIt).second->nRefCount );
2493 if( n > 1 )
2494 {
2495 // The refence is incremented. The object cannot be destroyed.
2496 // Release the guard at the earliest point.
2497 *ppRet = (*aIt).second;
2498 }
2499 else
2500 {
2501 // detruction of this type in progress (another thread!)
2502 // no acces through this weak reference
2503 ::osl_decrementInterlockedCount( &(*aIt).second->nRefCount );
2504 }
2505 }
2506 }
2507}
2508
2509//------------------------------------------------------------------------
2510extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) sal_Bool SAL_CALL typelib_typedescriptionreference_equals(
2511 const typelib_TypeDescriptionReference * p1,
2512 const typelib_TypeDescriptionReference * p2 )
2513 SAL_THROW_EXTERN_C()throw ()
2514{
2515 return (p1 == p2 ||
2516 (p1->eTypeClass == p2->eTypeClass &&
2517 p1->pTypeName->length == p2->pTypeName->length &&
2518 rtl_ustr_compare( p1->pTypeName->buffer, p2->pTypeName->buffer ) == 0));
2519}
2520
2521//##################################################################################################
2522extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_typedescriptionreference_assign(
2523 typelib_TypeDescriptionReference ** ppDest,
2524 typelib_TypeDescriptionReference * pSource )
2525 SAL_THROW_EXTERN_C()throw ()
2526{
2527 if (*ppDest != pSource)
2528 {
2529 ::typelib_typedescriptionreference_acquire( pSource );
2530 ::typelib_typedescriptionreference_release( *ppDest );
2531 *ppDest = pSource;
2532 }
2533}
2534
2535//##################################################################################################
2536extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) void SAL_CALL typelib_setCacheSize( sal_Int32 nNewSize )
2537 SAL_THROW_EXTERN_C()throw ()
2538{
2539 OSL_ENSURE( nNewSize >= 0, "### illegal cache size given!" )do { if (true && (!(nNewSize >= 0))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/typelib/typelib.cxx"
":" "2539" ": "), "%s", "### illegal cache size given!"); } }
while (false)
;
2540 if (nNewSize >= 0)
2541 {
2542 TypeDescriptor_Init_Impl &rInit = Init::get();
2543 MutexGuard aGuard( rInit.getMutex() );
2544 if ((nNewSize < nCacheSize) && rInit.pCache)
2545 {
2546 while ((sal_Int32)rInit.pCache->size() != nNewSize)
2547 {
2548 typelib_typedescription_release( rInit.pCache->front() );
2549 rInit.pCache->pop_front();
2550 }
2551 }
2552 nCacheSize = nNewSize;
2553 }
2554}
2555
2556
2557static sal_Bool s_aAssignableFromTab[11][11] =
2558{
2559 /* from CH,BO,BY,SH,US,LO,UL,HY,UH,FL,DO */
2560/* TypeClass_CHAR */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
2561/* TypeClass_BOOLEAN */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
2562/* TypeClass_BYTE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
2563/* TypeClass_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
2564/* TypeClass_UNSIGNED_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
2565/* TypeClass_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
2566/* TypeClass_UNSIGNED_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
2567/* TypeClass_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
2568/* TypeClass_UNSIGNED_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
2569/* TypeClass_FLOAT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0 },
2570/* TypeClass_DOUBLE */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1 }
2571};
2572
2573//##################################################################################################
2574extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) sal_Bool SAL_CALL typelib_typedescriptionreference_isAssignableFrom(
2575 typelib_TypeDescriptionReference * pAssignable,
2576 typelib_TypeDescriptionReference * pFrom )
2577 SAL_THROW_EXTERN_C()throw ()
2578{
2579 if (pAssignable && pFrom)
2580 {
2581 typelib_TypeClass eAssignable = pAssignable->eTypeClass;
2582 typelib_TypeClass eFrom = pFrom->eTypeClass;
2583
2584 if (eAssignable == typelib_TypeClass_ANY) // anything can be assigned to an any .)
2585 return sal_True((sal_Bool)1);
2586 if (eAssignable == eFrom)
2587 {
2588 if (type_equals( pAssignable, pFrom )) // first shot
2589 {
2590 return sal_True((sal_Bool)1);
2591 }
2592 else
2593 {
2594 switch (eAssignable)
2595 {
2596 case typelib_TypeClass_STRUCT:
2597 case typelib_TypeClass_EXCEPTION:
2598 {
2599 typelib_TypeDescription * pFromDescr = 0;
2600 TYPELIB_DANGER_GET( &pFromDescr, pFrom ){ typelib_TypeDescriptionReference * pMacroTypeRef = (pFrom);
typelib_TypeDescription ** ppMacroTypeDescr = (&pFromDescr
); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr
, pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef
->pType->pWeakRef) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release
( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef
->pType; } }
;
2601 if (! ((typelib_CompoundTypeDescription *)pFromDescr)->pBaseTypeDescription)
2602 {
2603 TYPELIB_DANGER_RELEASE( pFromDescr ){ if ((((pFromDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| ((pFromDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) typelib_typedescription_release( pFromDescr ); }
;
2604 return sal_False((sal_Bool)0);
2605 }
2606 sal_Bool bRet = typelib_typedescriptionreference_isAssignableFrom(
2607 pAssignable,
2608 ((typelib_TypeDescription *)((typelib_CompoundTypeDescription *)pFromDescr)->pBaseTypeDescription)->pWeakRef );
2609 TYPELIB_DANGER_RELEASE( pFromDescr ){ if ((((pFromDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| ((pFromDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) typelib_typedescription_release( pFromDescr ); }
;
2610 return bRet;
2611 }
2612 case typelib_TypeClass_INTERFACE:
2613 {
2614 typelib_TypeDescription * pFromDescr = 0;
2615 TYPELIB_DANGER_GET( &pFromDescr, pFrom ){ typelib_TypeDescriptionReference * pMacroTypeRef = (pFrom);
typelib_TypeDescription ** ppMacroTypeDescr = (&pFromDescr
); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr
, pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef
->pType->pWeakRef) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release
( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef
->pType; } }
;
2616 typelib_InterfaceTypeDescription * pFromIfc
2617 = reinterpret_cast<
2618 typelib_InterfaceTypeDescription * >(pFromDescr);
2619 bool bRet = false;
2620 for (sal_Int32 i = 0; i < pFromIfc->nBaseTypes; ++i) {
2621 if (typelib_typedescriptionreference_isAssignableFrom(
2622 pAssignable,
2623 pFromIfc->ppBaseTypes[i]->aBase.pWeakRef))
2624 {
2625 bRet = true;
2626 break;
2627 }
2628 }
2629 TYPELIB_DANGER_RELEASE( pFromDescr ){ if ((((pFromDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| ((pFromDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) typelib_typedescription_release( pFromDescr ); }
;
2630 return bRet;
2631 }
2632 default:
2633 {
2634 return sal_False((sal_Bool)0);
2635 }
2636 }
2637 }
2638 }
2639 return (eAssignable >= typelib_TypeClass_CHAR && eAssignable <= typelib_TypeClass_DOUBLE &&
2640 eFrom >= typelib_TypeClass_CHAR && eFrom <= typelib_TypeClass_DOUBLE &&
2641 s_aAssignableFromTab[eAssignable-1][eFrom-1]);
2642 }
2643 return sal_False((sal_Bool)0);
2644}
2645//##################################################################################################
2646extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) sal_Bool SAL_CALL typelib_typedescription_isAssignableFrom(
2647 typelib_TypeDescription * pAssignable,
2648 typelib_TypeDescription * pFrom )
2649 SAL_THROW_EXTERN_C()throw ()
2650{
2651 return typelib_typedescriptionreference_isAssignableFrom(
2652 pAssignable->pWeakRef, pFrom->pWeakRef );
2653}
2654
2655//##################################################################################################
2656extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) sal_Bool SAL_CALL typelib_typedescription_complete(
2657 typelib_TypeDescription ** ppTypeDescr )
2658 SAL_THROW_EXTERN_C()throw ()
2659{
2660 return complete(ppTypeDescr, true);
2661}
2662
2663/* vim:set shiftwidth=4 softtabstop=4 expandtab: */