Files
swift-mirror/stdlib/public/SDK/Dispatch/Dispatch.mm
Matt Wright 1ff4ca0d41 dispatch_source_create returns NULL but is marked up as nonnull
dispatch_source_create is marked up as non-null but can actually return
null in programming error issues. In order to maintain the nullabilty
contract, these issues will now cause the overlay to assert and crash
rather than return a null pointer out of a non-null call.

Resolves: <rdar://problem/39937177>
2018-07-13 10:47:09 -07:00

58 lines
2.2 KiB
Plaintext

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include <swift/Runtime/Debug.h>
#include <dispatch/dispatch.h>
#include <objc/runtime.h>
#include <stdio.h>
@protocol OS_dispatch_source;
@protocol OS_dispatch_source_mach_send;
@protocol OS_dispatch_source_mach_recv;
@protocol OS_dispatch_source_memorypressure;
@protocol OS_dispatch_source_proc;
@protocol OS_dispatch_source_read;
@protocol OS_dispatch_source_signal;
@protocol OS_dispatch_source_timer;
@protocol OS_dispatch_source_data_add;
@protocol OS_dispatch_source_data_or;
@protocol OS_dispatch_source_vnode;
@protocol OS_dispatch_source_write;
// #include <dispatch/private.h>
__attribute__((constructor))
static void _dispatch_overlay_constructor() {
Class source = objc_lookUpClass("OS_dispatch_source");
if (source) {
class_addProtocol(source, @protocol(OS_dispatch_source));
class_addProtocol(source, @protocol(OS_dispatch_source_mach_send));
class_addProtocol(source, @protocol(OS_dispatch_source_mach_recv));
class_addProtocol(source, @protocol(OS_dispatch_source_memorypressure));
class_addProtocol(source, @protocol(OS_dispatch_source_proc));
class_addProtocol(source, @protocol(OS_dispatch_source_read));
class_addProtocol(source, @protocol(OS_dispatch_source_signal));
class_addProtocol(source, @protocol(OS_dispatch_source_timer));
class_addProtocol(source, @protocol(OS_dispatch_source_data_add));
class_addProtocol(source, @protocol(OS_dispatch_source_data_or));
class_addProtocol(source, @protocol(OS_dispatch_source_vnode));
class_addProtocol(source, @protocol(OS_dispatch_source_write));
}
}
extern "C" void
_swift_dispatch_source_create_abort(void)
{
swift::swift_reportError(0,
"dispatch_source_create returned NULL, invalid parameters passed to dispatch_source_create");
abort();
}