Skip to content

don't hold references to unowned DispatchData objects (SR-3628) #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/swift/DispatchStubs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ _swift_dispatch_release(dispatch_object_t obj) {
dispatch_release(obj);
}

SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" void
_swift_dispatch_retain(dispatch_object_t obj) {
dispatch_retain(obj);
}

// DISPATCH_RUNTIME_STDLIB_INTERFACE
// extern "C" dispatch_queue_t
// _swift_apply_current_root_queue() {
Expand Down
12 changes: 7 additions & 5 deletions src/swift/Wrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,20 @@ extension DispatchSource : DispatchSourceProcess,

internal class __DispatchData : DispatchObject {
internal let __wrapped:dispatch_data_t
internal let __owned:Bool

final internal override func wrapped() -> dispatch_object_t {
return unsafeBitCast(__wrapped, to: dispatch_object_t.self)
}

internal init(data:dispatch_data_t, owned:Bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that owned tag should really be transferOwnership: Bool but the patch LGTM and I should have realized when we reviewed the earlier patch :/

__wrapped = data
__owned = owned
if !owned {
_swift_dispatch_retain(unsafeBitCast(data, to: dispatch_object_t.self))
}
}

deinit {
if __owned {
_swift_dispatch_release(wrapped())
}
_swift_dispatch_release(wrapped())
}
}

Expand Down Expand Up @@ -335,3 +334,6 @@ internal enum _OSQoSClass : UInt32 {

@_silgen_name("_swift_dispatch_release")
internal func _swift_dispatch_release(_ obj: dispatch_object_t) -> Void

@_silgen_name("_swift_dispatch_retain")
internal func _swift_dispatch_retain(_ obj: dispatch_object_t) -> Void