|
|
|||
File indexing completed on 2026-01-09 09:40:44
0001 // Copyright 2018 The Abseil Authors. 0002 // 0003 // Licensed under the Apache License, Version 2.0 (the "License"); 0004 // you may not use this file except in compliance with the License. 0005 // You may obtain a copy of the License at 0006 // 0007 // https://www.apache.org/licenses/LICENSE-2.0 0008 // 0009 // Unless required by applicable law or agreed to in writing, software 0010 // distributed under the License is distributed on an "AS IS" BASIS, 0011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0012 // See the License for the specific language governing permissions and 0013 // limitations under the License. 0014 0015 #ifndef ABSL_BASE_INTERNAL_HIDE_PTR_H_ 0016 #define ABSL_BASE_INTERNAL_HIDE_PTR_H_ 0017 0018 #include <cstdint> 0019 0020 #include "absl/base/config.h" 0021 0022 namespace absl { 0023 ABSL_NAMESPACE_BEGIN 0024 namespace base_internal { 0025 0026 // Arbitrary value with high bits set. Xor'ing with it is unlikely 0027 // to map one valid pointer to another valid pointer. 0028 constexpr uintptr_t HideMask() { 0029 return (uintptr_t{0xF03A5F7BU} << (sizeof(uintptr_t) - 4) * 8) | 0xF03A5F7BU; 0030 } 0031 0032 // Hide a pointer from the leak checker. For internal use only. 0033 // Differs from absl::IgnoreLeak(ptr) in that absl::IgnoreLeak(ptr) causes ptr 0034 // and all objects reachable from ptr to be ignored by the leak checker. 0035 template <class T> 0036 inline uintptr_t HidePtr(T* ptr) { 0037 return reinterpret_cast<uintptr_t>(ptr) ^ HideMask(); 0038 } 0039 0040 // Return a pointer that has been hidden from the leak checker. 0041 // For internal use only. 0042 template <class T> 0043 inline T* UnhidePtr(uintptr_t hidden) { 0044 return reinterpret_cast<T*>(hidden ^ HideMask()); 0045 } 0046 0047 } // namespace base_internal 0048 ABSL_NAMESPACE_END 0049 } // namespace absl 0050 0051 #endif // ABSL_BASE_INTERNAL_HIDE_PTR_H_
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|