25#include <osl/diagnose.h>
26#include <osl/interlck.h>
27#include <typelib/typedescription.h>
29#include <uno/sequence2.h>
43 uno_Sequence * pReallocate, std::size_t nElementSize, sal_Int32
nElements )
46 uno_Sequence * pNew =
nullptr;
50 if (pReallocate ==
nullptr)
52 pNew =
static_cast<uno_Sequence *
>(std::malloc( nSize ));
56 pNew =
static_cast<uno_Sequence *
>(std::realloc( pReallocate, nSize ));
70 uno_Sequence ** ppSeq,
71 typelib_TypeDescriptionReference * pElementType,
72 sal_Int32 nStartIndex, sal_Int32 nStopIndex,
75 uno_Sequence * pSeq = *ppSeq;
76 switch (pElementType->eTypeClass)
78 case typelib_TypeClass_CHAR:
84 pSeq->elements + (
sizeof(
sal_Unicode) * nStartIndex),
89 case typelib_TypeClass_BOOLEAN:
95 pSeq->elements + (
sizeof(
sal_Bool) * nStartIndex),
97 sizeof(
sal_Bool) * (nStopIndex - nStartIndex) );
100 case typelib_TypeClass_BYTE:
106 pSeq->elements + (
sizeof(
sal_Int8) * nStartIndex),
108 sizeof(
sal_Int8) * (nStopIndex - nStartIndex) );
111 case typelib_TypeClass_SHORT:
112 case typelib_TypeClass_UNSIGNED_SHORT:
114 pSeq =
reallocSeq( pSeq,
sizeof(sal_Int16), nAlloc );
118 pSeq->elements + (
sizeof(sal_Int16) * nStartIndex),
120 sizeof(sal_Int16) * (nStopIndex - nStartIndex) );
123 case typelib_TypeClass_LONG:
124 case typelib_TypeClass_UNSIGNED_LONG:
126 pSeq =
reallocSeq( pSeq,
sizeof(sal_Int32), nAlloc );
130 pSeq->elements + (
sizeof(sal_Int32) * nStartIndex),
132 sizeof(sal_Int32) * (nStopIndex - nStartIndex) );
135 case typelib_TypeClass_HYPER:
136 case typelib_TypeClass_UNSIGNED_HYPER:
138 pSeq =
reallocSeq( pSeq,
sizeof(sal_Int64), nAlloc );
142 pSeq->elements + (
sizeof(sal_Int64) * nStartIndex),
144 sizeof(sal_Int64) * (nStopIndex - nStartIndex) );
147 case typelib_TypeClass_FLOAT:
150 pSeq =
reallocSeq( pSeq,
sizeof(
float), nAlloc );
153 float * pElements =
reinterpret_cast<float *
>(pSeq->elements);
154 for ( sal_Int32
nPos = nStartIndex;
nPos < nStopIndex; ++
nPos )
156 pElements[
nPos] = 0.0;
161 case typelib_TypeClass_DOUBLE:
164 pSeq =
reallocSeq( pSeq,
sizeof(
double), nAlloc );
167 double * pElements =
reinterpret_cast<double *
>(pSeq->elements);
168 for ( sal_Int32
nPos = nStartIndex;
nPos < nStopIndex; ++
nPos )
170 pElements[
nPos] = 0.0;
175 case typelib_TypeClass_STRING:
178 pSeq =
reallocSeq( pSeq,
sizeof(rtl_uString *), nAlloc );
181 rtl_uString ** pElements =
reinterpret_cast<rtl_uString **
>(pSeq->elements);
182 for ( sal_Int32
nPos = nStartIndex;
nPos < nStopIndex; ++
nPos )
184 pElements[
nPos] =
nullptr;
185 rtl_uString_new( &pElements[
nPos] );
190 case typelib_TypeClass_TYPE:
195 pSeq,
sizeof(typelib_TypeDescriptionReference *), nAlloc );
199 typelib_TypeDescriptionReference ** pElements =
200 reinterpret_cast<typelib_TypeDescriptionReference **
>(pSeq->elements);
201 for ( sal_Int32
nPos = nStartIndex;
nPos < nStopIndex; ++
nPos )
208 case typelib_TypeClass_ANY:
214 uno_Any * pElements =
reinterpret_cast<uno_Any *
>(pSeq->elements);
215 for ( sal_Int32
nPos = nStartIndex;
nPos < nStopIndex; ++
nPos )
222 case typelib_TypeClass_ENUM:
225 pSeq =
reallocSeq( pSeq,
sizeof(sal_Int32), nAlloc );
229 TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
231 reinterpret_cast<typelib_EnumTypeDescription *
>(
232 pElementTypeDescr)->nDefaultEnumValue;
233 TYPELIB_DANGER_RELEASE( pElementTypeDescr );
235 sal_Int32 * pElements =
reinterpret_cast<sal_Int32 *
>(pSeq->elements);
236 for ( sal_Int32
nPos = nStartIndex;
nPos < nStopIndex; ++
nPos )
238 pElements[
nPos] = eEnum;
243 case typelib_TypeClass_STRUCT:
244 case typelib_TypeClass_EXCEPTION:
247 TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
248 sal_Int32 nElementSize = pElementTypeDescr->nSize;
251 pSeq =
reallocSeq( pSeq, nElementSize, nAlloc );
254 char * pElements = pSeq->elements;
255 for ( sal_Int32
nPos = nStartIndex;
nPos < nStopIndex; ++
nPos )
258 pElements + (nElementSize *
nPos),
259 reinterpret_cast<typelib_CompoundTypeDescription *
>(pElementTypeDescr) );
263 TYPELIB_DANGER_RELEASE( pElementTypeDescr );
266 case typelib_TypeClass_SEQUENCE:
271 pSeq =
reallocSeq(pSeq,
sizeof(uno_Sequence*), nAlloc);
275 uno_Sequence ** pElements =
276 reinterpret_cast<uno_Sequence **
>(pSeq->elements);
277 for ( sal_Int32
nPos = nStartIndex;
nPos < nStopIndex; ++
nPos )
284 case typelib_TypeClass_INTERFACE:
286 pSeq =
reallocSeq( pSeq,
sizeof(
void *), nAlloc );
290 pSeq->elements + (
sizeof(
void *) * nStartIndex),
292 sizeof(
void *) * (nStopIndex - nStartIndex) );
296 OSL_FAIL(
"### unexpected element type!" );
303 OSL_ASSERT( nAlloc >= 0 );
312 uno_Sequence ** ppSeq,
void * pSourceElements,
313 typelib_TypeDescriptionReference * pElementType,
314 sal_Int32 nStopIndex,
315 uno_AcquireFunc acquire,
318 uno_Sequence * pSeq = *ppSeq;
319 switch (pElementType->eTypeClass)
321 case typelib_TypeClass_CHAR:
331 case typelib_TypeClass_BOOLEAN:
341 case typelib_TypeClass_BYTE:
351 case typelib_TypeClass_SHORT:
352 case typelib_TypeClass_UNSIGNED_SHORT:
353 pSeq =
reallocSeq( pSeq,
sizeof(sal_Int16), nAlloc );
359 sizeof(sal_Int16) * nStopIndex );
362 case typelib_TypeClass_LONG:
363 case typelib_TypeClass_UNSIGNED_LONG:
364 pSeq =
reallocSeq( pSeq,
sizeof(sal_Int32), nAlloc );
370 sizeof(sal_Int32) * nStopIndex );
373 case typelib_TypeClass_HYPER:
374 case typelib_TypeClass_UNSIGNED_HYPER:
375 pSeq =
reallocSeq( pSeq,
sizeof(sal_Int64), nAlloc );
381 sizeof(sal_Int64) * nStopIndex );
384 case typelib_TypeClass_FLOAT:
385 pSeq =
reallocSeq( pSeq,
sizeof(
float), nAlloc );
391 sizeof(
float) * nStopIndex );
394 case typelib_TypeClass_DOUBLE:
395 pSeq =
reallocSeq( pSeq,
sizeof(
double), nAlloc );
401 sizeof(
double) * nStopIndex );
404 case typelib_TypeClass_ENUM:
405 pSeq =
reallocSeq( pSeq,
sizeof(sal_Int32), nAlloc );
411 sizeof(sal_Int32) * nStopIndex );
414 case typelib_TypeClass_STRING:
416 pSeq =
reallocSeq( pSeq,
sizeof(rtl_uString *), nAlloc );
419 rtl_uString ** pDestElements =
reinterpret_cast<rtl_uString **
>(pSeq->elements);
424 ::rtl_uString_acquire(
425 static_cast<rtl_uString **
>(pSourceElements)[
nPos] );
426 pDestElements[
nPos] =
static_cast<rtl_uString **
>(pSourceElements)[
nPos];
431 case typelib_TypeClass_TYPE:
434 pSeq,
sizeof(typelib_TypeDescriptionReference *), nAlloc );
437 typelib_TypeDescriptionReference ** pDestElements =
438 reinterpret_cast<typelib_TypeDescriptionReference **
>(pSeq->elements);
442 static_cast<typelib_TypeDescriptionReference **
>(
443 pSourceElements)[
nPos] );
444 pDestElements[
nPos] =
445 static_cast<typelib_TypeDescriptionReference **
>(
446 pSourceElements)[
nPos];
451 case typelib_TypeClass_ANY:
456 uno_Any * pDestElements =
reinterpret_cast<uno_Any *
>(pSeq->elements);
461 &pDestElements[
nPos],
463 pSource->pType,
nullptr,
469 case typelib_TypeClass_STRUCT:
470 case typelib_TypeClass_EXCEPTION:
473 TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
474 sal_Int32 nElementSize = pElementTypeDescr->nSize;
476 pSeq =
reallocSeq( pSeq, nElementSize, nAlloc );
479 char * pDestElements = pSeq->elements;
481 typelib_CompoundTypeDescription * pTypeDescr =
482 reinterpret_cast<typelib_CompoundTypeDescription *
>(pElementTypeDescr);
486 pDestElements + (nElementSize *
nPos);
488 static_cast<char *
>(pSourceElements) + (nElementSize *
nPos);
490 if (pTypeDescr->pBaseTypeDescription)
495 pTypeDescr->pBaseTypeDescription, acquire,
nullptr );
499 typelib_TypeDescriptionReference ** ppTypeRefs =
500 pTypeDescr->ppTypeRefs;
501 sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
502 sal_Int32 nDescr = pTypeDescr->nMembers;
507 pDest + pMemberOffsets[nDescr],
508 pSource + pMemberOffsets[nDescr],
509 ppTypeRefs[nDescr], acquire );
514 TYPELIB_DANGER_RELEASE( pElementTypeDescr );
517 case typelib_TypeClass_SEQUENCE:
520 pSeq =
reallocSeq(pSeq,
sizeof(uno_Sequence*), nAlloc);
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);
531 static_cast<uno_Sequence **
>(pSourceElements)[
nPos],
532 pSeqElementType, acquire,
nullptr );
533 OSL_ASSERT( pNew !=
nullptr );
536 pDestElements[
nPos ] = pNew;
538 TYPELIB_DANGER_RELEASE( pElementTypeDescr );
542 case typelib_TypeClass_INTERFACE:
544 pSeq =
reallocSeq( pSeq,
sizeof(
void *), nAlloc );
547 void ** pDestElements =
reinterpret_cast<void **
>(pSeq->elements);
550 pDestElements[
nPos] =
static_cast<void **
>(pSourceElements)[
nPos];
557 OSL_FAIL(
"### unexpected element type!" );
572 uno_Sequence ** ppSequence,
573 typelib_TypeDescriptionReference * pElementType,
575 uno_AcquireFunc acquire, uno_ReleaseFunc release )
578 uno_Sequence * pSeq = *ppSequence;
581 if (pSeq->nRefCount > 1 ||
583 typelib_TypeClass_ANY == pElementType->eTypeClass ||
584 typelib_TypeClass_STRUCT == pElementType->eTypeClass ||
585 typelib_TypeClass_EXCEPTION == pElementType->eTypeClass)
588 uno_Sequence * pNew =
nullptr;
591 sal_Int32 nCopy = (nRest > 0 ?
nElements : nSize);
596 &pNew, pSeq->elements, pElementType,
600 if (ret && nRest > 0)
605 nCopy >= 0 ? -1 : nSize );
611 if (osl_atomic_decrement( &pSeq->nRefCount ) == 0)
616 pSeq->elements, pElementType,
626 OSL_ASSERT( pSeq->nRefCount == 1 );
630 ppSequence, pElementType,
637 pSeq->elements, pElementType,
641 *ppSequence =
reallocSeq( pSeq, nElementSize, nSize );
642 OSL_ASSERT( *ppSequence !=
nullptr );
643 ret = (*ppSequence !=
nullptr);
656 uno_Sequence ** ppSequence, typelib_TypeDescriptionReference * pType,
657 void * pElements, sal_Int32 len,
658 uno_AcquireFunc acquire )
666 TYPELIB_DANGER_GET( &pTypeDescr, pType );
668 typelib_TypeDescriptionReference * pElementType =
669 reinterpret_cast<typelib_IndirectTypeDescription *
>(pTypeDescr)->pType;
671 *ppSequence =
nullptr;
672 if (pElements ==
nullptr)
675 ppSequence, pElementType,
682 ppSequence, pElements, pElementType,
687 TYPELIB_DANGER_RELEASE( pTypeDescr );
695 OSL_ASSERT( (*ppSequence !=
nullptr) == ret );
702 void * pElements, sal_Int32 len,
703 uno_AcquireFunc acquire )
709 typelib_TypeDescriptionReference * pElementType =
710 reinterpret_cast<typelib_IndirectTypeDescription *
>(pTypeDescr)->pType;
712 *ppSequence =
nullptr;
713 if (pElements ==
nullptr)
716 ppSequence, pElementType,
723 ppSequence, pElements, pElementType,
734 OSL_ASSERT( (*ppSequence !=
nullptr) == ret );
740 uno_Sequence ** ppSequence, typelib_TypeDescriptionReference * pType,
741 sal_Int32 nSize, uno_AcquireFunc acquire, uno_ReleaseFunc release )
744 assert(ppSequence &&
"### null ptr!");
745 assert(nSize >= 0 &&
"### new size must be at least 0!");
748 if (nSize != (*ppSequence)->nElements)
751 TYPELIB_DANGER_GET( &pTypeDescr, pType );
753 ppSequence,
reinterpret_cast<typelib_IndirectTypeDescription *
>(pTypeDescr)->pType,
754 nSize, acquire, release );
755 TYPELIB_DANGER_RELEASE( pTypeDescr );
763 sal_Int32 nSize, uno_AcquireFunc acquire, uno_ReleaseFunc release )
766 OSL_ENSURE( ppSequence,
"### null ptr!" );
767 OSL_ENSURE( nSize >= 0,
"### new size must be at least 0!" );
770 if (nSize != (*ppSequence)->nElements)
773 ppSequence,
reinterpret_cast<typelib_IndirectTypeDescription *
>(pTypeDescr)->pType,
774 nSize, acquire, release );
781 uno_Sequence ** ppSequence,
782 typelib_TypeDescriptionReference * pType,
783 uno_AcquireFunc acquire, uno_ReleaseFunc release )
786 OSL_ENSURE( ppSequence,
"### null ptr!" );
788 uno_Sequence * pSequence = *ppSequence;
789 if (pSequence->nRefCount > 1)
791 uno_Sequence * pNew =
nullptr;
792 if (pSequence->nElements > 0)
795 TYPELIB_DANGER_GET( &pTypeDescr, pType );
798 &pNew, pSequence->elements,
799 reinterpret_cast<typelib_IndirectTypeDescription *
>(pTypeDescr)->pType,
800 pSequence->nElements, acquire,
801 pSequence->nElements );
808 TYPELIB_DANGER_RELEASE( pTypeDescr );
813 ret = (pNew !=
nullptr);
817 if (osl_atomic_decrement( &pSequence->nRefCount ) == 0)
818 std::free( pSequence );
828 uno_Sequence ** ppSequence,
830 uno_AcquireFunc acquire, uno_ReleaseFunc release )
833 OSL_ENSURE( ppSequence,
"### null ptr!" );
835 uno_Sequence * pSequence = *ppSequence;
836 if (pSequence->nRefCount > 1)
838 uno_Sequence * pNew =
nullptr;
839 if (pSequence->nElements > 0)
842 &pNew, pSequence->elements,
843 reinterpret_cast<typelib_IndirectTypeDescription *
>(pTypeDescr)->pType,
844 pSequence->nElements, acquire,
845 pSequence->nElements );
849 pSequence, pTypeDescr->pWeakRef, pTypeDescr, release );
856 ret = (pNew !=
nullptr);
860 if (osl_atomic_decrement( &pSequence->nRefCount ) == 0)
861 std::free( pSequence );
872 uno_Sequence ** ppDest,
873 uno_Sequence * pSource,
875 uno_ReleaseFunc release )
878 if (*ppDest != pSource)
880 osl_atomic_increment( &pSource->nRefCount );
888 uno_Sequence ** ppDest,
889 uno_Sequence * pSource,
890 typelib_TypeDescriptionReference * pType,
891 uno_ReleaseFunc release )
894 if (*ppDest != pSource)
896 osl_atomic_increment( &pSource->nRefCount );
903 uno_Sequence * sequence, typelib_TypeDescriptionReference * type,
904 uno_ReleaseFunc release)
void SAL_CALL uno_type_copyData(void *pDest, void *pSource, typelib_TypeDescriptionReference *pType, uno_AcquireFunc acquire) SAL_THROW_EXTERN_C()
struct _typelib_TypeDescription typelib_TypeDescription
void _acquire(void *p, uno_AcquireFunc acquire)
uno_Sequence * allocSeq(sal_Int32 nElementSize, sal_Int32 nElements)
void _defaultConstructStruct(void *pMem, typelib_CompoundTypeDescription *pTypeDescr)
void _copyConstructStruct(void *pDest, void *pSource, typelib_CompoundTypeDescription *pTypeDescr, uno_AcquireFunc acquire, uno_Mapping *mapping)
typelib_TypeDescriptionReference * _getVoidType()
void _copyConstructAny(uno_Any *pDestAny, void *pSource, typelib_TypeDescriptionReference *pType, typelib_TypeDescription *pTypeDescr, uno_AcquireFunc acquire, uno_Mapping *mapping)
static bool icopyConstructFromElements(uno_Sequence **ppSeq, void *pSourceElements, typelib_TypeDescriptionReference *pElementType, sal_Int32 nStopIndex, uno_AcquireFunc acquire, sal_Int32 nAlloc)
sal_Int32 idestructElements(void *pElements, typelib_TypeDescriptionReference *pElementType, sal_Int32 nStartIndex, sal_Int32 nStopIndex, uno_ReleaseFunc release)
void idestructSequence(uno_Sequence *pSeq, typelib_TypeDescriptionReference *pType, typelib_TypeDescription *pTypeDescr, uno_ReleaseFunc release)
static bool idefaultConstructElements(uno_Sequence **ppSeq, typelib_TypeDescriptionReference *pElementType, sal_Int32 nStartIndex, sal_Int32 nStopIndex, sal_Int32 nAlloc)
void idestroySequence(uno_Sequence *pSeq, typelib_TypeDescriptionReference *pType, typelib_TypeDescription *pTypeDescr, uno_ReleaseFunc release)
void CONSTRUCT_EMPTY_ANY(uno_Any *pAny)
static uno_Sequence * reallocSeq(uno_Sequence *pReallocate, std::size_t nElementSize, sal_Int32 nElements)
static bool ireallocSequence(uno_Sequence **ppSequence, typelib_TypeDescriptionReference *pElementType, sal_Int32 nSize, uno_AcquireFunc acquire, uno_ReleaseFunc release)
sal_uInt32 calcSeqMemSize(sal_Int32 nElementSize, sal_Int32 nElements)
uno_Sequence * createEmptySequence()
uno_Sequence * icopyConstructSequence(uno_Sequence *pSource, typelib_TypeDescriptionReference *pElementType, uno_AcquireFunc acquire, uno_Mapping *mapping)
#define TYPE_ACQUIRE(pType)
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()
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()
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()
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()
sal_Bool SAL_CALL uno_type_sequence_reference2One(uno_Sequence **ppSequence, typelib_TypeDescriptionReference *pType, uno_AcquireFunc acquire, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
void SAL_CALL uno_type_sequence_assign(uno_Sequence **ppDest, uno_Sequence *pSource, typelib_TypeDescriptionReference *pType, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
void uno_type_sequence_destroy(uno_Sequence *sequence, typelib_TypeDescriptionReference *type, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
void SAL_CALL uno_sequence_assign(uno_Sequence **ppDest, uno_Sequence *pSource, typelib_TypeDescription *pTypeDescr, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
sal_Bool SAL_CALL uno_sequence_reference2One(uno_Sequence **ppSequence, typelib_TypeDescription *pTypeDescr, uno_AcquireFunc acquire, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
#define SAL_THROW_EXTERN_C()