1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
36 //##################################################################################################
37 //#### destruction #################################################################################
38 //##################################################################################################
40 //--------------------------------------------------------------------------------------------------
41 inline void _destructUnion(
43 typelib_TypeDescription
* pTypeDescr
,
44 uno_ReleaseFunc release
)
47 typelib_TypeDescriptionReference
* pType
= _unionGetSetType( pValue
, pTypeDescr
);
48 ::uno_type_destructData(
49 (char *)pValue
+ ((typelib_UnionTypeDescription
*)pTypeDescr
)->nValueOffset
,
51 ::typelib_typedescriptionreference_release( pType
);
53 //==================================================================================================
56 typelib_CompoundTypeDescription
* pTypeDescr
,
57 uno_ReleaseFunc release
)
59 //--------------------------------------------------------------------------------------------------
60 inline void _destructStruct(
62 typelib_CompoundTypeDescription
* pTypeDescr
,
63 uno_ReleaseFunc release
)
66 if (pTypeDescr
->pBaseTypeDescription
)
68 destructStruct( pValue
, pTypeDescr
->pBaseTypeDescription
, release
);
71 typelib_TypeDescriptionReference
** ppTypeRefs
= pTypeDescr
->ppTypeRefs
;
72 sal_Int32
* pMemberOffsets
= pTypeDescr
->pMemberOffsets
;
73 sal_Int32 nDescr
= pTypeDescr
->nMembers
;
76 ::uno_type_destructData(
77 (char *)pValue
+ pMemberOffsets
[nDescr
],
78 ppTypeRefs
[nDescr
], release
);
82 //--------------------------------------------------------------------------------------------------
83 inline void _destructArray(
85 typelib_ArrayTypeDescription
* pTypeDescr
,
86 uno_ReleaseFunc release
)
89 typelib_TypeDescription
* pElementType
= NULL
;
90 TYPELIB_DANGER_GET( &pElementType
, ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
);
91 sal_Int32 nElementSize
= pElementType
->nSize
;
92 TYPELIB_DANGER_RELEASE( pElementType
);
94 sal_Int32 nTotalElements
= pTypeDescr
->nTotalElements
;
95 for(sal_Int32 i
=0; i
< nTotalElements
; i
++)
97 ::uno_type_destructData(
98 (sal_Char
*)pValue
+ i
* nElementSize
,
99 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
, release
);
102 typelib_typedescriptionreference_release(((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
);
105 //==============================================================================
106 void destructSequence(
107 uno_Sequence
* pSequence
,
108 typelib_TypeDescriptionReference
* pType
,
109 typelib_TypeDescription
* pTypeDescr
,
110 uno_ReleaseFunc release
);
112 //--------------------------------------------------------------------------------------------------
113 inline void _destructAny(
115 uno_ReleaseFunc release
)
118 typelib_TypeDescriptionReference
* pType
= pAny
->pType
;
120 switch (pType
->eTypeClass
)
122 case typelib_TypeClass_HYPER
:
123 case typelib_TypeClass_UNSIGNED_HYPER
:
124 if (sizeof(void *) < sizeof(sal_Int64
))
126 ::rtl_freeMemory( pAny
->pData
);
129 case typelib_TypeClass_FLOAT
:
130 if (sizeof(void *) < sizeof(float))
132 ::rtl_freeMemory( pAny
->pData
);
135 case typelib_TypeClass_DOUBLE
:
136 if (sizeof(void *) < sizeof(double))
138 ::rtl_freeMemory( pAny
->pData
);
141 case typelib_TypeClass_STRING
:
142 ::rtl_uString_release( (rtl_uString
*)pAny
->pReserved
);
144 case typelib_TypeClass_TYPE
:
145 ::typelib_typedescriptionreference_release(
146 (typelib_TypeDescriptionReference
*)pAny
->pReserved
);
148 case typelib_TypeClass_ANY
:
149 OSL_ENSURE( sal_False
, "### unexpected nested any!" );
150 ::uno_any_destruct( (uno_Any
*)pAny
->pData
, release
);
151 ::rtl_freeMemory( pAny
->pData
);
153 case typelib_TypeClass_TYPEDEF
:
154 OSL_ENSURE( 0, "### unexpected typedef!" );
156 case typelib_TypeClass_STRUCT
:
157 case typelib_TypeClass_EXCEPTION
:
159 typelib_TypeDescription
* pTypeDescr
= 0;
160 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
161 _destructStruct( pAny
->pData
, (typelib_CompoundTypeDescription
*)pTypeDescr
, release
);
162 TYPELIB_DANGER_RELEASE( pTypeDescr
);
163 ::rtl_freeMemory( pAny
->pData
);
166 case typelib_TypeClass_UNION
:
168 typelib_TypeDescription
* pTypeDescr
= 0;
169 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
170 _destructUnion( pAny
->pData
, pTypeDescr
, release
);
171 TYPELIB_DANGER_RELEASE( pTypeDescr
);
172 ::rtl_freeMemory( pAny
->pData
);
175 case typelib_TypeClass_SEQUENCE
:
178 *(uno_Sequence
**) &pAny
->pReserved
, pType
, 0, release
);
181 case typelib_TypeClass_INTERFACE
:
182 _release( pAny
->pReserved
, release
);
187 #if OSL_DEBUG_LEVEL > 0
188 pAny
->pData
= (void *)0xdeadbeef;
191 ::typelib_typedescriptionreference_release( pType
);
193 //--------------------------------------------------------------------------------------------------
194 inline sal_Int32
idestructElements(
195 void * pElements
, typelib_TypeDescriptionReference
* pElementType
,
196 sal_Int32 nStartIndex
, sal_Int32 nStopIndex
,
197 uno_ReleaseFunc release
)
200 switch (pElementType
->eTypeClass
)
202 case typelib_TypeClass_CHAR
:
203 return (sal_Int32
)(sizeof(sal_Unicode
));
204 case typelib_TypeClass_BOOLEAN
:
205 return (sal_Int32
)(sizeof(sal_Bool
));
206 case typelib_TypeClass_BYTE
:
207 return (sal_Int32
)(sizeof(sal_Int8
));
208 case typelib_TypeClass_SHORT
:
209 case typelib_TypeClass_UNSIGNED_SHORT
:
210 return (sal_Int32
)(sizeof(sal_Int16
));
211 case typelib_TypeClass_LONG
:
212 case typelib_TypeClass_UNSIGNED_LONG
:
213 return (sal_Int32
)(sizeof(sal_Int32
));
214 case typelib_TypeClass_HYPER
:
215 case typelib_TypeClass_UNSIGNED_HYPER
:
216 return (sal_Int32
)(sizeof(sal_Int64
));
217 case typelib_TypeClass_FLOAT
:
218 return (sal_Int32
)(sizeof(float));
219 case typelib_TypeClass_DOUBLE
:
220 return (sal_Int32
)(sizeof(double));
222 case typelib_TypeClass_STRING
:
224 rtl_uString
** pDest
= (rtl_uString
**)pElements
;
225 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
227 ::rtl_uString_release( pDest
[nPos
] );
229 return (sal_Int32
)(sizeof(rtl_uString
*));
231 case typelib_TypeClass_TYPE
:
233 typelib_TypeDescriptionReference
** pDest
= (typelib_TypeDescriptionReference
**)pElements
;
234 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
236 ::typelib_typedescriptionreference_release( pDest
[nPos
] );
238 return (sal_Int32
)(sizeof(typelib_TypeDescriptionReference
*));
240 case typelib_TypeClass_ANY
:
242 uno_Any
* pDest
= (uno_Any
*)pElements
;
243 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
245 _destructAny( &pDest
[nPos
], release
);
247 return (sal_Int32
)(sizeof(uno_Any
));
249 case typelib_TypeClass_ENUM
:
250 return (sal_Int32
)(sizeof(sal_Int32
));
251 case typelib_TypeClass_STRUCT
:
252 case typelib_TypeClass_EXCEPTION
:
254 typelib_TypeDescription
* pElementTypeDescr
= 0;
255 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
256 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
257 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
260 (char *)pElements
+ (nElementSize
* nPos
),
261 (typelib_CompoundTypeDescription
*)pElementTypeDescr
,
264 sal_Int32 nSize
= pElementTypeDescr
->nSize
;
265 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
268 case typelib_TypeClass_UNION
:
270 typelib_TypeDescription
* pElementTypeDescr
= 0;
271 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
272 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
273 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
276 (char *)pElements
+ (nElementSize
* nPos
),
280 sal_Int32 nSize
= pElementTypeDescr
->nSize
;
281 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
284 case typelib_TypeClass_SEQUENCE
:
286 typelib_TypeDescription
* pElementTypeDescr
= 0;
287 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
288 uno_Sequence
** pDest
= (uno_Sequence
**)pElements
;
289 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
293 pElementTypeDescr
->pWeakRef
, pElementTypeDescr
,
296 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
297 return (sal_Int32
)(sizeof(uno_Sequence
*));
299 case typelib_TypeClass_INTERFACE
:
303 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
305 void * p
= ((void **)pElements
)[nPos
];
314 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
316 uno_Interface
* p
= ((uno_Interface
**)pElements
)[nPos
];
323 return (sal_Int32
)(sizeof(void *));
331 //------------------------------------------------------------------------------
332 inline void idestructSequence(
334 typelib_TypeDescriptionReference
* pType
,
335 typelib_TypeDescription
* pTypeDescr
,
336 uno_ReleaseFunc release
)
338 if (::osl_decrementInterlockedCount( &pSeq
->nRefCount
) == 0)
340 if (pSeq
->nElements
> 0)
346 ((typelib_IndirectTypeDescription
*) pTypeDescr
)->pType
, 0,
347 pSeq
->nElements
, release
);
351 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
354 ((typelib_IndirectTypeDescription
*) pTypeDescr
)->pType
, 0,
355 pSeq
->nElements
, release
);
356 TYPELIB_DANGER_RELEASE( pTypeDescr
);
359 ::rtl_freeMemory( pSeq
);
363 //--------------------------------------------------------------------------------------------------
364 inline void _destructData(
366 typelib_TypeDescriptionReference
* pType
,
367 typelib_TypeDescription
* pTypeDescr
,
368 uno_ReleaseFunc release
)
371 switch (pType
->eTypeClass
)
373 case typelib_TypeClass_STRING
:
374 ::rtl_uString_release( *(rtl_uString
**)pValue
);
376 case typelib_TypeClass_TYPE
:
377 ::typelib_typedescriptionreference_release( *(typelib_TypeDescriptionReference
**)pValue
);
379 case typelib_TypeClass_ANY
:
380 _destructAny( (uno_Any
*)pValue
, release
);
382 case typelib_TypeClass_TYPEDEF
:
383 OSL_ENSURE( 0, "### unexpected typedef!" );
385 case typelib_TypeClass_STRUCT
:
386 case typelib_TypeClass_EXCEPTION
:
389 _destructStruct( pValue
, (typelib_CompoundTypeDescription
*)pTypeDescr
, release
);
393 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
394 _destructStruct( pValue
, (typelib_CompoundTypeDescription
*)pTypeDescr
, release
);
395 TYPELIB_DANGER_RELEASE( pTypeDescr
);
398 case typelib_TypeClass_ARRAY
:
401 _destructArray( pValue
, (typelib_ArrayTypeDescription
*)pTypeDescr
, release
);
405 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
406 _destructArray( pValue
, (typelib_ArrayTypeDescription
*)pTypeDescr
, release
);
407 TYPELIB_DANGER_RELEASE( pTypeDescr
);
410 case typelib_TypeClass_UNION
:
413 _destructUnion( pValue
, pTypeDescr
, release
);
417 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
418 _destructUnion( pValue
, pTypeDescr
, release
);
419 TYPELIB_DANGER_RELEASE( pTypeDescr
);
422 case typelib_TypeClass_SEQUENCE
:
425 *(uno_Sequence
**)pValue
, pType
, pTypeDescr
, release
);
428 case typelib_TypeClass_INTERFACE
:
429 _release( *(void **)pValue
, release
);