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 .
22 #include <rtl/alloc.h>
23 #include <osl/diagnose.h>
24 #include <osl/interlck.h>
25 #include <typelib/typedescription.h>
27 #include <uno/dispatcher.h>
28 #include <uno/sequence2.h>
40 //------------------------------------------------------------------------------
41 static inline uno_Sequence
* reallocSeq(
42 uno_Sequence
* pReallocate
, sal_Size nElementSize
, sal_Int32 nElements
)
44 OSL_ASSERT( nElements
>= 0 );
45 uno_Sequence
* pNew
= 0;
46 sal_uInt32 nSize
= calcSeqMemSize( nElementSize
, nElements
);
51 pNew
= (uno_Sequence
*) rtl_allocateMemory( nSize
);
55 pNew
= (uno_Sequence
*) rtl_reallocateMemory( pReallocate
, nSize
);
61 pNew
->nElements
= nElements
;
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
74 uno_Sequence
* pSeq
= *ppSeq
;
75 switch (pElementType
->eTypeClass
)
77 case typelib_TypeClass_CHAR
:
79 pSeq
= reallocSeq( pSeq
, sizeof(sal_Unicode
), nAlloc
);
83 pSeq
->elements
+ (sizeof(sal_Unicode
) * nStartIndex
),
85 sizeof(sal_Unicode
) * (nStopIndex
- nStartIndex
) );
88 case typelib_TypeClass_BOOLEAN
:
90 pSeq
= reallocSeq( pSeq
, sizeof(sal_Bool
), nAlloc
);
94 pSeq
->elements
+ (sizeof(sal_Bool
) * nStartIndex
),
96 sizeof(sal_Bool
) * (nStopIndex
- nStartIndex
) );
99 case typelib_TypeClass_BYTE
:
101 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int8
), nAlloc
);
105 pSeq
->elements
+ (sizeof(sal_Int8
) * nStartIndex
),
107 sizeof(sal_Int8
) * (nStopIndex
- nStartIndex
) );
110 case typelib_TypeClass_SHORT
:
111 case typelib_TypeClass_UNSIGNED_SHORT
:
113 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int16
), nAlloc
);
117 pSeq
->elements
+ (sizeof(sal_Int16
) * nStartIndex
),
119 sizeof(sal_Int16
) * (nStopIndex
- nStartIndex
) );
122 case typelib_TypeClass_LONG
:
123 case typelib_TypeClass_UNSIGNED_LONG
:
125 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
129 pSeq
->elements
+ (sizeof(sal_Int32
) * nStartIndex
),
131 sizeof(sal_Int32
) * (nStopIndex
- nStartIndex
) );
134 case typelib_TypeClass_HYPER
:
135 case typelib_TypeClass_UNSIGNED_HYPER
:
137 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int64
), nAlloc
);
141 pSeq
->elements
+ (sizeof(sal_Int64
) * nStartIndex
),
143 sizeof(sal_Int64
) * (nStopIndex
- nStartIndex
) );
146 case typelib_TypeClass_FLOAT
:
149 pSeq
= reallocSeq( pSeq
, sizeof(float), nAlloc
);
152 float * pElements
= (float *) pSeq
->elements
;
153 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
155 pElements
[nPos
] = 0.0;
160 case typelib_TypeClass_DOUBLE
:
163 pSeq
= reallocSeq( pSeq
, sizeof(double), nAlloc
);
166 double * pElements
= (double *) pSeq
->elements
;
167 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
169 pElements
[nPos
] = 0.0;
174 case typelib_TypeClass_STRING
:
177 pSeq
= reallocSeq( pSeq
, sizeof(rtl_uString
*), nAlloc
);
180 rtl_uString
** pElements
= (rtl_uString
**) pSeq
->elements
;
181 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
184 rtl_uString_new( &pElements
[nPos
] );
189 case typelib_TypeClass_TYPE
:
194 pSeq
, sizeof(typelib_TypeDescriptionReference
*), nAlloc
);
198 typelib_TypeDescriptionReference
** pElements
=
199 (typelib_TypeDescriptionReference
**) pSeq
->elements
;
200 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
202 pElements
[nPos
] = _getVoidType();
207 case typelib_TypeClass_ANY
:
210 pSeq
= reallocSeq( pSeq
, sizeof(uno_Any
), nAlloc
);
213 uno_Any
* pElements
= (uno_Any
*) pSeq
->elements
;
214 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
216 CONSTRUCT_EMPTY_ANY( &pElements
[nPos
] );
221 case typelib_TypeClass_ENUM
:
224 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
227 typelib_TypeDescription
* pElementTypeDescr
= 0;
228 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
230 ((typelib_EnumTypeDescription
*)
231 pElementTypeDescr
)->nDefaultEnumValue
;
232 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
234 sal_Int32
* pElements
= (sal_Int32
*) pSeq
->elements
;
235 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
237 pElements
[nPos
] = eEnum
;
242 case typelib_TypeClass_STRUCT
:
243 case typelib_TypeClass_EXCEPTION
:
245 typelib_TypeDescription
* pElementTypeDescr
= 0;
246 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
247 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
250 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
253 char * pElements
= pSeq
->elements
;
254 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
256 _defaultConstructStruct(
257 pElements
+ (nElementSize
* nPos
),
258 (typelib_CompoundTypeDescription
*)pElementTypeDescr
);
262 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
265 case typelib_TypeClass_ARRAY
:
267 typelib_TypeDescription
* pElementTypeDescr
= 0;
268 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
269 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
272 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
275 char * pElements
= pSeq
->elements
;
276 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
278 _defaultConstructArray(
279 pElements
+ (nElementSize
* nPos
),
280 (typelib_ArrayTypeDescription
*)pElementTypeDescr
);
284 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
287 case typelib_TypeClass_UNION
:
289 typelib_TypeDescription
* pElementTypeDescr
= 0;
290 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
291 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
294 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
297 sal_Int32 nValueOffset
=
298 ((typelib_UnionTypeDescription
*)
299 pElementTypeDescr
)->nValueOffset
;
300 sal_Int64 nDefaultDiscr
=
301 ((typelib_UnionTypeDescription
*)
302 pElementTypeDescr
)->nDefaultDiscriminant
;
304 typelib_TypeDescription
* pDefaultTypeDescr
= 0;
307 ((typelib_UnionTypeDescription
*)
308 pElementTypeDescr
)->pDefaultTypeRef
);
310 char * pElements
= pSeq
->elements
;
311 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
313 char * pMem
= pElements
+ (nElementSize
* nPos
);
315 (char *)pMem
+ nValueOffset
, pDefaultTypeDescr
);
316 *(sal_Int64
*)pMem
= nDefaultDiscr
;
318 TYPELIB_DANGER_RELEASE( pDefaultTypeDescr
);
321 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
324 case typelib_TypeClass_SEQUENCE
:
327 pSeq
= reallocSeq( pSeq
, sizeof(uno_Sequence
*), nAlloc
);
330 uno_Sequence
** pElements
=
331 (uno_Sequence
**) pSeq
->elements
;
332 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
334 pElements
[nPos
] = createEmptySequence();
339 case typelib_TypeClass_INTERFACE
: // either C++ or C-UNO interface
341 pSeq
= reallocSeq( pSeq
, sizeof(void *), nAlloc
);
345 pSeq
->elements
+ (sizeof(void *) * nStartIndex
),
347 sizeof(void *) * (nStopIndex
- nStartIndex
) );
351 OSL_FAIL( "### unexpected element type!" );
358 OSL_ASSERT( nAlloc
>= 0 ); // must have been an allocation failure
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
376 uno_Sequence
* pSeq
= *ppSeq
;
377 switch (pElementType
->eTypeClass
)
379 case typelib_TypeClass_CHAR
:
381 pSeq
= reallocSeq( pSeq
, sizeof(sal_Unicode
), nAlloc
);
385 pSeq
->elements
+ (sizeof(sal_Unicode
) * nStartIndex
),
386 (char *)pSourceElements
+ (sizeof(sal_Unicode
) * nStartIndex
),
387 sizeof(sal_Unicode
) * (nStopIndex
- nStartIndex
) );
390 case typelib_TypeClass_BOOLEAN
:
392 pSeq
= reallocSeq( pSeq
, sizeof(sal_Bool
), nAlloc
);
396 pSeq
->elements
+ (sizeof(sal_Bool
) * nStartIndex
),
397 (char *)pSourceElements
+ (sizeof(sal_Bool
) * nStartIndex
),
398 sizeof(sal_Bool
) * (nStopIndex
- nStartIndex
) );
401 case typelib_TypeClass_BYTE
:
403 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int8
), nAlloc
);
407 pSeq
->elements
+ (sizeof(sal_Int8
) * nStartIndex
),
408 (char *)pSourceElements
+ (sizeof(sal_Int8
) * nStartIndex
),
409 sizeof(sal_Int8
) * (nStopIndex
- nStartIndex
) );
412 case typelib_TypeClass_SHORT
:
413 case typelib_TypeClass_UNSIGNED_SHORT
:
415 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int16
), nAlloc
);
419 pSeq
->elements
+ (sizeof(sal_Int16
) * nStartIndex
),
420 (char *)pSourceElements
+ (sizeof(sal_Int16
) * nStartIndex
),
421 sizeof(sal_Int16
) * (nStopIndex
- nStartIndex
) );
424 case typelib_TypeClass_LONG
:
425 case typelib_TypeClass_UNSIGNED_LONG
:
427 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
431 pSeq
->elements
+ (sizeof(sal_Int32
) * nStartIndex
),
432 (char *)pSourceElements
+ (sizeof(sal_Int32
) * nStartIndex
),
433 sizeof(sal_Int32
) * (nStopIndex
- nStartIndex
) );
436 case typelib_TypeClass_HYPER
:
437 case typelib_TypeClass_UNSIGNED_HYPER
:
439 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int64
), nAlloc
);
443 pSeq
->elements
+ (sizeof(sal_Int64
) * nStartIndex
),
444 (char *)pSourceElements
+ (sizeof(sal_Int64
) * nStartIndex
),
445 sizeof(sal_Int64
) * (nStopIndex
- nStartIndex
) );
448 case typelib_TypeClass_FLOAT
:
450 pSeq
= reallocSeq( pSeq
, sizeof(float), nAlloc
);
454 pSeq
->elements
+ (sizeof(float) * nStartIndex
),
455 (char *)pSourceElements
+ (sizeof(float) * nStartIndex
),
456 sizeof(float) * (nStopIndex
- nStartIndex
) );
459 case typelib_TypeClass_DOUBLE
:
461 pSeq
= reallocSeq( pSeq
, sizeof(double), nAlloc
);
465 pSeq
->elements
+ (sizeof(double) * nStartIndex
),
466 (char *)pSourceElements
+ (sizeof(double) * nStartIndex
),
467 sizeof(double) * (nStopIndex
- nStartIndex
) );
470 case typelib_TypeClass_ENUM
:
472 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
476 pSeq
->elements
+ (sizeof(sal_Int32
) * nStartIndex
),
477 (char *)pSourceElements
+ (sizeof(sal_Int32
) * nStartIndex
),
478 sizeof(sal_Int32
) * (nStopIndex
- nStartIndex
) );
481 case typelib_TypeClass_STRING
:
484 pSeq
= reallocSeq( pSeq
, sizeof(rtl_uString
*), nAlloc
);
487 rtl_uString
** pDestElements
= (rtl_uString
**) pSeq
->elements
;
488 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
490 ::rtl_uString_acquire(
491 ((rtl_uString
**)pSourceElements
)[nPos
] );
492 pDestElements
[nPos
] = ((rtl_uString
**)pSourceElements
)[nPos
];
497 case typelib_TypeClass_TYPE
:
502 pSeq
, sizeof(typelib_TypeDescriptionReference
*), nAlloc
);
506 typelib_TypeDescriptionReference
** pDestElements
=
507 (typelib_TypeDescriptionReference
**) pSeq
->elements
;
508 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
511 ((typelib_TypeDescriptionReference
**)
512 pSourceElements
)[nPos
] );
513 pDestElements
[nPos
] =
514 ((typelib_TypeDescriptionReference
**)
515 pSourceElements
)[nPos
];
520 case typelib_TypeClass_ANY
:
523 pSeq
= reallocSeq( pSeq
, sizeof(uno_Any
), nAlloc
);
526 uno_Any
* pDestElements
= (uno_Any
*) pSeq
->elements
;
527 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
529 uno_Any
* pSource
= (uno_Any
*)pSourceElements
+ nPos
;
531 &pDestElements
[nPos
],
539 case typelib_TypeClass_STRUCT
:
540 case typelib_TypeClass_EXCEPTION
:
542 typelib_TypeDescription
* pElementTypeDescr
= 0;
543 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
544 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
547 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
550 char * pDestElements
= pSeq
->elements
;
552 typelib_CompoundTypeDescription
* pTypeDescr
=
553 (typelib_CompoundTypeDescription
*)pElementTypeDescr
;
554 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
557 pDestElements
+ (nElementSize
* nPos
);
559 (char *)pSourceElements
+ (nElementSize
* nPos
);
561 if (pTypeDescr
->pBaseTypeDescription
)
564 _copyConstructStruct(
566 pTypeDescr
->pBaseTypeDescription
, acquire
, 0 );
570 typelib_TypeDescriptionReference
** ppTypeRefs
=
571 pTypeDescr
->ppTypeRefs
;
572 sal_Int32
* pMemberOffsets
= pTypeDescr
->pMemberOffsets
;
573 sal_Int32 nDescr
= pTypeDescr
->nMembers
;
578 pDest
+ pMemberOffsets
[nDescr
],
579 pSource
+ pMemberOffsets
[nDescr
],
580 ppTypeRefs
[nDescr
], acquire
);
585 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
588 case typelib_TypeClass_UNION
:
590 typelib_TypeDescription
* pElementTypeDescr
= 0;
591 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
592 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
595 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
598 char * pDestElements
= pSeq
->elements
;
600 sal_Int32 nValueOffset
=
601 ((typelib_UnionTypeDescription
*)
602 pElementTypeDescr
)->nValueOffset
;
603 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
606 pDestElements
+ (nElementSize
* nPos
);
608 (char *)pSourceElements
+ (nElementSize
* nPos
);
610 typelib_TypeDescriptionReference
* pSetType
= _unionGetSetType(
611 pSource
, pElementTypeDescr
);
613 pDest
+ nValueOffset
,
614 pSource
+ nValueOffset
,
616 *(sal_Int64
*)pDest
= *(sal_Int64
*)pSource
;
617 typelib_typedescriptionreference_release( pSetType
);
621 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
624 case typelib_TypeClass_SEQUENCE
: // sequence of sequence
627 pSeq
= reallocSeq( pSeq
, sizeof(uno_Sequence
*), nAlloc
);
630 typelib_TypeDescription
* pElementTypeDescr
= 0;
631 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
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
)
637 uno_Sequence
* pNew
= icopyConstructSequence(
638 ((uno_Sequence
**) pSourceElements
)[nPos
],
639 pSeqElementType
, acquire
, 0 );
640 OSL_ASSERT( pNew
!= 0 );
641 // ought never be a memory allocation problem,
642 // because of reference counted sequence handles
643 pDestElements
[ nPos
] = pNew
;
645 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
649 case typelib_TypeClass_INTERFACE
:
652 pSeq
= reallocSeq( pSeq
, sizeof(void *), nAlloc
);
655 void ** pDestElements
= (void **) pSeq
->elements
;
656 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
658 _acquire( pDestElements
[nPos
] =
659 ((void **)pSourceElements
)[nPos
], acquire
);
665 OSL_FAIL( "### unexpected element type!" );
672 OSL_ASSERT( nAlloc
>= 0 ); // must have been an allocation failure
682 //------------------------------------------------------------------------------
683 static inline bool ireallocSequence(
684 uno_Sequence
** ppSequence
,
685 typelib_TypeDescriptionReference
* pElementType
,
687 uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
690 uno_Sequence
* pSeq
= *ppSequence
;
691 sal_Int32 nElements
= pSeq
->nElements
;
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
)
699 // split sequence and construct new one from scratch
700 uno_Sequence
* pNew
= 0;
702 sal_Int32 nRest
= nSize
- nElements
;
703 sal_Int32 nCopy
= (nRest
> 0 ? nElements
: nSize
);
707 ret
= icopyConstructFromElements(
708 &pNew
, pSeq
->elements
, pElementType
,
710 nSize
); // alloc to nSize
712 if (ret
&& nRest
> 0)
714 ret
= idefaultConstructElements(
717 nCopy
>= 0 ? -1 /* no mem allocation */ : nSize
);
723 if (osl_atomic_decrement( &pSeq
->nRefCount
) == 0)
728 pSeq
->elements
, pElementType
,
729 0, nElements
, release
);
731 rtl_freeMemory( pSeq
);
738 OSL_ASSERT( pSeq
->nRefCount
== 1 );
739 if (nSize
> nElements
) // default construct the rest
741 ret
= idefaultConstructElements(
742 ppSequence
, pElementType
,
744 nSize
); // realloc to nSize
746 else // or destruct the rest and realloc mem
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 );
755 ret
= (*ppSequence
!= 0);
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
)
777 typelib_TypeDescription
* pTypeDescr
= 0;
778 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
780 typelib_TypeDescriptionReference
* pElementType
=
781 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
;
786 ret
= idefaultConstructElements(
787 ppSequence
, pElementType
,
789 len
); // alloc to len
793 ret
= icopyConstructFromElements(
794 ppSequence
, pElements
, pElementType
,
796 len
); // alloc to len
799 TYPELIB_DANGER_RELEASE( pTypeDescr
);
803 *ppSequence
= createEmptySequence();
807 OSL_ASSERT( (*ppSequence
!= 0) == ret
);
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
)
821 typelib_TypeDescriptionReference
* pElementType
=
822 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
;
827 ret
= idefaultConstructElements(
828 ppSequence
, pElementType
,
830 len
); // alloc to len
834 ret
= icopyConstructFromElements(
835 ppSequence
, pElements
, pElementType
,
837 len
); // alloc to len
842 *ppSequence
= createEmptySequence();
846 OSL_ASSERT( (*ppSequence
!= 0) == ret
);
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
)
856 OSL_ENSURE( ppSequence
, "### null ptr!" );
857 OSL_ENSURE( nSize
>= 0, "### new size must be at least 0!" );
860 if (nSize
!= (*ppSequence
)->nElements
)
862 typelib_TypeDescription
* pTypeDescr
= 0;
863 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
864 ret
= ireallocSequence(
865 ppSequence
, ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
866 nSize
, acquire
, release
);
867 TYPELIB_DANGER_RELEASE( pTypeDescr
);
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
)
878 OSL_ENSURE( ppSequence
, "### null ptr!" );
879 OSL_ENSURE( nSize
>= 0, "### new size must be at least 0!" );
882 if (nSize
!= (*ppSequence
)->nElements
)
884 ret
= ireallocSequence(
885 ppSequence
, ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
886 nSize
, acquire
, release
);
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
)
898 OSL_ENSURE( ppSequence
, "### null ptr!" );
900 uno_Sequence
* pSequence
= *ppSequence
;
901 if (pSequence
->nRefCount
> 1)
903 uno_Sequence
* pNew
= 0;
904 if (pSequence
->nElements
> 0)
906 typelib_TypeDescription
* pTypeDescr
= 0;
907 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
909 ret
= icopyConstructFromElements(
910 &pNew
, pSequence
->elements
,
911 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
912 0, pSequence
->nElements
, acquire
,
913 pSequence
->nElements
); // alloc nElements
916 idestructSequence( *ppSequence
, pType
, pTypeDescr
, release
);
920 TYPELIB_DANGER_RELEASE( pTypeDescr
);
924 pNew
= allocSeq( 0, 0 );
928 // easy destruction of empty sequence:
929 if (osl_atomic_decrement( &pSequence
->nRefCount
) == 0)
930 rtl_freeMemory( pSequence
);
938 //##############################################################################
939 sal_Bool SAL_CALL
uno_sequence_reference2One(
940 uno_Sequence
** ppSequence
,
941 typelib_TypeDescription
* pTypeDescr
,
942 uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
945 OSL_ENSURE( ppSequence
, "### null ptr!" );
947 uno_Sequence
* pSequence
= *ppSequence
;
948 if (pSequence
->nRefCount
> 1)
950 uno_Sequence
* pNew
= 0;
951 if (pSequence
->nElements
> 0)
953 ret
= icopyConstructFromElements(
954 &pNew
, pSequence
->elements
,
955 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
956 0, pSequence
->nElements
, acquire
,
957 pSequence
->nElements
); // alloc nElements
961 pSequence
, pTypeDescr
->pWeakRef
, pTypeDescr
, release
);
967 pNew
= allocSeq( 0, 0 );
971 // easy destruction of empty sequence:
972 if (osl_atomic_decrement( &pSequence
->nRefCount
) == 0)
973 rtl_freeMemory( pSequence
);
982 //##############################################################################
983 void SAL_CALL
uno_sequence_assign(
984 uno_Sequence
** ppDest
,
985 uno_Sequence
* pSource
,
986 typelib_TypeDescription
* pTypeDescr
,
987 uno_ReleaseFunc release
)
990 if (*ppDest
!= pSource
)
992 osl_atomic_increment( &pSource
->nRefCount
);
993 idestructSequence( *ppDest
, pTypeDescr
->pWeakRef
, pTypeDescr
, release
);
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()
1006 if (*ppDest
!= pSource
)
1008 osl_atomic_increment( &pSource
->nRefCount
);
1009 idestructSequence( *ppDest
, pType
, 0, release
);
1016 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */