diff --git a/Sources/NIO/ByteBuffer-core.swift b/Sources/NIO/ByteBuffer-core.swift index 8132aa2e4b..bc6b38065d 100644 --- a/Sources/NIO/ByteBuffer-core.swift +++ b/Sources/NIO/ByteBuffer-core.swift @@ -18,7 +18,11 @@ import ucrt let sysMalloc: @convention(c) (size_t) -> UnsafeMutableRawPointer? = malloc let sysRealloc: @convention(c) (UnsafeMutableRawPointer?, size_t) -> UnsafeMutableRawPointer? = realloc -let sysFree: @convention(c) (UnsafeMutableRawPointer?) -> Void = free + +/// Xcode 13 GM shipped with a bug in the SDK that caused `free`'s first argument to be annotated as +/// non-nullable. To that end, we define a thunk through to `free` that matches that constraint, as we +/// never pass a `nil` pointer to it. +let sysFree: @convention(c) (UnsafeMutableRawPointer) -> Void = { free($0) } extension _ByteBufferSlice: Equatable {} @@ -78,7 +82,7 @@ public struct ByteBufferAllocator { internal init(hookedMalloc: @escaping @convention(c) (size_t) -> UnsafeMutableRawPointer?, hookedRealloc: @escaping @convention(c) (UnsafeMutableRawPointer?, size_t) -> UnsafeMutableRawPointer?, - hookedFree: @escaping @convention(c) (UnsafeMutableRawPointer?) -> Void, + hookedFree: @escaping @convention(c) (UnsafeMutableRawPointer) -> Void, hookedMemcpy: @escaping @convention(c) (UnsafeMutableRawPointer, UnsafeRawPointer, size_t) -> Void) { self.malloc = hookedMalloc self.realloc = hookedRealloc @@ -108,7 +112,7 @@ public struct ByteBufferAllocator { internal let malloc: @convention(c) (size_t) -> UnsafeMutableRawPointer? internal let realloc: @convention(c) (UnsafeMutableRawPointer?, size_t) -> UnsafeMutableRawPointer? - internal let free: @convention(c) (UnsafeMutableRawPointer?) -> Void + internal let free: @convention(c) (UnsafeMutableRawPointer) -> Void internal let memcpy: @convention(c) (UnsafeMutableRawPointer, UnsafeRawPointer, size_t) -> Void } diff --git a/Tests/NIOTests/ByteBufferTest.swift b/Tests/NIOTests/ByteBufferTest.swift index 954ed06261..44db6612a7 100644 --- a/Tests/NIOTests/ByteBufferTest.swift +++ b/Tests/NIOTests/ByteBufferTest.swift @@ -2989,7 +2989,7 @@ private func testAllocationOfReallyBigByteBuffer_memcpyHook(_ dst: UnsafeMutable private var testReserveCapacityLarger_reallocCount = 0 private var testReserveCapacityLarger_mallocCount = 0 -private func testReserveCapacityLarger_freeHook( _ ptr: UnsafeMutableRawPointer?) -> Void { +private func testReserveCapacityLarger_freeHook( _ ptr: UnsafeMutableRawPointer) -> Void { free(ptr) } diff --git a/Tests/NIOTests/CodecTest.swift b/Tests/NIOTests/CodecTest.swift index a2bb38fe41..964e887f64 100644 --- a/Tests/NIOTests/CodecTest.swift +++ b/Tests/NIOTests/CodecTest.swift @@ -18,7 +18,7 @@ import XCTest private var testDecoderIsNotQuadratic_mallocs = 0 private var testDecoderIsNotQuadratic_reallocs = 0 -private func testDecoderIsNotQuadratic_freeHook(_ ptr: UnsafeMutableRawPointer?) -> Void { +private func testDecoderIsNotQuadratic_freeHook(_ ptr: UnsafeMutableRawPointer) -> Void { free(ptr) } diff --git a/docker/docker-compose.2004.main.yaml b/docker/docker-compose.2004.main.yaml index ac3fbf7209..66c8d98186 100644 --- a/docker/docker-compose.2004.main.yaml +++ b/docker/docker-compose.2004.main.yaml @@ -23,17 +23,17 @@ services: - MAX_ALLOCS_ALLOWED_1000_addRemoveHandlers_handlercontext=9050 - MAX_ALLOCS_ALLOWED_1000_addRemoveHandlers_handlername=9050 - MAX_ALLOCS_ALLOWED_1000_addRemoveHandlers_handlertype=9050 - - MAX_ALLOCS_ALLOWED_1000_autoReadGetAndSet=29050 + - MAX_ALLOCS_ALLOWED_1000_autoReadGetAndSet=28050 - MAX_ALLOCS_ALLOWED_1000_autoReadGetAndSet_sync=0 - MAX_ALLOCS_ALLOWED_1000_getHandlers=9050 - MAX_ALLOCS_ALLOWED_1000_getHandlers_sync=37 - MAX_ALLOCS_ALLOWED_1000_reqs_1_conn=30450 - MAX_ALLOCS_ALLOWED_1000_tcpbootstraps=4050 - - MAX_ALLOCS_ALLOWED_1000_tcpconnections=172050 + - MAX_ALLOCS_ALLOWED_1000_tcpconnections=168050 - MAX_ALLOCS_ALLOWED_1000_udp_reqs=12050 - MAX_ALLOCS_ALLOWED_1000_udpbootstraps=2050 - - MAX_ALLOCS_ALLOWED_1000_udpconnections=96050 - - MAX_ALLOCS_ALLOWED_1_reqs_1000_conn=453000 + - MAX_ALLOCS_ALLOWED_1000_udpconnections=93050 + - MAX_ALLOCS_ALLOWED_1_reqs_1000_conn=450050 - MAX_ALLOCS_ALLOWED_bytebuffer_lots_of_rw=2050 - MAX_ALLOCS_ALLOWED_creating_10000_headers=0 - MAX_ALLOCS_ALLOWED_decode_1000_ws_frames=2050 @@ -42,15 +42,15 @@ services: - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_new_buffer=3050 - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_new_buffer_with_space=3050 - MAX_ALLOCS_ALLOWED_future_erase_result=4050 - - MAX_ALLOCS_ALLOWED_future_lots_of_callbacks=60050 + - MAX_ALLOCS_ALLOWED_future_lots_of_callbacks=59050 - MAX_ALLOCS_ALLOWED_modifying_1000_circular_buffer_elements=0 - MAX_ALLOCS_ALLOWED_modifying_byte_buffer_view=2050 - MAX_ALLOCS_ALLOWED_ping_pong_1000_reqs_1_conn=4400 - - MAX_ALLOCS_ALLOWED_read_10000_chunks_from_file=190050 + - MAX_ALLOCS_ALLOWED_read_10000_chunks_from_file=160050 - MAX_ALLOCS_ALLOWED_schedule_10000_tasks=90050 - MAX_ALLOCS_ALLOWED_scheduling_10000_executions=20150 - MAX_ALLOCS_ALLOWED_udp_1000_reqs_1_conn=12200 - - MAX_ALLOCS_ALLOWED_udp_1_reqs_1000_conn=190050 + - MAX_ALLOCS_ALLOWED_udp_1_reqs_1000_conn=188050 # - SANITIZER_ARG=--sanitize=thread # TSan broken still - SWIFT_TEST_VERB=build # WARNING: THIS DISABLES ALL TESTS. Please remove (workaround https://bugs.swift.org/browse/SR-14268)