Skip to content

Commit dedb448

Browse files
committed
use unsafeBitCast to avoid dropping to C to cast OpaquePointers
1 parent 759e8f8 commit dedb448

File tree

2 files changed

+8
-37
lines changed

2 files changed

+8
-37
lines changed

src/swift/DispatchStubs.cc

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#define DISPATCH_RUNTIME_STDLIB_INTERFACE __attribute__((__visibility__("default")))
1717

18-
#if 0
18+
#if USE_OBJC
1919
@protocol OS_dispatch_source;
2020
@protocol OS_dispatch_source_mach_send;
2121
@protocol OS_dispatch_source_mach_recv;
@@ -49,9 +49,9 @@ static void _dispatch_overlay_constructor() {
4949
}
5050
}
5151

52-
#endif
52+
#endif /* USE_OBJC */
5353

54-
#if 0
54+
#if 0 /* FIXME -- adding directory to include path may need build-script plumbing to do properly... */
5555
#include "swift/Runtime/Config.h"
5656
#else
5757
#define SWIFT_CC(x) /* FIXME!! */
@@ -161,19 +161,6 @@ _swift_dispatch_sync(dispatch_queue_t queue, dispatch_block_t block) {
161161
dispatch_sync(queue, block);
162162
}
163163

164-
#define PUN(t) \
165-
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE \
166-
extern "C" dispatch_object_t \
167-
_dispatch_pun_##t##_to_object(dispatch_##t##_t obj) { \
168-
return (dispatch_object_t)obj; \
169-
}
170-
171-
PUN(group)
172-
PUN(semaphore)
173-
PUN(io)
174-
PUN(queue)
175-
PUN(source)
176-
177164
// DISPATCH_RUNTIME_STDLIB_INTERFACE
178165
// extern "C" dispatch_queue_t
179166
// _swift_apply_current_root_queue() {

src/swift/Wrapper.swift

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class DispatchGroup : DispatchObject {
4444
internal let __wrapped:dispatch_group_t;
4545

4646
internal override func wrapped() -> dispatch_object_t {
47-
return _dispatch_pun_group_to_object(__wrapped)
47+
return unsafeBitCast(__wrapped, to: dispatch_object_t.self)
4848
}
4949

5050
public override init() {
@@ -64,7 +64,7 @@ public class DispatchSemaphore : DispatchObject {
6464
internal let __wrapped: dispatch_semaphore_t;
6565

6666
internal override func wrapped() -> dispatch_object_t {
67-
return _dispatch_pun_semaphore_to_object(__wrapped)
67+
return unsafeBitCast(__wrapped, to: dispatch_object_t.self)
6868
}
6969

7070
public init(value: Int) {
@@ -76,7 +76,7 @@ public class DispatchIO : DispatchObject {
7676
internal let __wrapped:dispatch_io_t
7777

7878
internal override func wrapped() -> dispatch_object_t {
79-
return _dispatch_pun_io_to_object(__wrapped)
79+
return unsafeBitCast(__wrapped, to: dispatch_object_t.self)
8080
}
8181

8282
internal init(__type: UInt, fd: Int32, queue: DispatchQueue,
@@ -117,7 +117,7 @@ public class DispatchQueue : DispatchObject {
117117
internal let __wrapped:dispatch_queue_t;
118118

119119
internal override func wrapped() -> dispatch_object_t {
120-
return _dispatch_pun_queue_to_object(__wrapped)
120+
return unsafeBitCast(__wrapped, to: dispatch_object_t.self)
121121
}
122122

123123
internal init(__label: String, attr: dispatch_queue_attr_t?) {
@@ -145,7 +145,7 @@ public class DispatchSource : DispatchObject,
145145
internal let __wrapped:dispatch_source_t
146146

147147
internal override func wrapped() -> dispatch_object_t {
148-
return _dispatch_pun_source_to_object(__wrapped)
148+
return unsafeBitCast(__wrapped, to: dispatch_object_t.self)
149149
}
150150

151151
internal init(source:dispatch_source_t) {
@@ -281,19 +281,3 @@ internal enum _OSQoSClass : UInt32 {
281281
}
282282
}
283283
}
284-
285-
286-
@_silgen_name("_dispatch_pun_group_to_object")
287-
internal func _dispatch_pun_group_to_object(_ group:dispatch_group_t) -> dispatch_object_t
288-
289-
@_silgen_name("_dispatch_pun_semaphore_to_object")
290-
internal func _dispatch_pun_semaphore_to_object(_ semaphore:dispatch_semaphore_t) -> dispatch_object_t
291-
292-
@_silgen_name("_dispatch_pun_io_to_object")
293-
internal func _dispatch_pun_io_to_object(_ io:dispatch_io_t) -> dispatch_object_t
294-
295-
@_silgen_name("_dispatch_pun_queue_to_object")
296-
internal func _dispatch_pun_queue_to_object(_ queue:dispatch_queue_t) -> dispatch_object_t
297-
298-
@_silgen_name("_dispatch_pun_source_to_object")
299-
internal func _dispatch_pun_source_to_object(_ source:dispatch_source_t) -> dispatch_object_t

0 commit comments

Comments
 (0)