Branch data 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 : : #ifndef DESTR_HXX
20 : : #define DESTR_HXX
21 : :
22 : : #include "prim.hxx"
23 : :
24 : :
25 : : namespace cppu
26 : : {
27 : :
28 : : //##################################################################################################
29 : : //#### destruction #################################################################################
30 : : //##################################################################################################
31 : :
32 : : //--------------------------------------------------------------------------------------------------
33 : 0 : inline void _destructUnion(
34 : : void * pValue,
35 : : typelib_TypeDescription * pTypeDescr,
36 : : uno_ReleaseFunc release )
37 : : SAL_THROW(())
38 : : {
39 : 0 : typelib_TypeDescriptionReference * pType = _unionGetSetType( pValue, pTypeDescr );
40 : : ::uno_type_destructData(
41 : 0 : (char *)pValue + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset,
42 : 0 : pType, release );
43 : 0 : ::typelib_typedescriptionreference_release( pType );
44 : 0 : }
45 : : //==================================================================================================
46 : : void destructStruct(
47 : : void * pValue,
48 : : typelib_CompoundTypeDescription * pTypeDescr,
49 : : uno_ReleaseFunc release )
50 : : SAL_THROW(());
51 : : //--------------------------------------------------------------------------------------------------
52 : 21749820 : inline void _destructStruct(
53 : : void * pValue,
54 : : typelib_CompoundTypeDescription * pTypeDescr,
55 : : uno_ReleaseFunc release )
56 : : SAL_THROW(())
57 : : {
58 [ + + ]: 21749820 : if (pTypeDescr->pBaseTypeDescription)
59 : : {
60 : 799011 : destructStruct( pValue, pTypeDescr->pBaseTypeDescription, release );
61 : : }
62 : :
63 : 21749820 : typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs;
64 : 21749820 : sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
65 : 21749820 : sal_Int32 nDescr = pTypeDescr->nMembers;
66 [ + + ]: 110258395 : while (nDescr--)
67 : : {
68 : : ::uno_type_destructData(
69 : 177017154 : (char *)pValue + pMemberOffsets[nDescr],
70 : 88508577 : ppTypeRefs[nDescr], release );
71 : : }
72 : 21749818 : }
73 : :
74 : : //--------------------------------------------------------------------------------------------------
75 : 0 : inline void _destructArray(
76 : : void * pValue,
77 : : typelib_ArrayTypeDescription * pTypeDescr,
78 : : uno_ReleaseFunc release )
79 : : throw ()
80 : : {
81 : 0 : typelib_TypeDescription * pElementType = NULL;
82 [ # # ][ # # ]: 0 : TYPELIB_DANGER_GET( &pElementType, ((typelib_IndirectTypeDescription *)pTypeDescr)->pType );
[ # # ][ # # ]
[ # # ]
83 : 0 : sal_Int32 nElementSize = pElementType->nSize;
84 [ # # ][ # # ]: 0 : TYPELIB_DANGER_RELEASE( pElementType );
85 : :
86 : 0 : sal_Int32 nTotalElements = pTypeDescr->nTotalElements;
87 [ # # ]: 0 : for(sal_Int32 i=0; i < nTotalElements; i++)
88 : : {
89 : : ::uno_type_destructData(
90 : 0 : (sal_Char *)pValue + i * nElementSize,
91 : 0 : ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, release );
92 : : }
93 : :
94 : 0 : typelib_typedescriptionreference_release(((typelib_IndirectTypeDescription *)pTypeDescr)->pType);
95 : 0 : }
96 : :
97 : : //==============================================================================
98 : : void destructSequence(
99 : : uno_Sequence * pSequence,
100 : : typelib_TypeDescriptionReference * pType,
101 : : typelib_TypeDescription * pTypeDescr,
102 : : uno_ReleaseFunc release );
103 : :
104 : : //--------------------------------------------------------------------------------------------------
105 : 165510136 : inline void _destructAny(
106 : : uno_Any * pAny,
107 : : uno_ReleaseFunc release )
108 : : SAL_THROW(())
109 : : {
110 : 165510136 : typelib_TypeDescriptionReference * pType = pAny->pType;
111 : :
112 [ + + + + : 165510136 : switch (pType->eTypeClass)
+ - - + -
+ + + ]
113 : : {
114 : : case typelib_TypeClass_HYPER:
115 : : case typelib_TypeClass_UNSIGNED_HYPER:
116 : : if (sizeof(void *) < sizeof(sal_Int64))
117 : : {
118 : 206319 : ::rtl_freeMemory( pAny->pData );
119 : : }
120 : 206319 : break;
121 : : case typelib_TypeClass_FLOAT:
122 : : if (sizeof(void *) < sizeof(float))
123 : : {
124 : : ::rtl_freeMemory( pAny->pData );
125 : : }
126 : 806588 : break;
127 : : case typelib_TypeClass_DOUBLE:
128 : : if (sizeof(void *) < sizeof(double))
129 : : {
130 : 428388 : ::rtl_freeMemory( pAny->pData );
131 : : }
132 : 428388 : break;
133 : : case typelib_TypeClass_STRING:
134 : 28533026 : ::rtl_uString_release( (rtl_uString *)pAny->pReserved );
135 : 28533025 : break;
136 : : case typelib_TypeClass_TYPE:
137 : : ::typelib_typedescriptionreference_release(
138 : 137760 : (typelib_TypeDescriptionReference *)pAny->pReserved );
139 : 137760 : break;
140 : : case typelib_TypeClass_ANY:
141 : : OSL_FAIL( "### unexpected nested any!" );
142 : 0 : ::uno_any_destruct( (uno_Any *)pAny->pData, release );
143 : 0 : ::rtl_freeMemory( pAny->pData );
144 : 0 : break;
145 : : case typelib_TypeClass_TYPEDEF:
146 : : OSL_FAIL( "### unexpected typedef!" );
147 : 0 : break;
148 : : case typelib_TypeClass_STRUCT:
149 : : case typelib_TypeClass_EXCEPTION:
150 : : {
151 : 3599839 : typelib_TypeDescription * pTypeDescr = 0;
152 [ + - ][ - + ]: 3599839 : TYPELIB_DANGER_GET( &pTypeDescr, pType );
[ + - ][ - + ]
[ # # ]
153 [ + - ]: 3599839 : _destructStruct( pAny->pData, (typelib_CompoundTypeDescription *)pTypeDescr, release );
154 [ + - ][ - + ]: 3599838 : TYPELIB_DANGER_RELEASE( pTypeDescr );
155 : 3599838 : ::rtl_freeMemory( pAny->pData );
156 : : break;
157 : : }
158 : : case typelib_TypeClass_UNION:
159 : : {
160 : 0 : typelib_TypeDescription * pTypeDescr = 0;
161 [ # # ][ # # ]: 0 : TYPELIB_DANGER_GET( &pTypeDescr, pType );
[ # # ][ # # ]
[ # # ]
162 : 0 : _destructUnion( pAny->pData, pTypeDescr, release );
163 [ # # ][ # # ]: 0 : TYPELIB_DANGER_RELEASE( pTypeDescr );
164 : 0 : ::rtl_freeMemory( pAny->pData );
165 : : break;
166 : : }
167 : : case typelib_TypeClass_SEQUENCE:
168 : : {
169 : : destructSequence(
170 : 5748696 : *(uno_Sequence **) &pAny->pReserved, pType, 0, release );
171 : 5748696 : break;
172 : : }
173 : : case typelib_TypeClass_INTERFACE:
174 : 36654574 : _release( pAny->pReserved, release );
175 : 36654586 : break;
176 : : default:
177 : 89394946 : break;
178 : : }
179 : : #if OSL_DEBUG_LEVEL > 0
180 : : pAny->pData = (void *)0xdeadbeef;
181 : : #endif
182 : :
183 : 165510147 : ::typelib_typedescriptionreference_release( pType );
184 : 165510303 : }
185 : : //--------------------------------------------------------------------------------------------------
186 : 12114345 : inline sal_Int32 idestructElements(
187 : : void * pElements, typelib_TypeDescriptionReference * pElementType,
188 : : sal_Int32 nStartIndex, sal_Int32 nStopIndex,
189 : : uno_ReleaseFunc release )
190 : : SAL_THROW(())
191 : : {
192 [ - + + + : 12114345 : switch (pElementType->eTypeClass)
+ + + + +
+ + + + -
+ + - ]
193 : : {
194 : : case typelib_TypeClass_CHAR:
195 : 0 : return (sal_Int32)(sizeof(sal_Unicode));
196 : : case typelib_TypeClass_BOOLEAN:
197 : 37806 : return (sal_Int32)(sizeof(sal_Bool));
198 : : case typelib_TypeClass_BYTE:
199 : 2508692 : return (sal_Int32)(sizeof(sal_Int8));
200 : : case typelib_TypeClass_SHORT:
201 : : case typelib_TypeClass_UNSIGNED_SHORT:
202 : 7459 : return (sal_Int32)(sizeof(sal_Int16));
203 : : case typelib_TypeClass_LONG:
204 : : case typelib_TypeClass_UNSIGNED_LONG:
205 : 46334 : return (sal_Int32)(sizeof(sal_Int32));
206 : : case typelib_TypeClass_HYPER:
207 : : case typelib_TypeClass_UNSIGNED_HYPER:
208 : 1845 : return (sal_Int32)(sizeof(sal_Int64));
209 : : case typelib_TypeClass_FLOAT:
210 : 30 : return (sal_Int32)(sizeof(float));
211 : : case typelib_TypeClass_DOUBLE:
212 : 322903 : return (sal_Int32)(sizeof(double));
213 : :
214 : : case typelib_TypeClass_STRING:
215 : : {
216 : 2288021 : rtl_uString ** pDest = (rtl_uString **)pElements;
217 [ + + ]: 10225286 : for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
218 : : {
219 : 7937265 : ::rtl_uString_release( pDest[nPos] );
220 : : }
221 : 2288021 : return (sal_Int32)(sizeof(rtl_uString *));
222 : : }
223 : : case typelib_TypeClass_TYPE:
224 : : {
225 : 12246 : typelib_TypeDescriptionReference ** pDest = (typelib_TypeDescriptionReference **)pElements;
226 [ + + ]: 267893 : for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
227 : : {
228 : 255647 : ::typelib_typedescriptionreference_release( pDest[nPos] );
229 : : }
230 : 12246 : return (sal_Int32)(sizeof(typelib_TypeDescriptionReference *));
231 : : }
232 : : case typelib_TypeClass_ANY:
233 : : {
234 : 985883 : uno_Any * pDest = (uno_Any *)pElements;
235 [ + + ]: 4106394 : for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
236 : : {
237 : 3120511 : _destructAny( &pDest[nPos], release );
238 : : }
239 : 985883 : return (sal_Int32)(sizeof(uno_Any));
240 : : }
241 : : case typelib_TypeClass_ENUM:
242 : 7189 : return (sal_Int32)(sizeof(sal_Int32));
243 : : case typelib_TypeClass_STRUCT:
244 : : case typelib_TypeClass_EXCEPTION:
245 : : {
246 : 3067800 : typelib_TypeDescription * pElementTypeDescr = 0;
247 [ + - ][ - + ]: 3067800 : TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
[ + - ][ - + ]
[ # # ]
248 : 3067800 : sal_Int32 nElementSize = pElementTypeDescr->nSize;
249 [ + + ]: 20144761 : for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
250 : : {
251 : : _destructStruct(
252 : 17076961 : (char *)pElements + (nElementSize * nPos),
253 : : (typelib_CompoundTypeDescription *)pElementTypeDescr,
254 [ + - ]: 17076961 : release );
255 : : }
256 : 3067800 : sal_Int32 nSize = pElementTypeDescr->nSize;
257 [ + - ][ - + ]: 3067800 : TYPELIB_DANGER_RELEASE( pElementTypeDescr );
258 : 3067800 : return nSize;
259 : : }
260 : : case typelib_TypeClass_UNION:
261 : : {
262 : 0 : typelib_TypeDescription * pElementTypeDescr = 0;
263 [ # # ][ # # ]: 0 : TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
[ # # ][ # # ]
[ # # ]
264 : 0 : sal_Int32 nElementSize = pElementTypeDescr->nSize;
265 [ # # ]: 0 : for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
266 : : {
267 : : _destructUnion(
268 : 0 : (char *)pElements + (nElementSize * nPos),
269 : : pElementTypeDescr,
270 : 0 : release );
271 : : }
272 : 0 : sal_Int32 nSize = pElementTypeDescr->nSize;
273 [ # # ][ # # ]: 0 : TYPELIB_DANGER_RELEASE( pElementTypeDescr );
274 : 0 : return nSize;
275 : : }
276 : : case typelib_TypeClass_SEQUENCE:
277 : : {
278 : 94430 : typelib_TypeDescription * pElementTypeDescr = 0;
279 [ + - ][ - + ]: 94430 : TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
[ + - ][ - + ]
[ # # ]
280 : 94430 : uno_Sequence ** pDest = (uno_Sequence **)pElements;
281 [ + + ]: 315488 : for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
282 : : {
283 : : destructSequence(
284 : 221058 : pDest[nPos],
285 : : pElementTypeDescr->pWeakRef, pElementTypeDescr,
286 [ + - ]: 221058 : release );
287 : : }
288 [ + - ][ - + ]: 94430 : TYPELIB_DANGER_RELEASE( pElementTypeDescr );
289 : 94430 : return (sal_Int32)(sizeof(uno_Sequence *));
290 : : }
291 : : case typelib_TypeClass_INTERFACE:
292 : : {
293 [ + + ]: 2733707 : if (release)
294 : : {
295 [ + + ]: 12527597 : for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
296 : : {
297 : 9794045 : void * p = ((void **)pElements)[nPos];
298 [ + + ]: 9794045 : if (p)
299 : : {
300 : 9503300 : (*release)( p );
301 : : }
302 : : }
303 : : }
304 : : else
305 : : {
306 [ + + ]: 424 : for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
307 : : {
308 : 271 : uno_Interface * p = ((uno_Interface **)pElements)[nPos];
309 [ + + ]: 271 : if (p)
310 : : {
311 : 243 : (*p->release)( p );
312 : : }
313 : : }
314 : : }
315 : 2733705 : return (sal_Int32)(sizeof(void *));
316 : : }
317 : : default:
318 : : OSL_ASSERT(false);
319 : 12114343 : return 0;
320 : : }
321 : : }
322 : :
323 : : //------------------------------------------------------------------------------
324 : 39901243 : inline void idestructSequence(
325 : : uno_Sequence * pSeq,
326 : : typelib_TypeDescriptionReference * pType,
327 : : typelib_TypeDescription * pTypeDescr,
328 : : uno_ReleaseFunc release )
329 : : {
330 [ + + ]: 39901243 : if (::osl_decrementInterlockedCount( &pSeq->nRefCount ) == 0)
331 : : {
332 [ + + ]: 11167519 : if (pSeq->nElements > 0)
333 : : {
334 [ + + ]: 10767470 : if (pTypeDescr)
335 : : {
336 : : idestructElements(
337 : : pSeq->elements,
338 : : ((typelib_IndirectTypeDescription *) pTypeDescr)->pType, 0,
339 : 230417 : pSeq->nElements, release );
340 : : }
341 : : else
342 : : {
343 [ + - ][ + + ]: 10537053 : TYPELIB_DANGER_GET( &pTypeDescr, pType );
[ + # ]
[ # + # # ]
[ # # ]
344 : : idestructElements(
345 : : pSeq->elements,
346 : : ((typelib_IndirectTypeDescription *) pTypeDescr)->pType, 0,
347 : 10537054 : pSeq->nElements, release );
348 [ # + ][ + # ]: 10537041 : TYPELIB_DANGER_RELEASE( pTypeDescr );
349 : : }
350 : : }
351 : 11167519 : ::rtl_freeMemory( pSeq );
352 : : }
353 : 39901303 : }
354 : :
355 : : //--------------------------------------------------------------------------------------------------
356 : 115972566 : inline void _destructData(
357 : : void * pValue,
358 : : typelib_TypeDescriptionReference * pType,
359 : : typelib_TypeDescription * pTypeDescr,
360 : : uno_ReleaseFunc release )
361 : : SAL_THROW(())
362 : : {
363 [ + + + - : 115972566 : switch (pType->eTypeClass)
+ - - + +
+ ]
364 : : {
365 : : case typelib_TypeClass_STRING:
366 : 27204797 : ::rtl_uString_release( *(rtl_uString **)pValue );
367 : 27204795 : break;
368 : : case typelib_TypeClass_TYPE:
369 : 1174033 : ::typelib_typedescriptionreference_release( *(typelib_TypeDescriptionReference **)pValue );
370 : 1174033 : break;
371 : : case typelib_TypeClass_ANY:
372 : 16466220 : _destructAny( (uno_Any *)pValue, release );
373 : 16466220 : break;
374 : : case typelib_TypeClass_TYPEDEF:
375 : : OSL_FAIL( "### unexpected typedef!" );
376 : 0 : break;
377 : : case typelib_TypeClass_STRUCT:
378 : : case typelib_TypeClass_EXCEPTION:
379 [ + + ]: 274009 : if (pTypeDescr)
380 : : {
381 : 34660 : _destructStruct( pValue, (typelib_CompoundTypeDescription *)pTypeDescr, release );
382 : : }
383 : : else
384 : : {
385 [ + - ][ - + ]: 239349 : TYPELIB_DANGER_GET( &pTypeDescr, pType );
[ + - ][ - + ]
[ # # ]
386 : 239349 : _destructStruct( pValue, (typelib_CompoundTypeDescription *)pTypeDescr, release );
387 [ - + ][ + - ]: 239349 : TYPELIB_DANGER_RELEASE( pTypeDescr );
388 : : }
389 : 274009 : break;
390 : : case typelib_TypeClass_ARRAY:
391 [ # # ]: 0 : if (pTypeDescr)
392 : : {
393 : 0 : _destructArray( pValue, (typelib_ArrayTypeDescription *)pTypeDescr, release );
394 : : }
395 : : else
396 : : {
397 [ # # ][ # # ]: 0 : TYPELIB_DANGER_GET( &pTypeDescr, pType );
[ # # ][ # # ]
[ # # ]
398 : 0 : _destructArray( pValue, (typelib_ArrayTypeDescription *)pTypeDescr, release );
399 [ # # ][ # # ]: 0 : TYPELIB_DANGER_RELEASE( pTypeDescr );
400 : : }
401 : 0 : break;
402 : : case typelib_TypeClass_UNION:
403 [ # # ]: 0 : if (pTypeDescr)
404 : : {
405 : 0 : _destructUnion( pValue, pTypeDescr, release );
406 : : }
407 : : else
408 : : {
409 [ # # ][ # # ]: 0 : TYPELIB_DANGER_GET( &pTypeDescr, pType );
[ # # ][ # # ]
[ # # ]
410 : 0 : _destructUnion( pValue, pTypeDescr, release );
411 [ # # ][ # # ]: 0 : TYPELIB_DANGER_RELEASE( pTypeDescr );
412 : : }
413 : 0 : break;
414 : : case typelib_TypeClass_SEQUENCE:
415 : : {
416 : : idestructSequence(
417 : 27406858 : *(uno_Sequence **)pValue, pType, pTypeDescr, release );
418 : 27407101 : break;
419 : : }
420 : : case typelib_TypeClass_INTERFACE:
421 : 723618 : _release( *(void **)pValue, release );
422 : 723618 : break;
423 : : default:
424 : 42723031 : break;
425 : : }
426 : 115972807 : }
427 : :
428 : : }
429 : :
430 : : #endif
431 : :
432 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|