Skip to content

Commit ea112a7

Browse files
authored
Merge pull request #111 from wickwirew/swift-5-10-fix
Fix build error with swift_allocObject in swift 5.10
2 parents 73c9021 + 318f8a3 commit ea112a7

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Sources/CRuntime/include/CRuntime.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef cruntime_h
22
#define cruntime_h
33

4+
#include <stdlib.h>
5+
46
const void * _Nullable swift_getTypeByMangledNameInContext(
57
const char * _Nullable typeNameStart,
68
int typeNameLength,
@@ -9,7 +11,7 @@ const void * _Nullable swift_getTypeByMangledNameInContext(
911

1012
const void * _Nullable swift_allocObject(
1113
const void * _Nullable type,
12-
int requiredSize,
13-
int requiredAlignmentMask);
14+
size_t requiredSize,
15+
size_t requiredAlignmentMask);
1416

1517
#endif

Sources/Runtime/Factory/Factory.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ func buildClass(type: Any.Type) throws -> Any {
6161
var md = ClassMetadata(type: type)
6262
let info = md.toTypeInfo()
6363
let metadata = unsafeBitCast(type, to: UnsafeRawPointer.self)
64-
let instanceSize = Int32(md.pointer.pointee.instanceSize)
64+
let instanceSize = Int(md.pointer.pointee.instanceSize)
6565

6666
// https://github.com/wickwirew/Runtime/issues/49
6767
// Docs specify that the alignment should be "always one less than a power of 2 that's at least alignof(void*)"
6868
// https://github.com/apple/swift/blob/7123d2614b5f222d03b3762cb110d27a9dd98e24/include/swift/Runtime/HeapObject.h#L56-L57
6969
// We could use md.alignment and deduct 1, or just use the instanceAlignmentMask from the ClassMetadata.
70-
let alignmentMask = Int32(md.pointer.pointee.instanceAlignmentMask)
70+
let alignmentMask = Int(md.pointer.pointee.instanceAlignmentMask)
7171

7272
guard let value = swift_allocObject(metadata, instanceSize, alignmentMask) else {
7373
throw RuntimeError.unableToBuildType(type: type)

0 commit comments

Comments
 (0)