File tree Expand file tree Collapse file tree 1 file changed +39
-2
lines changed Expand file tree Collapse file tree 1 file changed +39
-2
lines changed Original file line number Diff line number Diff line change 18
18
#include " swift/Runtime/Heap.h"
19
19
#include " Private.h"
20
20
#include " swift/Runtime/Debug.h"
21
+ #include < algorithm>
21
22
#include < stdlib.h>
22
23
23
24
using namespace swift ;
24
25
26
+ #if defined(__APPLE__)
27
+ // Apple malloc is always 16-byte aligned.
28
+ # define MALLOC_ALIGN_MASK 15
29
+
30
+ #elif defined(__linux__)
31
+ // Linux malloc is 16-byte aligned on 64-bit, and 8-byte aligned on 32-bit.
32
+ # if defined(__LP64)
33
+ # define MALLOC_ALIGN_MASK 15
34
+ # else
35
+ # define MALLOC_ALIGN_MASK 7
36
+ # endif
37
+
38
+ #elif defined(_WIN64)
39
+ // Windows malloc is 16-byte aligned on 64-bit and 8-byte aligned on 32-bit.
40
+ # define MALLOC_ALIGN_MASK 15
41
+ #elif defined(_WIN32)
42
+ # define MALLOC_ALIGN_MASK 7
43
+
44
+ #else
45
+ // Unknown alignment, but the standard requires alignment suitable for the largest
46
+ // standard types.
47
+ # define MALLOC_ALIGN_MASK std::max (alignof (void *), alignof(double ))
48
+
49
+ #endif
50
+
51
+
52
+
25
53
void *swift::swift_slowAlloc (size_t size, size_t alignMask) {
26
- void *p = AlignedAlloc (size, alignMask + 1 );
54
+ void *p;
55
+ if (alignMask <= MALLOC_ALIGN_MASK) {
56
+ p = malloc (size);
57
+ } else {
58
+ p = AlignedAlloc (size, alignMask + 1 );
59
+ }
27
60
if (!p) swift::crash (" Could not allocate memory." );
28
61
return p;
29
62
}
30
63
31
64
void swift::swift_slowDealloc (void *ptr, size_t bytes, size_t alignMask) {
32
- AlignedFree (ptr);
65
+ if (alignMask <= MALLOC_ALIGN_MASK) {
66
+ free (ptr);
67
+ } else {
68
+ AlignedFree (ptr);
69
+ }
33
70
}
You can’t perform that action at this time.
0 commit comments