Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "rtl/strbuf.hxx"
31 : : #include "rtl/string.hxx"
32 : : #include "rtl/ustring.hxx"
33 : : #include "osl/process.h"
34 : : #include "osl/diagnose.hxx"
35 : : #include "boost/bind.hpp"
36 : : #include <vector>
37 : :
38 : : // define own ones, independent of OSL_DEBUG_LEVEL:
39 : : #define DEBUGBASE_ENSURE_(c, f, l, m) \
40 : : do \
41 : : { \
42 : : if (!(c) && _OSL_GLOBAL osl_assertFailedLine(f, l, m)) \
43 : : _OSL_GLOBAL osl_breakDebug(); \
44 : : } while (0)
45 : : #define DEBUGBASE_ENSURE(c, m) DEBUGBASE_ENSURE_(c, OSL_THIS_FILE, __LINE__, m)
46 : :
47 : : namespace {
48 : :
49 : : typedef std::vector<rtl::OString, rtl::Allocator<rtl::OString> > OStringVec;
50 : :
51 : : struct StaticDebugBaseAddressFilter
52 : : : rtl::StaticWithInit<OStringVec, StaticDebugBaseAddressFilter> {
53 : 0 : OStringVec operator()() const {
54 [ # # ]: 0 : OStringVec vec;
55 : 0 : rtl_uString * pStr = 0;
56 : : rtl::OUString const name(
57 [ # # ]: 0 : RTL_CONSTASCII_USTRINGPARAM("OSL_DEBUGBASE_STORE_ADDRESSES") );
58 [ # # ][ # # ]: 0 : if (osl_getEnvironment( name.pData, &pStr ) == osl_Process_E_None) {
59 : 0 : rtl::OUString const str(pStr);
60 : 0 : rtl_uString_release(pStr);
61 : 0 : sal_Int32 nIndex = 0;
62 [ # # ]: 0 : do {
63 : : vec.push_back( rtl::OUStringToOString(
64 : : str.getToken( 0, ';', nIndex ),
65 [ # # ][ # # ]: 0 : RTL_TEXTENCODING_ASCII_US ) );
66 : : }
67 : 0 : while (nIndex >= 0);
68 : : }
69 : 0 : return vec;
70 : : }
71 : : };
72 : :
73 : 0 : inline bool isSubStr( char const* pStr, rtl::OString const& subStr )
74 : : {
75 : 0 : return rtl_str_indexOfStr( pStr, subStr.getStr() ) >= 0;
76 : : }
77 : :
78 : : struct DebugBaseMutex : ::rtl::Static<osl::Mutex, DebugBaseMutex> {};
79 : :
80 : : } // anon namespace
81 : :
82 : : extern "C" {
83 : :
84 : : // These functions presumably should not be extern "C", but changing
85 : : // that would break binary compatibility.
86 : : #if SUPD < 400
87 : : #ifdef __clang__
88 : : #pragma clang diagnostic push
89 : : // Guard against slightly older clang versions that don't have
90 : : // -Wreturn-type-c-linkage...
91 : : #pragma clang diagnostic ignored "-Wunknown-pragmas"
92 : : #pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
93 : : #endif
94 : : #endif
95 : 0 : osl::Mutex & SAL_CALL osl_detail_ObjectRegistry_getMutex()
96 : : SAL_THROW_EXTERN_C()
97 : : {
98 : 0 : return DebugBaseMutex::get();
99 : : }
100 : : #if SUPD < 400
101 : : #ifdef __clang__
102 : : #pragma clang diagnostic pop
103 : : #endif
104 : : #endif
105 : :
106 : 0 : bool SAL_CALL osl_detail_ObjectRegistry_storeAddresses( char const* pName )
107 : : SAL_THROW_EXTERN_C()
108 : : {
109 [ # # ]: 0 : OStringVec const& rVec = StaticDebugBaseAddressFilter::get();
110 [ # # ]: 0 : if (rVec.empty())
111 : 0 : return false;
112 : : // check for "all":
113 : 0 : rtl::OString const& rFirst = rVec[0];
114 [ # # ]: 0 : if (rtl_str_compare_WithLength( rFirst.getStr(), rFirst.getLength(),
115 : 0 : RTL_CONSTASCII_STRINGPARAM("all") ) == 0)
116 : 0 : return true;
117 : 0 : OStringVec::const_iterator const iEnd( rVec.end() );
118 : : return std::find_if( rVec.begin(), iEnd,
119 [ # # ][ # # ]: 0 : boost::bind( &isSubStr, pName, _1 ) ) != iEnd;
[ # # ]
120 : : }
121 : :
122 : 0 : bool SAL_CALL osl_detail_ObjectRegistry_checkObjectCount(
123 : : osl::detail::ObjectRegistryData const& rData, std::size_t nExpected )
124 : : SAL_THROW_EXTERN_C()
125 : : {
126 : : std::size_t nSize;
127 [ # # ]: 0 : if (rData.m_bStoreAddresses)
128 : 0 : nSize = rData.m_addresses.size();
129 : : else
130 : 0 : nSize = static_cast<std::size_t>(rData.m_nCount);
131 : :
132 : 0 : bool const bRet = (nSize == nExpected);
133 [ # # ]: 0 : if (! bRet) {
134 : 0 : rtl::OStringBuffer buf;
135 [ # # ]: 0 : buf.append( RTL_CONSTASCII_STRINGPARAM("unexpected number of ") );
136 [ # # ]: 0 : buf.append( rData.m_pName );
137 [ # # ]: 0 : buf.append( RTL_CONSTASCII_STRINGPARAM(": ") );
138 [ # # ]: 0 : buf.append( static_cast<sal_Int64>(nSize) );
139 [ # # ]: 0 : buf.append("; Expected: ");
140 [ # # ]: 0 : buf.append( static_cast<sal_Int64>(nExpected) );
141 [ # # ][ # # ]: 0 : DEBUGBASE_ENSURE( false, buf.makeStringAndClear().getStr() );
[ # # ]
142 : : }
143 : 0 : return bRet;
144 : : }
145 : :
146 : 0 : void SAL_CALL osl_detail_ObjectRegistry_registerObject(
147 : : osl::detail::ObjectRegistryData & rData, void const* pObj )
148 : : SAL_THROW_EXTERN_C()
149 : : {
150 [ # # ]: 0 : if (rData.m_bStoreAddresses) {
151 [ # # ]: 0 : osl::MutexGuard const guard( osl_detail_ObjectRegistry_getMutex() );
152 : : std::pair<osl::detail::VoidPointerSet::iterator, bool> const insertion(
153 [ # # ]: 0 : rData.m_addresses.insert(pObj) );
154 [ # # ][ # # ]: 0 : DEBUGBASE_ENSURE( insertion.second, "### insertion failed!?" );
[ # # ][ # # ]
[ # # ]
155 [ # # ]: 0 : static_cast<void>(insertion);
156 : : }
157 : : else {
158 : 0 : osl_incrementInterlockedCount(&rData.m_nCount);
159 : : }
160 : 0 : }
161 : :
162 : 0 : void SAL_CALL osl_detail_ObjectRegistry_revokeObject(
163 : : osl::detail::ObjectRegistryData & rData, void const* pObj )
164 : : SAL_THROW_EXTERN_C()
165 : : {
166 [ # # ]: 0 : if (rData.m_bStoreAddresses) {
167 [ # # ]: 0 : osl::MutexGuard const guard( osl_detail_ObjectRegistry_getMutex() );
168 [ # # ]: 0 : std::size_t const n = rData.m_addresses.erase(pObj);
169 [ # # ][ # # ]: 0 : DEBUGBASE_ENSURE( n == 1, "erased more than 1 entry!?" );
[ # # ][ # # ]
[ # # ]
170 [ # # ]: 0 : static_cast<void>(n);
171 : : }
172 : : else {
173 : 0 : osl_decrementInterlockedCount(&rData.m_nCount);
174 : : }
175 : 0 : }
176 : :
177 [ + - ][ + - ]: 9039 : } // extern "C"
178 : :
179 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|