tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sal / osl / all / debugbase.cxx
blob6f409d21c7688c9e1dc982516210b4c53ee5859f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <rtl/string.hxx>
21 #include <rtl/ustring.hxx>
22 #include <osl/process.h>
23 #include <osl/diagnose.hxx>
24 #include <sal/log.hxx>
25 #include <o3tl/string_view.hxx>
27 #include <algorithm>
28 #include <vector>
30 namespace {
32 const std::vector<OString>& StaticDebugBaseAddressFilter()
34 static const std::vector<OString> theFilter = []()
36 std::vector<OString> vec;
37 rtl_uString * pStr = nullptr;
38 if (osl_getEnvironment( u"OSL_DEBUGBASE_STORE_ADDRESSES"_ustr.pData, &pStr )
39 == osl_Process_E_None)
41 OUString const str(pStr);
42 rtl_uString_release(pStr);
43 sal_Int32 nIndex = 0;
44 do {
45 vec.push_back( OUStringToOString(
46 o3tl::getToken(str, 0, ';', nIndex ),
47 RTL_TEXTENCODING_ASCII_US ) );
49 while (nIndex >= 0);
51 return vec;
52 }();
53 return theFilter;
56 bool isSubStr( char const* pStr, OString const& subStr )
58 return rtl_str_indexOfStr( pStr, subStr.getStr() ) >= 0;
61 } // anon namespace
63 extern "C" {
65 // These functions presumably should not be extern "C", but changing
66 // that would break binary compatibility.
67 #ifdef __clang__
68 #pragma clang diagnostic push
69 #pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
70 #endif
72 osl::Mutex & SAL_CALL osl_detail_ObjectRegistry_getMutex() noexcept
74 static osl::Mutex aMutex;
75 return aMutex;
77 #ifdef __clang__
78 #pragma clang diagnostic pop
79 #endif
81 bool SAL_CALL osl_detail_ObjectRegistry_storeAddresses( char const* pName ) noexcept
83 std::vector<OString> const& rVec = StaticDebugBaseAddressFilter();
84 if (rVec.empty())
85 return false;
86 // check for "all":
87 OString const& rFirst = rVec[0];
88 if ( rFirst == "all" )
89 return true;
90 auto const iEnd( rVec.cend() );
91 return std::any_of( rVec.begin(), iEnd,
92 [pName] (OString const& it) { return isSubStr(pName, it); });
95 bool SAL_CALL osl_detail_ObjectRegistry_checkObjectCount(
96 osl::detail::ObjectRegistryData const& rData, std::size_t nExpected ) noexcept
98 std::size_t nSize;
99 if (rData.m_bStoreAddresses)
100 nSize = rData.m_addresses.size();
101 else
102 nSize = static_cast<std::size_t>(rData.m_nCount);
104 bool const bRet = (nSize == nExpected);
105 SAL_WARN_IF(
106 !bRet, "sal.osl",
107 "unexpected number of " << rData.m_pName << ": " << nSize
108 << "; Expected: " << nExpected);
109 return bRet;
112 void SAL_CALL osl_detail_ObjectRegistry_registerObject(
113 osl::detail::ObjectRegistryData & rData, void const* pObj ) noexcept
115 if (rData.m_bStoreAddresses) {
116 osl::MutexGuard const guard( osl_detail_ObjectRegistry_getMutex() );
117 std::pair<osl::detail::VoidPointerSet::iterator, bool> const insertion(
118 rData.m_addresses.insert(pObj) );
119 SAL_WARN_IF(!insertion.second, "sal.osl", "insertion failed!?");
121 else {
122 osl_atomic_increment(&rData.m_nCount);
126 void SAL_CALL osl_detail_ObjectRegistry_revokeObject(
127 osl::detail::ObjectRegistryData & rData, void const* pObj ) noexcept
129 if (rData.m_bStoreAddresses) {
130 osl::MutexGuard const guard( osl_detail_ObjectRegistry_getMutex() );
131 std::size_t const n = rData.m_addresses.erase(pObj);
132 SAL_WARN_IF(n != 1, "sal.osl", "erased more than 1 entry!?");
134 else {
135 osl_atomic_decrement(&rData.m_nCount);
139 } // extern "C"
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */