VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/alloc-ef-cpp.cpp@ 44528

Last change on this file since 44528 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1/* $Id: alloc-ef-cpp.cpp 44528 2013-02-04 14:27:54Z vboxsync $ */
2/** @file
3 * IPRT - Memory Allocation, C++ electric fence.
4 */
5
6/*
7 * Copyright (C) 2006-2011 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include "alloc-ef.h"
31
32#include <iprt/asm.h>
33#include <new>
34
35
36/*******************************************************************************
37* Defined Constants And Macros *
38*******************************************************************************/
39/** @todo test this on MSC */
40
41/** MSC declares the operators as cdecl it seems. */
42#ifdef _MSC_VER
43# define RT_EF_CDECL __cdecl
44#else
45# define RT_EF_CDECL
46#endif
47
48/** MSC doesn't use the standard namespace. */
49#ifdef _MSC_VER
50# define RT_EF_SIZE_T size_t
51#else
52# define RT_EF_SIZE_T std::size_t
53#endif
54
55/** The hint that we're throwing std::bad_alloc is not apprecitated by MSC. */
56#ifdef RT_EXCEPTIONS_ENABLED
57# ifdef _MSC_VER
58# define RT_EF_THROWS_BAD_ALLOC
59# else
60# define RT_EF_THROWS_BAD_ALLOC throw(std::bad_alloc)
61# endif
62#else /* !RT_EXCEPTIONS_ENABLED */
63# define RT_EF_THROWS_BAD_ALLOC
64#endif /* !RT_EXCEPTIONS_ENABLED */
65
66
67void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb) RT_EF_THROWS_BAD_ALLOC
68{
69 void *pv = rtR3MemAlloc("new", RTMEMTYPE_NEW, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
70 if (!pv)
71 throw std::bad_alloc();
72 return pv;
73}
74
75
76void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb, const std::nothrow_t &) RT_NO_THROW
77{
78 void *pv = rtR3MemAlloc("new nothrow", RTMEMTYPE_NEW, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
79 return pv;
80}
81
82
83void RT_EF_CDECL operator delete(void *pv) RT_NO_THROW
84{
85 rtR3MemFree("delete", RTMEMTYPE_DELETE, pv, ASMReturnAddress(), NULL, 0, NULL);
86}
87
88
89void RT_EF_CDECL operator delete(void * pv, const std::nothrow_t &) RT_NO_THROW
90{
91 rtR3MemFree("delete nothrow", RTMEMTYPE_DELETE, pv, ASMReturnAddress(), NULL, 0, NULL);
92}
93
94
95/*
96 *
97 * Array object form.
98 * Array object form.
99 * Array object form.
100 *
101 */
102
103void *RT_EF_CDECL operator new[](RT_EF_SIZE_T cb) RT_EF_THROWS_BAD_ALLOC
104{
105 void *pv = rtR3MemAlloc("new[]", RTMEMTYPE_NEW_ARRAY, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
106 if (!pv)
107 throw std::bad_alloc();
108 return pv;
109}
110
111
112void * RT_EF_CDECL operator new[](RT_EF_SIZE_T cb, const std::nothrow_t &) RT_NO_THROW
113{
114 void *pv = rtR3MemAlloc("new[] nothrow", RTMEMTYPE_NEW_ARRAY, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
115 return pv;
116}
117
118
119void RT_EF_CDECL operator delete[](void * pv) RT_NO_THROW
120{
121 rtR3MemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, ASMReturnAddress(), NULL, 0, NULL);
122}
123
124
125void RT_EF_CDECL operator delete[](void *pv, const std::nothrow_t &) RT_NO_THROW
126{
127 rtR3MemFree("delete[] nothrow", RTMEMTYPE_DELETE_ARRAY, pv, ASMReturnAddress(), NULL, 0, NULL);
128}
129
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette