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

Generated by: LCOV version 1.10