Skip to content

Commit

Permalink
[windows] fix a few zlib UInt/UInt32 mismatches
Browse files Browse the repository at this point in the history
  • Loading branch information
nil4 committed Oct 25, 2024
1 parent d03c660 commit f915395
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Sources/RoyalVNCKit/Compression/ZlibInflateStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,20 @@ extension ZlibInflateStream {
/// total number of bytes output so far
var totalOut: UInt {
get {
#if os(Windows)
let result: UInt = .init(streamPtr.pointee.total_out)
return result
#else
streamPtr.pointee.total_out
#endif
}
set {
#if os(Windows)
let value: UInt32 = .init(newValue)
streamPtr.pointee.total_out = value
#else
streamPtr.pointee.total_out = newValue
#endif
}
}

Expand All @@ -95,10 +105,20 @@ extension ZlibInflateStream {
/// total number of input bytes read so far
var totalIn: UInt {
get {
#if os(Windows)
let result: UInt = .init(streamPtr.pointee.total_in)
return result
#else
streamPtr.pointee.total_in
#endif
}
set {
#if os(Windows)
let value: UInt32 = .init(newValue)
streamPtr.pointee.total_in = value
#else
streamPtr.pointee.total_in = newValue
#endif
}
}

Expand Down Expand Up @@ -140,10 +160,20 @@ extension ZlibInflateStream {
/// Adler-32 or CRC-32 value of the uncompressed data
var adler: UInt {
get {
#if os(Windows)
let result: UInt = .init(streamPtr.pointee.adler)
return result
#else
streamPtr.pointee.adler
#endif
}
set {
#if os(Windows)
let value: UInt32 = .init(newValue)
streamPtr.pointee.adler = value
#else
streamPtr.pointee.adler = newValue
#endif
}
}
}
Expand Down

3 comments on commit f915395

@lemonmojo
Copy link
Member

Choose a reason for hiding this comment

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

@nil4 I think you can get rid of the #ifs by wrapping the assignments/return values with .init(x). On platforms that already return the expected type that's a no-op and on the other platforms that'll convert the value to the expected type.

@nil4
Copy link
Contributor Author

@nil4 nil4 commented on f915395 Oct 25, 2024

Choose a reason for hiding this comment

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

Will give it a try

@nil4
Copy link
Contributor Author

@nil4 nil4 commented on f915395 Oct 25, 2024

Choose a reason for hiding this comment

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

Seems to work -- done. Thanks for the tip!

Please sign in to comment.