LCOV - code coverage report
Current view: top level - bridges/source/cpp_uno/gcc3_linux_intel - uno2cpp.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 116 125 92.8 %
Date: 2014-04-11 Functions: 3 3 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             : 
      20             : 
      21             : #if defined (FREEBSD) || defined(NETBSD) || defined(OPENBSD) || defined(DRAGONFLY)
      22             : #include <stdlib.h>
      23             : #else
      24             : #include <alloca.h>
      25             : #endif
      26             : 
      27             : #include <com/sun/star/uno/genfunc.hxx>
      28             : #include "com/sun/star/uno/RuntimeException.hpp"
      29             : #include <uno/data.h>
      30             : 
      31             : #include "bridges/cpp_uno/shared/bridge.hxx"
      32             : #include "bridges/cpp_uno/shared/types.hxx"
      33             : #include "bridges/cpp_uno/shared/unointerfaceproxy.hxx"
      34             : #include "bridges/cpp_uno/shared/vtables.hxx"
      35             : 
      36             : #include "callvirtualmethod.hxx"
      37             : #include "share.hxx"
      38             : 
      39             : using namespace ::rtl;
      40             : using namespace ::com::sun::star::uno;
      41             : 
      42             : namespace
      43             : {
      44             : 
      45      200962 : static void cpp_call(
      46             :     bridges::cpp_uno::shared::UnoInterfaceProxy * pThis,
      47             :     bridges::cpp_uno::shared::VtableSlot aVtableSlot,
      48             :     typelib_TypeDescriptionReference * pReturnTypeRef,
      49             :     sal_Int32 nParams, typelib_MethodParameter * pParams,
      50             :     void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc )
      51             : {
      52             :       // max space for: [complex ret ptr], values|ptr ...
      53             :       char * pCppStack      =
      54      200962 :           (char *)alloca( sizeof(sal_Int32) + ((nParams+2) * sizeof(sal_Int64)) );
      55      200962 :       char * pCppStackStart = pCppStack;
      56             : 
      57             :     // return
      58      200962 :     typelib_TypeDescription * pReturnTypeDescr = 0;
      59      200962 :     TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
      60             :     OSL_ENSURE( pReturnTypeDescr, "### expected return type description!" );
      61             : 
      62      200962 :     void * pCppReturn = 0; // if != 0 && != pUnoReturn, needs reconversion
      63      200962 :     bool bSimpleReturn = true;
      64             : 
      65      200962 :     if (pReturnTypeDescr)
      66             :     {
      67      200962 :         bSimpleReturn = x86::isSimpleReturnType(pReturnTypeDescr);
      68      200962 :         if (bSimpleReturn)
      69             :         {
      70       78585 :             pCppReturn = pUnoReturn; // direct way for simple types
      71             :         }
      72             :         else
      73             :         {
      74             :             // complex return via ptr
      75             :             pCppReturn = *(void **)pCppStack
      76             :                 = (bridges::cpp_uno::shared::relatesToInterfaceType(
      77      122377 :                        pReturnTypeDescr )
      78      100673 :                    ? alloca( pReturnTypeDescr->nSize )
      79      223050 :                    : pUnoReturn); // direct way
      80      122377 :             pCppStack += sizeof(void *);
      81             :         }
      82             :     }
      83             :     // push this
      84      200962 :     void * pAdjustedThisPtr = reinterpret_cast< void ** >(pThis->getCppI())
      85      200962 :         + aVtableSlot.offset;
      86      200962 :     *(void**)pCppStack = pAdjustedThisPtr;
      87      200962 :     pCppStack += sizeof( void* );
      88             : 
      89             :     // stack space
      90             :     OSL_ENSURE( sizeof(void *) == sizeof(sal_Int32), "### unexpected size!" );
      91             :     // args
      92      200962 :     void ** pCppArgs  = (void **)alloca( 3 * sizeof(void *) * nParams );
      93             :     // indices of values this have to be converted (interface conversion cpp<=>uno)
      94      200962 :     sal_Int32 * pTempIndices = (sal_Int32 *)(pCppArgs + nParams);
      95             :     // type descriptions for reconversions
      96      200962 :     typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pCppArgs + (2 * nParams));
      97             : 
      98      200962 :     sal_Int32 nTempIndices   = 0;
      99             : 
     100      363679 :     for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
     101             :     {
     102      162717 :         const typelib_MethodParameter & rParam = pParams[nPos];
     103      162717 :         typelib_TypeDescription * pParamTypeDescr = 0;
     104      162717 :         TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
     105             : 
     106      325434 :         if (!rParam.bOut
     107      162717 :             && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
     108             :         {
     109      102651 :             uno_copyAndConvertData( pCppArgs[nPos] = pCppStack, pUnoArgs[nPos], pParamTypeDescr,
     110      136868 :                                     pThis->getBridge()->getUno2Cpp() );
     111             : 
     112       34217 :             switch (pParamTypeDescr->eTypeClass)
     113             :             {
     114             :             case typelib_TypeClass_HYPER:
     115             :             case typelib_TypeClass_UNSIGNED_HYPER:
     116             :             case typelib_TypeClass_DOUBLE:
     117        1403 :                 pCppStack += sizeof(sal_Int32); // extra long
     118        1403 :                 break;
     119             :             default:
     120       32814 :                 break;
     121             :             }
     122             :             // no longer needed
     123       34217 :             TYPELIB_DANGER_RELEASE( pParamTypeDescr );
     124             :         }
     125             :         else // ptr to complex value | ref
     126             :         {
     127      128500 :             if (! rParam.bIn) // is pure out
     128             :             {
     129             :                 // cpp out is constructed mem, uno out is not!
     130             :                 uno_constructData(
     131         312 :                     *(void **)pCppStack = pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
     132         468 :                     pParamTypeDescr );
     133         156 :                 pTempIndices[nTempIndices] = nPos; // default constructed for cpp call
     134             :                 // will be released at reconversion
     135         156 :                 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
     136             :             }
     137             :             // is in/inout
     138      128344 :             else if (bridges::cpp_uno::shared::relatesToInterfaceType(
     139      128344 :                          pParamTypeDescr ))
     140             :             {
     141             :                 uno_copyAndConvertData(
     142       58916 :                     *(void **)pCppStack = pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
     143       29458 :                     pUnoArgs[nPos], pParamTypeDescr,
     144      117832 :                     pThis->getBridge()->getUno2Cpp() );
     145             : 
     146       29458 :                 pTempIndices[nTempIndices] = nPos; // has to be reconverted
     147             :                 // will be released at reconversion
     148       29458 :                 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
     149             :             }
     150             :             else // direct way
     151             :             {
     152       98886 :                 *(void **)pCppStack = pCppArgs[nPos] = pUnoArgs[nPos];
     153             :                 // no longer needed
     154       98886 :                 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
     155             :             }
     156             :         }
     157      162717 :         pCppStack += sizeof(sal_Int32); // standard parameter length
     158             :     }
     159             : 
     160             :     try
     161             :     {
     162             :         OSL_ENSURE( !( (pCppStack - pCppStackStart ) & 3), "UNALIGNED STACK !!! (Please DO panic)" );
     163             :         CPPU_CURRENT_NAMESPACE::callVirtualMethod(
     164             :             pAdjustedThisPtr, aVtableSlot.index,
     165             :             pCppReturn, pReturnTypeDescr, bSimpleReturn,
     166      200962 :             (sal_Int32 *)pCppStackStart, (pCppStack - pCppStackStart) / sizeof(sal_Int32) );
     167             :         // NO exception occurred...
     168      197556 :         *ppUnoExc = 0;
     169             : 
     170             :         // reconvert temporary params
     171      424211 :         for ( ; nTempIndices--; )
     172             :         {
     173       29099 :             sal_Int32 nIndex = pTempIndices[nTempIndices];
     174       29099 :             typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndices];
     175             : 
     176       29099 :             if (pParams[nIndex].bIn)
     177             :             {
     178       28943 :                 if (pParams[nIndex].bOut) // inout
     179             :                 {
     180           6 :                     uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 ); // destroy uno value
     181          12 :                     uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
     182          18 :                                             pThis->getBridge()->getCpp2Uno() );
     183             :                 }
     184             :             }
     185             :             else // pure out
     186             :             {
     187         312 :                 uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
     188         468 :                                         pThis->getBridge()->getCpp2Uno() );
     189             :             }
     190             :             // destroy temp cpp param => cpp: every param was constructed
     191       29099 :             uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
     192             : 
     193       29099 :             TYPELIB_DANGER_RELEASE( pParamTypeDescr );
     194             :         }
     195             :         // return value
     196      197556 :         if (pCppReturn && pUnoReturn != pCppReturn)
     197             :         {
     198             :             uno_copyAndConvertData( pUnoReturn, pCppReturn, pReturnTypeDescr,
     199      100373 :                                     pThis->getBridge()->getCpp2Uno() );
     200      100373 :             uno_destructData( pCppReturn, pReturnTypeDescr, cpp_release );
     201             :         }
     202             :     }
     203        3406 :      catch (...)
     204             :      {
     205             :          // fill uno exception
     206             :          fillUnoException(
     207             :              reinterpret_cast< CPPU_CURRENT_NAMESPACE::__cxa_eh_globals * >(
     208        3406 :                  __cxxabiv1::__cxa_get_globals())->caughtExceptions,
     209        6812 :              *ppUnoExc, pThis->getBridge()->getCpp2Uno());
     210             : 
     211             :         // temporary params
     212        7327 :         for ( ; nTempIndices--; )
     213             :         {
     214         515 :             sal_Int32 nIndex = pTempIndices[nTempIndices];
     215             :             // destroy temp cpp param => cpp: every param was constructed
     216         515 :             uno_destructData( pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndices], cpp_release );
     217         515 :             TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndices] );
     218             :         }
     219             :         // return type
     220        3406 :         if (pReturnTypeDescr)
     221        3406 :             TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
     222             :     }
     223      200962 : }
     224             : 
     225             : }
     226             : 
     227             : namespace x86
     228             : {
     229      232291 :     bool isSimpleReturnType(typelib_TypeDescription * pTD, bool recursive)
     230             :     {
     231      232291 :         if (bridges::cpp_uno::shared::isSimpleType( pTD ))
     232      104578 :             return true;
     233             : #if defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) || \
     234             :     defined(MACOSX) || defined(DRAGONFLY)
     235             :         // Only structs of exactly 1, 2, 4, or 8 bytes are returned through
     236             :         // registers, see <http://developer.apple.com/documentation/DeveloperTools/
     237             :         // Conceptual/LowLevelABI/Articles/IA32.html>:
     238             :         if (pTD->eTypeClass == typelib_TypeClass_STRUCT &&
     239             :             (recursive || pTD->nSize <= 2 || pTD->nSize == 4 || pTD->nSize == 8))
     240             :         {
     241             :             typelib_CompoundTypeDescription *const pCompTD =
     242             :                 (typelib_CompoundTypeDescription *) pTD;
     243             :             for ( sal_Int32 pos = pCompTD->nMembers; pos--; ) {
     244             :                 typelib_TypeDescription * pMemberTD = 0;
     245             :                 TYPELIB_DANGER_GET( &pMemberTD, pCompTD->ppTypeRefs[pos] );
     246             :                 bool const b = isSimpleReturnType(pMemberTD, true);
     247             :                 TYPELIB_DANGER_RELEASE( pMemberTD );
     248             :                 if (! b)
     249             :                     return false;
     250             :             }
     251             :             return true;
     252             :         }
     253             : #else
     254             :         (void)recursive;
     255             : #endif
     256      127714 :         return false;
     257             :     }
     258             : }
     259             : 
     260             : namespace bridges { namespace cpp_uno { namespace shared {
     261             : 
     262      208892 : void unoInterfaceProxyDispatch(
     263             :     uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr,
     264             :     void * pReturn, void * pArgs[], uno_Any ** ppException )
     265             : {
     266             :     // is my surrogate
     267             :     bridges::cpp_uno::shared::UnoInterfaceProxy * pThis
     268      208892 :         = static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy * >(pUnoI);
     269             : 
     270      208892 :     switch (pMemberDescr->eTypeClass)
     271             :     {
     272             :     case typelib_TypeClass_INTERFACE_ATTRIBUTE:
     273             :     {
     274             :         VtableSlot aVtableSlot(
     275             :             getVtableSlot(
     276             :                 reinterpret_cast<
     277             :                     typelib_InterfaceAttributeTypeDescription const * >(
     278        7334 :                         pMemberDescr)));
     279        7334 :         if (pReturn)
     280             :         {
     281             :             // dependent dispatch
     282             :             cpp_call(
     283             :                 pThis, aVtableSlot,
     284             :                 ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef,
     285             :                 0, 0, // no params
     286        6188 :                 pReturn, pArgs, ppException );
     287             :         }
     288             :         else
     289             :         {
     290             :             // is SET
     291             :             typelib_MethodParameter aParam;
     292             :             aParam.pTypeRef =
     293        1146 :                 ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef;
     294        1146 :             aParam.bIn      = sal_True;
     295        1146 :             aParam.bOut     = sal_False;
     296             : 
     297        1146 :             typelib_TypeDescriptionReference * pReturnTypeRef = 0;
     298        1146 :             OUString aVoidName("void");
     299             :             typelib_typedescriptionreference_new(
     300        1146 :                 &pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
     301             : 
     302             :             // dependent dispatch
     303        1146 :             aVtableSlot.index += 1; // get, then set method
     304             :             cpp_call(
     305             :                 pThis, aVtableSlot,
     306             :                 pReturnTypeRef,
     307             :                 1, &aParam,
     308        1146 :                 pReturn, pArgs, ppException );
     309             : 
     310        1146 :             typelib_typedescriptionreference_release( pReturnTypeRef );
     311             :         }
     312             : 
     313        7334 :         break;
     314             :     }
     315             :     case typelib_TypeClass_INTERFACE_METHOD:
     316             :     {
     317             :         VtableSlot aVtableSlot(
     318             :             getVtableSlot(
     319             :                 reinterpret_cast<
     320             :                     typelib_InterfaceMethodTypeDescription const * >(
     321      201558 :                         pMemberDescr)));
     322      201558 :         switch (aVtableSlot.index)
     323             :         {
     324             :             // standard calls
     325             :         case 1: // acquire uno interface
     326           0 :             (*pUnoI->acquire)( pUnoI );
     327           0 :             *ppException = 0;
     328           0 :             break;
     329             :         case 2: // release uno interface
     330           0 :             (*pUnoI->release)( pUnoI );
     331           0 :             *ppException = 0;
     332           0 :             break;
     333             :         case 0: // queryInterface() opt
     334             :         {
     335       25197 :             typelib_TypeDescription * pTD = 0;
     336       25197 :             TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( pArgs[0] )->getTypeLibType() );
     337       25197 :             if (pTD)
     338             :             {
     339       25197 :                 uno_Interface * pInterface = 0;
     340       25197 :                 (*pThis->pBridge->getUnoEnv()->getRegisteredInterface)(
     341             :                     pThis->pBridge->getUnoEnv(),
     342       25197 :                     (void **)&pInterface, pThis->oid.pData, (typelib_InterfaceTypeDescription *)pTD );
     343             : 
     344       25197 :                 if (pInterface)
     345             :                 {
     346             :                     ::uno_any_construct(
     347             :                         reinterpret_cast< uno_Any * >( pReturn ),
     348        7930 :                         &pInterface, pTD, 0 );
     349        7930 :                     (*pInterface->release)( pInterface );
     350        7930 :                     TYPELIB_DANGER_RELEASE( pTD );
     351        7930 :                     *ppException = 0;
     352        7930 :                     break;
     353             :                 }
     354       17267 :                 TYPELIB_DANGER_RELEASE( pTD );
     355             :             }
     356             :         } // else perform queryInterface()
     357             :         default:
     358             :             // dependent dispatch
     359             :             cpp_call(
     360             :                 pThis, aVtableSlot,
     361             :                 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pReturnTypeRef,
     362             :                 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->nParams,
     363             :                 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pParams,
     364      193628 :                 pReturn, pArgs, ppException );
     365             :         }
     366      201558 :         break;
     367             :     }
     368             :     default:
     369             :     {
     370             :         ::com::sun::star::uno::RuntimeException aExc(
     371             :             OUString("illegal member type description!"),
     372           0 :             ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
     373             : 
     374           0 :         Type const & rExcType = ::getCppuType( &aExc );
     375             :         // binary identical null reference
     376           0 :         ::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), 0 );
     377             :     }
     378             :     }
     379      208892 : }
     380             : 
     381             : } } }
     382             : 
     383             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10