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 .
20 #include <sal/config.h>
26 #include <osl/diagnose.h>
27 #include <osl/interlck.h>
28 #include <typelib/typedescription.h>
30 #include <uno/sequence2.h>
43 static uno_Sequence
* reallocSeq(
44 uno_Sequence
* pReallocate
, std::size_t nElementSize
, sal_Int32 nElements
)
46 OSL_ASSERT( nElements
>= 0 );
47 uno_Sequence
* pNew
= nullptr;
48 sal_uInt32 nSize
= calcSeqMemSize( nElementSize
, nElements
);
51 if (pReallocate
== nullptr)
53 pNew
= static_cast<uno_Sequence
*>(std::malloc( nSize
));
57 pNew
= static_cast<uno_Sequence
*>(std::realloc( pReallocate
, nSize
));
63 pNew
->nElements
= nElements
;
70 static bool idefaultConstructElements(
71 uno_Sequence
** ppSeq
,
72 typelib_TypeDescriptionReference
* pElementType
,
73 sal_Int32 nStartIndex
, sal_Int32 nStopIndex
,
74 sal_Int32 nAlloc
) // >= 0 means (re)alloc memory for nAlloc elements
76 uno_Sequence
* pSeq
= *ppSeq
;
77 switch (pElementType
->eTypeClass
)
79 case typelib_TypeClass_CHAR
:
81 pSeq
= reallocSeq( pSeq
, sizeof(sal_Unicode
), nAlloc
);
85 pSeq
->elements
+ (sizeof(sal_Unicode
) * nStartIndex
),
87 sizeof(sal_Unicode
) * (nStopIndex
- nStartIndex
) );
90 case typelib_TypeClass_BOOLEAN
:
92 pSeq
= reallocSeq( pSeq
, sizeof(sal_Bool
), nAlloc
);
96 pSeq
->elements
+ (sizeof(sal_Bool
) * nStartIndex
),
98 sizeof(sal_Bool
) * (nStopIndex
- nStartIndex
) );
101 case typelib_TypeClass_BYTE
:
103 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int8
), nAlloc
);
107 pSeq
->elements
+ (sizeof(sal_Int8
) * nStartIndex
),
109 sizeof(sal_Int8
) * (nStopIndex
- nStartIndex
) );
112 case typelib_TypeClass_SHORT
:
113 case typelib_TypeClass_UNSIGNED_SHORT
:
115 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int16
), nAlloc
);
119 pSeq
->elements
+ (sizeof(sal_Int16
) * nStartIndex
),
121 sizeof(sal_Int16
) * (nStopIndex
- nStartIndex
) );
124 case typelib_TypeClass_LONG
:
125 case typelib_TypeClass_UNSIGNED_LONG
:
127 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
131 pSeq
->elements
+ (sizeof(sal_Int32
) * nStartIndex
),
133 sizeof(sal_Int32
) * (nStopIndex
- nStartIndex
) );
136 case typelib_TypeClass_HYPER
:
137 case typelib_TypeClass_UNSIGNED_HYPER
:
139 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int64
), nAlloc
);
143 pSeq
->elements
+ (sizeof(sal_Int64
) * nStartIndex
),
145 sizeof(sal_Int64
) * (nStopIndex
- nStartIndex
) );
148 case typelib_TypeClass_FLOAT
:
151 pSeq
= reallocSeq( pSeq
, sizeof(float), nAlloc
);
154 float * pElements
= reinterpret_cast<float *>(pSeq
->elements
);
155 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
157 pElements
[nPos
] = 0.0;
162 case typelib_TypeClass_DOUBLE
:
165 pSeq
= reallocSeq( pSeq
, sizeof(double), nAlloc
);
168 double * pElements
= reinterpret_cast<double *>(pSeq
->elements
);
169 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
171 pElements
[nPos
] = 0.0;
176 case typelib_TypeClass_STRING
:
179 pSeq
= reallocSeq( pSeq
, sizeof(rtl_uString
*), nAlloc
);
182 rtl_uString
** pElements
= reinterpret_cast<rtl_uString
**>(pSeq
->elements
);
183 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
185 pElements
[nPos
] = nullptr;
186 rtl_uString_new( &pElements
[nPos
] );
191 case typelib_TypeClass_TYPE
:
196 pSeq
, sizeof(typelib_TypeDescriptionReference
*), nAlloc
);
200 typelib_TypeDescriptionReference
** pElements
=
201 reinterpret_cast<typelib_TypeDescriptionReference
**>(pSeq
->elements
);
202 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
204 pElements
[nPos
] = _getVoidType();
209 case typelib_TypeClass_ANY
:
212 pSeq
= reallocSeq( pSeq
, sizeof(uno_Any
), nAlloc
);
215 uno_Any
* pElements
= reinterpret_cast<uno_Any
*>(pSeq
->elements
);
216 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
218 CONSTRUCT_EMPTY_ANY( &pElements
[nPos
] );
223 case typelib_TypeClass_ENUM
:
226 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
229 typelib_TypeDescription
* pElementTypeDescr
= nullptr;
230 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
231 if (pElementTypeDescr
== nullptr) {
235 reinterpret_cast<typelib_EnumTypeDescription
*>(
236 pElementTypeDescr
)->nDefaultEnumValue
;
237 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
239 sal_Int32
* pElements
= reinterpret_cast<sal_Int32
*>(pSeq
->elements
);
240 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
242 pElements
[nPos
] = eEnum
;
247 case typelib_TypeClass_STRUCT
:
248 case typelib_TypeClass_EXCEPTION
:
250 typelib_TypeDescription
* pElementTypeDescr
= nullptr;
251 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
252 if (pElementTypeDescr
== nullptr) {
255 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
258 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
261 char * pElements
= pSeq
->elements
;
262 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
264 _defaultConstructStruct(
265 pElements
+ (nElementSize
* nPos
),
266 reinterpret_cast<typelib_CompoundTypeDescription
*>(pElementTypeDescr
) );
270 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
273 case typelib_TypeClass_SEQUENCE
:
277 // coverity[suspicious_sizeof : FALSE] - sizeof(uno_Sequence*) is correct here
278 pSeq
= reallocSeq(pSeq
, sizeof(uno_Sequence
*), nAlloc
);
282 uno_Sequence
** pElements
=
283 reinterpret_cast<uno_Sequence
**>(pSeq
->elements
);
284 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
286 pElements
[nPos
] = createEmptySequence();
291 case typelib_TypeClass_INTERFACE
: // either C++ or C-UNO interface
293 pSeq
= reallocSeq( pSeq
, sizeof(void *), nAlloc
);
297 pSeq
->elements
+ (sizeof(void *) * nStartIndex
),
299 sizeof(void *) * (nStopIndex
- nStartIndex
) );
303 OSL_FAIL( "### unexpected element type!" );
310 OSL_ASSERT( nAlloc
>= 0 ); // must have been an allocation failure
317 // coverity[ -tainted_data_sink : arg-1 ]
318 static bool icopyConstructFromElements(
319 uno_Sequence
** ppSeq
, void * pSourceElements
,
320 typelib_TypeDescriptionReference
* pElementType
,
321 sal_Int32 nStopIndex
,
322 uno_AcquireFunc acquire
,
325 uno_Sequence
* pSeq
= *ppSeq
;
326 switch (pElementType
->eTypeClass
)
328 case typelib_TypeClass_CHAR
:
329 pSeq
= reallocSeq( pSeq
, sizeof(sal_Unicode
), nAlloc
);
335 sizeof(sal_Unicode
) * nStopIndex
);
338 case typelib_TypeClass_BOOLEAN
:
339 pSeq
= reallocSeq( pSeq
, sizeof(sal_Bool
), nAlloc
);
345 sizeof(sal_Bool
) * nStopIndex
);
348 case typelib_TypeClass_BYTE
:
349 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int8
), nAlloc
);
355 sizeof(sal_Int8
) * nStopIndex
);
358 case typelib_TypeClass_SHORT
:
359 case typelib_TypeClass_UNSIGNED_SHORT
:
360 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int16
), nAlloc
);
366 sizeof(sal_Int16
) * nStopIndex
);
369 case typelib_TypeClass_LONG
:
370 case typelib_TypeClass_UNSIGNED_LONG
:
371 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
377 sizeof(sal_Int32
) * nStopIndex
);
380 case typelib_TypeClass_HYPER
:
381 case typelib_TypeClass_UNSIGNED_HYPER
:
382 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int64
), nAlloc
);
388 sizeof(sal_Int64
) * nStopIndex
);
391 case typelib_TypeClass_FLOAT
:
392 pSeq
= reallocSeq( pSeq
, sizeof(float), nAlloc
);
398 sizeof(float) * nStopIndex
);
401 case typelib_TypeClass_DOUBLE
:
402 pSeq
= reallocSeq( pSeq
, sizeof(double), nAlloc
);
408 sizeof(double) * nStopIndex
);
411 case typelib_TypeClass_ENUM
:
412 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
418 sizeof(sal_Int32
) * nStopIndex
);
421 case typelib_TypeClass_STRING
:
423 pSeq
= reallocSeq( pSeq
, sizeof(rtl_uString
*), nAlloc
);
426 rtl_uString
** pDestElements
= reinterpret_cast<rtl_uString
**>(pSeq
->elements
);
427 for ( sal_Int32 nPos
= 0; nPos
< nStopIndex
; ++nPos
)
429 // This code tends to trigger coverity's overrun-buffer-arg warning
430 // coverity[index_parm_via_loop_bound] - https://communities.coverity.com/thread/2993
431 ::rtl_uString_acquire(
432 static_cast<rtl_uString
**>(pSourceElements
)[nPos
] );
433 pDestElements
[nPos
] = static_cast<rtl_uString
**>(pSourceElements
)[nPos
];
438 case typelib_TypeClass_TYPE
:
441 pSeq
, sizeof(typelib_TypeDescriptionReference
*), nAlloc
);
444 typelib_TypeDescriptionReference
** pDestElements
=
445 reinterpret_cast<typelib_TypeDescriptionReference
**>(pSeq
->elements
);
446 for ( sal_Int32 nPos
= 0; nPos
< nStopIndex
; ++nPos
)
449 static_cast<typelib_TypeDescriptionReference
**>(
450 pSourceElements
)[nPos
] );
451 pDestElements
[nPos
] =
452 static_cast<typelib_TypeDescriptionReference
**>(
453 pSourceElements
)[nPos
];
458 case typelib_TypeClass_ANY
:
460 pSeq
= reallocSeq( pSeq
, sizeof(uno_Any
), nAlloc
);
463 uno_Any
* pDestElements
= reinterpret_cast<uno_Any
*>(pSeq
->elements
);
464 for ( sal_Int32 nPos
= 0; nPos
< nStopIndex
; ++nPos
)
466 uno_Any
* pSource
= static_cast<uno_Any
*>(pSourceElements
) + nPos
;
468 &pDestElements
[nPos
],
470 pSource
->pType
, nullptr,
476 case typelib_TypeClass_STRUCT
:
477 case typelib_TypeClass_EXCEPTION
:
479 typelib_TypeDescription
* pElementTypeDescr
= nullptr;
480 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
481 if (pElementTypeDescr
== nullptr) {
484 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
486 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
489 char * pDestElements
= pSeq
->elements
;
491 typelib_CompoundTypeDescription
* pTypeDescr
=
492 reinterpret_cast<typelib_CompoundTypeDescription
*>(pElementTypeDescr
);
493 for ( sal_Int32 nPos
= 0; nPos
< nStopIndex
; ++nPos
)
496 pDestElements
+ (nElementSize
* nPos
);
498 static_cast<char *>(pSourceElements
) + (nElementSize
* nPos
);
500 if (pTypeDescr
->pBaseTypeDescription
)
503 _copyConstructStruct(
505 pTypeDescr
->pBaseTypeDescription
, acquire
, nullptr );
509 typelib_TypeDescriptionReference
** ppTypeRefs
=
510 pTypeDescr
->ppTypeRefs
;
511 sal_Int32
* pMemberOffsets
= pTypeDescr
->pMemberOffsets
;
512 sal_Int32 nDescr
= pTypeDescr
->nMembers
;
517 pDest
+ pMemberOffsets
[nDescr
],
518 pSource
+ pMemberOffsets
[nDescr
],
519 ppTypeRefs
[nDescr
], acquire
);
524 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
527 case typelib_TypeClass_SEQUENCE
: // sequence of sequence
529 // coverity[suspicious_sizeof : FALSE] - sizeof(uno_Sequence*) is correct here
530 pSeq
= reallocSeq(pSeq
, sizeof(uno_Sequence
*), nAlloc
);
533 typelib_TypeDescription
* pElementTypeDescr
= nullptr;
534 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
535 if (pElementTypeDescr
== nullptr) {
538 typelib_TypeDescriptionReference
* pSeqElementType
=
539 reinterpret_cast<typelib_IndirectTypeDescription
*>(pElementTypeDescr
)->pType
;
540 uno_Sequence
** pDestElements
= reinterpret_cast<uno_Sequence
**>(pSeq
->elements
);
541 for ( sal_Int32 nPos
= 0; nPos
< nStopIndex
; ++nPos
)
543 uno_Sequence
* pNew
= icopyConstructSequence(
544 static_cast<uno_Sequence
**>(pSourceElements
)[nPos
],
545 pSeqElementType
, acquire
, nullptr );
546 OSL_ASSERT( pNew
!= nullptr );
547 // ought never be a memory allocation problem,
548 // because of reference counted sequence handles
549 pDestElements
[ nPos
] = pNew
;
551 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
555 case typelib_TypeClass_INTERFACE
:
557 pSeq
= reallocSeq( pSeq
, sizeof(void *), nAlloc
);
560 void ** pDestElements
= reinterpret_cast<void **>(pSeq
->elements
);
561 for ( sal_Int32 nPos
= 0; nPos
< nStopIndex
; ++nPos
)
563 pDestElements
[nPos
] = static_cast<void **>(pSourceElements
)[nPos
];
564 _acquire( pDestElements
[nPos
], acquire
);
570 OSL_FAIL( "### unexpected element type!" );
577 return false; // allocation failure
584 static bool ireallocSequence(
585 uno_Sequence
** ppSequence
,
586 typelib_TypeDescriptionReference
* pElementType
,
588 uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
591 uno_Sequence
* pSeq
= *ppSequence
;
592 sal_Int32 nElements
= pSeq
->nElements
;
594 if (pSeq
->nRefCount
> 1 ||
595 // not mem-copyable elements?
596 typelib_TypeClass_ANY
== pElementType
->eTypeClass
||
597 typelib_TypeClass_STRUCT
== pElementType
->eTypeClass
||
598 typelib_TypeClass_EXCEPTION
== pElementType
->eTypeClass
)
600 // split sequence and construct new one from scratch
601 uno_Sequence
* pNew
= nullptr;
603 sal_Int32 nRest
= nSize
- nElements
;
604 sal_Int32 nCopy
= (nRest
> 0 ? nElements
: nSize
);
608 ret
= icopyConstructFromElements(
609 &pNew
, pSeq
->elements
, pElementType
,
611 nSize
); // alloc to nSize
613 if (ret
&& nRest
> 0)
615 ret
= idefaultConstructElements(
618 nCopy
>= 0 ? -1 /* no mem allocation */ : nSize
);
624 if (osl_atomic_decrement( &pSeq
->nRefCount
) == 0)
629 pSeq
->elements
, pElementType
,
630 0, nElements
, release
);
639 OSL_ASSERT( pSeq
->nRefCount
== 1 );
640 if (nSize
> nElements
) // default construct the rest
642 ret
= idefaultConstructElements(
643 ppSequence
, pElementType
,
645 nSize
); // realloc to nSize
647 else // or destruct the rest and realloc mem
649 sal_Int32 nElementSize
= idestructElements(
650 pSeq
->elements
, pElementType
,
651 nSize
, nElements
, release
);
652 // warning: it is assumed that the following will never fail,
653 // else this leads to a sequence null handle
654 *ppSequence
= reallocSeq( pSeq
, nElementSize
, nSize
);
655 OSL_ASSERT( *ppSequence
!= nullptr );
656 ret
= (*ppSequence
!= nullptr);
668 sal_Bool SAL_CALL
uno_type_sequence_construct(
669 uno_Sequence
** ppSequence
, typelib_TypeDescriptionReference
* pType
,
670 void * pElements
, sal_Int32 len
,
671 uno_AcquireFunc acquire
) noexcept
677 typelib_TypeDescription
* pTypeDescr
= nullptr;
678 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
679 if (pTypeDescr
== nullptr) {
683 typelib_TypeDescriptionReference
* pElementType
=
684 reinterpret_cast<typelib_IndirectTypeDescription
*>(pTypeDescr
)->pType
;
686 *ppSequence
= nullptr;
687 if (pElements
== nullptr)
689 ret
= idefaultConstructElements(
690 ppSequence
, pElementType
,
692 len
); // alloc to len
696 ret
= icopyConstructFromElements(
697 ppSequence
, pElements
, pElementType
,
699 len
); // alloc to len
702 TYPELIB_DANGER_RELEASE( pTypeDescr
);
706 *ppSequence
= createEmptySequence();
710 OSL_ASSERT( (*ppSequence
!= nullptr) == ret
);
715 sal_Bool SAL_CALL
uno_sequence_construct(
716 uno_Sequence
** ppSequence
, typelib_TypeDescription
* pTypeDescr
,
717 void * pElements
, sal_Int32 len
,
718 uno_AcquireFunc acquire
) noexcept
723 typelib_TypeDescriptionReference
* pElementType
=
724 reinterpret_cast<typelib_IndirectTypeDescription
*>(pTypeDescr
)->pType
;
726 *ppSequence
= nullptr;
727 if (pElements
== nullptr)
729 ret
= idefaultConstructElements(
730 ppSequence
, pElementType
,
732 len
); // alloc to len
736 ret
= icopyConstructFromElements(
737 ppSequence
, pElements
, pElementType
,
739 len
); // alloc to len
744 *ppSequence
= createEmptySequence();
748 OSL_ASSERT( (*ppSequence
!= nullptr) == ret
);
753 sal_Bool SAL_CALL
uno_type_sequence_realloc(
754 uno_Sequence
** ppSequence
, typelib_TypeDescriptionReference
* pType
,
755 sal_Int32 nSize
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
) noexcept
757 assert(ppSequence
&& "### null ptr!");
758 assert(nSize
>= 0 && "### new size must be at least 0!");
761 if (nSize
!= (*ppSequence
)->nElements
)
763 typelib_TypeDescription
* pTypeDescr
= nullptr;
764 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
765 ret
= ireallocSequence(
766 ppSequence
, reinterpret_cast<typelib_IndirectTypeDescription
*>(pTypeDescr
)->pType
,
767 nSize
, acquire
, release
);
768 TYPELIB_DANGER_RELEASE( pTypeDescr
);
774 sal_Bool SAL_CALL
uno_sequence_realloc(
775 uno_Sequence
** ppSequence
, typelib_TypeDescription
* pTypeDescr
,
776 sal_Int32 nSize
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
) noexcept
778 assert(ppSequence
&& "### null ptr!");
779 OSL_ENSURE( nSize
>= 0, "### new size must be at least 0!" );
782 if (nSize
!= (*ppSequence
)->nElements
)
784 ret
= ireallocSequence(
785 ppSequence
, reinterpret_cast<typelib_IndirectTypeDescription
*>(pTypeDescr
)->pType
,
786 nSize
, acquire
, release
);
792 sal_Bool SAL_CALL
uno_type_sequence_reference2One(
793 uno_Sequence
** ppSequence
,
794 typelib_TypeDescriptionReference
* pType
,
795 uno_AcquireFunc acquire
, uno_ReleaseFunc release
) noexcept
797 assert(ppSequence
&& "### null ptr!");
799 uno_Sequence
* pSequence
= *ppSequence
;
800 if (pSequence
->nRefCount
> 1)
802 uno_Sequence
* pNew
= nullptr;
803 if (pSequence
->nElements
> 0)
805 typelib_TypeDescription
* pTypeDescr
= nullptr;
806 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
808 ret
= icopyConstructFromElements(
809 &pNew
, pSequence
->elements
,
810 reinterpret_cast<typelib_IndirectTypeDescription
*>(pTypeDescr
)->pType
,
811 pSequence
->nElements
, acquire
,
812 pSequence
->nElements
); // alloc nElements
815 idestructSequence( *ppSequence
, pType
, pTypeDescr
, release
);
819 TYPELIB_DANGER_RELEASE( pTypeDescr
);
823 pNew
= allocSeq( 0, 0 );
824 ret
= (pNew
!= nullptr);
827 // easy destruction of empty sequence:
828 if (osl_atomic_decrement( &pSequence
->nRefCount
) == 0)
829 std::free( pSequence
);
838 sal_Bool SAL_CALL
uno_sequence_reference2One(
839 uno_Sequence
** ppSequence
,
840 typelib_TypeDescription
* pTypeDescr
,
841 uno_AcquireFunc acquire
, uno_ReleaseFunc release
) noexcept
843 assert(ppSequence
&& "### null ptr!");
845 uno_Sequence
* pSequence
= *ppSequence
;
846 if (pSequence
->nRefCount
> 1)
848 uno_Sequence
* pNew
= nullptr;
849 if (pSequence
->nElements
> 0)
851 ret
= icopyConstructFromElements(
852 &pNew
, pSequence
->elements
,
853 reinterpret_cast<typelib_IndirectTypeDescription
*>(pTypeDescr
)->pType
,
854 pSequence
->nElements
, acquire
,
855 pSequence
->nElements
); // alloc nElements
859 pSequence
, pTypeDescr
->pWeakRef
, pTypeDescr
, release
);
865 pNew
= allocSeq( 0, 0 );
866 ret
= (pNew
!= nullptr);
869 // easy destruction of empty sequence:
870 if (osl_atomic_decrement( &pSequence
->nRefCount
) == 0)
871 std::free( pSequence
);
881 void SAL_CALL
uno_sequence_assign(
882 uno_Sequence
** ppDest
,
883 uno_Sequence
* pSource
,
884 typelib_TypeDescription
* pTypeDescr
,
885 uno_ReleaseFunc release
) noexcept
887 if (*ppDest
!= pSource
)
889 osl_atomic_increment( &pSource
->nRefCount
);
890 idestructSequence( *ppDest
, pTypeDescr
->pWeakRef
, pTypeDescr
, release
);
896 void SAL_CALL
uno_type_sequence_assign(
897 uno_Sequence
** ppDest
,
898 uno_Sequence
* pSource
,
899 typelib_TypeDescriptionReference
* pType
,
900 uno_ReleaseFunc release
) noexcept
902 if (*ppDest
!= pSource
)
904 osl_atomic_increment( &pSource
->nRefCount
);
905 idestructSequence( *ppDest
, pType
, nullptr, release
);
910 void uno_type_sequence_destroy(
911 uno_Sequence
* sequence
, typelib_TypeDescriptionReference
* type
,
912 uno_ReleaseFunc release
) noexcept
914 idestroySequence(sequence
, type
, nullptr, release
);
919 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */