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 INCLUDED_CPPU_SOURCE_UNO_DESTR_HXX
20 : #define INCLUDED_CPPU_SOURCE_UNO_DESTR_HXX
21 :
22 : #include <sal/config.h>
23 :
24 : #include <cassert>
25 :
26 : #include "prim.hxx"
27 :
28 :
29 : namespace cppu
30 : {
31 :
32 :
33 : //#### destruction #################################################################################
34 :
35 :
36 :
37 : void destructStruct(
38 : void * pValue,
39 : typelib_CompoundTypeDescription * pTypeDescr,
40 : uno_ReleaseFunc release );
41 :
42 69011915 : inline void _destructStruct(
43 : void * pValue,
44 : typelib_CompoundTypeDescription * pTypeDescr,
45 : uno_ReleaseFunc release )
46 : {
47 69011915 : if (pTypeDescr->pBaseTypeDescription)
48 : {
49 1714031 : destructStruct( pValue, pTypeDescr->pBaseTypeDescription, release );
50 : }
51 :
52 69011915 : typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs;
53 69011915 : sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
54 69011915 : sal_Int32 nDescr = pTypeDescr->nMembers;
55 402084066 : while (nDescr--)
56 : {
57 : ::uno_type_destructData(
58 528120474 : static_cast<char *>(pValue) + pMemberOffsets[nDescr],
59 792180711 : ppTypeRefs[nDescr], release );
60 : }
61 69011914 : }
62 :
63 :
64 : void destructSequence(
65 : uno_Sequence * pSequence,
66 : typelib_TypeDescriptionReference * pType,
67 : typelib_TypeDescription * pTypeDescr,
68 : uno_ReleaseFunc release );
69 :
70 :
71 3974176296 : inline void _destructAny(
72 : uno_Any * pAny,
73 : uno_ReleaseFunc release )
74 : {
75 3974176296 : typelib_TypeDescriptionReference * pType = pAny->pType;
76 :
77 3974176296 : switch (pType->eTypeClass)
78 : {
79 : case typelib_TypeClass_HYPER:
80 : case typelib_TypeClass_UNSIGNED_HYPER:
81 : if (sizeof(void *) < sizeof(sal_Int64))
82 : {
83 : ::rtl_freeMemory( pAny->pData );
84 : }
85 451917 : break;
86 : case typelib_TypeClass_FLOAT:
87 : if (sizeof(void *) < sizeof(float))
88 : {
89 : ::rtl_freeMemory( pAny->pData );
90 : }
91 1357865 : break;
92 : case typelib_TypeClass_DOUBLE:
93 : if (sizeof(void *) < sizeof(double))
94 : {
95 : ::rtl_freeMemory( pAny->pData );
96 : }
97 3916792 : break;
98 : case typelib_TypeClass_STRING:
99 182176849 : ::rtl_uString_release( static_cast<rtl_uString *>(pAny->pReserved) );
100 182176856 : break;
101 : case typelib_TypeClass_TYPE:
102 : ::typelib_typedescriptionreference_release(
103 69283 : static_cast<typelib_TypeDescriptionReference *>(pAny->pReserved) );
104 69283 : break;
105 : case typelib_TypeClass_ANY:
106 : OSL_FAIL( "### unexpected nested any!" );
107 0 : ::uno_any_destruct( static_cast<uno_Any *>(pAny->pData), release );
108 0 : ::rtl_freeMemory( pAny->pData );
109 0 : break;
110 : case typelib_TypeClass_TYPEDEF:
111 : OSL_FAIL( "### unexpected typedef!" );
112 0 : break;
113 : case typelib_TypeClass_STRUCT:
114 : case typelib_TypeClass_EXCEPTION:
115 : {
116 31918767 : typelib_TypeDescription * pTypeDescr = 0;
117 31918767 : TYPELIB_DANGER_GET( &pTypeDescr, pType );
118 31918767 : _destructStruct( pAny->pData, reinterpret_cast<typelib_CompoundTypeDescription *>(pTypeDescr), release );
119 31918766 : TYPELIB_DANGER_RELEASE( pTypeDescr );
120 31918766 : ::rtl_freeMemory( pAny->pData );
121 31918767 : break;
122 : }
123 : case typelib_TypeClass_SEQUENCE:
124 : {
125 : destructSequence(
126 12327753 : static_cast<uno_Sequence *>(pAny->pReserved), pType, 0, release );
127 12327753 : break;
128 : }
129 : case typelib_TypeClass_INTERFACE:
130 2634819117 : _release( pAny->pReserved, release );
131 2634819078 : break;
132 : default:
133 1107137953 : break;
134 : }
135 : #if OSL_DEBUG_LEVEL > 0
136 : pAny->pData = reinterpret_cast<void *>(0xdeadbeef);
137 : #endif
138 :
139 3974176264 : ::typelib_typedescriptionreference_release( pType );
140 3974175672 : }
141 :
142 243417599 : inline sal_Int32 idestructElements(
143 : void * pElements, typelib_TypeDescriptionReference * pElementType,
144 : sal_Int32 nStartIndex, sal_Int32 nStopIndex,
145 : uno_ReleaseFunc release )
146 : {
147 243417599 : switch (pElementType->eTypeClass)
148 : {
149 : case typelib_TypeClass_CHAR:
150 0 : return (sal_Int32)(sizeof(sal_Unicode));
151 : case typelib_TypeClass_BOOLEAN:
152 55897 : return (sal_Int32)(sizeof(sal_Bool));
153 : case typelib_TypeClass_BYTE:
154 2952501 : return (sal_Int32)(sizeof(sal_Int8));
155 : case typelib_TypeClass_SHORT:
156 : case typelib_TypeClass_UNSIGNED_SHORT:
157 1643 : return (sal_Int32)(sizeof(sal_Int16));
158 : case typelib_TypeClass_LONG:
159 : case typelib_TypeClass_UNSIGNED_LONG:
160 99128 : return (sal_Int32)(sizeof(sal_Int32));
161 : case typelib_TypeClass_HYPER:
162 : case typelib_TypeClass_UNSIGNED_HYPER:
163 1207 : return (sal_Int32)(sizeof(sal_Int64));
164 : case typelib_TypeClass_FLOAT:
165 6 : return (sal_Int32)(sizeof(float));
166 : case typelib_TypeClass_DOUBLE:
167 461063 : return (sal_Int32)(sizeof(double));
168 :
169 : case typelib_TypeClass_STRING:
170 : {
171 2129053 : rtl_uString ** pDest = static_cast<rtl_uString **>(pElements);
172 12057539 : for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
173 : {
174 9928486 : ::rtl_uString_release( pDest[nPos] );
175 : }
176 2129053 : return (sal_Int32)(sizeof(rtl_uString *));
177 : }
178 : case typelib_TypeClass_TYPE:
179 : {
180 45956 : typelib_TypeDescriptionReference ** pDest = static_cast<typelib_TypeDescriptionReference **>(pElements);
181 1398191 : for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
182 : {
183 1352235 : ::typelib_typedescriptionreference_release( pDest[nPos] );
184 : }
185 45956 : return (sal_Int32)(sizeof(typelib_TypeDescriptionReference *));
186 : }
187 : case typelib_TypeClass_ANY:
188 : {
189 28499425 : uno_Any * pDest = static_cast<uno_Any *>(pElements);
190 61429473 : for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
191 : {
192 32930048 : _destructAny( &pDest[nPos], release );
193 : }
194 28499425 : return (sal_Int32)(sizeof(uno_Any));
195 : }
196 : case typelib_TypeClass_ENUM:
197 48627 : return (sal_Int32)(sizeof(sal_Int32));
198 : case typelib_TypeClass_STRUCT:
199 : case typelib_TypeClass_EXCEPTION:
200 : {
201 5394709 : typelib_TypeDescription * pElementTypeDescr = 0;
202 5394709 : TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
203 5394709 : sal_Int32 nElementSize = pElementTypeDescr->nSize;
204 39715422 : for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
205 : {
206 : _destructStruct(
207 68641426 : static_cast<char *>(pElements) + (nElementSize * nPos),
208 : reinterpret_cast<typelib_CompoundTypeDescription *>(pElementTypeDescr),
209 102962139 : release );
210 : }
211 5394709 : sal_Int32 nSize = pElementTypeDescr->nSize;
212 5394709 : TYPELIB_DANGER_RELEASE( pElementTypeDescr );
213 5394709 : return nSize;
214 : }
215 : case typelib_TypeClass_SEQUENCE:
216 : {
217 211601 : typelib_TypeDescription * pElementTypeDescr = 0;
218 211601 : TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
219 211601 : uno_Sequence ** pDest = static_cast<uno_Sequence **>(pElements);
220 5683448 : for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
221 : {
222 : destructSequence(
223 5471847 : pDest[nPos],
224 : pElementTypeDescr->pWeakRef, pElementTypeDescr,
225 10943694 : release );
226 : }
227 211601 : TYPELIB_DANGER_RELEASE( pElementTypeDescr );
228 211601 : return (sal_Int32)(sizeof(uno_Sequence *));
229 : }
230 : case typelib_TypeClass_INTERFACE:
231 : {
232 203516783 : if (release)
233 : {
234 1200667749 : for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
235 : {
236 997151031 : void * p = static_cast<void **>(pElements)[nPos];
237 997151031 : if (p)
238 : {
239 996795455 : (*release)( p );
240 : }
241 : }
242 : }
243 : else
244 : {
245 188 : for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
246 : {
247 120 : uno_Interface * p = static_cast<uno_Interface **>(pElements)[nPos];
248 120 : if (p)
249 : {
250 109 : (*p->release)( p );
251 : }
252 : }
253 : }
254 203516786 : return (sal_Int32)(sizeof(void *));
255 : }
256 : default:
257 : OSL_ASSERT(false);
258 0 : return 0;
259 : }
260 : }
261 :
262 241808800 : inline void idestroySequence(
263 : uno_Sequence * pSeq,
264 : typelib_TypeDescriptionReference * pType,
265 : typelib_TypeDescription * pTypeDescr,
266 : uno_ReleaseFunc release )
267 : {
268 : assert(pSeq != nullptr);
269 : assert(pSeq->nRefCount == 0);
270 241808800 : if (pSeq->nElements > 0)
271 : {
272 240942384 : if (pTypeDescr)
273 : {
274 : idestructElements(
275 : pSeq->elements,
276 : reinterpret_cast<typelib_IndirectTypeDescription *>(pTypeDescr)->pType, 0,
277 495076 : pSeq->nElements, release );
278 : }
279 : else
280 : {
281 240447308 : TYPELIB_DANGER_GET( &pTypeDescr, pType );
282 : idestructElements(
283 : pSeq->elements,
284 : reinterpret_cast<typelib_IndirectTypeDescription *>(pTypeDescr)->pType, 0,
285 240447301 : pSeq->nElements, release );
286 240447299 : TYPELIB_DANGER_RELEASE( pTypeDescr );
287 : }
288 : }
289 241808777 : ::rtl_freeMemory( pSeq );
290 241808814 : }
291 :
292 28863395 : inline void idestructSequence(
293 : uno_Sequence * pSeq,
294 : typelib_TypeDescriptionReference * pType,
295 : typelib_TypeDescription * pTypeDescr,
296 : uno_ReleaseFunc release )
297 : {
298 28863395 : if (osl_atomic_decrement( &pSeq->nRefCount ) == 0)
299 : {
300 6545808 : idestroySequence(pSeq, pType, pTypeDescr, release);
301 : }
302 28863395 : }
303 :
304 264824427 : inline void _destructData(
305 : void * pValue,
306 : typelib_TypeDescriptionReference * pType,
307 : typelib_TypeDescription * pTypeDescr,
308 : uno_ReleaseFunc release )
309 : {
310 264824427 : switch (pType->eTypeClass)
311 : {
312 : case typelib_TypeClass_STRING:
313 79262141 : ::rtl_uString_release( *static_cast<rtl_uString **>(pValue) );
314 79262142 : break;
315 : case typelib_TypeClass_TYPE:
316 2999820 : ::typelib_typedescriptionreference_release( *static_cast<typelib_TypeDescriptionReference **>(pValue) );
317 2999820 : break;
318 : case typelib_TypeClass_ANY:
319 53678983 : _destructAny( static_cast<uno_Any *>(pValue), release );
320 53678984 : break;
321 : case typelib_TypeClass_TYPEDEF:
322 : OSL_FAIL( "### unexpected typedef!" );
323 0 : break;
324 : case typelib_TypeClass_STRUCT:
325 : case typelib_TypeClass_EXCEPTION:
326 1058404 : if (pTypeDescr)
327 : {
328 29702 : _destructStruct( pValue, reinterpret_cast<typelib_CompoundTypeDescription *>(pTypeDescr), release );
329 : }
330 : else
331 : {
332 1028702 : TYPELIB_DANGER_GET( &pTypeDescr, pType );
333 1028702 : _destructStruct( pValue, reinterpret_cast<typelib_CompoundTypeDescription *>(pTypeDescr), release );
334 1028702 : TYPELIB_DANGER_RELEASE( pTypeDescr );
335 : }
336 1058404 : break;
337 : case typelib_TypeClass_SEQUENCE:
338 : {
339 : idestructSequence(
340 599145 : *static_cast<uno_Sequence **>(pValue), pType, pTypeDescr, release );
341 599145 : break;
342 : }
343 : case typelib_TypeClass_INTERFACE:
344 692999 : _release( *static_cast<void **>(pValue), release );
345 692999 : break;
346 : default:
347 126532935 : break;
348 : }
349 264824429 : }
350 :
351 : }
352 :
353 : #endif
354 :
355 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|