Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
Main Page
Related Pages
Topics
Namespaces
Data Structures
Files
File List
Globals
EXTERNAL_HEADERS
RSL
etc
config
src
STD_BAD_ALLOC.cpp
Go to the documentation of this file.
1
// checking for class std::bad_alloc
2
3
25
#include "config.h"
26
#include "
nodbg.h
"
27
28
#if !defined (_RWSTD_NO_NEW_THROWS) && !defined (_RWSTD_NO_NEW_OFLOW_SAFE)
29
# include <
stddef.h
>
// for size_t
30
#endif
// !_RWSTD_NO_NEW_THROWS && !_RWSTD_NO_NEW_OFLOW_SAFE
31
32
#ifndef _RWSTD_NO_SETRLIMIT
33
// test for setrlimit() presence before compiling current file
34
#endif
35
36
// proclimits.h must be included only after #if[n]def _RWSTD_NO_SETRLIMIT
37
#include "
proclimits.h
"
38
39
#ifndef _RWSTD_NO_HONOR_STD
40
# ifdef _RWSTD_NO_STD_TERMINATE
41
# include "
terminate.h
"
42
# endif
// _RWSTD_NO_STD_TERMINATE
43
#endif
// _RWSTD_NO_HONOR_STD
44
45
// will fail if namespaces aren't supported
46
namespace
std
{
47
48
struct
bad_alloc
{ };
49
50
}
51
52
// force a failure if namespace std isn't honored
53
enum
bad_alloc
{ };
54
55
56
int
main
()
57
{
58
// prevent MSVC's libc from popping up a dialog box
59
// with an out-of-memory message
60
nodbg
();
61
62
try
{
63
64
#ifndef _RWSTD_NO_NEW_THROWS
65
# ifndef _RWSTD_NO_NEW_OFLOW_SAFE
66
67
void
*
p
= ::operator
new
(size_t (-1));
68
69
if
(!
p
)
70
return
1;
71
72
# else
// if defined (_RWSTD_NO_NEW_OFLOW_SAFE)
73
74
limit_memory
(0);
75
76
for
(
unsigned
long
n
= 1UL << (
sizeof
(
long
) * 8 - 1);
77
0 !=
n
;
n
|= (
n
>> 1)) {
78
79
// try to allocate a huge amount of memory
80
void
*
p
= ::operator
new
(
n
);
81
82
if
(!
p
)
83
return
1;
84
}
85
86
# endif
// _RWSTD_NO_NEW_OFLOW_SAFE
87
#else
// if defined (_RWSTD_NO_NEW_THROWS)
88
89
return
4;
90
91
#endif
92
93
}
94
catch
(
std::bad_alloc
&) {
95
return
0;
96
}
97
catch
(...) {
98
return
2;
99
}
100
101
return
3;
102
}
n
#define n
Definition
17.names.cpp:130
p
#define p
Definition
17.names.cpp:132
main
int main()
Definition
STD_BAD_ALLOC.cpp:56
std
Definition
json.h:5363
nodbg.h
nodbg
void nodbg()
Definition
nodbg.h:52
proclimits.h
limit_memory
void limit_memory(unsigned long limit)
Definition
proclimits.h:30
stddef.h
bad_alloc
Definition
GLOBAL_BAD_ALLOC.cpp:46
std::bad_alloc
Definition
EXCEPTION_SPECIFICATION_ON_NEW.cpp:34
terminate.h
Generated by
1.9.8