LCOV - code coverage report
Current view: top level - bridges/source/cpp_uno/gcc3_linux_x86-64 - except.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 44 55 80.0 %
Date: 2015-06-13 12:38:46 Functions: 4 4 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             : #include <stdio.h>
      22             : #include <string.h>
      23             : 
      24             : #include <rtl/ustrbuf.hxx>
      25             : #include <sal/log.hxx>
      26             : 
      27             : #include <com/sun/star/uno/genfunc.hxx>
      28             : #include "com/sun/star/uno/RuntimeException.hpp"
      29             : #include <typelib/typedescription.hxx>
      30             : #include <uno/any2.h>
      31             : 
      32             : #include "rtti.hxx"
      33             : #include "share.hxx"
      34             : 
      35             : 
      36             : using namespace ::std;
      37             : using namespace ::com::sun::star::uno;
      38             : using namespace ::__cxxabiv1;
      39             : 
      40             : 
      41             : namespace CPPU_CURRENT_NAMESPACE
      42             : {
      43             : 
      44       27860 : static OUString toUNOname( char const * p )
      45             : {
      46             : #if OSL_DEBUG_LEVEL > 1
      47             :     char const * start = p;
      48             : #endif
      49             : 
      50             :     // example: N3com3sun4star4lang24IllegalArgumentExceptionE
      51             : 
      52       27860 :     OUStringBuffer buf( 64 );
      53             :     assert( 'N' == *p );
      54       27860 :     ++p; // skip N
      55             : 
      56      196787 :     while ('E' != *p)
      57             :     {
      58             :         // read chars count
      59      141067 :         long n = (*p++ - '0');
      60      309997 :         while ('0' <= *p && '9' >= *p)
      61             :         {
      62       27863 :             n *= 10;
      63       27863 :             n += (*p++ - '0');
      64             :         }
      65      141067 :         buf.appendAscii( p, n );
      66      141067 :         p += n;
      67      141067 :         if ('E' != *p)
      68      113207 :             buf.append( '.' );
      69             :     }
      70             : 
      71             : #if OSL_DEBUG_LEVEL > 1
      72             :     OUString ret( buf.makeStringAndClear() );
      73             :     OString c_ret( OUStringToOString( ret, RTL_TEXTENCODING_ASCII_US ) );
      74             :     fprintf( stderr, "> toUNOname(): %s => %s\n", start, c_ret.getStr() );
      75             :     return ret;
      76             : #else
      77       27860 :     return buf.makeStringAndClear();
      78             : #endif
      79             : }
      80             : 
      81             : extern "C" {
      82       22964 : static void _GLIBCXX_CDTOR_CALLABI deleteException( void * pExc )
      83             : {
      84       22964 :     __cxa_exception const * header = (static_cast<__cxa_exception const *>(pExc) - 1);
      85       22964 :     typelib_TypeDescription * pTD = 0;
      86       22964 :     OUString unoName( toUNOname( header->exceptionType->name() ) );
      87       22964 :     ::typelib_typedescription_getByName( &pTD, unoName.pData );
      88             :     assert(pTD && "### unknown exception type! leaving out destruction => leaking!!!");
      89       22964 :     if (pTD)
      90             :     {
      91       22964 :         ::uno_destructData( pExc, pTD, cpp_release );
      92       22964 :         ::typelib_typedescription_release( pTD );
      93       22964 :     }
      94       22964 : }
      95             : }
      96             : 
      97       22964 : void raiseException( uno_Any * pUnoExc, uno_Mapping * pUno2Cpp )
      98             : {
      99             : #if OSL_DEBUG_LEVEL > 1
     100             :     OString cstr(
     101             :         OUStringToOString(
     102             :             OUString::unacquired( &pUnoExc->pType->pTypeName ),
     103             :             RTL_TEXTENCODING_ASCII_US ) );
     104             :     fprintf( stderr, "> uno exception occurred: %s\n", cstr.getStr() );
     105             : #endif
     106             :     void * pCppExc;
     107             :     type_info * rtti;
     108             : 
     109             :     {
     110             :     // construct cpp exception object
     111       22964 :     typelib_TypeDescription * pTypeDescr = 0;
     112       22964 :     TYPELIB_DANGER_GET( &pTypeDescr, pUnoExc->pType );
     113             :     assert(pTypeDescr);
     114       22964 :     if (! pTypeDescr)
     115             :     {
     116             :         throw RuntimeException(
     117           0 :             "cannot get typedescription for type " +
     118           0 :             OUString::unacquired( &pUnoExc->pType->pTypeName ) );
     119             :     }
     120             : 
     121       22964 :     pCppExc = __cxxabiv1::__cxa_allocate_exception( pTypeDescr->nSize );
     122       22964 :     ::uno_copyAndConvertData( pCppExc, pUnoExc->pData, pTypeDescr, pUno2Cpp );
     123             : 
     124             :     // destruct uno exception
     125       22964 :     ::uno_any_destruct( pUnoExc, 0 );
     126             :     // avoiding locked counts
     127       22964 :     rtti = x86_64::getRtti(*pTypeDescr);
     128       22964 :     TYPELIB_DANGER_RELEASE( pTypeDescr );
     129             :     assert(rtti && "### no rtti for throwing exception!");
     130       22964 :     if (! rtti)
     131             :     {
     132             :         throw RuntimeException(
     133           0 :             "no rtti for type " +
     134           0 :             OUString::unacquired( &pUnoExc->pType->pTypeName ) );
     135             :     }
     136             :     }
     137             : 
     138       22964 :     __cxxabiv1::__cxa_throw( pCppExc, rtti, deleteException );
     139             : }
     140             : 
     141        4896 : void fillUnoException( __cxa_exception * header, uno_Any * pUnoExc, uno_Mapping * pCpp2Uno )
     142             : {
     143        4896 :     if (! header)
     144             :     {
     145           0 :         RuntimeException aRE( "no exception header!" );
     146           0 :         Type const & rType = cppu::UnoType<decltype(aRE)>::get();
     147           0 :         uno_type_any_constructAndConvert( pUnoExc, &aRE, rType.getTypeLibType(), pCpp2Uno );
     148             :         SAL_WARN("bridges", aRE.Message);
     149        4896 :         return;
     150             :     }
     151             : 
     152        4896 :     typelib_TypeDescription * pExcTypeDescr = 0;
     153        4896 :     OUString unoName( toUNOname( header->exceptionType->name() ) );
     154             : #if OSL_DEBUG_LEVEL > 1
     155             :     OString cstr_unoName( OUStringToOString( unoName, RTL_TEXTENCODING_ASCII_US ) );
     156             :     fprintf( stderr, "> c++ exception occurred: %s\n", cstr_unoName.getStr() );
     157             : #endif
     158        4896 :     typelib_typedescription_getByName( &pExcTypeDescr, unoName.pData );
     159        4896 :     if (0 == pExcTypeDescr)
     160             :     {
     161           0 :         RuntimeException aRE( "exception type not found: " + unoName );
     162           0 :         Type const & rType = cppu::UnoType<decltype(aRE)>::get();
     163           0 :         uno_type_any_constructAndConvert( pUnoExc, &aRE, rType.getTypeLibType(), pCpp2Uno );
     164           0 :         SAL_WARN("bridges", aRE.Message);
     165             :     }
     166             :     else
     167             :     {
     168             :         // construct uno exception any
     169        4896 :         uno_any_constructAndConvert( pUnoExc, header->adjustedPtr, pExcTypeDescr, pCpp2Uno );
     170        4896 :         typelib_typedescription_release( pExcTypeDescr );
     171        4896 :     }
     172             : }
     173             : 
     174             : }
     175             : 
     176             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11