LCOV - code coverage report
Current view: top level - sal/osl/all - debugbase.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 47 2.1 %
Date: 2015-06-13 12:38:46 Functions: 2 9 22.2 %
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             : #include "rtl/strbuf.hxx"
      21             : #include "rtl/string.hxx"
      22             : #include "rtl/ustring.hxx"
      23             : #include "osl/process.h"
      24             : #include "osl/diagnose.hxx"
      25             : #include "sal/log.hxx"
      26             : #include "boost/bind.hpp"
      27             : #include <algorithm>
      28             : #include <vector>
      29             : 
      30             : namespace {
      31             : 
      32             : typedef std::vector<rtl::OString> OStringVec;
      33             : 
      34             : struct StaticDebugBaseAddressFilter
      35             :     : rtl::StaticWithInit<OStringVec, StaticDebugBaseAddressFilter> {
      36           0 :     OStringVec operator()() const {
      37           0 :         OStringVec vec;
      38           0 :         rtl_uString * pStr = 0;
      39             :         rtl::OUString const name(
      40           0 :             "OSL_DEBUGBASE_STORE_ADDRESSES" );
      41           0 :         if (osl_getEnvironment( name.pData, &pStr ) == osl_Process_E_None) {
      42           0 :             rtl::OUString const str(pStr);
      43           0 :             rtl_uString_release(pStr);
      44           0 :             sal_Int32 nIndex = 0;
      45           0 :             do {
      46             :                 vec.push_back( rtl::OUStringToOString(
      47             :                                    str.getToken( 0, ';', nIndex ),
      48           0 :                                    RTL_TEXTENCODING_ASCII_US ) );
      49             :             }
      50           0 :             while (nIndex >= 0);
      51             :         }
      52           0 :         return vec;
      53             :     }
      54             : };
      55             : 
      56           0 : inline bool isSubStr( char const* pStr, rtl::OString const& subStr )
      57             : {
      58           0 :     return rtl_str_indexOfStr( pStr, subStr.getStr() ) >= 0;
      59             : }
      60             : 
      61             : struct DebugBaseMutex : rtl::Static<osl::Mutex, DebugBaseMutex> {};
      62             : 
      63             : } // anon namespace
      64             : 
      65             : extern "C" {
      66             : 
      67             : // These functions presumably should not be extern "C", but changing
      68             : // that would break binary compatibility.
      69             : #ifdef __clang__
      70             : #pragma clang diagnostic push
      71             : // Guard against slightly older clang versions that don't have
      72             : // -Wreturn-type-c-linkage...
      73             : #pragma clang diagnostic ignored "-Wunknown-pragmas"
      74             : #pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
      75             : #endif
      76             : 
      77           0 : osl::Mutex & SAL_CALL osl_detail_ObjectRegistry_getMutex()
      78             :     SAL_THROW_EXTERN_C()
      79             : {
      80           0 :     return DebugBaseMutex::get();
      81             : }
      82             : #ifdef __clang__
      83             : #pragma clang diagnostic pop
      84             : #endif
      85             : 
      86           0 : bool SAL_CALL osl_detail_ObjectRegistry_storeAddresses( char const* pName )
      87             :     SAL_THROW_EXTERN_C()
      88             : {
      89           0 :     OStringVec const& rVec = StaticDebugBaseAddressFilter::get();
      90           0 :     if (rVec.empty())
      91           0 :         return false;
      92             :     // check for "all":
      93           0 :     rtl::OString const& rFirst = rVec[0];
      94           0 :     if (rtl_str_compare_WithLength( rFirst.getStr(), rFirst.getLength(),
      95           0 :                                     RTL_CONSTASCII_STRINGPARAM("all") ) == 0)
      96           0 :         return true;
      97           0 :     OStringVec::const_iterator const iEnd( rVec.end() );
      98             :     return std::find_if( rVec.begin(), iEnd,
      99           0 :                          boost::bind( &isSubStr, pName, _1 ) ) != iEnd;
     100             : }
     101             : 
     102           0 : bool SAL_CALL osl_detail_ObjectRegistry_checkObjectCount(
     103             :     osl::detail::ObjectRegistryData const& rData, std::size_t nExpected )
     104             :     SAL_THROW_EXTERN_C()
     105             : {
     106             :     std::size_t nSize;
     107           0 :     if (rData.m_bStoreAddresses)
     108           0 :         nSize = rData.m_addresses.size();
     109             :     else
     110           0 :         nSize = static_cast<std::size_t>(rData.m_nCount);
     111             : 
     112           0 :     bool const bRet = (nSize == nExpected);
     113             :     SAL_WARN_IF(
     114             :         !bRet, "sal.osl",
     115             :         "unexpected number of " << rData.m_pName << ": " << nSize
     116             :             << "; Expected: " << nExpected);
     117           0 :     return bRet;
     118             : }
     119             : 
     120           0 : void SAL_CALL osl_detail_ObjectRegistry_registerObject(
     121             :     osl::detail::ObjectRegistryData & rData, void const* pObj )
     122             :     SAL_THROW_EXTERN_C()
     123             : {
     124           0 :     if (rData.m_bStoreAddresses) {
     125           0 :         osl::MutexGuard const guard( osl_detail_ObjectRegistry_getMutex() );
     126             :         std::pair<osl::detail::VoidPointerSet::iterator, bool> const insertion(
     127           0 :             rData.m_addresses.insert(pObj) );
     128           0 :         SAL_WARN_IF(!insertion.second, "sal.osl", "insertion failed!?");
     129             :     }
     130             :     else {
     131           0 :         osl_atomic_increment(&rData.m_nCount);
     132             :     }
     133           0 : }
     134             : 
     135           0 : void SAL_CALL osl_detail_ObjectRegistry_revokeObject(
     136             :     osl::detail::ObjectRegistryData & rData, void const* pObj )
     137             :     SAL_THROW_EXTERN_C()
     138             : {
     139           0 :     if (rData.m_bStoreAddresses) {
     140           0 :         osl::MutexGuard const guard( osl_detail_ObjectRegistry_getMutex() );
     141           0 :         std::size_t const n = rData.m_addresses.erase(pObj);
     142           0 :         SAL_WARN_IF(n != 1, "sal.osl", "erased more than 1 entry!?");
     143             :     }
     144             :     else {
     145           0 :         osl_atomic_decrement(&rData.m_nCount);
     146             :     }
     147           0 : }
     148             : 
     149        5736 : } // extern "C"
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11