1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cppu.hxx"
30 #include <rtl/memory.h>
31 #include <rtl/alloc.h>
32 #include <osl/diagnose.h>
33 #include <osl/interlck.h>
34 #include <typelib/typedescription.h>
36 #include <uno/dispatcher.h>
37 #include <uno/sequence2.h>
49 //------------------------------------------------------------------------------
50 static inline uno_Sequence
* reallocSeq(
51 uno_Sequence
* pReallocate
, sal_Size nElementSize
, sal_Int32 nElements
)
53 OSL_ASSERT( nElements
>= 0 );
54 uno_Sequence
* pNew
= 0;
55 sal_uInt32 nSize
= calcSeqMemSize( nElementSize
, nElements
);
60 pNew
= (uno_Sequence
*) rtl_allocateMemory( nSize
);
64 pNew
= (uno_Sequence
*) rtl_reallocateMemory( pReallocate
, nSize
);
70 pNew
->nElements
= nElements
;
76 //------------------------------------------------------------------------------
77 static inline bool idefaultConstructElements(
78 uno_Sequence
** ppSeq
,
79 typelib_TypeDescriptionReference
* pElementType
,
80 sal_Int32 nStartIndex
, sal_Int32 nStopIndex
,
81 sal_Int32 nAlloc
= -1 ) // >= 0 means (re)alloc memory for nAlloc elements
83 uno_Sequence
* pSeq
= *ppSeq
;
84 switch (pElementType
->eTypeClass
)
86 case typelib_TypeClass_CHAR
:
88 pSeq
= reallocSeq( pSeq
, sizeof(sal_Unicode
), nAlloc
);
92 pSeq
->elements
+ (sizeof(sal_Unicode
) * nStartIndex
),
93 sizeof(sal_Unicode
) * (nStopIndex
- nStartIndex
) );
96 case typelib_TypeClass_BOOLEAN
:
98 pSeq
= reallocSeq( pSeq
, sizeof(sal_Bool
), nAlloc
);
102 pSeq
->elements
+ (sizeof(sal_Bool
) * nStartIndex
),
103 sizeof(sal_Bool
) * (nStopIndex
- nStartIndex
) );
106 case typelib_TypeClass_BYTE
:
108 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int8
), nAlloc
);
112 pSeq
->elements
+ (sizeof(sal_Int8
) * nStartIndex
),
113 sizeof(sal_Int8
) * (nStopIndex
- nStartIndex
) );
116 case typelib_TypeClass_SHORT
:
117 case typelib_TypeClass_UNSIGNED_SHORT
:
119 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int16
), nAlloc
);
123 pSeq
->elements
+ (sizeof(sal_Int16
) * nStartIndex
),
124 sizeof(sal_Int16
) * (nStopIndex
- nStartIndex
) );
127 case typelib_TypeClass_LONG
:
128 case typelib_TypeClass_UNSIGNED_LONG
:
130 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
134 pSeq
->elements
+ (sizeof(sal_Int32
) * nStartIndex
),
135 sizeof(sal_Int32
) * (nStopIndex
- nStartIndex
) );
138 case typelib_TypeClass_HYPER
:
139 case typelib_TypeClass_UNSIGNED_HYPER
:
141 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int64
), nAlloc
);
145 pSeq
->elements
+ (sizeof(sal_Int64
) * nStartIndex
),
146 sizeof(sal_Int64
) * (nStopIndex
- nStartIndex
) );
149 case typelib_TypeClass_FLOAT
:
152 pSeq
= reallocSeq( pSeq
, sizeof(float), nAlloc
);
155 float * pElements
= (float *) pSeq
->elements
;
156 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
158 pElements
[nPos
] = 0.0;
163 case typelib_TypeClass_DOUBLE
:
166 pSeq
= reallocSeq( pSeq
, sizeof(double), nAlloc
);
169 double * pElements
= (double *) pSeq
->elements
;
170 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
172 pElements
[nPos
] = 0.0;
177 case typelib_TypeClass_STRING
:
180 pSeq
= reallocSeq( pSeq
, sizeof(rtl_uString
*), nAlloc
);
183 rtl_uString
** pElements
= (rtl_uString
**) pSeq
->elements
;
184 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
187 rtl_uString_new( &pElements
[nPos
] );
192 case typelib_TypeClass_TYPE
:
197 pSeq
, sizeof(typelib_TypeDescriptionReference
*), nAlloc
);
201 typelib_TypeDescriptionReference
** pElements
=
202 (typelib_TypeDescriptionReference
**) pSeq
->elements
;
203 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
205 pElements
[nPos
] = _getVoidType();
210 case typelib_TypeClass_ANY
:
213 pSeq
= reallocSeq( pSeq
, sizeof(uno_Any
), nAlloc
);
216 uno_Any
* pElements
= (uno_Any
*) pSeq
->elements
;
217 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
219 CONSTRUCT_EMPTY_ANY( &pElements
[nPos
] );
224 case typelib_TypeClass_ENUM
:
227 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
230 typelib_TypeDescription
* pElementTypeDescr
= 0;
231 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
233 ((typelib_EnumTypeDescription
*)
234 pElementTypeDescr
)->nDefaultEnumValue
;
235 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
237 sal_Int32
* pElements
= (sal_Int32
*) pSeq
->elements
;
238 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
240 pElements
[nPos
] = eEnum
;
245 case typelib_TypeClass_STRUCT
:
246 case typelib_TypeClass_EXCEPTION
:
248 typelib_TypeDescription
* pElementTypeDescr
= 0;
249 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
250 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
253 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
256 char * pElements
= pSeq
->elements
;
257 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
259 _defaultConstructStruct(
260 pElements
+ (nElementSize
* nPos
),
261 (typelib_CompoundTypeDescription
*)pElementTypeDescr
);
265 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
268 case typelib_TypeClass_ARRAY
:
270 typelib_TypeDescription
* pElementTypeDescr
= 0;
271 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
272 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
275 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
278 char * pElements
= pSeq
->elements
;
279 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
281 _defaultConstructArray(
282 pElements
+ (nElementSize
* nPos
),
283 (typelib_ArrayTypeDescription
*)pElementTypeDescr
);
287 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
290 case typelib_TypeClass_UNION
:
292 typelib_TypeDescription
* pElementTypeDescr
= 0;
293 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
294 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
297 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
300 sal_Int32 nValueOffset
=
301 ((typelib_UnionTypeDescription
*)
302 pElementTypeDescr
)->nValueOffset
;
303 sal_Int64 nDefaultDiscr
=
304 ((typelib_UnionTypeDescription
*)
305 pElementTypeDescr
)->nDefaultDiscriminant
;
307 typelib_TypeDescription
* pDefaultTypeDescr
= 0;
310 ((typelib_UnionTypeDescription
*)
311 pElementTypeDescr
)->pDefaultTypeRef
);
313 char * pElements
= pSeq
->elements
;
314 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
316 char * pMem
= pElements
+ (nElementSize
* nPos
);
318 (char *)pMem
+ nValueOffset
, pDefaultTypeDescr
);
319 *(sal_Int64
*)pMem
= nDefaultDiscr
;
321 TYPELIB_DANGER_RELEASE( pDefaultTypeDescr
);
324 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
327 case typelib_TypeClass_SEQUENCE
:
330 pSeq
= reallocSeq( pSeq
, sizeof(uno_Sequence
*), nAlloc
);
333 uno_Sequence
** pElements
=
334 (uno_Sequence
**) pSeq
->elements
;
335 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
337 pElements
[nPos
] = createEmptySequence();
342 case typelib_TypeClass_INTERFACE
: // either C++ or C-UNO interface
344 pSeq
= reallocSeq( pSeq
, sizeof(void *), nAlloc
);
348 pSeq
->elements
+ (sizeof(void *) * nStartIndex
),
349 sizeof(void *) * (nStopIndex
- nStartIndex
) );
353 OSL_ENSURE( 0, "### unexpected element type!" );
360 OSL_ASSERT( nAlloc
>= 0 ); // must have been an allocation failure
370 //------------------------------------------------------------------------------
371 static inline bool icopyConstructFromElements(
372 uno_Sequence
** ppSeq
, void * pSourceElements
,
373 typelib_TypeDescriptionReference
* pElementType
,
374 sal_Int32 nStartIndex
, sal_Int32 nStopIndex
,
375 uno_AcquireFunc acquire
,
376 sal_Int32 nAlloc
= -1 ) // >= 0 means (re)alloc memory for nAlloc elements
378 uno_Sequence
* pSeq
= *ppSeq
;
379 switch (pElementType
->eTypeClass
)
381 case typelib_TypeClass_CHAR
:
383 pSeq
= reallocSeq( pSeq
, sizeof(sal_Unicode
), nAlloc
);
387 pSeq
->elements
+ (sizeof(sal_Unicode
) * nStartIndex
),
388 (char *)pSourceElements
+ (sizeof(sal_Unicode
) * nStartIndex
),
389 sizeof(sal_Unicode
) * (nStopIndex
- nStartIndex
) );
392 case typelib_TypeClass_BOOLEAN
:
394 pSeq
= reallocSeq( pSeq
, sizeof(sal_Bool
), nAlloc
);
398 pSeq
->elements
+ (sizeof(sal_Bool
) * nStartIndex
),
399 (char *)pSourceElements
+ (sizeof(sal_Bool
) * nStartIndex
),
400 sizeof(sal_Bool
) * (nStopIndex
- nStartIndex
) );
403 case typelib_TypeClass_BYTE
:
405 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int8
), nAlloc
);
409 pSeq
->elements
+ (sizeof(sal_Int8
) * nStartIndex
),
410 (char *)pSourceElements
+ (sizeof(sal_Int8
) * nStartIndex
),
411 sizeof(sal_Int8
) * (nStopIndex
- nStartIndex
) );
414 case typelib_TypeClass_SHORT
:
415 case typelib_TypeClass_UNSIGNED_SHORT
:
417 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int16
), nAlloc
);
421 pSeq
->elements
+ (sizeof(sal_Int16
) * nStartIndex
),
422 (char *)pSourceElements
+ (sizeof(sal_Int16
) * nStartIndex
),
423 sizeof(sal_Int16
) * (nStopIndex
- nStartIndex
) );
426 case typelib_TypeClass_LONG
:
427 case typelib_TypeClass_UNSIGNED_LONG
:
429 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
433 pSeq
->elements
+ (sizeof(sal_Int32
) * nStartIndex
),
434 (char *)pSourceElements
+ (sizeof(sal_Int32
) * nStartIndex
),
435 sizeof(sal_Int32
) * (nStopIndex
- nStartIndex
) );
438 case typelib_TypeClass_HYPER
:
439 case typelib_TypeClass_UNSIGNED_HYPER
:
441 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int64
), nAlloc
);
445 pSeq
->elements
+ (sizeof(sal_Int64
) * nStartIndex
),
446 (char *)pSourceElements
+ (sizeof(sal_Int64
) * nStartIndex
),
447 sizeof(sal_Int64
) * (nStopIndex
- nStartIndex
) );
450 case typelib_TypeClass_FLOAT
:
452 pSeq
= reallocSeq( pSeq
, sizeof(float), nAlloc
);
456 pSeq
->elements
+ (sizeof(float) * nStartIndex
),
457 (char *)pSourceElements
+ (sizeof(float) * nStartIndex
),
458 sizeof(float) * (nStopIndex
- nStartIndex
) );
461 case typelib_TypeClass_DOUBLE
:
463 pSeq
= reallocSeq( pSeq
, sizeof(double), nAlloc
);
467 pSeq
->elements
+ (sizeof(double) * nStartIndex
),
468 (char *)pSourceElements
+ (sizeof(double) * nStartIndex
),
469 sizeof(double) * (nStopIndex
- nStartIndex
) );
472 case typelib_TypeClass_ENUM
:
474 pSeq
= reallocSeq( pSeq
, sizeof(sal_Int32
), nAlloc
);
478 pSeq
->elements
+ (sizeof(sal_Int32
) * nStartIndex
),
479 (char *)pSourceElements
+ (sizeof(sal_Int32
) * nStartIndex
),
480 sizeof(sal_Int32
) * (nStopIndex
- nStartIndex
) );
483 case typelib_TypeClass_STRING
:
486 pSeq
= reallocSeq( pSeq
, sizeof(rtl_uString
*), nAlloc
);
489 rtl_uString
** pDestElements
= (rtl_uString
**) pSeq
->elements
;
490 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
492 ::rtl_uString_acquire(
493 ((rtl_uString
**)pSourceElements
)[nPos
] );
494 pDestElements
[nPos
] = ((rtl_uString
**)pSourceElements
)[nPos
];
499 case typelib_TypeClass_TYPE
:
504 pSeq
, sizeof(typelib_TypeDescriptionReference
*), nAlloc
);
508 typelib_TypeDescriptionReference
** pDestElements
=
509 (typelib_TypeDescriptionReference
**) pSeq
->elements
;
510 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
513 ((typelib_TypeDescriptionReference
**)
514 pSourceElements
)[nPos
] );
515 pDestElements
[nPos
] =
516 ((typelib_TypeDescriptionReference
**)
517 pSourceElements
)[nPos
];
522 case typelib_TypeClass_ANY
:
525 pSeq
= reallocSeq( pSeq
, sizeof(uno_Any
), nAlloc
);
528 uno_Any
* pDestElements
= (uno_Any
*) pSeq
->elements
;
529 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
531 uno_Any
* pSource
= (uno_Any
*)pSourceElements
+ nPos
;
533 &pDestElements
[nPos
],
541 case typelib_TypeClass_STRUCT
:
542 case typelib_TypeClass_EXCEPTION
:
544 typelib_TypeDescription
* pElementTypeDescr
= 0;
545 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
546 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
549 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
552 char * pDestElements
= pSeq
->elements
;
554 typelib_CompoundTypeDescription
* pTypeDescr
=
555 (typelib_CompoundTypeDescription
*)pElementTypeDescr
;
556 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
559 pDestElements
+ (nElementSize
* nPos
);
561 (char *)pSourceElements
+ (nElementSize
* nPos
);
563 if (pTypeDescr
->pBaseTypeDescription
)
566 _copyConstructStruct(
568 pTypeDescr
->pBaseTypeDescription
, acquire
, 0 );
572 typelib_TypeDescriptionReference
** ppTypeRefs
=
573 pTypeDescr
->ppTypeRefs
;
574 sal_Int32
* pMemberOffsets
= pTypeDescr
->pMemberOffsets
;
575 sal_Int32 nDescr
= pTypeDescr
->nMembers
;
580 pDest
+ pMemberOffsets
[nDescr
],
581 pSource
+ pMemberOffsets
[nDescr
],
582 ppTypeRefs
[nDescr
], acquire
);
587 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
590 case typelib_TypeClass_UNION
:
592 typelib_TypeDescription
* pElementTypeDescr
= 0;
593 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
594 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
597 pSeq
= reallocSeq( pSeq
, nElementSize
, nAlloc
);
600 char * pDestElements
= pSeq
->elements
;
602 sal_Int32 nValueOffset
=
603 ((typelib_UnionTypeDescription
*)
604 pElementTypeDescr
)->nValueOffset
;
605 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
608 pDestElements
+ (nElementSize
* nPos
);
610 (char *)pSourceElements
+ (nElementSize
* nPos
);
612 typelib_TypeDescriptionReference
* pSetType
= _unionGetSetType(
613 pSource
, pElementTypeDescr
);
615 pDest
+ nValueOffset
,
616 pSource
+ nValueOffset
,
618 *(sal_Int64
*)pDest
= *(sal_Int64
*)pSource
;
619 typelib_typedescriptionreference_release( pSetType
);
623 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
626 case typelib_TypeClass_SEQUENCE
: // sequence of sequence
629 pSeq
= reallocSeq( pSeq
, sizeof(uno_Sequence
*), nAlloc
);
632 typelib_TypeDescription
* pElementTypeDescr
= 0;
633 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
634 typelib_TypeDescriptionReference
* pSeqElementType
=
635 ((typelib_IndirectTypeDescription
*) pElementTypeDescr
)->pType
;
636 uno_Sequence
** pDestElements
= (uno_Sequence
**) pSeq
->elements
;
637 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
639 uno_Sequence
* pNew
= icopyConstructSequence(
640 ((uno_Sequence
**) pSourceElements
)[nPos
],
641 pSeqElementType
, acquire
, 0 );
642 OSL_ASSERT( pNew
!= 0 );
643 // ought never be a memory allocation problem,
644 // because of reference counted sequence handles
645 pDestElements
[ nPos
] = pNew
;
647 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
651 case typelib_TypeClass_INTERFACE
:
654 pSeq
= reallocSeq( pSeq
, sizeof(void *), nAlloc
);
657 void ** pDestElements
= (void **) pSeq
->elements
;
658 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
660 _acquire( pDestElements
[nPos
] =
661 ((void **)pSourceElements
)[nPos
], acquire
);
667 OSL_ENSURE( 0, "### unexpected element type!" );
674 OSL_ASSERT( nAlloc
>= 0 ); // must have been an allocation failure
684 //------------------------------------------------------------------------------
685 static inline bool ireallocSequence(
686 uno_Sequence
** ppSequence
,
687 typelib_TypeDescriptionReference
* pElementType
,
689 uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
692 uno_Sequence
* pSeq
= *ppSequence
;
693 sal_Int32 nElements
= pSeq
->nElements
;
695 if (pSeq
->nRefCount
> 1 ||
696 // not mem-copyable elements?
697 typelib_TypeClass_ANY
== pElementType
->eTypeClass
||
698 typelib_TypeClass_STRUCT
== pElementType
->eTypeClass
||
699 typelib_TypeClass_EXCEPTION
== pElementType
->eTypeClass
)
701 // split sequence and construct new one from scratch
702 uno_Sequence
* pNew
= 0;
704 sal_Int32 nRest
= nSize
- nElements
;
705 sal_Int32 nCopy
= (nRest
> 0 ? nElements
: nSize
);
709 ret
= icopyConstructFromElements(
710 &pNew
, pSeq
->elements
, pElementType
,
712 nSize
); // alloc to nSize
714 if (ret
&& nRest
> 0)
716 ret
= idefaultConstructElements(
719 nCopy
>= 0 ? -1 /* no mem allocation */ : nSize
);
725 if (osl_decrementInterlockedCount( &pSeq
->nRefCount
) == 0)
730 pSeq
->elements
, pElementType
,
731 0, nElements
, release
);
733 rtl_freeMemory( pSeq
);
740 OSL_ASSERT( pSeq
->nRefCount
== 1 );
741 if (nSize
> nElements
) // default construct the rest
743 ret
= idefaultConstructElements(
744 ppSequence
, pElementType
,
746 nSize
); // realloc to nSize
748 else // or destruct the rest and realloc mem
750 sal_Int32 nElementSize
= idestructElements(
751 pSeq
->elements
, pElementType
,
752 nSize
, nElements
, release
);
753 // warning: it is assumed that the following will never fail,
754 // else this leads to a sequence null handle
755 *ppSequence
= reallocSeq( pSeq
, nElementSize
, nSize
);
756 OSL_ASSERT( *ppSequence
!= 0 );
757 ret
= (*ppSequence
!= 0);
769 //##############################################################################
770 sal_Bool SAL_CALL
uno_type_sequence_construct(
771 uno_Sequence
** ppSequence
, typelib_TypeDescriptionReference
* pType
,
772 void * pElements
, sal_Int32 len
,
773 uno_AcquireFunc acquire
)
779 typelib_TypeDescription
* pTypeDescr
= 0;
780 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
782 typelib_TypeDescriptionReference
* pElementType
=
783 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
;
788 ret
= idefaultConstructElements(
789 ppSequence
, pElementType
,
791 len
); // alloc to len
795 ret
= icopyConstructFromElements(
796 ppSequence
, pElements
, pElementType
,
798 len
); // alloc to len
801 TYPELIB_DANGER_RELEASE( pTypeDescr
);
805 *ppSequence
= createEmptySequence();
809 OSL_ASSERT( (*ppSequence
!= 0) == ret
);
813 //##############################################################################
814 sal_Bool SAL_CALL
uno_sequence_construct(
815 uno_Sequence
** ppSequence
, typelib_TypeDescription
* pTypeDescr
,
816 void * pElements
, sal_Int32 len
,
817 uno_AcquireFunc acquire
)
823 typelib_TypeDescriptionReference
* pElementType
=
824 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
;
829 ret
= idefaultConstructElements(
830 ppSequence
, pElementType
,
832 len
); // alloc to len
836 ret
= icopyConstructFromElements(
837 ppSequence
, pElements
, pElementType
,
839 len
); // alloc to len
844 *ppSequence
= createEmptySequence();
848 OSL_ASSERT( (*ppSequence
!= 0) == ret
);
852 //##############################################################################
853 sal_Bool SAL_CALL
uno_type_sequence_realloc(
854 uno_Sequence
** ppSequence
, typelib_TypeDescriptionReference
* pType
,
855 sal_Int32 nSize
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
858 OSL_ENSURE( ppSequence
, "### null ptr!" );
859 OSL_ENSURE( nSize
>= 0, "### new size must be at least 0!" );
862 if (nSize
!= (*ppSequence
)->nElements
)
864 typelib_TypeDescription
* pTypeDescr
= 0;
865 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
866 ret
= ireallocSequence(
867 ppSequence
, ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
868 nSize
, acquire
, release
);
869 TYPELIB_DANGER_RELEASE( pTypeDescr
);
874 //##############################################################################
875 sal_Bool SAL_CALL
uno_sequence_realloc(
876 uno_Sequence
** ppSequence
, typelib_TypeDescription
* pTypeDescr
,
877 sal_Int32 nSize
, uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
880 OSL_ENSURE( ppSequence
, "### null ptr!" );
881 OSL_ENSURE( nSize
>= 0, "### new size must be at least 0!" );
884 if (nSize
!= (*ppSequence
)->nElements
)
886 ret
= ireallocSequence(
887 ppSequence
, ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
888 nSize
, acquire
, release
);
893 //##############################################################################
894 sal_Bool SAL_CALL
uno_type_sequence_reference2One(
895 uno_Sequence
** ppSequence
,
896 typelib_TypeDescriptionReference
* pType
,
897 uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
900 OSL_ENSURE( ppSequence
, "### null ptr!" );
902 uno_Sequence
* pSequence
= *ppSequence
;
903 if (pSequence
->nRefCount
> 1)
905 uno_Sequence
* pNew
= 0;
906 if (pSequence
->nElements
> 0)
908 typelib_TypeDescription
* pTypeDescr
= 0;
909 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
911 ret
= icopyConstructFromElements(
912 &pNew
, pSequence
->elements
,
913 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
914 0, pSequence
->nElements
, acquire
,
915 pSequence
->nElements
); // alloc nElements
918 idestructSequence( *ppSequence
, pType
, pTypeDescr
, release
);
922 TYPELIB_DANGER_RELEASE( pTypeDescr
);
926 pNew
= allocSeq( 0, 0 );
930 // easy destruction of empty sequence:
931 if (osl_decrementInterlockedCount( &pSequence
->nRefCount
) == 0)
932 rtl_freeMemory( pSequence
);
940 //##############################################################################
941 sal_Bool SAL_CALL
uno_sequence_reference2One(
942 uno_Sequence
** ppSequence
,
943 typelib_TypeDescription
* pTypeDescr
,
944 uno_AcquireFunc acquire
, uno_ReleaseFunc release
)
947 OSL_ENSURE( ppSequence
, "### null ptr!" );
949 uno_Sequence
* pSequence
= *ppSequence
;
950 if (pSequence
->nRefCount
> 1)
952 uno_Sequence
* pNew
= 0;
953 if (pSequence
->nElements
> 0)
955 ret
= icopyConstructFromElements(
956 &pNew
, pSequence
->elements
,
957 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
,
958 0, pSequence
->nElements
, acquire
,
959 pSequence
->nElements
); // alloc nElements
963 pSequence
, pTypeDescr
->pWeakRef
, pTypeDescr
, release
);
969 pNew
= allocSeq( 0, 0 );
973 // easy destruction of empty sequence:
974 if (osl_decrementInterlockedCount( &pSequence
->nRefCount
) == 0)
975 rtl_freeMemory( pSequence
);
984 //##############################################################################
985 void SAL_CALL
uno_sequence_assign(
986 uno_Sequence
** ppDest
,
987 uno_Sequence
* pSource
,
988 typelib_TypeDescription
* pTypeDescr
,
989 uno_ReleaseFunc release
)
992 if (*ppDest
!= pSource
)
994 ::osl_incrementInterlockedCount( &pSource
->nRefCount
);
995 idestructSequence( *ppDest
, pTypeDescr
->pWeakRef
, pTypeDescr
, release
);
1000 //##############################################################################
1001 void SAL_CALL
uno_type_sequence_assign(
1002 uno_Sequence
** ppDest
,
1003 uno_Sequence
* pSource
,
1004 typelib_TypeDescriptionReference
* pType
,
1005 uno_ReleaseFunc release
)
1006 SAL_THROW_EXTERN_C()
1008 if (*ppDest
!= pSource
)
1010 ::osl_incrementInterlockedCount( &pSource
->nRefCount
);
1011 idestructSequence( *ppDest
, pType
, 0, release
);