1 | /** @file
|
---|
2 | * IPRT / No-CRT - Our own new header.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2022 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef IPRT_INCLUDED_nocrt_new
|
---|
27 | #define IPRT_INCLUDED_nocrt_new
|
---|
28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
29 | # pragma once
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <iprt/types.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | /** MSC declares the operators as cdecl it seems. */
|
---|
36 | #ifdef _MSC_VER
|
---|
37 | # define RT_NEW_DELETE_CDECL __cdecl
|
---|
38 | #else
|
---|
39 | # define RT_NEW_DELETE_CDECL
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | /** MSC doesn't use the standard namespace. */
|
---|
43 | #ifdef _MSC_VER
|
---|
44 | # define RT_NEW_DELETE_SIZE_T size_t
|
---|
45 | #else
|
---|
46 | # define RT_NEW_DELETE_SIZE_T std::size_t
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | /** The hint that we're throwing std::bad_alloc is not apprecitated by MSC. */
|
---|
50 | #ifdef RT_EXCEPTIONS_ENABLED
|
---|
51 | # ifdef _MSC_VER
|
---|
52 | # define RT_NEW_DELETE_THROWS_BAD_ALLOC
|
---|
53 | # define RT_NEW_DELETE_NOTHROW RT_NO_THROW_DEF
|
---|
54 | # else
|
---|
55 | # ifdef _GLIBCXX_THROW
|
---|
56 | # define RT_NEW_DELETE_THROWS_BAD_ALLOC _GLIBCXX_THROW(std::bad_alloc)
|
---|
57 | # elif defined(__cplusplus) && (__cplusplus + 0) < 201700
|
---|
58 | # define RT_NEW_DELETE_THROWS_BAD_ALLOC throw(std::bad_alloc)
|
---|
59 | # else
|
---|
60 | # define RT_NEW_DELETE_THROWS_BAD_ALLOC noexcept(false)
|
---|
61 | # endif
|
---|
62 | # define RT_NEW_DELETE_NOTHROW throw()
|
---|
63 | # endif
|
---|
64 | #else /* !RT_EXCEPTIONS_ENABLED */
|
---|
65 | # define RT_NEW_DELETE_THROWS_BAD_ALLOC
|
---|
66 | # define RT_NEW_DELETE_NOTHROW
|
---|
67 | #endif /* !RT_EXCEPTIONS_ENABLED */
|
---|
68 |
|
---|
69 |
|
---|
70 | #ifdef IPRT_NO_CRT
|
---|
71 |
|
---|
72 | namespace std
|
---|
73 | {
|
---|
74 | struct nothrow_t
|
---|
75 | {
|
---|
76 | explicit nothrow_t()
|
---|
77 | {}
|
---|
78 | };
|
---|
79 | extern __declspec(selectany) nothrow_t const nothrow;
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | void *RT_NEW_DELETE_CDECL operator new(RT_NEW_DELETE_SIZE_T cb) RT_NEW_DELETE_THROWS_BAD_ALLOC;
|
---|
84 | void *RT_NEW_DELETE_CDECL operator new(RT_NEW_DELETE_SIZE_T cb, const std::nothrow_t &) RT_NEW_DELETE_NOTHROW;
|
---|
85 | void *RT_NEW_DELETE_CDECL operator new(RT_NEW_DELETE_SIZE_T cb, void *pvPlacment) RT_NEW_DELETE_NOTHROW;
|
---|
86 | void RT_NEW_DELETE_CDECL operator delete(void *pv) RT_NEW_DELETE_NOTHROW;
|
---|
87 | #ifdef __cpp_sized_deallocation
|
---|
88 | void RT_NEW_DELETE_CDECL operator delete(void *pv, RT_NEW_DELETE_SIZE_T cb) RT_NEW_DELETE_NOTHROW;
|
---|
89 | #endif
|
---|
90 | void RT_NEW_DELETE_CDECL operator delete(void *pv, const std::nothrow_t &) RT_NEW_DELETE_NOTHROW;
|
---|
91 |
|
---|
92 |
|
---|
93 | void *RT_NEW_DELETE_CDECL operator new[](RT_NEW_DELETE_SIZE_T cb) RT_NEW_DELETE_THROWS_BAD_ALLOC;
|
---|
94 | void *RT_NEW_DELETE_CDECL operator new[](RT_NEW_DELETE_SIZE_T cb, const std::nothrow_t &) RT_NEW_DELETE_NOTHROW;
|
---|
95 | void *RT_NEW_DELETE_CDECL operator new[](RT_NEW_DELETE_SIZE_T cb, void *pvPlacement) RT_NEW_DELETE_NOTHROW;
|
---|
96 | void RT_NEW_DELETE_CDECL operator delete[](void * pv) RT_NEW_DELETE_NOTHROW;
|
---|
97 | #ifdef __cpp_sized_deallocation
|
---|
98 | void RT_NEW_DELETE_CDECL operator delete[](void * pv, RT_NEW_DELETE_SIZE_T cb) RT_NEW_DELETE_NOTHROW;
|
---|
99 | #endif
|
---|
100 | void RT_NEW_DELETE_CDECL operator delete[](void *pv, const std::nothrow_t &) RT_NEW_DELETE_NOTHROW;
|
---|
101 |
|
---|
102 |
|
---|
103 | #else /* IPRT_NO_CRT */
|
---|
104 | # include <new>
|
---|
105 | #endif /* IPRT_NO_CRT */
|
---|
106 |
|
---|
107 | #endif /* !IPRT_INCLUDED_nocrt_new */
|
---|
108 |
|
---|