OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/allocator/type_profiler.h" | |
6 | |
7 #if defined(TYPE_PROFILING) | |
8 | |
9 namespace base { | |
10 namespace type_profiler { | |
11 | |
12 // These variables are not in the InterceptFunctios class so that: | |
jar (doing other things)
2012/09/06 19:31:43
nit: InterceptFunctios --> InterceptFunctions
Dai Mikurube (NOT FULLTIME)
2012/09/07 08:06:45
Finally, removed the comment.
| |
13 // * They are visible from __op_new_intercept__ and __op_delete_intercept__. | |
14 // * They are invisible from any other functions. | |
jar (doing other things)
2012/09/06 19:31:43
I don't understand why you didn't just make them p
Dai Mikurube (NOT FULLTIME)
2012/09/07 08:06:45
Done.
| |
15 // | |
16 // Note that it is impossible to hide them by 'friend' | |
17 // since __op_new_intercept__ and __op_delete_intercept__ must be global. | |
jar (doing other things)
2012/09/06 19:31:43
Global function can be friends.
Nice example in ht
Dai Mikurube (NOT FULLTIME)
2012/09/07 08:06:45
Done.
| |
18 static InterceptFunction* g_new_intercept = NopIntercept; | |
19 static InterceptFunction* g_delete_intercept = NopIntercept; | |
20 | |
21 // static | |
22 bool InterceptFunctions::SetFunctions(InterceptFunction* new_intercept, | |
23 InterceptFunction* delete_intercept) { | |
24 #if !defined(NDEBUG) | |
25 // DCHECKs are wanted for these checks, but base/logging is not acceptable. | |
jar (doing other things)
2012/09/06 19:31:43
It is confusing to have code in base/allocator/*,
Dai Mikurube (NOT FULLTIME)
2012/09/07 08:06:45
Done.
| |
26 // This file is linked with many non-Chromium code. | |
27 if (g_new_intercept != NopIntercept) | |
28 return false; | |
29 if (g_delete_intercept != NopIntercept) | |
30 return false; | |
31 #endif // !defined(NDEBUG) | |
32 | |
33 g_new_intercept = new_intercept; | |
34 g_delete_intercept = delete_intercept; | |
35 return true; | |
36 } | |
37 | |
38 // static | |
39 bool InterceptFunctions::IsAvailable() { | |
40 return g_new_intercept != NopIntercept || g_delete_intercept != NopIntercept; | |
41 } | |
42 | |
43 void* NopIntercept(void* ptr, size_t size, const std::type_info& type) { | |
44 return ptr; | |
45 } | |
46 | |
47 } // namespace type_profiler | |
48 } // namespace base | |
49 | |
50 void* __op_new_intercept__(void* ptr, | |
51 size_t size, | |
52 const std::type_info& type) { | |
53 return base::type_profiler::g_new_intercept(ptr, size, type); | |
54 } | |
55 | |
56 void* __op_delete_intercept__(void* ptr, | |
57 size_t size, | |
58 const std::type_info& type) { | |
59 return base::type_profiler::g_delete_intercept(ptr, size, type); | |
60 } | |
61 | |
62 #endif // defined(TYPE_PROFILING) | |
OLD | NEW |