1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sequence.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppu.hxx"
33 #include <rtl/memory.h>
34 #include <rtl/alloc.h>
35 #include <osl/diagnose.h>
36 #include <osl/interlck.h>
37 #include <typelib/typedescription.h>
39 #include <uno/dispatcher.h>
40 #include <uno/sequence2.h>
52 //------------------------------------------------------------------------------
53 static inline uno_Sequence
* reallocSeq(
54 uno_Sequence
* pReallocate
, sal_Size nElementSize
, sal_Int32 nElements
)
56 OSL_ASSERT( nElements
>= 0 );
57 uno_Sequence
* pNew
= 0;
58 sal_uInt32 nSize
= calcSeqMemSize( nElementSize
, nElements
);
63 pNew
= (uno_Sequence
*) rtl_allocateMemory( nSize
);
67 pNew
= (uno_Sequence
*) rtl_reallocateMemory( pReallocate
, nSize
);
73 pNew
->nElements
= nElements
;
79 //------------------------------------------------------------------------------
80 static inline bool idefaultConstructElements(
81 uno_Sequence
** ppSeq
,
82 typelib_TypeDescriptionReference
* pElementType
,
83 sal_Int32 nStartIndex
, sal_Int32 nStopIndex
,
84 sal_Int32 nAlloc
= -1 ) // >= 0 means (re)alloc memory for nAlloc elements
86 uno_Sequence
* pSeq
= *ppSeq
;
87 switch (pElementType
->eTypeClass
)
89 case typelib_TypeClass_CHAR
:
91 pSeq
= reallocSeq( pSeq
, sizeof(sal_Unicode
), nAlloc
);
95 pSeq
->elements
+ (sizeof(sal_Unicode
) * nStartIndex
),
96 sizeof(sal_Unicode
) * (nStopIndex
- nStartIndex
) );
99 case typelib_TypeClass_BOOLEAN
:
101 pSeq
= reallocSeq( pSeq
, sizeof(sal_Bool
), nAlloc
);
105 pSeq
->elements
+ (sizeof(sal_Bool
) * nStartIndex
),
106 sizeof(sal_Bool
) * (nStopIndex
- nStartIndex
) );
109 case typelib_TypeClass_BYTE
:
111 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int8
), nAlloc
);
115 pSeq
->elements
+ (sizeof(sal_Int8
) * nStartIndex
),
116 sizeof(sal_Int8
) * (nStopIndex
- nStartIndex
) );
119 case typelib_TypeClass_SHORT
:
120 case typelib_TypeClass_UNSIGNED_SHORT
:
122 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int16
), nAlloc
);
126 pSeq
->elements
+ (sizeof(sal_Int16
) * nStartIndex
),
127 sizeof(sal_Int16
) * (nStopIndex
- nStartIndex
) );
130 case typelib_TypeClass_LONG
:
131 case typelib_TypeClass_UNSIGNED_LONG
:
133 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
137 pSeq
->elements
+ (sizeof(sal_Int32
) * nStartIndex
),
138 sizeof(sal_Int32
) * (nStopIndex
- nStartIndex
) );
141 case typelib_TypeClass_HYPER
:
142 case typelib_TypeClass_UNSIGNED_HYPER
:
144 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int64
), nAlloc
);
148 pSeq
->elements
+ (sizeof(sal_Int64
) * nStartIndex
),
149 sizeof(sal_Int64
) * (nStopIndex
- nStartIndex
) );
152 case typelib_TypeClass_FLOAT
:
155 pSeq
= reallocSeq( pSeq
, sizeof(float), nAlloc
);
158 float * pElements
= (float *) pSeq
->elements
;
159 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
161 pElements
[nPos
] = 0.0;
166 case typelib_TypeClass_DOUBLE
:
169 pSeq
= reallocSeq( pSeq
, sizeof(double), nAlloc
);
172 double * pElements
= (double *) pSeq
->elements
;
173 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
175 pElements
[nPos
] = 0.0;
180 case typelib_TypeClass_STRING
:
183 pSeq
= reallocSeq( pSeq
, sizeof(rtl_uString
*), nAlloc
);
186 rtl_uString
** pElements
= (rtl_uString
**) pSeq
->elements
;
187 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
190 rtl_uString_new( &pElements
[nPos
] );
195 case typelib_TypeClass_TYPE
:
200 pSeq
, sizeof(typelib_TypeDescriptionReference
*), nAlloc
);
204 typelib_TypeDescriptionReference
** pElements
=
205 (typelib_TypeDescriptionReference
**) pSeq
->elements
;
206 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
208 pElements
[nPos
] = _getVoidType();
213 case typelib_TypeClass_ANY
:
216 pSeq
= reallocSeq( pSeq
, sizeof(uno_Any
), nAlloc
);
219 uno_Any
* pElements
= (uno_Any
*) pSeq
->elements
;
220 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
222 CONSTRUCT_EMPTY_ANY( &pElements
[nPos
] );
227 case typelib_TypeClass_ENUM
:
230 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
233 typelib_TypeDescription
* pElementTypeDescr
= 0;
234 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
236 ((typelib_EnumTypeDescription
*)
237 pElementTypeDescr
)->nDefaultEnumValue
;
238 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
240 sal_Int32
* pElements
= (sal_Int32
*) pSeq
->elements
;
241 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
243 pElements
[nPos
] = eEnum
;
248 case typelib_TypeClass_STRUCT
:
249 case typelib_TypeClass_EXCEPTION
:
251 typelib_TypeDescription
* pElementTypeDescr
= 0;
252 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
253 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
256 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
259 char * pElements
= pSeq
->elements
;
260 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
262 _defaultConstructStruct(
263 pElements
+ (nElementSize
* nPos
),
264 (typelib_CompoundTypeDescription
*)pElementTypeDescr
);
268 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
271 case typelib_TypeClass_ARRAY
:
273 typelib_TypeDescription
* pElementTypeDescr
= 0;
274 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
275 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
278 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
281 char * pElements
= pSeq
->elements
;
282 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
284 _defaultConstructArray(
285 pElements
+ (nElementSize
* nPos
),
286 (typelib_ArrayTypeDescription
*)pElementTypeDescr
);
290 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
293 case typelib_TypeClass_UNION
:
295 typelib_TypeDescription
* pElementTypeDescr
= 0;
296 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
297 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
300 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
303 sal_Int32 nValueOffset
=
304 ((typelib_UnionTypeDescription
*)
305 pElementTypeDescr
)->nValueOffset
;
306 sal_Int64 nDefaultDiscr
=
307 ((typelib_UnionTypeDescription
*)
308 pElementTypeDescr
)->nDefaultDiscriminant
;
310 typelib_TypeDescription
* pDefaultTypeDescr
= 0;
313 ((typelib_UnionTypeDescription
*)
314 pElementTypeDescr
)->pDefaultTypeRef
);
316 char * pElements
= pSeq
->elements
;
317 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
319 char * pMem
= pElements
+ (nElementSize
* nPos
);
321 (char *)pMem
+ nValueOffset
, pDefaultTypeDescr
);
322 *(sal_Int64
*)pMem
= nDefaultDiscr
;
324 TYPELIB_DANGER_RELEASE( pDefaultTypeDescr
);
327 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
330 case typelib_TypeClass_SEQUENCE
:
333 pSeq
= reallocSeq( pSeq
, sizeof(uno_Sequence
*), nAlloc
);
336 uno_Sequence
** pElements
=
337 (uno_Sequence
**) pSeq
->elements
;
338 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
340 pElements
[nPos
] = createEmptySequence();
345 case typelib_TypeClass_INTERFACE
: // either C++ or C-UNO interface
347 pSeq
= reallocSeq( pSeq
, sizeof(void *), nAlloc
);
351 pSeq
->elements
+ (sizeof(void *) * nStartIndex
),
352 sizeof(void *) * (nStopIndex
- nStartIndex
) );
356 OSL_ENSURE( 0, "### unexpected element type!" );
363 OSL_ASSERT( nAlloc
>= 0 ); // must have been an allocation failure
373 //------------------------------------------------------------------------------
374 static inline bool icopyConstructFromElements(
375 uno_Sequence
** ppSeq
, void * pSourceElements
,
376 typelib_TypeDescriptionReference
* pElementType
,
377 sal_Int32 nStartIndex
, sal_Int32 nStopIndex
,
378 uno_AcquireFunc acquire
,
379 sal_Int32 nAlloc
= -1 ) // >= 0 means (re)alloc memory for nAlloc elements
381 uno_Sequence
* pSeq
= *ppSeq
;
382 switch (pElementType
->eTypeClass
)
384 case typelib_TypeClass_CHAR
:
386 pSeq
= reallocSeq( pSeq
, sizeof(sal_Unicode
), nAlloc
);
390 pSeq
->elements
+ (sizeof(sal_Unicode
) * nStartIndex
),
391 (char *)pSourceElements
+ (sizeof(sal_Unicode
) * nStartIndex
),
392 sizeof(sal_Unicode
) * (nStopIndex
- nStartIndex
) );
395 case typelib_TypeClass_BOOLEAN
:
397 pSeq
= reallocSeq( pSeq
, sizeof(sal_Bool
), nAlloc
);
401 pSeq
->elements
+ (sizeof(sal_Bool
) * nStartIndex
),
402 (char *)pSourceElements
+ (sizeof(sal_Bool
) * nStartIndex
),
403 sizeof(sal_Bool
) * (nStopIndex
- nStartIndex
) );
406 case typelib_TypeClass_BYTE
:
408 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int8
), nAlloc
);
412 pSeq
->elements
+ (sizeof(sal_Int8
) * nStartIndex
),
413 (char *)pSourceElements
+ (sizeof(sal_Int8
) * nStartIndex
),
414 sizeof(sal_Int8
) * (nStopIndex
- nStartIndex
) );
417 case typelib_TypeClass_SHORT
:
418 case typelib_TypeClass_UNSIGNED_SHORT
:
420 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int16
), nAlloc
);
424 pSeq
->elements
+ (sizeof(sal_Int16
) * nStartIndex
),
425 (char *)pSourceElements
+ (sizeof(sal_Int16
) * nStartIndex
),
426 sizeof(sal_Int16
) * (nStopIndex
- nStartIndex
) );
429 case typelib_TypeClass_LONG
:
430 case typelib_TypeClass_UNSIGNED_LONG
:
432 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
436 pSeq
->elements
+ (sizeof(sal_Int32
) * nStartIndex
),
437 (char *)pSourceElements
+ (sizeof(sal_Int32
) * nStartIndex
),
438 sizeof(sal_Int32
) * (nStopIndex
- nStartIndex
) );
441 case typelib_TypeClass_HYPER
:
442 case typelib_TypeClass_UNSIGNED_HYPER
:
444 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int64
), nAlloc
);
448 pSeq
->elements
+ (sizeof(sal_Int64
) * nStartIndex
),
449 (char *)pSourceElements
+ (sizeof(sal_Int64
) * nStartIndex
),
450 sizeof(sal_Int64
) * (nStopIndex
- nStartIndex
) );
453 case typelib_TypeClass_FLOAT
:
455 pSeq
= reallocSeq( pSeq
, sizeof(float), nAlloc
);
459 pSeq
->elements
+ (sizeof(float) * nStartIndex
),
460 (char *)pSourceElements
+ (sizeof(float) * nStartIndex
),
461 sizeof(float) * (nStopIndex
- nStartIndex
) );
464 case typelib_TypeClass_DOUBLE
:
466 pSeq
= reallocSeq( pSeq
, sizeof(double), nAlloc
);
470 pSeq
->elements
+ (sizeof(double) * nStartIndex
),
471 (char *)pSourceElements
+ (sizeof(double) * nStartIndex
),
472 sizeof(double) * (nStopIndex
- nStartIndex
) );
475 case typelib_TypeClass_ENUM
:
477 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
481 pSeq
->elements
+ (sizeof(sal_Int32
) * nStartIndex
),
482 (char *)pSourceElements
+ (sizeof(sal_Int32
) * nStartIndex
),
483 sizeof(sal_Int32
) * (nStopIndex
- nStartIndex
) );
486 case typelib_TypeClass_STRING
:
489 pSeq
= reallocSeq( pSeq
, sizeof(rtl_uString
*), nAlloc
);
492 rtl_uString
** pDestElements
= (rtl_uString
**) pSeq
->elements
;
493 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
495 ::rtl_uString_acquire(
496 ((rtl_uString
**)pSourceElements
)[nPos
] );
497 pDestElements
[nPos
] = ((rtl_uString
**)pSourceElements
)[nPos
];
502 case typelib_TypeClass_TYPE
:
507 pSeq
, sizeof(typelib_TypeDescriptionReference
*), nAlloc
);
511 typelib_TypeDescriptionReference
** pDestElements
=
512 (typelib_TypeDescriptionReference
**) pSeq
->elements
;
513 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
516 ((typelib_TypeDescriptionReference
**)
517 pSourceElements
)[nPos
] );
518 pDestElements
[nPos
] =
519 ((typelib_TypeDescriptionReference
**)
520 pSourceElements
)[nPos
];
525 case typelib_TypeClass_ANY
:
528 pSeq
= reallocSeq( pSeq
, sizeof(uno_Any
), nAlloc
);
531 uno_Any
* pDestElements
= (uno_Any
*) pSeq
->elements
;
532 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
534 uno_Any
* pSource
= (uno_Any
*)pSourceElements
+ nPos
;
536 &pDestElements
[nPos
],
544 case typelib_TypeClass_STRUCT
:
545 case typelib_TypeClass_EXCEPTION
:
547 typelib_TypeDescription
* pElementTypeDescr
= 0;
548 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
549 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
552 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
555 char * pDestElements
= pSeq
->elements
;
557 typelib_CompoundTypeDescription
* pTypeDescr
=
558 (typelib_CompoundTypeDescription
*)pElementTypeDescr
;
559 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
562 pDestElements
+ (nElementSize
* nPos
);
564 (char *)pSourceElements
+ (nElementSize
* nPos
);
566 if (pTypeDescr
->pBaseTypeDescription
)
569 _copyConstructStruct(
571 pTypeDescr
->pBaseTypeDescription
, acquire
, 0 );
575 typelib_TypeDescriptionReference
** ppTypeRefs
=
576 pTypeDescr
->ppTypeRefs
;
577 sal_Int32
* pMemberOffsets
= pTypeDescr
->pMemberOffsets
;
578 sal_Int32 nDescr
= pTypeDescr
->nMembers
;
583 pDest
+ pMemberOffsets
[nDescr
],
584 pSource
+ pMemberOffsets
[nDescr
],
585 ppTypeRefs
[nDescr
], acquire
);
590 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
593 case typelib_TypeClass_UNION
:
595 typelib_TypeDescription
* pElementTypeDescr
= 0;
596 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
597 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
600 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
603 char * pDestElements
= pSeq
->elements
;
605 sal_Int32 nValueOffset
=
606 ((typelib_UnionTypeDescription
*)
607 pElementTypeDescr
)->nValueOffset
;
608 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
611 pDestElements
+ (nElementSize
* nPos
);
613 (char *)pSourceElements
+ (nElementSize
* nPos
);
615 typelib_TypeDescriptionReference
* pSetType
= _unionGetSetType(
616 pSource
, pElementTypeDescr
);
618 pDest
+ nValueOffset
,
619 pSource
+ nValueOffset
,
621 *(sal_Int64
*)pDest
= *(sal_Int64
*)pSource
;
622 typelib_typedescriptionreference_release( pSetType
);
626 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
629 case typelib_TypeClass_SEQUENCE
: // sequence of sequence
632 pSeq
= reallocSeq( pSeq
, sizeof(uno_Sequence
*), nAlloc
);
635 typelib_TypeDescription
* pElementTypeDescr
= 0;
636 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
637 typelib_TypeDescriptionReference
* pSeqElementType
=
638 ((typelib_IndirectTypeDescription
*) pElementTypeDescr
)->pType
;
639 uno_Sequence
** pDestElements
= (uno_Sequence
**) pSeq
->elements
;
640 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
642 uno_Sequence
* pNew
= icopyConstructSequence(
643 ((uno_Sequence
**) pSourceElements
)[nPos
],
644 pSeqElementType
, acquire
, 0 );
645 OSL_ASSERT( pNew
!= 0 );
646 // ought never be a memory allocation problem,
647 // because of reference counted sequence handles
648 pDestElements
[ nPos
] = pNew
;
650 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
654 case typelib_TypeClass_INTERFACE
:
657 pSeq
= reallocSeq( pSeq
, sizeof(void *), nAlloc
);
660 void ** pDestElements
= (void **) pSeq
->elements
;
661 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
663 _acquire( pDestElements
[nPos
] =
664 ((void **)pSourceElements
)[nPos
], acquire
);
670 OSL_ENSURE( 0, "### unexpected element type!" );
677 OSL_ASSERT( nAlloc
>= 0 ); // must have been an allocation failure
687 //------------------------------------------------------------------------------
688 static inline bool ireallocSequence(
689 uno_Sequence
** ppSequence
,
690 typelib_TypeDescriptionReference
* pElementType
,
692 uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
695 uno_Sequence
* pSeq
= *ppSequence
;
696 sal_Int32 nElements
= pSeq
->nElements
;
698 if (pSeq
->nRefCount
> 1 ||
699 // not mem-copyable elements?
700 typelib_TypeClass_ANY
== pElementType
->eTypeClass
||
701 typelib_TypeClass_STRUCT
== pElementType
->eTypeClass
||
702 typelib_TypeClass_EXCEPTION
== pElementType
->eTypeClass
)
704 // split sequence and construct new one from scratch
705 uno_Sequence
* pNew
= 0;
707 sal_Int32 nRest
= nSize
- nElements
;
708 sal_Int32 nCopy
= (nRest
> 0 ? nElements
: nSize
);
712 ret
= icopyConstructFromElements(
713 &pNew
, pSeq
->elements
, pElementType
,
715 nSize
); // alloc to nSize
717 if (ret
&& nRest
> 0)
719 ret
= idefaultConstructElements(
722 nCopy
>= 0 ? -1 /* no mem allocation */ : nSize
);
728 if (osl_decrementInterlockedCount( &pSeq
->nRefCount
) == 0)
733 pSeq
->elements
, pElementType
,
734 0, nElements
, release
);
736 rtl_freeMemory( pSeq
);
743 OSL_ASSERT( pSeq
->nRefCount
== 1 );
744 if (nSize
> nElements
) // default construct the rest
746 ret
= idefaultConstructElements(
747 ppSequence
, pElementType
,
749 nSize
); // realloc to nSize
751 else // or destruct the rest and realloc mem
753 sal_Int32 nElementSize
= idestructElements(
754 pSeq
->elements
, pElementType
,
755 nSize
, nElements
, release
);
756 // warning: it is assumed that the following will never fail,
757 // else this leads to a sequence null handle
758 *ppSequence
= reallocSeq( pSeq
, nElementSize
, nSize
);
759 OSL_ASSERT( *ppSequence
!= 0 );
760 ret
= (*ppSequence
!= 0);
772 //##############################################################################
773 sal_Bool SAL_CALL
uno_type_sequence_construct(
774 uno_Sequence
** ppSequence
, typelib_TypeDescriptionReference
* pType
,
775 void * pElements
, sal_Int32 len
,
776 uno_AcquireFunc acquire
)
782 typelib_TypeDescription
* pTypeDescr
= 0;
783 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
785 typelib_TypeDescriptionReference
* pElementType
=
786 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
;
791 ret
= idefaultConstructElements(
792 ppSequence
, pElementType
,
794 len
); // alloc to len
798 ret
= icopyConstructFromElements(
799 ppSequence
, pElements
, pElementType
,
801 len
); // alloc to len
804 TYPELIB_DANGER_RELEASE( pTypeDescr
);
808 *ppSequence
= createEmptySequence();
812 OSL_ASSERT( (*ppSequence
!= 0) == ret
);
816 //##############################################################################
817 sal_Bool SAL_CALL
uno_sequence_construct(
818 uno_Sequence
** ppSequence
, typelib_TypeDescription
* pTypeDescr
,
819 void * pElements
, sal_Int32 len
,
820 uno_AcquireFunc acquire
)
826 typelib_TypeDescriptionReference
* pElementType
=
827 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
;
832 ret
= idefaultConstructElements(
833 ppSequence
, pElementType
,
835 len
); // alloc to len
839 ret
= icopyConstructFromElements(
840 ppSequence
, pElements
, pElementType
,
842 len
); // alloc to len
847 *ppSequence
= createEmptySequence();
851 OSL_ASSERT( (*ppSequence
!= 0) == ret
);
855 //##############################################################################
856 sal_Bool SAL_CALL
uno_type_sequence_realloc(
857 uno_Sequence
** ppSequence
, typelib_TypeDescriptionReference
* pType
,
858 sal_Int32 nSize
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
861 OSL_ENSURE( ppSequence
, "### null ptr!" );
862 OSL_ENSURE( nSize
>= 0, "### new size must be at least 0!" );
865 if (nSize
!= (*ppSequence
)->nElements
)
867 typelib_TypeDescription
* pTypeDescr
= 0;
868 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
869 ret
= ireallocSequence(
870 ppSequence
, ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
871 nSize
, acquire
, release
);
872 TYPELIB_DANGER_RELEASE( pTypeDescr
);
877 //##############################################################################
878 sal_Bool SAL_CALL
uno_sequence_realloc(
879 uno_Sequence
** ppSequence
, typelib_TypeDescription
* pTypeDescr
,
880 sal_Int32 nSize
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
883 OSL_ENSURE( ppSequence
, "### null ptr!" );
884 OSL_ENSURE( nSize
>= 0, "### new size must be at least 0!" );
887 if (nSize
!= (*ppSequence
)->nElements
)
889 ret
= ireallocSequence(
890 ppSequence
, ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
891 nSize
, acquire
, release
);
896 //##############################################################################
897 sal_Bool SAL_CALL
uno_type_sequence_reference2One(
898 uno_Sequence
** ppSequence
,
899 typelib_TypeDescriptionReference
* pType
,
900 uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
903 OSL_ENSURE( ppSequence
, "### null ptr!" );
905 uno_Sequence
* pSequence
= *ppSequence
;
906 if (pSequence
->nRefCount
> 1)
908 uno_Sequence
* pNew
= 0;
909 if (pSequence
->nElements
> 0)
911 typelib_TypeDescription
* pTypeDescr
= 0;
912 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
914 ret
= icopyConstructFromElements(
915 &pNew
, pSequence
->elements
,
916 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
917 0, pSequence
->nElements
, acquire
,
918 pSequence
->nElements
); // alloc nElements
921 idestructSequence( *ppSequence
, pType
, pTypeDescr
, release
);
925 TYPELIB_DANGER_RELEASE( pTypeDescr
);
929 pNew
= allocSeq( 0, 0 );
933 // easy destruction of empty sequence:
934 if (osl_decrementInterlockedCount( &pSequence
->nRefCount
) == 0)
935 rtl_freeMemory( pSequence
);
943 //##############################################################################
944 sal_Bool SAL_CALL
uno_sequence_reference2One(
945 uno_Sequence
** ppSequence
,
946 typelib_TypeDescription
* pTypeDescr
,
947 uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
950 OSL_ENSURE( ppSequence
, "### null ptr!" );
952 uno_Sequence
* pSequence
= *ppSequence
;
953 if (pSequence
->nRefCount
> 1)
955 uno_Sequence
* pNew
= 0;
956 if (pSequence
->nElements
> 0)
958 ret
= icopyConstructFromElements(
959 &pNew
, pSequence
->elements
,
960 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
961 0, pSequence
->nElements
, acquire
,
962 pSequence
->nElements
); // alloc nElements
966 pSequence
, pTypeDescr
->pWeakRef
, pTypeDescr
, release
);
972 pNew
= allocSeq( 0, 0 );
976 // easy destruction of empty sequence:
977 if (osl_decrementInterlockedCount( &pSequence
->nRefCount
) == 0)
978 rtl_freeMemory( pSequence
);
987 //##############################################################################
988 void SAL_CALL
uno_sequence_assign(
989 uno_Sequence
** ppDest
,
990 uno_Sequence
* pSource
,
991 typelib_TypeDescription
* pTypeDescr
,
992 uno_ReleaseFunc release
)
995 if (*ppDest
!= pSource
)
997 ::osl_incrementInterlockedCount( &pSource
->nRefCount
);
998 idestructSequence( *ppDest
, pTypeDescr
->pWeakRef
, pTypeDescr
, release
);
1003 //##############################################################################
1004 void SAL_CALL
uno_type_sequence_assign(
1005 uno_Sequence
** ppDest
,
1006 uno_Sequence
* pSource
,
1007 typelib_TypeDescriptionReference
* pType
,
1008 uno_ReleaseFunc release
)
1009 SAL_THROW_EXTERN_C()
1011 if (*ppDest
!= pSource
)
1013 ::osl_incrementInterlockedCount( &pSource
->nRefCount
);
1014 idestructSequence( *ppDest
, pType
, 0, release
);