1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <sal/config.h>
22 #include <osl/diagnose.h>
33 //#### destruction #################################################################################
38 typelib_CompoundTypeDescription
* pTypeDescr
,
39 uno_ReleaseFunc release
);
41 inline void _destructStruct(
43 typelib_CompoundTypeDescription
* pTypeDescr
,
44 uno_ReleaseFunc release
)
46 if (pTypeDescr
->pBaseTypeDescription
)
48 destructStruct( pValue
, pTypeDescr
->pBaseTypeDescription
, release
);
51 typelib_TypeDescriptionReference
** ppTypeRefs
= pTypeDescr
->ppTypeRefs
;
52 sal_Int32
* pMemberOffsets
= pTypeDescr
->pMemberOffsets
;
53 sal_Int32 nDescr
= pTypeDescr
->nMembers
;
56 ::uno_type_destructData(
57 static_cast<char *>(pValue
) + pMemberOffsets
[nDescr
],
58 ppTypeRefs
[nDescr
], release
);
63 void destructSequence(
64 uno_Sequence
* pSequence
,
65 typelib_TypeDescriptionReference
* pType
,
66 typelib_TypeDescription
* pTypeDescr
,
67 uno_ReleaseFunc release
);
70 inline void _destructAny(
72 uno_ReleaseFunc release
)
74 typelib_TypeDescriptionReference
* pType
= pAny
->pType
;
76 switch (pType
->eTypeClass
)
78 case typelib_TypeClass_HYPER
:
79 case typelib_TypeClass_UNSIGNED_HYPER
:
80 if (sizeof(void *) < sizeof(sal_Int64
))
82 std::free( pAny
->pData
);
85 case typelib_TypeClass_FLOAT
:
86 if (sizeof(void *) < sizeof(float))
88 std::free( pAny
->pData
);
91 case typelib_TypeClass_DOUBLE
:
92 if (sizeof(void *) < sizeof(double))
94 std::free( pAny
->pData
);
97 case typelib_TypeClass_STRING
:
98 ::rtl_uString_release( static_cast<rtl_uString
*>(pAny
->pReserved
) );
100 case typelib_TypeClass_TYPE
:
101 ::typelib_typedescriptionreference_release(
102 static_cast<typelib_TypeDescriptionReference
*>(pAny
->pReserved
) );
104 case typelib_TypeClass_ANY
:
105 OSL_FAIL( "### unexpected nested any!" );
106 ::uno_any_destruct( static_cast<uno_Any
*>(pAny
->pData
), release
);
107 std::free( pAny
->pData
);
109 case typelib_TypeClass_TYPEDEF
:
110 OSL_FAIL( "### unexpected typedef!" );
112 case typelib_TypeClass_STRUCT
:
113 case typelib_TypeClass_EXCEPTION
:
115 typelib_TypeDescription
* pTypeDescr
= nullptr;
116 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
117 _destructStruct( pAny
->pData
, reinterpret_cast<typelib_CompoundTypeDescription
*>(pTypeDescr
), release
);
118 TYPELIB_DANGER_RELEASE( pTypeDescr
);
119 std::free( pAny
->pData
);
122 case typelib_TypeClass_SEQUENCE
:
125 static_cast<uno_Sequence
*>(pAny
->pReserved
), pType
, nullptr, release
);
128 case typelib_TypeClass_INTERFACE
:
129 _release( pAny
->pReserved
, release
);
134 #if OSL_DEBUG_LEVEL > 0
135 pAny
->pData
= reinterpret_cast<void *>(uintptr_t(0xdeadbeef));
138 ::typelib_typedescriptionreference_release( pType
);
141 inline sal_Int32
idestructElements(
142 void * pElements
, typelib_TypeDescriptionReference
* pElementType
,
143 sal_Int32 nStartIndex
, sal_Int32 nStopIndex
,
144 uno_ReleaseFunc release
)
146 switch (pElementType
->eTypeClass
)
148 case typelib_TypeClass_CHAR
:
149 return sal_Int32(sizeof(sal_Unicode
));
150 case typelib_TypeClass_BOOLEAN
:
151 return sal_Int32(sizeof(sal_Bool
));
152 case typelib_TypeClass_BYTE
:
153 return sal_Int32(sizeof(sal_Int8
));
154 case typelib_TypeClass_SHORT
:
155 case typelib_TypeClass_UNSIGNED_SHORT
:
156 return sal_Int32(sizeof(sal_Int16
));
157 case typelib_TypeClass_LONG
:
158 case typelib_TypeClass_UNSIGNED_LONG
:
159 return sal_Int32(sizeof(sal_Int32
));
160 case typelib_TypeClass_HYPER
:
161 case typelib_TypeClass_UNSIGNED_HYPER
:
162 return sal_Int32(sizeof(sal_Int64
));
163 case typelib_TypeClass_FLOAT
:
164 return sal_Int32(sizeof(float));
165 case typelib_TypeClass_DOUBLE
:
166 return sal_Int32(sizeof(double));
168 case typelib_TypeClass_STRING
:
170 rtl_uString
** pDest
= static_cast<rtl_uString
**>(pElements
);
171 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
173 ::rtl_uString_release( pDest
[nPos
] );
175 return sal_Int32(sizeof(rtl_uString
*));
177 case typelib_TypeClass_TYPE
:
179 typelib_TypeDescriptionReference
** pDest
= static_cast<typelib_TypeDescriptionReference
**>(pElements
);
180 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
182 ::typelib_typedescriptionreference_release( pDest
[nPos
] );
184 return sal_Int32(sizeof(typelib_TypeDescriptionReference
*));
186 case typelib_TypeClass_ANY
:
188 uno_Any
* pDest
= static_cast<uno_Any
*>(pElements
);
189 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
191 _destructAny( &pDest
[nPos
], release
);
193 return sal_Int32(sizeof(uno_Any
));
195 case typelib_TypeClass_ENUM
:
196 return sal_Int32(sizeof(sal_Int32
));
197 case typelib_TypeClass_STRUCT
:
198 case typelib_TypeClass_EXCEPTION
:
200 typelib_TypeDescription
* pElementTypeDescr
= nullptr;
201 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
202 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
203 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
206 static_cast<char *>(pElements
) + (nElementSize
* nPos
),
207 reinterpret_cast<typelib_CompoundTypeDescription
*>(pElementTypeDescr
),
210 sal_Int32 nSize
= pElementTypeDescr
->nSize
;
211 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
214 case typelib_TypeClass_SEQUENCE
:
216 typelib_TypeDescription
* pElementTypeDescr
= nullptr;
217 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
218 uno_Sequence
** pDest
= static_cast<uno_Sequence
**>(pElements
);
219 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
223 pElementTypeDescr
->pWeakRef
, pElementTypeDescr
,
226 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
227 return sal_Int32(sizeof(uno_Sequence
*));
229 case typelib_TypeClass_INTERFACE
:
233 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
235 void * p
= static_cast<void **>(pElements
)[nPos
];
244 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
246 uno_Interface
* p
= static_cast<uno_Interface
**>(pElements
)[nPos
];
253 return sal_Int32(sizeof(void *));
261 inline void idestroySequence(
263 typelib_TypeDescriptionReference
* pType
,
264 typelib_TypeDescription
* pTypeDescr
,
265 uno_ReleaseFunc release
)
267 assert(pSeq
!= nullptr);
268 assert(pSeq
->nRefCount
== 0);
269 if (pSeq
->nElements
> 0)
275 reinterpret_cast<typelib_IndirectTypeDescription
*>(pTypeDescr
)->pType
, 0,
276 pSeq
->nElements
, release
);
280 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
283 reinterpret_cast<typelib_IndirectTypeDescription
*>(pTypeDescr
)->pType
, 0,
284 pSeq
->nElements
, release
);
285 TYPELIB_DANGER_RELEASE( pTypeDescr
);
291 inline void idestructSequence(
293 typelib_TypeDescriptionReference
* pType
,
294 typelib_TypeDescription
* pTypeDescr
,
295 uno_ReleaseFunc release
)
297 if (osl_atomic_decrement( &pSeq
->nRefCount
) == 0)
299 idestroySequence(pSeq
, pType
, pTypeDescr
, release
);
303 inline void _destructData(
305 typelib_TypeDescriptionReference
* pType
,
306 typelib_TypeDescription
* pTypeDescr
,
307 uno_ReleaseFunc release
)
309 switch (pType
->eTypeClass
)
311 case typelib_TypeClass_STRING
:
312 ::rtl_uString_release( *static_cast<rtl_uString
**>(pValue
) );
314 case typelib_TypeClass_TYPE
:
315 ::typelib_typedescriptionreference_release( *static_cast<typelib_TypeDescriptionReference
**>(pValue
) );
317 case typelib_TypeClass_ANY
:
318 _destructAny( static_cast<uno_Any
*>(pValue
), release
);
320 case typelib_TypeClass_TYPEDEF
:
321 OSL_FAIL( "### unexpected typedef!" );
323 case typelib_TypeClass_STRUCT
:
324 case typelib_TypeClass_EXCEPTION
:
327 _destructStruct( pValue
, reinterpret_cast<typelib_CompoundTypeDescription
*>(pTypeDescr
), release
);
331 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
332 _destructStruct( pValue
, reinterpret_cast<typelib_CompoundTypeDescription
*>(pTypeDescr
), release
);
333 TYPELIB_DANGER_RELEASE( pTypeDescr
);
336 case typelib_TypeClass_SEQUENCE
:
339 *static_cast<uno_Sequence
**>(pValue
), pType
, pTypeDescr
, release
);
342 case typelib_TypeClass_INTERFACE
:
343 _release( *static_cast<void **>(pValue
), release
);
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */