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

Side by Side Diff: core/fxcrt/include/fx_memory.h

Issue 2031653003: Get rid of NULLs in fpdfsdk/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@nullptr_core
Patch Set: rebase Created 4 years, 6 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
« no previous file with comments | « core/fxcrt/fx_basic_bstring_unittest.cpp ('k') | fpdfsdk/formfiller/cba_fontmap.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #ifndef CORE_FXCRT_INCLUDE_FX_MEMORY_H_ 7 #ifndef CORE_FXCRT_INCLUDE_FX_MEMORY_H_
8 #define CORE_FXCRT_INCLUDE_FX_MEMORY_H_ 8 #define CORE_FXCRT_INCLUDE_FX_MEMORY_H_
9 9
10 #include "core/fxcrt/include/fx_system.h" 10 #include "core/fxcrt/include/fx_system.h"
11 11
12 #ifdef __cplusplus 12 #ifdef __cplusplus
13 extern "C" { 13 extern "C" {
14 #endif 14 #endif
15 15
16 // For external C libraries to malloc through PDFium. These may return NULL. 16 // For external C libraries to malloc through PDFium. These may return nullptr.
17 void* FXMEM_DefaultAlloc(size_t byte_size, int flags); 17 void* FXMEM_DefaultAlloc(size_t byte_size, int flags);
18 void* FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags); 18 void* FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags);
19 void FXMEM_DefaultFree(void* pointer, int flags); 19 void FXMEM_DefaultFree(void* pointer, int flags);
20 20
21 #ifdef __cplusplus 21 #ifdef __cplusplus
22 } // extern "C" 22 } // extern "C"
23 23
24 #include <stdlib.h> 24 #include <stdlib.h>
25 #include <limits> 25 #include <limits>
26 #include <new> 26 #include <new>
(...skipping 27 matching lines...) Expand all
54 inline void* FX_ReallocOrDie(void* ptr, 54 inline void* FX_ReallocOrDie(void* ptr,
55 size_t num_members, 55 size_t num_members,
56 size_t member_size) { 56 size_t member_size) {
57 if (void* result = FX_SafeRealloc(ptr, num_members, member_size)) { 57 if (void* result = FX_SafeRealloc(ptr, num_members, member_size)) {
58 return result; 58 return result;
59 } 59 }
60 FX_OutOfMemoryTerminate(); // Never returns. 60 FX_OutOfMemoryTerminate(); // Never returns.
61 return nullptr; // Suppress compiler warning. 61 return nullptr; // Suppress compiler warning.
62 } 62 }
63 63
64 // Never returns NULL. 64 // Never returns nullptr.
65 #define FX_Alloc(type, size) (type*) FX_AllocOrDie(size, sizeof(type)) 65 #define FX_Alloc(type, size) (type*) FX_AllocOrDie(size, sizeof(type))
66 #define FX_Alloc2D(type, w, h) (type*) FX_AllocOrDie2D(w, h, sizeof(type)) 66 #define FX_Alloc2D(type, w, h) (type*) FX_AllocOrDie2D(w, h, sizeof(type))
67 #define FX_Realloc(type, ptr, size) \ 67 #define FX_Realloc(type, ptr, size) \
68 (type*) FX_ReallocOrDie(ptr, size, sizeof(type)) 68 (type*) FX_ReallocOrDie(ptr, size, sizeof(type))
69 69
70 // May return NULL. 70 // May return nullptr.
71 #define FX_TryAlloc(type, size) (type*) calloc(size, sizeof(type)) 71 #define FX_TryAlloc(type, size) (type*) calloc(size, sizeof(type))
72 #define FX_TryRealloc(type, ptr, size) \ 72 #define FX_TryRealloc(type, ptr, size) \
73 (type*) FX_SafeRealloc(ptr, size, sizeof(type)) 73 (type*) FX_SafeRealloc(ptr, size, sizeof(type))
74 74
75 #define FX_Free(ptr) free(ptr) 75 #define FX_Free(ptr) free(ptr)
76 76
77 // The FX_ArraySize(arr) macro returns the # of elements in an array arr. 77 // The FX_ArraySize(arr) macro returns the # of elements in an array arr.
78 // The expression is a compile-time constant, and therefore can be 78 // The expression is a compile-time constant, and therefore can be
79 // used in defining new arrays, for example. If you use FX_ArraySize on 79 // used in defining new arrays, for example. If you use FX_ArraySize on
80 // a pointer by mistake, you will get a compile-time error. 80 // a pointer by mistake, you will get a compile-time error.
(...skipping 20 matching lines...) Expand all
101 }; 101 };
102 102
103 class CFX_Deletable { 103 class CFX_Deletable {
104 public: 104 public:
105 virtual ~CFX_Deletable() {} 105 virtual ~CFX_Deletable() {}
106 }; 106 };
107 107
108 #endif // __cplusplus 108 #endif // __cplusplus
109 109
110 #endif // CORE_FXCRT_INCLUDE_FX_MEMORY_H_ 110 #endif // CORE_FXCRT_INCLUDE_FX_MEMORY_H_
OLDNEW
« no previous file with comments | « core/fxcrt/fx_basic_bstring_unittest.cpp ('k') | fpdfsdk/formfiller/cba_fontmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698