Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: base/allocator/generic_allocators.cc

Issue 419323002: clang/win: Fix a few warnings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // When possible, we implement allocator functions on top of the basic 5 // When possible, we implement allocator functions on top of the basic
6 // low-level functions malloc() and free(). This way, including a new 6 // low-level functions malloc() and free(). This way, including a new
7 // allocator is as simple as providing just a small interface. 7 // allocator is as simple as providing just a small interface.
8 // 8 //
9 // As such, this file should not contain any allocator-specific code. 9 // As such, this file should not contain any allocator-specific code.
10 10
(...skipping 10 matching lines...) Expand all
21 } 21 }
22 return ptr; 22 return ptr;
23 } 23 }
24 24
25 extern "C++" { 25 extern "C++" {
26 26
27 void* __cdecl operator new(size_t size) { 27 void* __cdecl operator new(size_t size) {
28 return generic_cpp_alloc(size, false); 28 return generic_cpp_alloc(size, false);
29 } 29 }
30 30
31 void operator delete(void* p) __THROW { 31 void operator delete(void* p) throw() {
32 free(p); 32 free(p);
33 } 33 }
34 34
35 void* operator new[](size_t size) { 35 void* operator new[](size_t size) {
36 return generic_cpp_alloc(size, false); 36 return generic_cpp_alloc(size, false);
37 } 37 }
38 38
39 void operator delete[](void* p) __THROW { 39 void operator delete[](void* p) throw() {
40 free(p); 40 free(p);
41 } 41 }
42 42
43 void* operator new(size_t size, const std::nothrow_t& nt) __THROW { 43 void* operator new(size_t size, const std::nothrow_t& nt) throw() {
44 return generic_cpp_alloc(size, true); 44 return generic_cpp_alloc(size, true);
45 } 45 }
46 46
47 void* operator new[](size_t size, const std::nothrow_t& nt) __THROW { 47 void* operator new[](size_t size, const std::nothrow_t& nt) throw() {
48 return generic_cpp_alloc(size, true); 48 return generic_cpp_alloc(size, true);
49 } 49 }
50 50
51 // This function behaves similarly to MSVC's _set_new_mode. 51 // This function behaves similarly to MSVC's _set_new_mode.
52 // If flag is 0 (default), calls to malloc will behave normally. 52 // If flag is 0 (default), calls to malloc will behave normally.
53 // If flag is 1, calls to malloc will behave like calls to new, 53 // If flag is 1, calls to malloc will behave like calls to new,
54 // and the std_new_handler will be invoked on failure. 54 // and the std_new_handler will be invoked on failure.
55 // Returns the previous mode. 55 // Returns the previous mode.
56 int _set_new_mode(int flag) __THROW { 56 int _set_new_mode(int flag) throw() {
57 int old_mode = new_mode; 57 int old_mode = new_mode;
58 new_mode = flag; 58 new_mode = flag;
59 return old_mode; 59 return old_mode;
60 } 60 }
61 61
62 } // extern "C++" 62 } // extern "C++"
63 63
64 extern "C" { 64 extern "C" {
65 65
66 void* calloc(size_t n, size_t elem_size) __THROW { 66 void* calloc(size_t n, size_t elem_size) {
67 // Overflow check 67 // Overflow check
68 const size_t size = n * elem_size; 68 const size_t size = n * elem_size;
69 if (elem_size != 0 && size / elem_size != n) return NULL; 69 if (elem_size != 0 && size / elem_size != n) return NULL;
70 70
71 void* result = malloc(size); 71 void* result = malloc(size);
72 if (result != NULL) { 72 if (result != NULL) {
73 memset(result, 0, size); 73 memset(result, 0, size);
74 } 74 }
75 return result; 75 return result;
76 } 76 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 159
160 void* _calloc_dbg(size_t n, size_t size, int, const char*, int) { 160 void* _calloc_dbg(size_t n, size_t size, int, const char*, int) {
161 return calloc(n, size); 161 return calloc(n, size);
162 } 162 }
163 #endif // NDEBUG 163 #endif // NDEBUG
164 164
165 #endif // WIN32 165 #endif // WIN32
166 166
167 } // extern C 167 } // extern C
168 168
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698