Line data 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 : #include "sal/config.h"
21 :
22 : #include <algorithm>
23 : #include <cassert>
24 : #include <stdarg.h>
25 :
26 : #include <osl/mutex.hxx>
27 : #include <osl/interlck.h>
28 : #include <rtl/ustring.hxx>
29 : #include <rtl/ustrbuf.hxx>
30 : #include <rtl/instance.hxx>
31 :
32 : #include <typelib/typedescription.h>
33 : #include "typelib.hxx"
34 :
35 :
36 : using namespace osl;
37 :
38 : using ::rtl::OUString;
39 : using ::rtl::OUStringBuffer;
40 :
41 : extern "C"
42 : {
43 :
44 :
45 : #ifdef SAL_W32
46 : #pragma pack(push, 8)
47 : #endif
48 :
49 : /**
50 : * The double member determines the alignment.
51 : * Under OS2 and MS-Windows the Alignment is min( 8, sizeof( type ) ).
52 : * The alignment of a structure is min( 8, sizeof( max basic type ) ), the greatest basic type
53 : * determines the alignment.
54 : */
55 : struct AlignSize_Impl
56 : {
57 : sal_Int16 nInt16;
58 : #ifdef AIX
59 : //double: doubleword aligned if -qalign=natural/-malign=natural
60 : //which isn't the default ABI. Otherwise word aligned, While a long long int
61 : //is always doubleword aligned, so use that instead.
62 : sal_Int64 dDouble;
63 : #else
64 : double dDouble;
65 : #endif
66 : };
67 :
68 : #ifdef SAL_W32
69 : #pragma pack(pop)
70 : #endif
71 :
72 : // the value of the maximal alignment
73 : static sal_Int32 nMaxAlignment = (sal_Int32)( reinterpret_cast<sal_Size>(&(reinterpret_cast<AlignSize_Impl *>(16))->dDouble) - 16);
74 :
75 18 : static inline sal_Int32 adjustAlignment( sal_Int32 nRequestedAlignment )
76 : {
77 18 : if( nRequestedAlignment > nMaxAlignment )
78 0 : nRequestedAlignment = nMaxAlignment;
79 18 : return nRequestedAlignment;
80 : }
81 :
82 : /**
83 : * Calculate the new size of the struktur.
84 : */
85 1 : static inline sal_Int32 newAlignedSize(
86 : sal_Int32 OldSize, sal_Int32 ElementSize, sal_Int32 NeededAlignment )
87 : {
88 1 : NeededAlignment = adjustAlignment( NeededAlignment );
89 1 : return (OldSize + NeededAlignment -1) / NeededAlignment * NeededAlignment + ElementSize;
90 : }
91 :
92 :
93 :
94 : namespace
95 : {
96 : struct typelib_StaticInitMutex : public rtl::Static< Mutex, typelib_StaticInitMutex > {};
97 : }
98 :
99 : // !for NOT REALLY WEAK TYPES only!
100 40979 : static inline typelib_TypeDescriptionReference * igetTypeByName( rtl_uString * pTypeName )
101 : {
102 40979 : typelib_TypeDescriptionReference * pRef = 0;
103 40979 : ::typelib_typedescriptionreference_getByName( &pRef, pTypeName );
104 40979 : if (pRef && pRef->pType && pRef->pType->pWeakRef) // found initialized td
105 : {
106 30592 : return pRef;
107 : }
108 : else
109 : {
110 10387 : return 0;
111 : }
112 : }
113 :
114 : extern "C"
115 : {
116 :
117 438787916 : typelib_TypeDescriptionReference ** SAL_CALL typelib_static_type_getByTypeClass(
118 : typelib_TypeClass eTypeClass )
119 : SAL_THROW_EXTERN_C()
120 : {
121 : static typelib_TypeDescriptionReference * s_aTypes[] = {
122 : 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
123 : 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
124 : 0, 0, 0 };
125 :
126 438787916 : if (! s_aTypes[eTypeClass])
127 : {
128 3229 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
129 3229 : if (! s_aTypes[eTypeClass])
130 : {
131 : static const char * s_aTypeNames[] = {
132 : "void", "char", "boolean", "byte",
133 : "short", "unsigned short", "long", "unsigned long",
134 : "hyper", "unsigned hyper", "float", "double",
135 : "string", "type", "any" };
136 :
137 3229 : switch (eTypeClass)
138 : {
139 : case typelib_TypeClass_EXCEPTION:
140 : case typelib_TypeClass_INTERFACE:
141 : {
142 : // type
143 513 : if (! s_aTypes[typelib_TypeClass_TYPE])
144 : {
145 512 : OUString sTypeName("type");
146 : ::typelib_typedescriptionreference_new(
147 512 : &s_aTypes[typelib_TypeClass_TYPE], typelib_TypeClass_TYPE, sTypeName.pData );
148 : // another static ref:
149 512 : ++s_aTypes[typelib_TypeClass_TYPE]->nStaticRefCount;
150 : }
151 : // any
152 513 : if (! s_aTypes[typelib_TypeClass_ANY])
153 : {
154 512 : OUString sTypeName("any");
155 : ::typelib_typedescriptionreference_new(
156 512 : &s_aTypes[typelib_TypeClass_ANY], typelib_TypeClass_ANY, sTypeName.pData );
157 : // another static ref:
158 512 : ++s_aTypes[typelib_TypeClass_ANY]->nStaticRefCount;
159 : }
160 : // string
161 513 : if (! s_aTypes[typelib_TypeClass_STRING])
162 : {
163 509 : OUString sTypeName("string");
164 : ::typelib_typedescriptionreference_new(
165 509 : &s_aTypes[typelib_TypeClass_STRING], typelib_TypeClass_STRING, sTypeName.pData );
166 : // another static ref:
167 509 : ++s_aTypes[typelib_TypeClass_STRING]->nStaticRefCount;
168 : }
169 : // XInterface
170 513 : if (! s_aTypes[typelib_TypeClass_INTERFACE])
171 : {
172 513 : OUString sTypeName("com.sun.star.uno.XInterface");
173 :
174 513 : typelib_InterfaceTypeDescription * pTD = 0;
175 :
176 513 : typelib_TypeDescriptionReference * pMembers[3] = { 0,0,0 };
177 1026 : OUString sMethodName0("com.sun.star.uno.XInterface::queryInterface");
178 : ::typelib_typedescriptionreference_new(
179 513 : &pMembers[0], typelib_TypeClass_INTERFACE_METHOD, sMethodName0.pData );
180 1026 : OUString sMethodName1("com.sun.star.uno.XInterface::acquire");
181 : ::typelib_typedescriptionreference_new(
182 513 : &pMembers[1], typelib_TypeClass_INTERFACE_METHOD, sMethodName1.pData );
183 1026 : OUString sMethodName2("com.sun.star.uno.XInterface::release");
184 : ::typelib_typedescriptionreference_new(
185 513 : &pMembers[2], typelib_TypeClass_INTERFACE_METHOD, sMethodName2.pData );
186 :
187 : ::typelib_typedescription_newInterface(
188 513 : &pTD, sTypeName.pData, 0, 0, 0, 0, 0, 0, 3, pMembers );
189 :
190 513 : ::typelib_typedescription_register( reinterpret_cast<typelib_TypeDescription **>(&pTD) );
191 : ::typelib_typedescriptionreference_acquire(
192 513 : s_aTypes[typelib_TypeClass_INTERFACE] = pTD->aBase.pWeakRef );
193 : // another static ref:
194 513 : ++s_aTypes[typelib_TypeClass_INTERFACE]->nStaticRefCount;
195 513 : ::typelib_typedescription_release( &pTD->aBase );
196 :
197 513 : ::typelib_typedescriptionreference_release( pMembers[0] );
198 513 : ::typelib_typedescriptionreference_release( pMembers[1] );
199 513 : ::typelib_typedescriptionreference_release( pMembers[2] );
200 : // Exception
201 : assert( ! s_aTypes[typelib_TypeClass_EXCEPTION] );
202 : {
203 513 : typelib_TypeDescription * pTD1 = 0;
204 513 : OUString sTypeName1("com.sun.star.uno.Exception");
205 :
206 : typelib_CompoundMember_Init aMembers[2];
207 1026 : OUString sMemberType0("string");
208 1026 : OUString sMemberName0("Message");
209 513 : aMembers[0].eTypeClass = typelib_TypeClass_STRING;
210 513 : aMembers[0].pTypeName = sMemberType0.pData;
211 513 : aMembers[0].pMemberName = sMemberName0.pData;
212 1026 : OUString sMemberType1("com.sun.star.uno.XInterface");
213 1026 : OUString sMemberName1("Context");
214 513 : aMembers[1].eTypeClass = typelib_TypeClass_INTERFACE;
215 513 : aMembers[1].pTypeName = sMemberType1.pData;
216 513 : aMembers[1].pMemberName = sMemberName1.pData;
217 :
218 : ::typelib_typedescription_new(
219 513 : &pTD1, typelib_TypeClass_EXCEPTION, sTypeName1.pData, 0, 2, aMembers );
220 513 : typelib_typedescription_register( &pTD1 );
221 : typelib_typedescriptionreference_acquire(
222 513 : s_aTypes[typelib_TypeClass_EXCEPTION] = pTD1->pWeakRef );
223 : // another static ref:
224 513 : ++s_aTypes[typelib_TypeClass_EXCEPTION]->nStaticRefCount;
225 : // RuntimeException
226 1026 : OUString sTypeName2("com.sun.star.uno.RuntimeException");
227 : ::typelib_typedescription_new(
228 513 : &pTD1, typelib_TypeClass_EXCEPTION, sTypeName2.pData, s_aTypes[typelib_TypeClass_EXCEPTION], 0, 0 );
229 513 : ::typelib_typedescription_register( &pTD1 );
230 1026 : ::typelib_typedescription_release( pTD1 );
231 : }
232 : // XInterface members
233 513 : typelib_InterfaceMethodTypeDescription * pMethod = 0;
234 : typelib_Parameter_Init aParameters[1];
235 1026 : OUString sParamName0("aType");
236 1026 : OUString sParamType0("type");
237 513 : aParameters[0].pParamName = sParamName0.pData;
238 513 : aParameters[0].eTypeClass = typelib_TypeClass_TYPE;
239 513 : aParameters[0].pTypeName = sParamType0.pData;
240 513 : aParameters[0].bIn = sal_True;
241 513 : aParameters[0].bOut = sal_False;
242 : rtl_uString * pExceptions[1];
243 1026 : OUString sExceptionName0("com.sun.star.uno.RuntimeException");
244 513 : pExceptions[0] = sExceptionName0.pData;
245 1026 : OUString sReturnType0("any");
246 : typelib_typedescription_newInterfaceMethod(
247 : &pMethod, 0, sal_False, sMethodName0.pData,
248 : typelib_TypeClass_ANY, sReturnType0.pData,
249 513 : 1, aParameters, 1, pExceptions );
250 513 : ::typelib_typedescription_register( reinterpret_cast<typelib_TypeDescription**>(&pMethod) );
251 :
252 1026 : OUString sReturnType1("void");
253 : ::typelib_typedescription_newInterfaceMethod(
254 : &pMethod, 1, sal_True, sMethodName1.pData,
255 513 : typelib_TypeClass_VOID, sReturnType1.pData, 0, 0, 0, 0 );
256 513 : ::typelib_typedescription_register( reinterpret_cast<typelib_TypeDescription**>(&pMethod) );
257 :
258 : ::typelib_typedescription_newInterfaceMethod(
259 : &pMethod, 2, sal_True, sMethodName2.pData,
260 : typelib_TypeClass_VOID, sReturnType1.pData,
261 513 : 0, 0, 0, 0 );
262 513 : ::typelib_typedescription_register( reinterpret_cast<typelib_TypeDescription**>(&pMethod) );
263 1026 : ::typelib_typedescription_release( &pMethod->aBase.aBase );
264 : }
265 513 : break;
266 : }
267 : default:
268 : {
269 2716 : OUString aTypeName( OUString::createFromAscii( s_aTypeNames[eTypeClass] ) );
270 2716 : ::typelib_typedescriptionreference_new( &s_aTypes[eTypeClass], eTypeClass, aTypeName.pData );
271 : // another static ref:
272 2716 : ++s_aTypes[eTypeClass]->nStaticRefCount;
273 : }
274 : }
275 3229 : }
276 : }
277 438787916 : return &s_aTypes[eTypeClass];
278 : }
279 :
280 169171 : void SAL_CALL typelib_static_type_init(
281 : typelib_TypeDescriptionReference ** ppRef,
282 : typelib_TypeClass eTypeClass, const sal_Char * pTypeName )
283 : SAL_THROW_EXTERN_C()
284 : {
285 169171 : if (! *ppRef)
286 : {
287 169171 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
288 169171 : if (! *ppRef)
289 : {
290 169170 : OUString aTypeName( OUString::createFromAscii( pTypeName ) );
291 169170 : ::typelib_typedescriptionreference_new( ppRef, eTypeClass, aTypeName.pData );
292 :
293 : // coverity[var_deref_op] - another static ref
294 169170 : ++((*ppRef)->nStaticRefCount);
295 169171 : }
296 : }
297 169171 : }
298 :
299 40927 : void SAL_CALL typelib_static_sequence_type_init(
300 : typelib_TypeDescriptionReference ** ppRef,
301 : typelib_TypeDescriptionReference * pElementType )
302 : SAL_THROW_EXTERN_C()
303 : {
304 40927 : if (! *ppRef)
305 : {
306 40927 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
307 40927 : if (! *ppRef)
308 : {
309 40927 : OUStringBuffer aBuf( 32 );
310 40927 : aBuf.appendAscii( "[]" );
311 40927 : aBuf.append( pElementType->pTypeName );
312 81854 : OUString aTypeName( aBuf.makeStringAndClear() );
313 :
314 : assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_SEQUENCE) );
315 40927 : *ppRef = igetTypeByName( aTypeName.pData );
316 40927 : if (!*ppRef)
317 : {
318 10370 : typelib_TypeDescription * pReg = 0;
319 : ::typelib_typedescription_new(
320 : &pReg, typelib_TypeClass_SEQUENCE,
321 10370 : aTypeName.pData, pElementType, 0, 0 );
322 :
323 10370 : ::typelib_typedescription_register( &pReg );
324 10370 : *ppRef = reinterpret_cast<typelib_TypeDescriptionReference *>(pReg);
325 : assert( *ppRef == pReg->pWeakRef );
326 : }
327 : // another static ref:
328 81854 : ++((*ppRef)->nStaticRefCount);
329 40927 : }
330 : }
331 40927 : }
332 :
333 :
334 : namespace {
335 :
336 44 : void init(
337 : typelib_TypeDescriptionReference ** ppRef,
338 : typelib_TypeClass eTypeClass, const sal_Char * pTypeName,
339 : typelib_TypeDescriptionReference * pBaseType,
340 : sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers,
341 : sal_Bool const * pParameterizedTypes)
342 : {
343 : assert( eTypeClass == typelib_TypeClass_STRUCT || eTypeClass == typelib_TypeClass_EXCEPTION );
344 :
345 44 : if (! *ppRef)
346 : {
347 44 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
348 44 : if (! *ppRef)
349 : {
350 : assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(eTypeClass) );
351 44 : OUString aTypeName( OUString::createFromAscii( pTypeName ) );
352 44 : *ppRef = igetTypeByName( aTypeName.pData );
353 44 : if (!*ppRef)
354 : {
355 14 : typelib_CompoundTypeDescription * pComp = 0;
356 : ::typelib_typedescription_newEmpty(
357 14 : reinterpret_cast<typelib_TypeDescription **>(&pComp), eTypeClass, aTypeName.pData );
358 :
359 14 : sal_Int32 nOffset = 0;
360 14 : if (pBaseType)
361 : {
362 : ::typelib_typedescriptionreference_getDescription(
363 14 : reinterpret_cast<typelib_TypeDescription **>(&pComp->pBaseTypeDescription), pBaseType );
364 : assert( pComp->pBaseTypeDescription );
365 14 : nOffset = pComp->pBaseTypeDescription->aBase.nSize;
366 : assert( newAlignedSize( 0, pComp->pBaseTypeDescription->aBase.nSize, pComp->pBaseTypeDescription->aBase.nAlignment ) == pComp->pBaseTypeDescription->aBase.nSize ); // unexpected offset
367 : }
368 :
369 14 : if (nMembers)
370 : {
371 1 : pComp->nMembers = nMembers;
372 1 : pComp->pMemberOffsets = new sal_Int32[ nMembers ];
373 1 : pComp->ppTypeRefs = new typelib_TypeDescriptionReference *[ nMembers ];
374 1 : if (pParameterizedTypes != 0) {
375 : reinterpret_cast< typelib_StructTypeDescription * >(
376 : pComp)->pParameterizedTypes
377 0 : = new sal_Bool[nMembers];
378 : }
379 2 : for ( sal_Int32 i = 0 ; i < nMembers; ++i )
380 : {
381 : ::typelib_typedescriptionreference_acquire(
382 1 : pComp->ppTypeRefs[i] = ppMembers[i] );
383 : // write offset
384 1 : typelib_TypeDescription * pTD = 0;
385 1 : TYPELIB_DANGER_GET( &pTD, pComp->ppTypeRefs[i] );
386 : assert( pTD->nSize ); // void member?
387 1 : nOffset = newAlignedSize( nOffset, pTD->nSize, pTD->nAlignment );
388 1 : pComp->pMemberOffsets[i] = nOffset - pTD->nSize;
389 1 : TYPELIB_DANGER_RELEASE( pTD );
390 :
391 1 : if (pParameterizedTypes != 0) {
392 : reinterpret_cast< typelib_StructTypeDescription * >(
393 0 : pComp)->pParameterizedTypes[i]
394 0 : = pParameterizedTypes[i];
395 : }
396 : }
397 : }
398 :
399 14 : typelib_TypeDescription * pReg = &pComp->aBase;
400 14 : pReg->pWeakRef = reinterpret_cast<typelib_TypeDescriptionReference *>(pReg);
401 : // sizeof(void) not allowed
402 14 : pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
403 14 : pReg->nAlignment = adjustAlignment( pReg->nAlignment );
404 14 : pReg->bComplete = sal_False;
405 :
406 14 : ::typelib_typedescription_register( &pReg );
407 14 : *ppRef = reinterpret_cast<typelib_TypeDescriptionReference *>(pReg);
408 : assert( *ppRef == pReg->pWeakRef );
409 : }
410 : // another static ref:
411 44 : ++((*ppRef)->nStaticRefCount);
412 44 : }
413 : }
414 44 : }
415 :
416 : }
417 :
418 44 : void SAL_CALL typelib_static_compound_type_init(
419 : typelib_TypeDescriptionReference ** ppRef,
420 : typelib_TypeClass eTypeClass, const sal_Char * pTypeName,
421 : typelib_TypeDescriptionReference * pBaseType,
422 : sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers )
423 : SAL_THROW_EXTERN_C()
424 : {
425 44 : init(ppRef, eTypeClass, pTypeName, pBaseType, nMembers, ppMembers, 0);
426 44 : }
427 :
428 0 : void SAL_CALL typelib_static_struct_type_init(
429 : typelib_TypeDescriptionReference ** ppRef, const sal_Char * pTypeName,
430 : typelib_TypeDescriptionReference * pBaseType,
431 : sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers,
432 : sal_Bool const * pParameterizedTypes )
433 : SAL_THROW_EXTERN_C()
434 : {
435 : init(
436 : ppRef, typelib_TypeClass_STRUCT, pTypeName, pBaseType, nMembers,
437 0 : ppMembers, pParameterizedTypes);
438 0 : }
439 :
440 0 : void SAL_CALL typelib_static_interface_type_init(
441 : typelib_TypeDescriptionReference ** ppRef,
442 : const sal_Char * pTypeName,
443 : typelib_TypeDescriptionReference * pBaseType )
444 : SAL_THROW_EXTERN_C()
445 : {
446 : // coverity[callee_ptr_arith]
447 : typelib_static_mi_interface_type_init(
448 0 : ppRef, pTypeName, pBaseType == 0 ? 0 : 1, &pBaseType);
449 0 : }
450 :
451 8 : void SAL_CALL typelib_static_mi_interface_type_init(
452 : typelib_TypeDescriptionReference ** ppRef,
453 : const sal_Char * pTypeName,
454 : sal_Int32 nBaseTypes,
455 : typelib_TypeDescriptionReference ** ppBaseTypes )
456 : SAL_THROW_EXTERN_C()
457 : {
458 8 : if (! *ppRef)
459 : {
460 8 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
461 8 : if (! *ppRef)
462 : {
463 : assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_INTERFACE) );
464 8 : OUString aTypeName( OUString::createFromAscii( pTypeName ) );
465 8 : *ppRef = igetTypeByName( aTypeName.pData );
466 8 : if (!*ppRef)
467 : {
468 3 : typelib_InterfaceTypeDescription * pIface = 0;
469 : ::typelib_typedescription_newEmpty(
470 3 : reinterpret_cast<typelib_TypeDescription **>(&pIface), typelib_TypeClass_INTERFACE, aTypeName.pData );
471 :
472 3 : pIface->nBaseTypes = std::max< sal_Int32 >(nBaseTypes, 1);
473 : pIface->ppBaseTypes = new typelib_InterfaceTypeDescription *[
474 3 : pIface->nBaseTypes];
475 3 : if (nBaseTypes > 0)
476 : {
477 4 : for (sal_Int32 i = 0; i < nBaseTypes; ++i) {
478 2 : pIface->ppBaseTypes[i] = 0;
479 : ::typelib_typedescriptionreference_getDescription(
480 2 : reinterpret_cast<typelib_TypeDescription **>(&pIface->ppBaseTypes[i]), ppBaseTypes[i] );
481 : assert( pIface->ppBaseTypes[i] );
482 : }
483 : }
484 : else
485 : {
486 1 : pIface->ppBaseTypes[0] = 0;
487 : ::typelib_typedescriptionreference_getDescription(
488 : reinterpret_cast<typelib_TypeDescription **>(&pIface->ppBaseTypes[0]),
489 1 : * ::typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE ) );
490 : assert( pIface->ppBaseTypes[0] );
491 : }
492 3 : pIface->pBaseTypeDescription = pIface->ppBaseTypes[0];
493 : typelib_typedescription_acquire(
494 3 : &pIface->pBaseTypeDescription->aBase);
495 :
496 3 : typelib_TypeDescription * pReg = &pIface->aBase;
497 3 : pReg->pWeakRef = reinterpret_cast<typelib_TypeDescriptionReference *>(pReg);
498 : // sizeof(void) not allowed
499 3 : pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
500 :
501 3 : pReg->nAlignment = adjustAlignment( pReg->nAlignment );
502 3 : pReg->bComplete = sal_False;
503 :
504 3 : ::typelib_typedescription_register( &pReg );
505 3 : *ppRef = reinterpret_cast<typelib_TypeDescriptionReference *>(pReg);
506 : assert( *ppRef == pReg->pWeakRef );
507 : }
508 : // another static ref:
509 8 : ++((*ppRef)->nStaticRefCount);
510 8 : }
511 : }
512 8 : }
513 :
514 :
515 0 : void SAL_CALL typelib_static_enum_type_init(
516 : typelib_TypeDescriptionReference ** ppRef,
517 : const sal_Char * pTypeName,
518 : sal_Int32 nDefaultValue )
519 : SAL_THROW_EXTERN_C()
520 : {
521 0 : if (! *ppRef)
522 : {
523 0 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
524 0 : if (! *ppRef)
525 : {
526 : assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ENUM) );
527 0 : OUString aTypeName( OUString::createFromAscii( pTypeName ) );
528 0 : *ppRef = igetTypeByName( aTypeName.pData );
529 0 : if (!*ppRef)
530 : {
531 0 : typelib_TypeDescription * pReg = 0;
532 : ::typelib_typedescription_newEmpty(
533 0 : &pReg, typelib_TypeClass_ENUM, aTypeName.pData );
534 0 : typelib_EnumTypeDescription * pEnum = reinterpret_cast<typelib_EnumTypeDescription *>(pReg);
535 :
536 0 : pEnum->nDefaultEnumValue = nDefaultValue;
537 :
538 0 : pReg->pWeakRef = reinterpret_cast<typelib_TypeDescriptionReference *>(pReg);
539 : // sizeof(void) not allowed
540 0 : pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
541 0 : pReg->nAlignment = ::adjustAlignment( pReg->nAlignment );
542 0 : pReg->bComplete = sal_False;
543 :
544 0 : ::typelib_typedescription_register( &pReg );
545 0 : *ppRef = reinterpret_cast<typelib_TypeDescriptionReference *>(pReg);
546 : assert( *ppRef == pReg->pWeakRef );
547 : }
548 : // another static ref:
549 0 : ++((*ppRef)->nStaticRefCount);
550 0 : }
551 : }
552 0 : }
553 :
554 : } // extern "C"
555 :
556 : }
557 :
558 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|