File: | cppu/source/uno/sequence.cxx |
Location: | line 633, column 17 |
Description: | Access to field 'pType' results in a dereference of a null pointer (loaded from variable 'pElementTypeDescr') |
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 <string.h> | |||
21 | ||||
22 | #include <rtl/alloc.h> | |||
23 | #include <osl/diagnose.h> | |||
24 | #include <osl/interlck.h> | |||
25 | #include <typelib/typedescription.h> | |||
26 | #include <uno/data.h> | |||
27 | #include <uno/dispatcher.h> | |||
28 | #include <uno/sequence2.h> | |||
29 | ||||
30 | #include "constr.hxx" | |||
31 | #include "copy.hxx" | |||
32 | #include "destr.hxx" | |||
33 | ||||
34 | ||||
35 | using namespace cppu; | |||
36 | ||||
37 | namespace cppu | |||
38 | { | |||
39 | ||||
40 | //------------------------------------------------------------------------------ | |||
41 | static inline uno_Sequence * reallocSeq( | |||
42 | uno_Sequence * pReallocate, sal_Size nElementSize, sal_Int32 nElements ) | |||
43 | { | |||
44 | OSL_ASSERT( nElements >= 0 )do { if (true && (!(nElements >= 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "44" ": "), "OSL_ASSERT: %s", "nElements >= 0"); } } while (false); | |||
45 | uno_Sequence * pNew = 0; | |||
46 | sal_uInt32 nSize = calcSeqMemSize( nElementSize, nElements ); | |||
47 | if (nSize > 0) | |||
48 | { | |||
49 | if (pReallocate == 0) | |||
50 | { | |||
51 | pNew = (uno_Sequence *) rtl_allocateMemory( nSize ); | |||
52 | } | |||
53 | else | |||
54 | { | |||
55 | pNew = (uno_Sequence *) rtl_reallocateMemory( pReallocate, nSize ); | |||
56 | } | |||
57 | if (pNew != 0) | |||
58 | { | |||
59 | // header init | |||
60 | pNew->nRefCount = 1; | |||
61 | pNew->nElements = nElements; | |||
62 | } | |||
63 | } | |||
64 | return pNew; | |||
65 | } | |||
66 | ||||
67 | //------------------------------------------------------------------------------ | |||
68 | static inline bool idefaultConstructElements( | |||
69 | uno_Sequence ** ppSeq, | |||
70 | typelib_TypeDescriptionReference * pElementType, | |||
71 | sal_Int32 nStartIndex, sal_Int32 nStopIndex, | |||
72 | sal_Int32 nAlloc = -1 ) // >= 0 means (re)alloc memory for nAlloc elements | |||
73 | { | |||
74 | uno_Sequence * pSeq = *ppSeq; | |||
75 | switch (pElementType->eTypeClass) | |||
76 | { | |||
77 | case typelib_TypeClass_CHAR: | |||
78 | if (nAlloc >= 0) | |||
79 | pSeq = reallocSeq( pSeq, sizeof(sal_Unicode), nAlloc ); | |||
80 | if (pSeq != 0) | |||
81 | { | |||
82 | memset( | |||
83 | pSeq->elements + (sizeof(sal_Unicode) * nStartIndex), | |||
84 | 0, | |||
85 | sizeof(sal_Unicode) * (nStopIndex - nStartIndex) ); | |||
86 | } | |||
87 | break; | |||
88 | case typelib_TypeClass_BOOLEAN: | |||
89 | if (nAlloc >= 0) | |||
90 | pSeq = reallocSeq( pSeq, sizeof(sal_Bool), nAlloc ); | |||
91 | if (pSeq != 0) | |||
92 | { | |||
93 | memset( | |||
94 | pSeq->elements + (sizeof(sal_Bool) * nStartIndex), | |||
95 | 0, | |||
96 | sizeof(sal_Bool) * (nStopIndex - nStartIndex) ); | |||
97 | } | |||
98 | break; | |||
99 | case typelib_TypeClass_BYTE: | |||
100 | if (nAlloc >= 0) | |||
101 | pSeq = reallocSeq( pSeq, sizeof(sal_Int8), nAlloc ); | |||
102 | if (pSeq != 0) | |||
103 | { | |||
104 | memset( | |||
105 | pSeq->elements + (sizeof(sal_Int8) * nStartIndex), | |||
106 | 0, | |||
107 | sizeof(sal_Int8) * (nStopIndex - nStartIndex) ); | |||
108 | } | |||
109 | break; | |||
110 | case typelib_TypeClass_SHORT: | |||
111 | case typelib_TypeClass_UNSIGNED_SHORT: | |||
112 | if (nAlloc >= 0) | |||
113 | pSeq = reallocSeq( pSeq, sizeof(sal_Int16), nAlloc ); | |||
114 | if (pSeq != 0) | |||
115 | { | |||
116 | memset( | |||
117 | pSeq->elements + (sizeof(sal_Int16) * nStartIndex), | |||
118 | 0, | |||
119 | sizeof(sal_Int16) * (nStopIndex - nStartIndex) ); | |||
120 | } | |||
121 | break; | |||
122 | case typelib_TypeClass_LONG: | |||
123 | case typelib_TypeClass_UNSIGNED_LONG: | |||
124 | if (nAlloc >= 0) | |||
125 | pSeq = reallocSeq( pSeq, sizeof(sal_Int32), nAlloc ); | |||
126 | if (pSeq != 0) | |||
127 | { | |||
128 | memset( | |||
129 | pSeq->elements + (sizeof(sal_Int32) * nStartIndex), | |||
130 | 0, | |||
131 | sizeof(sal_Int32) * (nStopIndex - nStartIndex) ); | |||
132 | } | |||
133 | break; | |||
134 | case typelib_TypeClass_HYPER: | |||
135 | case typelib_TypeClass_UNSIGNED_HYPER: | |||
136 | if (nAlloc >= 0) | |||
137 | pSeq = reallocSeq( pSeq, sizeof(sal_Int64), nAlloc ); | |||
138 | if (pSeq != 0) | |||
139 | { | |||
140 | memset( | |||
141 | pSeq->elements + (sizeof(sal_Int64) * nStartIndex), | |||
142 | 0, | |||
143 | sizeof(sal_Int64) * (nStopIndex - nStartIndex) ); | |||
144 | } | |||
145 | break; | |||
146 | case typelib_TypeClass_FLOAT: | |||
147 | { | |||
148 | if (nAlloc >= 0) | |||
149 | pSeq = reallocSeq( pSeq, sizeof(float), nAlloc ); | |||
150 | if (pSeq != 0) | |||
151 | { | |||
152 | float * pElements = (float *) pSeq->elements; | |||
153 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
154 | { | |||
155 | pElements[nPos] = 0.0; | |||
156 | } | |||
157 | } | |||
158 | break; | |||
159 | } | |||
160 | case typelib_TypeClass_DOUBLE: | |||
161 | { | |||
162 | if (nAlloc >= 0) | |||
163 | pSeq = reallocSeq( pSeq, sizeof(double), nAlloc ); | |||
164 | if (pSeq != 0) | |||
165 | { | |||
166 | double * pElements = (double *) pSeq->elements; | |||
167 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
168 | { | |||
169 | pElements[nPos] = 0.0; | |||
170 | } | |||
171 | } | |||
172 | break; | |||
173 | } | |||
174 | case typelib_TypeClass_STRING: | |||
175 | { | |||
176 | if (nAlloc >= 0) | |||
177 | pSeq = reallocSeq( pSeq, sizeof(rtl_uString *), nAlloc ); | |||
178 | if (pSeq != 0) | |||
179 | { | |||
180 | rtl_uString ** pElements = (rtl_uString **) pSeq->elements; | |||
181 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
182 | { | |||
183 | pElements[nPos] = 0; | |||
184 | rtl_uString_new( &pElements[nPos] ); | |||
185 | } | |||
186 | } | |||
187 | break; | |||
188 | } | |||
189 | case typelib_TypeClass_TYPE: | |||
190 | { | |||
191 | if (nAlloc >= 0) | |||
192 | { | |||
193 | pSeq = reallocSeq( | |||
194 | pSeq, sizeof(typelib_TypeDescriptionReference *), nAlloc ); | |||
195 | } | |||
196 | if (pSeq != 0) | |||
197 | { | |||
198 | typelib_TypeDescriptionReference ** pElements = | |||
199 | (typelib_TypeDescriptionReference **) pSeq->elements; | |||
200 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
201 | { | |||
202 | pElements[nPos] = _getVoidType(); | |||
203 | } | |||
204 | } | |||
205 | break; | |||
206 | } | |||
207 | case typelib_TypeClass_ANY: | |||
208 | { | |||
209 | if (nAlloc >= 0) | |||
210 | pSeq = reallocSeq( pSeq, sizeof(uno_Any), nAlloc ); | |||
211 | if (pSeq != 0) | |||
212 | { | |||
213 | uno_Any * pElements = (uno_Any *) pSeq->elements; | |||
214 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
215 | { | |||
216 | CONSTRUCT_EMPTY_ANY( &pElements[nPos] )(&pElements[nPos])->pType = _getVoidType(); (&pElements [nPos])->pData = (void *)0xdeadbeef;; | |||
217 | } | |||
218 | } | |||
219 | break; | |||
220 | } | |||
221 | case typelib_TypeClass_ENUM: | |||
222 | { | |||
223 | if (nAlloc >= 0) | |||
224 | pSeq = reallocSeq( pSeq, sizeof(sal_Int32), nAlloc ); | |||
225 | if (pSeq != 0) | |||
226 | { | |||
227 | typelib_TypeDescription * pElementTypeDescr = 0; | |||
228 | TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ){ typelib_TypeDescriptionReference * pMacroTypeRef = (pElementType ); typelib_TypeDescription ** ppMacroTypeDescr = (&pElementTypeDescr ); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr , pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef ->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } }; | |||
229 | sal_Int32 eEnum = | |||
230 | ((typelib_EnumTypeDescription *) | |||
231 | pElementTypeDescr)->nDefaultEnumValue; | |||
232 | TYPELIB_DANGER_RELEASE( pElementTypeDescr ){ if ((((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || ((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) typelib_typedescription_release( pElementTypeDescr ); }; | |||
233 | ||||
234 | sal_Int32 * pElements = (sal_Int32 *) pSeq->elements; | |||
235 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
236 | { | |||
237 | pElements[nPos] = eEnum; | |||
238 | } | |||
239 | } | |||
240 | break; | |||
241 | } | |||
242 | case typelib_TypeClass_STRUCT: | |||
243 | case typelib_TypeClass_EXCEPTION: | |||
244 | { | |||
245 | typelib_TypeDescription * pElementTypeDescr = 0; | |||
246 | TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ){ typelib_TypeDescriptionReference * pMacroTypeRef = (pElementType ); typelib_TypeDescription ** ppMacroTypeDescr = (&pElementTypeDescr ); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr , pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef ->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } }; | |||
247 | sal_Int32 nElementSize = pElementTypeDescr->nSize; | |||
248 | ||||
249 | if (nAlloc >= 0) | |||
250 | pSeq = reallocSeq( pSeq, nElementSize, nAlloc ); | |||
251 | if (pSeq != 0) | |||
252 | { | |||
253 | char * pElements = pSeq->elements; | |||
254 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
255 | { | |||
256 | _defaultConstructStruct( | |||
257 | pElements + (nElementSize * nPos), | |||
258 | (typelib_CompoundTypeDescription *)pElementTypeDescr ); | |||
259 | } | |||
260 | } | |||
261 | ||||
262 | TYPELIB_DANGER_RELEASE( pElementTypeDescr ){ if ((((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || ((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) typelib_typedescription_release( pElementTypeDescr ); }; | |||
263 | break; | |||
264 | } | |||
265 | case typelib_TypeClass_ARRAY: | |||
266 | { | |||
267 | typelib_TypeDescription * pElementTypeDescr = 0; | |||
268 | TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ){ typelib_TypeDescriptionReference * pMacroTypeRef = (pElementType ); typelib_TypeDescription ** ppMacroTypeDescr = (&pElementTypeDescr ); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr , pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef ->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } }; | |||
269 | sal_Int32 nElementSize = pElementTypeDescr->nSize; | |||
270 | ||||
271 | if (nAlloc >= 0) | |||
272 | pSeq = reallocSeq( pSeq, nElementSize, nAlloc ); | |||
273 | if (pSeq != 0) | |||
274 | { | |||
275 | char * pElements = pSeq->elements; | |||
276 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
277 | { | |||
278 | _defaultConstructArray( | |||
279 | pElements + (nElementSize * nPos), | |||
280 | (typelib_ArrayTypeDescription *)pElementTypeDescr ); | |||
281 | } | |||
282 | } | |||
283 | ||||
284 | TYPELIB_DANGER_RELEASE( pElementTypeDescr ){ if ((((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || ((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) typelib_typedescription_release( pElementTypeDescr ); }; | |||
285 | break; | |||
286 | } | |||
287 | case typelib_TypeClass_UNION: | |||
288 | { | |||
289 | typelib_TypeDescription * pElementTypeDescr = 0; | |||
290 | TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ){ typelib_TypeDescriptionReference * pMacroTypeRef = (pElementType ); typelib_TypeDescription ** ppMacroTypeDescr = (&pElementTypeDescr ); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr , pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef ->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } }; | |||
291 | sal_Int32 nElementSize = pElementTypeDescr->nSize; | |||
292 | ||||
293 | if (nAlloc >= 0) | |||
294 | pSeq = reallocSeq( pSeq, nElementSize, nAlloc ); | |||
295 | if (pSeq != 0) | |||
296 | { | |||
297 | sal_Int32 nValueOffset = | |||
298 | ((typelib_UnionTypeDescription *) | |||
299 | pElementTypeDescr)->nValueOffset; | |||
300 | sal_Int64 nDefaultDiscr = | |||
301 | ((typelib_UnionTypeDescription *) | |||
302 | pElementTypeDescr)->nDefaultDiscriminant; | |||
303 | ||||
304 | typelib_TypeDescription * pDefaultTypeDescr = 0; | |||
305 | TYPELIB_DANGER_GET({ typelib_TypeDescriptionReference * pMacroTypeRef = (((typelib_UnionTypeDescription *) pElementTypeDescr)->pDefaultTypeRef); typelib_TypeDescription ** ppMacroTypeDescr = (&pDefaultTypeDescr); if (((pMacroTypeRef ->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef ->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE)) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr , pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef ->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } } | |||
306 | &pDefaultTypeDescr,{ typelib_TypeDescriptionReference * pMacroTypeRef = (((typelib_UnionTypeDescription *) pElementTypeDescr)->pDefaultTypeRef); typelib_TypeDescription ** ppMacroTypeDescr = (&pDefaultTypeDescr); if (((pMacroTypeRef ->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef ->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE)) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr , pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef ->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } } | |||
307 | ((typelib_UnionTypeDescription *){ typelib_TypeDescriptionReference * pMacroTypeRef = (((typelib_UnionTypeDescription *) pElementTypeDescr)->pDefaultTypeRef); typelib_TypeDescription ** ppMacroTypeDescr = (&pDefaultTypeDescr); if (((pMacroTypeRef ->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef ->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE)) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr , pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef ->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } } | |||
308 | pElementTypeDescr)->pDefaultTypeRef ){ typelib_TypeDescriptionReference * pMacroTypeRef = (((typelib_UnionTypeDescription *) pElementTypeDescr)->pDefaultTypeRef); typelib_TypeDescription ** ppMacroTypeDescr = (&pDefaultTypeDescr); if (((pMacroTypeRef ->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef ->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE)) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr , pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef ->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } }; | |||
309 | ||||
310 | char * pElements = pSeq->elements; | |||
311 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
312 | { | |||
313 | char * pMem = pElements + (nElementSize * nPos); | |||
314 | ::uno_constructData( | |||
315 | (char *)pMem + nValueOffset, pDefaultTypeDescr ); | |||
316 | *(sal_Int64 *)pMem = nDefaultDiscr; | |||
317 | } | |||
318 | TYPELIB_DANGER_RELEASE( pDefaultTypeDescr ){ if ((((pDefaultTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || ((pDefaultTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) typelib_typedescription_release( pDefaultTypeDescr ); }; | |||
319 | } | |||
320 | ||||
321 | TYPELIB_DANGER_RELEASE( pElementTypeDescr ){ if ((((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || ((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) typelib_typedescription_release( pElementTypeDescr ); }; | |||
322 | break; | |||
323 | } | |||
324 | case typelib_TypeClass_SEQUENCE: | |||
325 | { | |||
326 | if (nAlloc >= 0) | |||
327 | pSeq = reallocSeq( pSeq, sizeof(uno_Sequence *), nAlloc ); | |||
328 | if (pSeq != 0) | |||
329 | { | |||
330 | uno_Sequence ** pElements = | |||
331 | (uno_Sequence **) pSeq->elements; | |||
332 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
333 | { | |||
334 | pElements[nPos] = createEmptySequence(); | |||
335 | } | |||
336 | } | |||
337 | break; | |||
338 | } | |||
339 | case typelib_TypeClass_INTERFACE: // either C++ or C-UNO interface | |||
340 | if (nAlloc >= 0) | |||
341 | pSeq = reallocSeq( pSeq, sizeof(void *), nAlloc ); | |||
342 | if (pSeq != 0) | |||
343 | { | |||
344 | memset( | |||
345 | pSeq->elements + (sizeof(void *) * nStartIndex), | |||
346 | 0, | |||
347 | sizeof(void *) * (nStopIndex - nStartIndex) ); | |||
348 | } | |||
349 | break; | |||
350 | default: | |||
351 | OSL_FAIL( "### unexpected element type!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "351" ": "), "%s", "### unexpected element type!"); } } while (false); | |||
352 | pSeq = 0; | |||
353 | break; | |||
354 | } | |||
355 | ||||
356 | if (pSeq == 0) | |||
357 | { | |||
358 | OSL_ASSERT( nAlloc >= 0 )do { if (true && (!(nAlloc >= 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "358" ": "), "OSL_ASSERT: %s", "nAlloc >= 0"); } } while (false); // must have been an allocation failure | |||
359 | return false; | |||
360 | } | |||
361 | else | |||
362 | { | |||
363 | *ppSeq = pSeq; | |||
364 | return true; | |||
365 | } | |||
366 | } | |||
367 | ||||
368 | //------------------------------------------------------------------------------ | |||
369 | static inline bool icopyConstructFromElements( | |||
370 | uno_Sequence ** ppSeq, void * pSourceElements, | |||
371 | typelib_TypeDescriptionReference * pElementType, | |||
372 | sal_Int32 nStartIndex, sal_Int32 nStopIndex, | |||
373 | uno_AcquireFunc acquire, | |||
374 | sal_Int32 nAlloc = -1 ) // >= 0 means (re)alloc memory for nAlloc elements | |||
375 | { | |||
376 | uno_Sequence * pSeq = *ppSeq; | |||
377 | switch (pElementType->eTypeClass) | |||
378 | { | |||
379 | case typelib_TypeClass_CHAR: | |||
380 | if (nAlloc >= 0) | |||
381 | pSeq = reallocSeq( pSeq, sizeof(sal_Unicode), nAlloc ); | |||
382 | if (pSeq != 0) | |||
383 | { | |||
384 | memcpy( | |||
385 | pSeq->elements + (sizeof(sal_Unicode) * nStartIndex), | |||
386 | (char *)pSourceElements + (sizeof(sal_Unicode) * nStartIndex), | |||
387 | sizeof(sal_Unicode) * (nStopIndex - nStartIndex) ); | |||
388 | } | |||
389 | break; | |||
390 | case typelib_TypeClass_BOOLEAN: | |||
391 | if (nAlloc >= 0) | |||
392 | pSeq = reallocSeq( pSeq, sizeof(sal_Bool), nAlloc ); | |||
393 | if (pSeq != 0) | |||
394 | { | |||
395 | memcpy( | |||
396 | pSeq->elements + (sizeof(sal_Bool) * nStartIndex), | |||
397 | (char *)pSourceElements + (sizeof(sal_Bool) * nStartIndex), | |||
398 | sizeof(sal_Bool) * (nStopIndex - nStartIndex) ); | |||
399 | } | |||
400 | break; | |||
401 | case typelib_TypeClass_BYTE: | |||
402 | if (nAlloc >= 0) | |||
403 | pSeq = reallocSeq( pSeq, sizeof(sal_Int8), nAlloc ); | |||
404 | if (pSeq != 0) | |||
405 | { | |||
406 | memcpy( | |||
407 | pSeq->elements + (sizeof(sal_Int8) * nStartIndex), | |||
408 | (char *)pSourceElements + (sizeof(sal_Int8) * nStartIndex), | |||
409 | sizeof(sal_Int8) * (nStopIndex - nStartIndex) ); | |||
410 | } | |||
411 | break; | |||
412 | case typelib_TypeClass_SHORT: | |||
413 | case typelib_TypeClass_UNSIGNED_SHORT: | |||
414 | if (nAlloc >= 0) | |||
415 | pSeq = reallocSeq( pSeq, sizeof(sal_Int16), nAlloc ); | |||
416 | if (pSeq != 0) | |||
417 | { | |||
418 | memcpy( | |||
419 | pSeq->elements + (sizeof(sal_Int16) * nStartIndex), | |||
420 | (char *)pSourceElements + (sizeof(sal_Int16) * nStartIndex), | |||
421 | sizeof(sal_Int16) * (nStopIndex - nStartIndex) ); | |||
422 | } | |||
423 | break; | |||
424 | case typelib_TypeClass_LONG: | |||
425 | case typelib_TypeClass_UNSIGNED_LONG: | |||
426 | if (nAlloc >= 0) | |||
427 | pSeq = reallocSeq( pSeq, sizeof(sal_Int32), nAlloc ); | |||
428 | if (pSeq != 0) | |||
429 | { | |||
430 | memcpy( | |||
431 | pSeq->elements + (sizeof(sal_Int32) * nStartIndex), | |||
432 | (char *)pSourceElements + (sizeof(sal_Int32) * nStartIndex), | |||
433 | sizeof(sal_Int32) * (nStopIndex - nStartIndex) ); | |||
434 | } | |||
435 | break; | |||
436 | case typelib_TypeClass_HYPER: | |||
437 | case typelib_TypeClass_UNSIGNED_HYPER: | |||
438 | if (nAlloc >= 0) | |||
439 | pSeq = reallocSeq( pSeq, sizeof(sal_Int64), nAlloc ); | |||
440 | if (pSeq != 0) | |||
441 | { | |||
442 | memcpy( | |||
443 | pSeq->elements + (sizeof(sal_Int64) * nStartIndex), | |||
444 | (char *)pSourceElements + (sizeof(sal_Int64) * nStartIndex), | |||
445 | sizeof(sal_Int64) * (nStopIndex - nStartIndex) ); | |||
446 | } | |||
447 | break; | |||
448 | case typelib_TypeClass_FLOAT: | |||
449 | if (nAlloc >= 0) | |||
450 | pSeq = reallocSeq( pSeq, sizeof(float), nAlloc ); | |||
451 | if (pSeq != 0) | |||
452 | { | |||
453 | memcpy( | |||
454 | pSeq->elements + (sizeof(float) * nStartIndex), | |||
455 | (char *)pSourceElements + (sizeof(float) * nStartIndex), | |||
456 | sizeof(float) * (nStopIndex - nStartIndex) ); | |||
457 | } | |||
458 | break; | |||
459 | case typelib_TypeClass_DOUBLE: | |||
460 | if (nAlloc >= 0) | |||
461 | pSeq = reallocSeq( pSeq, sizeof(double), nAlloc ); | |||
462 | if (pSeq != 0) | |||
463 | { | |||
464 | memcpy( | |||
465 | pSeq->elements + (sizeof(double) * nStartIndex), | |||
466 | (char *)pSourceElements + (sizeof(double) * nStartIndex), | |||
467 | sizeof(double) * (nStopIndex - nStartIndex) ); | |||
468 | } | |||
469 | break; | |||
470 | case typelib_TypeClass_ENUM: | |||
471 | if (nAlloc >= 0) | |||
472 | pSeq = reallocSeq( pSeq, sizeof(sal_Int32), nAlloc ); | |||
473 | if (pSeq != 0) | |||
474 | { | |||
475 | memcpy( | |||
476 | pSeq->elements + (sizeof(sal_Int32) * nStartIndex), | |||
477 | (char *)pSourceElements + (sizeof(sal_Int32) * nStartIndex), | |||
478 | sizeof(sal_Int32) * (nStopIndex - nStartIndex) ); | |||
479 | } | |||
480 | break; | |||
481 | case typelib_TypeClass_STRING: | |||
482 | { | |||
483 | if (nAlloc >= 0) | |||
484 | pSeq = reallocSeq( pSeq, sizeof(rtl_uString *), nAlloc ); | |||
485 | if (pSeq != 0) | |||
486 | { | |||
487 | rtl_uString ** pDestElements = (rtl_uString **) pSeq->elements; | |||
488 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
489 | { | |||
490 | ::rtl_uString_acquire( | |||
491 | ((rtl_uString **)pSourceElements)[nPos] ); | |||
492 | pDestElements[nPos] = ((rtl_uString **)pSourceElements)[nPos]; | |||
493 | } | |||
494 | } | |||
495 | break; | |||
496 | } | |||
497 | case typelib_TypeClass_TYPE: | |||
498 | { | |||
499 | if (nAlloc >= 0) | |||
500 | { | |||
501 | pSeq = reallocSeq( | |||
502 | pSeq, sizeof(typelib_TypeDescriptionReference *), nAlloc ); | |||
503 | } | |||
504 | if (pSeq != 0) | |||
505 | { | |||
506 | typelib_TypeDescriptionReference ** pDestElements = | |||
507 | (typelib_TypeDescriptionReference **) pSeq->elements; | |||
508 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
509 | { | |||
510 | TYPE_ACQUIRE(::osl_incrementInterlockedCount( &(((typelib_TypeDescriptionReference **) pSourceElements)[nPos])->nRefCount ); | |||
511 | ((typelib_TypeDescriptionReference **)::osl_incrementInterlockedCount( &(((typelib_TypeDescriptionReference **) pSourceElements)[nPos])->nRefCount ); | |||
512 | pSourceElements)[nPos] )::osl_incrementInterlockedCount( &(((typelib_TypeDescriptionReference **) pSourceElements)[nPos])->nRefCount );; | |||
513 | pDestElements[nPos] = | |||
514 | ((typelib_TypeDescriptionReference **) | |||
515 | pSourceElements)[nPos]; | |||
516 | } | |||
517 | } | |||
518 | break; | |||
519 | } | |||
520 | case typelib_TypeClass_ANY: | |||
521 | { | |||
522 | if (nAlloc >= 0) | |||
523 | pSeq = reallocSeq( pSeq, sizeof(uno_Any), nAlloc ); | |||
524 | if (pSeq != 0) | |||
525 | { | |||
526 | uno_Any * pDestElements = (uno_Any *) pSeq->elements; | |||
527 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
528 | { | |||
529 | uno_Any * pSource = (uno_Any *)pSourceElements + nPos; | |||
530 | _copyConstructAny( | |||
531 | &pDestElements[nPos], | |||
532 | pSource->pData, | |||
533 | pSource->pType, 0, | |||
534 | acquire, 0 ); | |||
535 | } | |||
536 | } | |||
537 | break; | |||
538 | } | |||
539 | case typelib_TypeClass_STRUCT: | |||
540 | case typelib_TypeClass_EXCEPTION: | |||
541 | { | |||
542 | typelib_TypeDescription * pElementTypeDescr = 0; | |||
543 | TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ){ typelib_TypeDescriptionReference * pMacroTypeRef = (pElementType ); typelib_TypeDescription ** ppMacroTypeDescr = (&pElementTypeDescr ); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr , pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef ->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } }; | |||
544 | sal_Int32 nElementSize = pElementTypeDescr->nSize; | |||
545 | ||||
546 | if (nAlloc >= 0) | |||
547 | pSeq = reallocSeq( pSeq, nElementSize, nAlloc ); | |||
548 | if (pSeq != 0) | |||
549 | { | |||
550 | char * pDestElements = pSeq->elements; | |||
551 | ||||
552 | typelib_CompoundTypeDescription * pTypeDescr = | |||
553 | (typelib_CompoundTypeDescription *)pElementTypeDescr; | |||
554 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
555 | { | |||
556 | char * pDest = | |||
557 | pDestElements + (nElementSize * nPos); | |||
558 | char * pSource = | |||
559 | (char *)pSourceElements + (nElementSize * nPos); | |||
560 | ||||
561 | if (pTypeDescr->pBaseTypeDescription) | |||
562 | { | |||
563 | // copy base value | |||
564 | _copyConstructStruct( | |||
565 | pDest, pSource, | |||
566 | pTypeDescr->pBaseTypeDescription, acquire, 0 ); | |||
567 | } | |||
568 | ||||
569 | // then copy members | |||
570 | typelib_TypeDescriptionReference ** ppTypeRefs = | |||
571 | pTypeDescr->ppTypeRefs; | |||
572 | sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets; | |||
573 | sal_Int32 nDescr = pTypeDescr->nMembers; | |||
574 | ||||
575 | while (nDescr--) | |||
576 | { | |||
577 | ::uno_type_copyData( | |||
578 | pDest + pMemberOffsets[nDescr], | |||
579 | pSource + pMemberOffsets[nDescr], | |||
580 | ppTypeRefs[nDescr], acquire ); | |||
581 | } | |||
582 | } | |||
583 | } | |||
584 | ||||
585 | TYPELIB_DANGER_RELEASE( pElementTypeDescr ){ if ((((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || ((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) typelib_typedescription_release( pElementTypeDescr ); }; | |||
586 | break; | |||
587 | } | |||
588 | case typelib_TypeClass_UNION: | |||
589 | { | |||
590 | typelib_TypeDescription * pElementTypeDescr = 0; | |||
591 | TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ){ typelib_TypeDescriptionReference * pMacroTypeRef = (pElementType ); typelib_TypeDescription ** ppMacroTypeDescr = (&pElementTypeDescr ); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr , pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef ->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } }; | |||
592 | sal_Int32 nElementSize = pElementTypeDescr->nSize; | |||
593 | ||||
594 | if (nAlloc >= 0) | |||
595 | pSeq = reallocSeq( pSeq, nElementSize, nAlloc ); | |||
596 | if (pSeq != 0) | |||
597 | { | |||
598 | char * pDestElements = pSeq->elements; | |||
599 | ||||
600 | sal_Int32 nValueOffset = | |||
601 | ((typelib_UnionTypeDescription *) | |||
602 | pElementTypeDescr)->nValueOffset; | |||
603 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
604 | { | |||
605 | char * pDest = | |||
606 | pDestElements + (nElementSize * nPos); | |||
607 | char * pSource = | |||
608 | (char *)pSourceElements + (nElementSize * nPos); | |||
609 | ||||
610 | typelib_TypeDescriptionReference * pSetType = _unionGetSetType( | |||
611 | pSource, pElementTypeDescr ); | |||
612 | ::uno_type_copyData( | |||
613 | pDest + nValueOffset, | |||
614 | pSource + nValueOffset, | |||
615 | pSetType, acquire ); | |||
616 | *(sal_Int64 *)pDest = *(sal_Int64 *)pSource; | |||
617 | typelib_typedescriptionreference_release( pSetType ); | |||
618 | } | |||
619 | } | |||
620 | ||||
621 | TYPELIB_DANGER_RELEASE( pElementTypeDescr ){ if ((((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || ((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) typelib_typedescription_release( pElementTypeDescr ); }; | |||
622 | break; | |||
623 | } | |||
624 | case typelib_TypeClass_SEQUENCE: // sequence of sequence | |||
625 | { | |||
626 | if (nAlloc >= 0) | |||
627 | pSeq = reallocSeq( pSeq, sizeof(uno_Sequence *), nAlloc ); | |||
628 | if (pSeq != 0) | |||
629 | { | |||
630 | typelib_TypeDescription * pElementTypeDescr = 0; | |||
631 | TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ){ typelib_TypeDescriptionReference * pMacroTypeRef = (pElementType ); typelib_TypeDescription ** ppMacroTypeDescr = (&pElementTypeDescr ); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr , pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef ->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } }; | |||
632 | typelib_TypeDescriptionReference * pSeqElementType = | |||
633 | ((typelib_IndirectTypeDescription *) pElementTypeDescr)->pType; | |||
| ||||
634 | uno_Sequence ** pDestElements = (uno_Sequence **) pSeq->elements; | |||
635 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
636 | { | |||
637 | uno_Sequence * pNew = icopyConstructSequence( | |||
638 | ((uno_Sequence **) pSourceElements)[nPos], | |||
639 | pSeqElementType, acquire, 0 ); | |||
640 | OSL_ASSERT( pNew != 0 )do { if (true && (!(pNew != 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "640" ": "), "OSL_ASSERT: %s", "pNew != 0"); } } while ( false); | |||
641 | // ought never be a memory allocation problem, | |||
642 | // because of reference counted sequence handles | |||
643 | pDestElements[ nPos ] = pNew; | |||
644 | } | |||
645 | TYPELIB_DANGER_RELEASE( pElementTypeDescr ){ if ((((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || ((pElementTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) typelib_typedescription_release( pElementTypeDescr ); }; | |||
646 | } | |||
647 | break; | |||
648 | } | |||
649 | case typelib_TypeClass_INTERFACE: | |||
650 | { | |||
651 | if (nAlloc >= 0) | |||
652 | pSeq = reallocSeq( pSeq, sizeof(void *), nAlloc ); | |||
653 | if (pSeq != 0) | |||
654 | { | |||
655 | void ** pDestElements = (void **) pSeq->elements; | |||
656 | for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) | |||
657 | { | |||
658 | _acquire( pDestElements[nPos] = | |||
659 | ((void **)pSourceElements)[nPos], acquire ); | |||
660 | } | |||
661 | } | |||
662 | break; | |||
663 | } | |||
664 | default: | |||
665 | OSL_FAIL( "### unexpected element type!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "665" ": "), "%s", "### unexpected element type!"); } } while (false); | |||
666 | pSeq = 0; | |||
667 | break; | |||
668 | } | |||
669 | ||||
670 | if (pSeq == 0) | |||
671 | { | |||
672 | OSL_ASSERT( nAlloc >= 0 )do { if (true && (!(nAlloc >= 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "672" ": "), "OSL_ASSERT: %s", "nAlloc >= 0"); } } while (false); // must have been an allocation failure | |||
673 | return false; | |||
674 | } | |||
675 | else | |||
676 | { | |||
677 | *ppSeq = pSeq; | |||
678 | return true; | |||
679 | } | |||
680 | } | |||
681 | ||||
682 | //------------------------------------------------------------------------------ | |||
683 | static inline bool ireallocSequence( | |||
684 | uno_Sequence ** ppSequence, | |||
685 | typelib_TypeDescriptionReference * pElementType, | |||
686 | sal_Int32 nSize, | |||
687 | uno_AcquireFunc acquire, uno_ReleaseFunc release ) | |||
688 | { | |||
689 | bool ret = true; | |||
690 | uno_Sequence * pSeq = *ppSequence; | |||
691 | sal_Int32 nElements = pSeq->nElements; | |||
692 | ||||
693 | if (pSeq->nRefCount > 1 || | |||
694 | // not mem-copyable elements? | |||
695 | typelib_TypeClass_ANY == pElementType->eTypeClass || | |||
696 | typelib_TypeClass_STRUCT == pElementType->eTypeClass || | |||
697 | typelib_TypeClass_EXCEPTION == pElementType->eTypeClass) | |||
698 | { | |||
699 | // split sequence and construct new one from scratch | |||
700 | uno_Sequence * pNew = 0; | |||
701 | ||||
702 | sal_Int32 nRest = nSize - nElements; | |||
703 | sal_Int32 nCopy = (nRest > 0 ? nElements : nSize); | |||
704 | ||||
705 | if (nCopy >= 0) | |||
706 | { | |||
707 | ret = icopyConstructFromElements( | |||
708 | &pNew, pSeq->elements, pElementType, | |||
709 | 0, nCopy, acquire, | |||
710 | nSize ); // alloc to nSize | |||
711 | } | |||
712 | if (ret && nRest > 0) | |||
713 | { | |||
714 | ret = idefaultConstructElements( | |||
715 | &pNew, pElementType, | |||
716 | nCopy, nSize, | |||
717 | nCopy >= 0 ? -1 /* no mem allocation */ : nSize ); | |||
718 | } | |||
719 | ||||
720 | if (ret) | |||
721 | { | |||
722 | // destruct sequence | |||
723 | if (osl_decrementInterlockedCount( &pSeq->nRefCount ) == 0) | |||
724 | { | |||
725 | if (nElements > 0) | |||
726 | { | |||
727 | idestructElements( | |||
728 | pSeq->elements, pElementType, | |||
729 | 0, nElements, release ); | |||
730 | } | |||
731 | rtl_freeMemory( pSeq ); | |||
732 | } | |||
733 | *ppSequence = pNew; | |||
734 | } | |||
735 | } | |||
736 | else | |||
737 | { | |||
738 | OSL_ASSERT( pSeq->nRefCount == 1 )do { if (true && (!(pSeq->nRefCount == 1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "738" ": "), "OSL_ASSERT: %s", "pSeq->nRefCount == 1" ); } } while (false); | |||
739 | if (nSize > nElements) // default construct the rest | |||
740 | { | |||
741 | ret = idefaultConstructElements( | |||
742 | ppSequence, pElementType, | |||
743 | nElements, nSize, | |||
744 | nSize ); // realloc to nSize | |||
745 | } | |||
746 | else // or destruct the rest and realloc mem | |||
747 | { | |||
748 | sal_Int32 nElementSize = idestructElements( | |||
749 | pSeq->elements, pElementType, | |||
750 | nSize, nElements, release ); | |||
751 | // warning: it is assumed that the following will never fail, | |||
752 | // else this leads to a sequence null handle | |||
753 | *ppSequence = reallocSeq( pSeq, nElementSize, nSize ); | |||
754 | OSL_ASSERT( *ppSequence != 0 )do { if (true && (!(*ppSequence != 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "754" ": "), "OSL_ASSERT: %s", "*ppSequence != 0"); } } while (false); | |||
755 | ret = (*ppSequence != 0); | |||
756 | } | |||
757 | } | |||
758 | ||||
759 | return ret; | |||
760 | } | |||
761 | ||||
762 | } | |||
763 | ||||
764 | extern "C" | |||
765 | { | |||
766 | ||||
767 | //############################################################################## | |||
768 | sal_Bool SAL_CALL uno_type_sequence_construct( | |||
769 | uno_Sequence ** ppSequence, typelib_TypeDescriptionReference * pType, | |||
770 | void * pElements, sal_Int32 len, | |||
771 | uno_AcquireFunc acquire ) | |||
772 | SAL_THROW_EXTERN_C()throw () | |||
773 | { | |||
774 | bool ret; | |||
775 | if (len) | |||
776 | { | |||
777 | typelib_TypeDescription * pTypeDescr = 0; | |||
778 | TYPELIB_DANGER_GET( &pTypeDescr, pType ){ typelib_TypeDescriptionReference * pMacroTypeRef = (pType); typelib_TypeDescription ** ppMacroTypeDescr = (&pTypeDescr ); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr , pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef ->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } }; | |||
779 | ||||
780 | typelib_TypeDescriptionReference * pElementType = | |||
781 | ((typelib_IndirectTypeDescription *)pTypeDescr)->pType; | |||
782 | ||||
783 | *ppSequence = 0; | |||
784 | if (pElements == 0) | |||
785 | { | |||
786 | ret = idefaultConstructElements( | |||
787 | ppSequence, pElementType, | |||
788 | 0, len, | |||
789 | len ); // alloc to len | |||
790 | } | |||
791 | else | |||
792 | { | |||
793 | ret = icopyConstructFromElements( | |||
794 | ppSequence, pElements, pElementType, | |||
795 | 0, len, acquire, | |||
796 | len ); // alloc to len | |||
797 | } | |||
798 | ||||
799 | TYPELIB_DANGER_RELEASE( pTypeDescr ){ if ((((pTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || ((pTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) typelib_typedescription_release( pTypeDescr ); }; | |||
800 | } | |||
801 | else | |||
802 | { | |||
803 | *ppSequence = createEmptySequence(); | |||
804 | ret = true; | |||
805 | } | |||
806 | ||||
807 | OSL_ASSERT( (*ppSequence != 0) == ret )do { if (true && (!((*ppSequence != 0) == ret))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "807" ": "), "OSL_ASSERT: %s", "(*ppSequence != 0) == ret" ); } } while (false); | |||
808 | return ret; | |||
809 | } | |||
810 | ||||
811 | //############################################################################## | |||
812 | sal_Bool SAL_CALL uno_sequence_construct( | |||
813 | uno_Sequence ** ppSequence, typelib_TypeDescription * pTypeDescr, | |||
814 | void * pElements, sal_Int32 len, | |||
815 | uno_AcquireFunc acquire ) | |||
816 | SAL_THROW_EXTERN_C()throw () | |||
817 | { | |||
818 | bool ret; | |||
819 | if (len > 0) | |||
820 | { | |||
821 | typelib_TypeDescriptionReference * pElementType = | |||
822 | ((typelib_IndirectTypeDescription *)pTypeDescr)->pType; | |||
823 | ||||
824 | *ppSequence = 0; | |||
825 | if (pElements == 0) | |||
826 | { | |||
827 | ret = idefaultConstructElements( | |||
828 | ppSequence, pElementType, | |||
829 | 0, len, | |||
830 | len ); // alloc to len | |||
831 | } | |||
832 | else | |||
833 | { | |||
834 | ret = icopyConstructFromElements( | |||
835 | ppSequence, pElements, pElementType, | |||
836 | 0, len, acquire, | |||
837 | len ); // alloc to len | |||
838 | } | |||
839 | } | |||
840 | else | |||
841 | { | |||
842 | *ppSequence = createEmptySequence(); | |||
843 | ret = true; | |||
844 | } | |||
845 | ||||
846 | OSL_ASSERT( (*ppSequence != 0) == ret )do { if (true && (!((*ppSequence != 0) == ret))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "846" ": "), "OSL_ASSERT: %s", "(*ppSequence != 0) == ret" ); } } while (false); | |||
847 | return ret; | |||
848 | } | |||
849 | ||||
850 | //############################################################################## | |||
851 | sal_Bool SAL_CALL uno_type_sequence_realloc( | |||
852 | uno_Sequence ** ppSequence, typelib_TypeDescriptionReference * pType, | |||
853 | sal_Int32 nSize, uno_AcquireFunc acquire, uno_ReleaseFunc release ) | |||
854 | SAL_THROW_EXTERN_C()throw () | |||
855 | { | |||
856 | OSL_ENSURE( ppSequence, "### null ptr!" )do { if (true && (!(ppSequence))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "856" ": "), "%s", "### null ptr!"); } } while (false); | |||
857 | OSL_ENSURE( nSize >= 0, "### new size must be at least 0!" )do { if (true && (!(nSize >= 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "857" ": "), "%s", "### new size must be at least 0!"); } } while (false); | |||
858 | ||||
859 | bool ret = true; | |||
860 | if (nSize != (*ppSequence)->nElements) | |||
861 | { | |||
862 | typelib_TypeDescription * pTypeDescr = 0; | |||
863 | TYPELIB_DANGER_GET( &pTypeDescr, pType ){ typelib_TypeDescriptionReference * pMacroTypeRef = (pType); typelib_TypeDescription ** ppMacroTypeDescr = (&pTypeDescr ); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr , pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef ->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } }; | |||
864 | ret = ireallocSequence( | |||
865 | ppSequence, ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, | |||
866 | nSize, acquire, release ); | |||
867 | TYPELIB_DANGER_RELEASE( pTypeDescr ){ if ((((pTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || ((pTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) typelib_typedescription_release( pTypeDescr ); }; | |||
868 | } | |||
869 | return ret; | |||
870 | } | |||
871 | ||||
872 | //############################################################################## | |||
873 | sal_Bool SAL_CALL uno_sequence_realloc( | |||
874 | uno_Sequence ** ppSequence, typelib_TypeDescription * pTypeDescr, | |||
875 | sal_Int32 nSize, uno_AcquireFunc acquire, uno_ReleaseFunc release ) | |||
876 | SAL_THROW_EXTERN_C()throw () | |||
877 | { | |||
878 | OSL_ENSURE( ppSequence, "### null ptr!" )do { if (true && (!(ppSequence))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "878" ": "), "%s", "### null ptr!"); } } while (false); | |||
879 | OSL_ENSURE( nSize >= 0, "### new size must be at least 0!" )do { if (true && (!(nSize >= 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "879" ": "), "%s", "### new size must be at least 0!"); } } while (false); | |||
880 | ||||
881 | bool ret = true; | |||
882 | if (nSize != (*ppSequence)->nElements) | |||
883 | { | |||
884 | ret = ireallocSequence( | |||
885 | ppSequence, ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, | |||
886 | nSize, acquire, release ); | |||
887 | } | |||
888 | return ret; | |||
889 | } | |||
890 | ||||
891 | //############################################################################## | |||
892 | sal_Bool SAL_CALL uno_type_sequence_reference2One( | |||
893 | uno_Sequence ** ppSequence, | |||
894 | typelib_TypeDescriptionReference * pType, | |||
895 | uno_AcquireFunc acquire, uno_ReleaseFunc release ) | |||
896 | SAL_THROW_EXTERN_C()throw () | |||
897 | { | |||
898 | OSL_ENSURE( ppSequence, "### null ptr!" )do { if (true && (!(ppSequence))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "898" ": "), "%s", "### null ptr!"); } } while (false); | |||
899 | bool ret = true; | |||
900 | uno_Sequence * pSequence = *ppSequence; | |||
901 | if (pSequence->nRefCount > 1) | |||
902 | { | |||
903 | uno_Sequence * pNew = 0; | |||
904 | if (pSequence->nElements > 0) | |||
905 | { | |||
906 | typelib_TypeDescription * pTypeDescr = 0; | |||
907 | TYPELIB_DANGER_GET( &pTypeDescr, pType ){ typelib_TypeDescriptionReference * pMacroTypeRef = (pType); typelib_TypeDescription ** ppMacroTypeDescr = (&pTypeDescr ); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr , pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef ->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } }; | |||
908 | ||||
909 | ret = icopyConstructFromElements( | |||
910 | &pNew, pSequence->elements, | |||
911 | ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, | |||
912 | 0, pSequence->nElements, acquire, | |||
913 | pSequence->nElements ); // alloc nElements | |||
914 | if (ret) | |||
915 | { | |||
916 | idestructSequence( *ppSequence, pType, pTypeDescr, release ); | |||
917 | *ppSequence = pNew; | |||
918 | } | |||
919 | ||||
920 | TYPELIB_DANGER_RELEASE( pTypeDescr ){ if ((((pTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || ((pTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) typelib_typedescription_release( pTypeDescr ); }; | |||
921 | } | |||
922 | else | |||
923 | { | |||
924 | pNew = allocSeq( 0, 0 ); | |||
925 | ret = (pNew != 0); | |||
926 | if (ret) | |||
927 | { | |||
928 | // easy destruction of empty sequence: | |||
929 | if (osl_decrementInterlockedCount( &pSequence->nRefCount ) == 0) | |||
930 | rtl_freeMemory( pSequence ); | |||
931 | *ppSequence = pNew; | |||
932 | } | |||
933 | } | |||
934 | } | |||
935 | return ret; | |||
936 | } | |||
937 | ||||
938 | //############################################################################## | |||
939 | sal_Bool SAL_CALL uno_sequence_reference2One( | |||
940 | uno_Sequence ** ppSequence, | |||
941 | typelib_TypeDescription * pTypeDescr, | |||
942 | uno_AcquireFunc acquire, uno_ReleaseFunc release ) | |||
943 | SAL_THROW_EXTERN_C()throw () | |||
944 | { | |||
945 | OSL_ENSURE( ppSequence, "### null ptr!" )do { if (true && (!(ppSequence))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/uno/sequence.cxx" ":" "945" ": "), "%s", "### null ptr!"); } } while (false); | |||
946 | bool ret = true; | |||
947 | uno_Sequence * pSequence = *ppSequence; | |||
948 | if (pSequence->nRefCount > 1) | |||
| ||||
949 | { | |||
950 | uno_Sequence * pNew = 0; | |||
951 | if (pSequence->nElements > 0) | |||
952 | { | |||
953 | ret = icopyConstructFromElements( | |||
954 | &pNew, pSequence->elements, | |||
955 | ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, | |||
956 | 0, pSequence->nElements, acquire, | |||
957 | pSequence->nElements ); // alloc nElements | |||
958 | if (ret) | |||
959 | { | |||
960 | idestructSequence( | |||
961 | pSequence, pTypeDescr->pWeakRef, pTypeDescr, release ); | |||
962 | *ppSequence = pNew; | |||
963 | } | |||
964 | } | |||
965 | else | |||
966 | { | |||
967 | pNew = allocSeq( 0, 0 ); | |||
968 | ret = (pNew != 0); | |||
969 | if (ret) | |||
970 | { | |||
971 | // easy destruction of empty sequence: | |||
972 | if (osl_decrementInterlockedCount( &pSequence->nRefCount ) == 0) | |||
973 | rtl_freeMemory( pSequence ); | |||
974 | *ppSequence = pNew; | |||
975 | } | |||
976 | } | |||
977 | ||||
978 | } | |||
979 | return ret; | |||
980 | } | |||
981 | ||||
982 | //############################################################################## | |||
983 | void SAL_CALL uno_sequence_assign( | |||
984 | uno_Sequence ** ppDest, | |||
985 | uno_Sequence * pSource, | |||
986 | typelib_TypeDescription * pTypeDescr, | |||
987 | uno_ReleaseFunc release ) | |||
988 | SAL_THROW_EXTERN_C()throw () | |||
989 | { | |||
990 | if (*ppDest != pSource) | |||
991 | { | |||
992 | ::osl_incrementInterlockedCount( &pSource->nRefCount ); | |||
993 | idestructSequence( *ppDest, pTypeDescr->pWeakRef, pTypeDescr, release ); | |||
994 | *ppDest = pSource; | |||
995 | } | |||
996 | } | |||
997 | ||||
998 | //############################################################################## | |||
999 | void SAL_CALL uno_type_sequence_assign( | |||
1000 | uno_Sequence ** ppDest, | |||
1001 | uno_Sequence * pSource, | |||
1002 | typelib_TypeDescriptionReference * pType, | |||
1003 | uno_ReleaseFunc release ) | |||
1004 | SAL_THROW_EXTERN_C()throw () | |||
1005 | { | |||
1006 | if (*ppDest != pSource) | |||
1007 | { | |||
1008 | ::osl_incrementInterlockedCount( &pSource->nRefCount ); | |||
1009 | idestructSequence( *ppDest, pType, 0, release ); | |||
1010 | *ppDest = pSource; | |||
1011 | } | |||
1012 | } | |||
1013 | ||||
1014 | } | |||
1015 | ||||
1016 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |