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