… | |
… | |
4 | #include <new> |
4 | #include <new> |
5 | #include <stdlib.h> |
5 | #include <stdlib.h> |
6 | #include <string.h> |
6 | #include <string.h> |
7 | #include "ecb.h" |
7 | #include "ecb.h" |
8 | #include "estl.h" |
8 | #include "estl.h" |
|
|
9 | |
|
|
10 | #include "emman.h" |
9 | |
11 | |
10 | // increases code size unless -fno-enforce-eh-specs |
12 | // increases code size unless -fno-enforce-eh-specs |
11 | #if __GNUC__ |
13 | #if __GNUC__ |
12 | # define NOTHROW |
14 | # define NOTHROW |
13 | # define THROW(x) |
15 | # define THROW(x) |
… | |
… | |
59 | { |
61 | { |
60 | void *operator new (size_t s); |
62 | void *operator new (size_t s); |
61 | void operator delete (void *p, size_t s); |
63 | void operator delete (void *p, size_t s); |
62 | }; |
64 | }; |
63 | |
65 | |
|
|
66 | // alas new/delete cannot be specified as inline in C++11 (see 17.6.4.6) |
|
|
67 | void *operator new (size_t s) throw (std::bad_alloc); |
|
|
68 | void operator delete (void *p) throw (); |
|
|
69 | |
64 | struct stringvec : simplevec<char *> |
70 | struct stringvec : simplevec<char *> |
65 | { |
71 | { |
66 | ~stringvec () |
72 | ~stringvec () |
67 | { |
73 | { |
68 | for (char **c = begin (); c != end (); c++) |
74 | for (char **c = begin (); c != end (); c++) |
… | |
… | |
84 | iterator end () const { return (iterator)simplevec<void *>::end (); } |
90 | iterator end () const { return (iterator)simplevec<void *>::end (); } |
85 | T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); } |
91 | T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); } |
86 | const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); } |
92 | const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); } |
87 | }; |
93 | }; |
88 | #endif |
94 | #endif |
89 | |
|
|
90 | inline void * |
|
|
91 | operator new (size_t size) |
|
|
92 | { |
|
|
93 | // TODO: use rxvt_malloc |
|
|
94 | return malloc (size); |
|
|
95 | } |
|
|
96 | |
|
|
97 | inline void |
|
|
98 | operator delete (void *p) |
|
|
99 | { |
|
|
100 | free (p); |
|
|
101 | } |
|
|
102 | |
95 | |
103 | template<typename T> |
96 | template<typename T> |
104 | struct auto_ptr |
97 | struct auto_ptr |
105 | { |
98 | { |
106 | T *p; |
99 | T *p; |
… | |
… | |
135 | } |
128 | } |
136 | |
129 | |
137 | // void because it makes sense in our context |
130 | // void because it makes sense in our context |
138 | void operator =(auto_ptr &a) |
131 | void operator =(auto_ptr &a) |
139 | { |
132 | { |
140 | *this = a.p; |
133 | reset (a.release ()); |
141 | a.p = 0; |
|
|
142 | } |
134 | } |
143 | |
135 | |
144 | template<typename A> |
136 | template<typename A> |
145 | void operator =(auto_ptr<A> &a) |
137 | void operator =(auto_ptr<A> &a) |
146 | { |
138 | { |
147 | *this = a.p; |
139 | reset (a.release ()); |
148 | a.p = 0; |
|
|
149 | } |
140 | } |
150 | |
141 | |
151 | T *operator ->() const { return p; } |
142 | T *operator ->() const { return p; } |
152 | T &operator *() const { return *p; } |
143 | T &operator *() const { return *p; } |
153 | |
144 | |