@@ -119,7 +119,7 @@ void *swift::swift_slowAlloc(size_t size, size_t alignMask) {
119
119
// i.e. 0 < alignment <= _minAllocationAlignment:
120
120
// The runtime may use either `free` or AlignedFree as long as it is
121
121
// consistent with allocation with the same alignment.
122
- void swift::swift_slowDealloc (void *ptr, size_t bytes , size_t alignMask) {
122
+ static void swift_slowDeallocImpl (void *ptr, size_t alignMask) {
123
123
if (alignMask <= MALLOC_ALIGN_MASK) {
124
124
#if defined(__APPLE__) && SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC
125
125
malloc_zone_free (DEFAULT_ZONE (), ptr);
@@ -130,3 +130,34 @@ void swift::swift_slowDealloc(void *ptr, size_t bytes, size_t alignMask) {
130
130
AlignedFree (ptr);
131
131
}
132
132
}
133
+
134
+ void swift::swift_slowDealloc (void *ptr, size_t bytes, size_t alignMask) {
135
+ swift_slowDeallocImpl (ptr, alignMask);
136
+ }
137
+
138
+ #if defined(__APPLE__) && defined(__MACH__) && SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC
139
+ // On Darwin, define our own, hidden operator new/delete implementations. We
140
+ // don't want to pick up any overrides that come from other code, but we also
141
+ // don't want to expose our overrides to any other code. We can't do this
142
+ // directly in C++, as the compiler has an implicit prototype with default
143
+ // visibility. However, if we implement them as C functions using the C++
144
+ // mangled names, the compiler accepts them without complaint, and the linker
145
+ // still links all internal uses with these overrides.
146
+
147
+ __attribute__ ((visibility((" hidden" )))) extern "C" void *_Znwm(size_t size) {
148
+ return swift_slowAlloc (size, MALLOC_ALIGN_MASK);
149
+ }
150
+
151
+ __attribute__ ((visibility((" hidden" )))) extern "C" void _ZdlPv(void *ptr) {
152
+ swift_slowDeallocImpl (ptr, MALLOC_ALIGN_MASK);
153
+ }
154
+
155
+ __attribute__ ((visibility((" hidden" )))) extern "C" void *_Znam(size_t size) {
156
+ return swift_slowAlloc (size, MALLOC_ALIGN_MASK);
157
+ }
158
+
159
+ __attribute__ ((visibility((" hidden" )))) extern "C" void _ZdaPv(void *ptr) {
160
+ swift_slowDeallocImpl (ptr, MALLOC_ALIGN_MASK);
161
+ }
162
+
163
+ #endif
0 commit comments