LCOV - code coverage report
Current view: top level - cppu/source/uno - destr.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 114 121 94.2 %
Date: 2014-04-11 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : #ifndef DESTR_HXX
      20             : #define DESTR_HXX
      21             : 
      22             : #include "prim.hxx"
      23             : 
      24             : 
      25             : namespace cppu
      26             : {
      27             : 
      28             : 
      29             : //#### destruction #################################################################################
      30             : 
      31             : 
      32             : 
      33             : void destructStruct(
      34             :     void * pValue,
      35             :     typelib_CompoundTypeDescription * pTypeDescr,
      36             :     uno_ReleaseFunc release )
      37             :     SAL_THROW(());
      38             : 
      39    25584284 : inline void _destructStruct(
      40             :     void * pValue,
      41             :     typelib_CompoundTypeDescription * pTypeDescr,
      42             :     uno_ReleaseFunc release )
      43             :     SAL_THROW(())
      44             : {
      45    25584284 :     if (pTypeDescr->pBaseTypeDescription)
      46             :     {
      47     1025175 :         destructStruct( pValue, pTypeDescr->pBaseTypeDescription, release );
      48             :     }
      49             : 
      50    25584284 :     typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs;
      51    25584284 :     sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
      52    25584284 :     sal_Int32 nDescr = pTypeDescr->nMembers;
      53   147012768 :     while (nDescr--)
      54             :     {
      55             :         ::uno_type_destructData(
      56   191688400 :             (char *)pValue + pMemberOffsets[nDescr],
      57   287532600 :             ppTypeRefs[nDescr], release );
      58             :     }
      59    25584284 : }
      60             : 
      61             : 
      62             : void destructSequence(
      63             :     uno_Sequence * pSequence,
      64             :     typelib_TypeDescriptionReference * pType,
      65             :     typelib_TypeDescription * pTypeDescr,
      66             :     uno_ReleaseFunc release );
      67             : 
      68             : 
      69   181403755 : inline void _destructAny(
      70             :     uno_Any * pAny,
      71             :     uno_ReleaseFunc release )
      72             :     SAL_THROW(())
      73             : {
      74   181403755 :     typelib_TypeDescriptionReference * pType = pAny->pType;
      75             : 
      76   181403755 :     switch (pType->eTypeClass)
      77             :     {
      78             :     case typelib_TypeClass_HYPER:
      79             :     case typelib_TypeClass_UNSIGNED_HYPER:
      80             :         if (sizeof(void *) < sizeof(sal_Int64))
      81             :         {
      82      231748 :             ::rtl_freeMemory( pAny->pData );
      83             :         }
      84      231748 :         break;
      85             :     case typelib_TypeClass_FLOAT:
      86             :         if (sizeof(void *) < sizeof(float))
      87             :         {
      88             :             ::rtl_freeMemory( pAny->pData );
      89             :         }
      90      865584 :         break;
      91             :     case typelib_TypeClass_DOUBLE:
      92             :         if (sizeof(void *) < sizeof(double))
      93             :         {
      94     2602390 :             ::rtl_freeMemory( pAny->pData );
      95             :         }
      96     2602390 :         break;
      97             :     case typelib_TypeClass_STRING:
      98    30268403 :         ::rtl_uString_release( (rtl_uString *)pAny->pReserved );
      99    30268400 :         break;
     100             :     case typelib_TypeClass_TYPE:
     101             :         ::typelib_typedescriptionreference_release(
     102       68954 :             (typelib_TypeDescriptionReference *)pAny->pReserved );
     103       68954 :         break;
     104             :     case typelib_TypeClass_ANY:
     105             :         OSL_FAIL( "### unexpected nested any!" );
     106           0 :         ::uno_any_destruct( (uno_Any *)pAny->pData, release );
     107           0 :         ::rtl_freeMemory( pAny->pData );
     108           0 :         break;
     109             :     case typelib_TypeClass_TYPEDEF:
     110             :         OSL_FAIL( "### unexpected typedef!" );
     111           0 :         break;
     112             :     case typelib_TypeClass_STRUCT:
     113             :     case typelib_TypeClass_EXCEPTION:
     114             :     {
     115     3273107 :         typelib_TypeDescription * pTypeDescr = 0;
     116     3273107 :         TYPELIB_DANGER_GET( &pTypeDescr, pType );
     117     3273107 :         _destructStruct( pAny->pData, (typelib_CompoundTypeDescription *)pTypeDescr, release );
     118     3273107 :         TYPELIB_DANGER_RELEASE( pTypeDescr );
     119     3273107 :         ::rtl_freeMemory( pAny->pData );
     120     3273107 :         break;
     121             :     }
     122             :     case typelib_TypeClass_SEQUENCE:
     123             :     {
     124             :         destructSequence(
     125     7451217 :             static_cast<uno_Sequence *>(pAny->pReserved), pType, 0, release );
     126     7451217 :         break;
     127             :     }
     128             :     case typelib_TypeClass_INTERFACE:
     129    43405009 :         _release( pAny->pReserved, release );
     130    43405023 :         break;
     131             :     default:
     132    93237343 :         break;
     133             :     }
     134             : #if OSL_DEBUG_LEVEL > 0
     135             :     pAny->pData = (void *)0xdeadbeef;
     136             : #endif
     137             : 
     138   181403766 :     ::typelib_typedescriptionreference_release( pType );
     139   181403781 : }
     140             : 
     141    14670493 : inline sal_Int32 idestructElements(
     142             :     void * pElements, typelib_TypeDescriptionReference * pElementType,
     143             :     sal_Int32 nStartIndex, sal_Int32 nStopIndex,
     144             :     uno_ReleaseFunc release )
     145             :     SAL_THROW(())
     146             : {
     147    14670493 :     switch (pElementType->eTypeClass)
     148             :     {
     149             :     case typelib_TypeClass_CHAR:
     150           0 :         return (sal_Int32)(sizeof(sal_Unicode));
     151             :     case typelib_TypeClass_BOOLEAN:
     152       23985 :         return (sal_Int32)(sizeof(sal_Bool));
     153             :     case typelib_TypeClass_BYTE:
     154     2884993 :         return (sal_Int32)(sizeof(sal_Int8));
     155             :     case typelib_TypeClass_SHORT:
     156             :     case typelib_TypeClass_UNSIGNED_SHORT:
     157        1301 :         return (sal_Int32)(sizeof(sal_Int16));
     158             :     case typelib_TypeClass_LONG:
     159             :     case typelib_TypeClass_UNSIGNED_LONG:
     160       61180 :         return (sal_Int32)(sizeof(sal_Int32));
     161             :     case typelib_TypeClass_HYPER:
     162             :     case typelib_TypeClass_UNSIGNED_HYPER:
     163        1287 :         return (sal_Int32)(sizeof(sal_Int64));
     164             :     case typelib_TypeClass_FLOAT:
     165           6 :         return (sal_Int32)(sizeof(float));
     166             :     case typelib_TypeClass_DOUBLE:
     167      273544 :         return (sal_Int32)(sizeof(double));
     168             : 
     169             :     case typelib_TypeClass_STRING:
     170             :     {
     171     1309843 :         rtl_uString ** pDest = (rtl_uString **)pElements;
     172     6415667 :         for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
     173             :         {
     174     5105824 :             ::rtl_uString_release( pDest[nPos] );
     175             :         }
     176     1309843 :         return (sal_Int32)(sizeof(rtl_uString *));
     177             :     }
     178             :     case typelib_TypeClass_TYPE:
     179             :     {
     180       21038 :         typelib_TypeDescriptionReference ** pDest = (typelib_TypeDescriptionReference **)pElements;
     181      502211 :         for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
     182             :         {
     183      481173 :             ::typelib_typedescriptionreference_release( pDest[nPos] );
     184             :         }
     185       21038 :         return (sal_Int32)(sizeof(typelib_TypeDescriptionReference *));
     186             :     }
     187             :     case typelib_TypeClass_ANY:
     188             :     {
     189     1049739 :         uno_Any * pDest = (uno_Any *)pElements;
     190     4817725 :         for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
     191             :         {
     192     3767986 :             _destructAny( &pDest[nPos], release );
     193             :         }
     194     1049739 :         return (sal_Int32)(sizeof(uno_Any));
     195             :     }
     196             :     case typelib_TypeClass_ENUM:
     197       19212 :         return (sal_Int32)(sizeof(sal_Int32));
     198             :     case typelib_TypeClass_STRUCT:
     199             :     case typelib_TypeClass_EXCEPTION:
     200             :     {
     201     3663555 :         typelib_TypeDescription * pElementTypeDescr = 0;
     202     3663555 :         TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
     203     3663555 :         sal_Int32 nElementSize = pElementTypeDescr->nSize;
     204    24632070 :         for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
     205             :         {
     206             :             _destructStruct(
     207    41937030 :                 (char *)pElements + (nElementSize * nPos),
     208             :                 (typelib_CompoundTypeDescription *)pElementTypeDescr,
     209    62905545 :                 release );
     210             :         }
     211     3663555 :         sal_Int32 nSize = pElementTypeDescr->nSize;
     212     3663555 :         TYPELIB_DANGER_RELEASE( pElementTypeDescr );
     213     3663555 :         return nSize;
     214             :     }
     215             :     case typelib_TypeClass_SEQUENCE:
     216             :     {
     217      115026 :         typelib_TypeDescription * pElementTypeDescr = 0;
     218      115026 :         TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
     219      115026 :         uno_Sequence ** pDest = (uno_Sequence **)pElements;
     220     5287872 :         for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
     221             :         {
     222             :             destructSequence(
     223     5172846 :                 pDest[nPos],
     224             :                 pElementTypeDescr->pWeakRef, pElementTypeDescr,
     225    10345692 :                 release );
     226             :         }
     227      115026 :         TYPELIB_DANGER_RELEASE( pElementTypeDescr );
     228      115026 :         return (sal_Int32)(sizeof(uno_Sequence *));
     229             :     }
     230             :     case typelib_TypeClass_INTERFACE:
     231             :     {
     232     5245784 :         if (release)
     233             :         {
     234    19952565 :             for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
     235             :             {
     236    14706851 :                 void * p = ((void **)pElements)[nPos];
     237    14706851 :                 if (p)
     238             :                 {
     239    14467749 :                     (*release)( p );
     240             :                 }
     241             :             }
     242             :         }
     243             :         else
     244             :         {
     245         190 :             for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
     246             :             {
     247         121 :                 uno_Interface * p = ((uno_Interface **)pElements)[nPos];
     248         121 :                 if (p)
     249             :                 {
     250         110 :                     (*p->release)( p );
     251             :                 }
     252             :             }
     253             :         }
     254     5245783 :         return (sal_Int32)(sizeof(void *));
     255             :     }
     256             :     default:
     257             :         OSL_ASSERT(false);
     258           0 :         return 0;
     259             :     }
     260             : }
     261             : 
     262             : 
     263    50131428 : inline void idestructSequence(
     264             :     uno_Sequence * pSeq,
     265             :     typelib_TypeDescriptionReference * pType,
     266             :     typelib_TypeDescription * pTypeDescr,
     267             :     uno_ReleaseFunc release )
     268             : {
     269    50131428 :     if (osl_atomic_decrement( &pSeq->nRefCount ) == 0)
     270             :     {
     271    13926930 :         if (pSeq->nElements > 0)
     272             :         {
     273    13139490 :             if (pTypeDescr)
     274             :             {
     275             :                 idestructElements(
     276             :                     pSeq->elements,
     277             :                     ((typelib_IndirectTypeDescription *) pTypeDescr)->pType, 0,
     278      347928 :                     pSeq->nElements, release );
     279             :             }
     280             :             else
     281             :             {
     282    12791562 :                 TYPELIB_DANGER_GET( &pTypeDescr, pType );
     283             :                 idestructElements(
     284             :                     pSeq->elements,
     285             :                     ((typelib_IndirectTypeDescription *) pTypeDescr)->pType, 0,
     286    12791564 :                     pSeq->nElements, release );
     287    12791563 :                 TYPELIB_DANGER_RELEASE( pTypeDescr );
     288             :             }
     289             :         }
     290    13926932 :         ::rtl_freeMemory( pSeq );
     291             :     }
     292    50131442 : }
     293             : 
     294             : 
     295   126812622 : inline void _destructData(
     296             :     void * pValue,
     297             :     typelib_TypeDescriptionReference * pType,
     298             :     typelib_TypeDescription * pTypeDescr,
     299             :     uno_ReleaseFunc release )
     300             :     SAL_THROW(())
     301             : {
     302   126812622 :     switch (pType->eTypeClass)
     303             :     {
     304             :     case typelib_TypeClass_STRING:
     305    33649490 :         ::rtl_uString_release( *(rtl_uString **)pValue );
     306    33649490 :         break;
     307             :     case typelib_TypeClass_TYPE:
     308      853028 :         ::typelib_typedescriptionreference_release( *(typelib_TypeDescriptionReference **)pValue );
     309      853028 :         break;
     310             :     case typelib_TypeClass_ANY:
     311    16670205 :         _destructAny( (uno_Any *)pValue, release );
     312    16670205 :         break;
     313             :     case typelib_TypeClass_TYPEDEF:
     314             :         OSL_FAIL( "### unexpected typedef!" );
     315           0 :         break;
     316             :     case typelib_TypeClass_STRUCT:
     317             :     case typelib_TypeClass_EXCEPTION:
     318      317487 :         if (pTypeDescr)
     319             :         {
     320       26838 :             _destructStruct( pValue, (typelib_CompoundTypeDescription *)pTypeDescr, release );
     321             :         }
     322             :         else
     323             :         {
     324      290649 :             TYPELIB_DANGER_GET( &pTypeDescr, pType );
     325      290649 :             _destructStruct( pValue, (typelib_CompoundTypeDescription *)pTypeDescr, release );
     326      290649 :             TYPELIB_DANGER_RELEASE( pTypeDescr );
     327             :         }
     328      317487 :         break;
     329             :     case typelib_TypeClass_SEQUENCE:
     330             :     {
     331             :         idestructSequence(
     332    31005300 :             *(uno_Sequence **)pValue, pType, pTypeDescr, release );
     333    31005332 :         break;
     334             :     }
     335             :     case typelib_TypeClass_INTERFACE:
     336      496702 :         _release( *(void **)pValue, release );
     337      496702 :         break;
     338             :     default:
     339    43820410 :         break;
     340             :     }
     341   126812654 : }
     342             : 
     343             : }
     344             : 
     345             : #endif
     346             : 
     347             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10