Skip to content

Correct signedness handling of DispatchTimeInterval #168

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
Sep 13, 2016
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
2 changes: 1 addition & 1 deletion src/swift/IO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public extension DispatchIO {
}

public func setInterval(interval: DispatchTimeInterval, flags: IntervalFlags = []) {
dispatch_io_set_interval(self.__wrapped, interval.rawValue, flags.rawValue)
dispatch_io_set_interval(self.__wrapped, UInt64(interval.rawValue), flags.rawValue)
}

public func close(flags: CloseFlags = []) {
Expand Down
4 changes: 2 additions & 2 deletions src/swift/Source.swift
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,15 @@ public extension DispatchSourceTimer {
}

public func scheduleRepeating(deadline: DispatchTime, interval: DispatchTimeInterval, leeway: DispatchTimeInterval = .nanoseconds(0)) {
dispatch_source_set_timer((self as! DispatchSource).__wrapped, deadline.rawValue, interval.rawValue, UInt64(leeway.rawValue))
dispatch_source_set_timer((self as! DispatchSource).__wrapped, deadline.rawValue, UInt64(interval.rawValue), UInt64(leeway.rawValue))
}

public func scheduleRepeating(deadline: DispatchTime, interval: Double, leeway: DispatchTimeInterval = .nanoseconds(0)) {
dispatch_source_set_timer((self as! DispatchSource).__wrapped, deadline.rawValue, UInt64(interval * Double(NSEC_PER_SEC)), UInt64(leeway.rawValue))
}

public func scheduleRepeating(wallDeadline: DispatchWallTime, interval: DispatchTimeInterval, leeway: DispatchTimeInterval = .nanoseconds(0)) {
dispatch_source_set_timer((self as! DispatchSource).__wrapped, wallDeadline.rawValue, interval.rawValue, UInt64(leeway.rawValue))
dispatch_source_set_timer((self as! DispatchSource).__wrapped, wallDeadline.rawValue, UInt64(interval.rawValue), UInt64(leeway.rawValue))
}

public func scheduleRepeating(wallDeadline: DispatchWallTime, interval: Double, leeway: DispatchTimeInterval = .nanoseconds(0)) {
Expand Down
18 changes: 9 additions & 9 deletions src/swift/Time.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,23 @@ public enum DispatchTimeInterval {
case microseconds(Int)
case nanoseconds(Int)

internal var rawValue: UInt64 {
internal var rawValue: Int64 {
switch self {
case .seconds(let s): return UInt64(s) * NSEC_PER_SEC
case .milliseconds(let ms): return UInt64(ms) * NSEC_PER_MSEC
case .microseconds(let us): return UInt64(us) * NSEC_PER_USEC
case .nanoseconds(let ns): return UInt64(ns)
case .seconds(let s): return Int64(s) * Int64(NSEC_PER_SEC)
case .milliseconds(let ms): return Int64(ms) * Int64(NSEC_PER_MSEC)
case .microseconds(let us): return Int64(us) * Int64(NSEC_PER_USEC)
case .nanoseconds(let ns): return Int64(ns)
}
}
}

public func +(time: DispatchTime, interval: DispatchTimeInterval) -> DispatchTime {
let t = CDispatch.dispatch_time(time.rawValue, Int64(interval.rawValue))
let t = CDispatch.dispatch_time(time.rawValue, interval.rawValue)
return DispatchTime(rawValue: t)
}

public func -(time: DispatchTime, interval: DispatchTimeInterval) -> DispatchTime {
let t = CDispatch.dispatch_time(time.rawValue, -Int64(interval.rawValue))
let t = CDispatch.dispatch_time(time.rawValue, -interval.rawValue)
return DispatchTime(rawValue: t)
}

Expand All @@ -120,12 +120,12 @@ public func -(time: DispatchTime, seconds: Double) -> DispatchTime {
}

public func +(time: DispatchWallTime, interval: DispatchTimeInterval) -> DispatchWallTime {
let t = CDispatch.dispatch_time(time.rawValue, Int64(interval.rawValue))
let t = CDispatch.dispatch_time(time.rawValue, interval.rawValue)
return DispatchWallTime(rawValue: t)
}

public func -(time: DispatchWallTime, interval: DispatchTimeInterval) -> DispatchWallTime {
let t = CDispatch.dispatch_time(time.rawValue, -Int64(interval.rawValue))
let t = CDispatch.dispatch_time(time.rawValue, -interval.rawValue)
return DispatchWallTime(rawValue: t)
}

Expand Down