From 8e35e526c6655bd8ab6f1e3b3bc8996a0561c6c7 Mon Sep 17 00:00:00 2001 From: Dzmitry Neviadomski Date: Fri, 15 Mar 2024 08:16:26 +0300 Subject: [PATCH] chore: fix warnings when compiling macOS client with either Xcode or CMake (#6676) * chore: fix CGFloat comparison warnings in macOS code. There are 2 cases: 1. Speed comparisons. The lowest significant value displayed in UI is 0.1 bytes per sec. See [NSString stringForSpeed] and [NSString stringForSpeedCompact]. 2. Ratio limit comparison. The lowest significant value displayed in UI is 0.01 (no unit). This is based on maximumFractionDigits=2 set in related XIB file. Signed-off-by: Dzmitry Neviadomski * chore: fix warning about shadowed variable CGFloat const difference was used twice in the same scope Signed-off-by: Dzmitry Neviadomski * chore: fix unused block parameter warnings Signed-off-by: Dzmitry Neviadomski * chore: disable GCC_WARN_64_TO_32_BIT_CONVERSION for libtransmission This warnings are not reported with CMake build. Signed-off-by: Dzmitry Neviadomski * chore: disable CLANG_WARN_STRICT_PROTOTYPES for dht This is third party target, warning is not enabled with CMake build. Signed-off-by: Dzmitry Neviadomski * chore: disable '-Wexit-time-destructors' warning with CMake. There are two cases when this is reported in libtransmission: 1. `log_state` in anonymous namespace in `log.cc`. 2. static inline `dh_pool_mutex` in `tr_handshake` in `handshake.h`. I don't see how this may be improved or how this affects correctness, so don't nag about that. Signed-off-by: Dzmitry Neviadomski --------- Signed-off-by: Dzmitry Neviadomski --- CMakeLists.txt | 1 - Transmission.xcodeproj/project.pbxproj | 12 ++++++++++++ macosx/BadgeView.mm | 3 ++- macosx/CMakeLists.txt | 2 ++ macosx/InfoOptionsViewController.mm | 3 ++- macosx/InfoWindowController.mm | 14 +++++++------- macosx/PortChecker.mm | 2 +- macosx/StatusBarController.mm | 5 +++-- macosx/TorrentTableView.mm | 4 ++-- macosx/Utils.h | 8 ++++++++ macosx/Utils.mm | 19 +++++++++++++++++++ 11 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 macosx/Utils.h create mode 100644 macosx/Utils.mm diff --git a/CMakeLists.txt b/CMakeLists.txt index fda16eeac..d5d667b35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -630,7 +630,6 @@ else() -Wextra -Wcast-align -Wduplicated-cond - -Wexit-time-destructors -Wextra-semi -Wextra-semi-stmt -Wextra-tokens diff --git a/Transmission.xcodeproj/project.pbxproj b/Transmission.xcodeproj/project.pbxproj index f0503bcbf..3282fc02d 100644 --- a/Transmission.xcodeproj/project.pbxproj +++ b/Transmission.xcodeproj/project.pbxproj @@ -452,6 +452,7 @@ ED8A16402735A8AA000D61F9 /* peer-mgr-active-requests.cc in Sources */ = {isa = PBXBuildFile; fileRef = ED8A163C2735A8AA000D61F9 /* peer-mgr-active-requests.cc */; }; ED8A16412735A8AA000D61F9 /* peer-mgr-wishlist.h in Headers */ = {isa = PBXBuildFile; fileRef = ED8A163D2735A8AA000D61F9 /* peer-mgr-wishlist.h */; }; ED8A16422735A8AA000D61F9 /* peer-mgr-wishlist.cc in Sources */ = {isa = PBXBuildFile; fileRef = ED8A163E2735A8AA000D61F9 /* peer-mgr-wishlist.cc */; }; + ED9862972B979AA2002F3035 /* Utils.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED9862962B979AA2002F3035 /* Utils.mm */; }; EDBAAC8C29E486BC00D9495F /* global-ip-cache.h in Headers */ = {isa = PBXBuildFile; fileRef = EDBAAC8B29E486BC00D9495F /* global-ip-cache.h */; }; EDBAAC8E29E486C200D9495F /* global-ip-cache.cc in Sources */ = {isa = PBXBuildFile; fileRef = EDBAAC8D29E486C200D9495F /* global-ip-cache.cc */; }; EDBDFA9E25AFCCA60093D9C1 /* evutil_time.c in Sources */ = {isa = PBXBuildFile; fileRef = EDBDFA9D25AFCCA60093D9C1 /* evutil_time.c */; }; @@ -1366,6 +1367,8 @@ ED8A163C2735A8AA000D61F9 /* peer-mgr-active-requests.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "peer-mgr-active-requests.cc"; sourceTree = ""; }; ED8A163D2735A8AA000D61F9 /* peer-mgr-wishlist.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = "peer-mgr-wishlist.h"; sourceTree = ""; }; ED8A163E2735A8AA000D61F9 /* peer-mgr-wishlist.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "peer-mgr-wishlist.cc"; sourceTree = ""; }; + ED9862952B979AA2002F3035 /* Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Utils.h; sourceTree = ""; }; + ED9862962B979AA2002F3035 /* Utils.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Utils.mm; sourceTree = ""; }; EDBAAC8B29E486BC00D9495F /* global-ip-cache.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = "global-ip-cache.h"; sourceTree = ""; }; EDBAAC8D29E486C200D9495F /* global-ip-cache.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "global-ip-cache.cc"; sourceTree = ""; }; EDBDFA9D25AFCCA60093D9C1 /* evutil_time.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = evutil_time.c; sourceTree = ""; }; @@ -1664,6 +1667,8 @@ A222EA7A0E6C32C4009FB003 /* BlocklistScheduler.mm */, ED86936D2ADAE34D00342B1A /* DefaultAppHelper.h */, ED86936E2ADAE34D00342B1A /* DefaultAppHelper.mm */, + ED9862952B979AA2002F3035 /* Utils.h */, + ED9862962B979AA2002F3035 /* Utils.mm */, A2AB883916A399A6008FAD50 /* VDKQueue */, ); name = Sources; @@ -3274,6 +3279,7 @@ A209EB9D1142E59A002B02D1 /* InfoPeersViewController.mm in Sources */, A209EBCE1142F2B4002B02D1 /* InfoFileViewController.mm in Sources */, A209EBF91142FEEE002B02D1 /* InfoOptionsViewController.mm in Sources */, + ED9862972B979AA2002F3035 /* Utils.mm in Sources */, A21F15AC11729A8B00CF5A9C /* AddMagnetWindowController.mm in Sources */, A2661D6112D0E8D9004F69D5 /* FilterBarView.mm in Sources */, A2F7CF5F13035FFD0016FF10 /* URLSheetWindowController.mm in Sources */, @@ -3930,6 +3936,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_CXX_LIBRARY = "libc++"; + GCC_WARN_64_TO_32_BIT_CONVERSION = NO; HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/dht", @@ -4184,6 +4191,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_CXX_LIBRARY = "libc++"; + GCC_WARN_64_TO_32_BIT_CONVERSION = NO; HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/dht", @@ -4359,6 +4367,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_OBJC_ARC = NO; + CLANG_WARN_STRICT_PROTOTYPES = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = NO; GENERATE_MASTER_OBJECT_FILE = YES; PRODUCT_NAME = dht; @@ -4369,6 +4378,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_OBJC_ARC = NO; + CLANG_WARN_STRICT_PROTOTYPES = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = NO; GENERATE_MASTER_OBJECT_FILE = YES; PRODUCT_NAME = dht; @@ -4379,6 +4389,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_OBJC_ARC = NO; + CLANG_WARN_STRICT_PROTOTYPES = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = NO; GENERATE_MASTER_OBJECT_FILE = YES; PRODUCT_NAME = dht; @@ -4513,6 +4524,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_CXX_LIBRARY = "libc++"; + GCC_WARN_64_TO_32_BIT_CONVERSION = NO; HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/dht", diff --git a/macosx/BadgeView.mm b/macosx/BadgeView.mm index 81b841c08..9841102c9 100644 --- a/macosx/BadgeView.mm +++ b/macosx/BadgeView.mm @@ -5,6 +5,7 @@ #import "BadgeView.h" #import "NSStringAdditions.h" #import "NSImageAdditions.h" +#import "Utils.h" static CGFloat const kBetweenPadding = 2.0; static NSImage* kWhiteUpArrow = [[NSImage imageNamed:@"UpArrowTemplate"] imageWithColor:NSColor.whiteColor]; @@ -61,7 +62,7 @@ typedef NS_ENUM(NSInteger, ArrowDirection) { - (BOOL)setRatesWithDownload:(CGFloat)downloadRate upload:(CGFloat)uploadRate { //only needs update if the badges were displayed or are displayed now - if (self.fDownloadRate == downloadRate && self.fUploadRate == uploadRate) + if (isSpeedEqual(self.fDownloadRate, downloadRate) && isSpeedEqual(self.fUploadRate, uploadRate)) { return NO; } diff --git a/macosx/CMakeLists.txt b/macosx/CMakeLists.txt index 9ef277835..2e04f2ab1 100644 --- a/macosx/CMakeLists.txt +++ b/macosx/CMakeLists.txt @@ -191,6 +191,8 @@ target_sources(${TR_NAME}-mac TrackerTableView.mm URLSheetWindowController.h URLSheetWindowController.mm + Utils.h + Utils.mm WebSeedTableView.h WebSeedTableView.mm) diff --git a/macosx/InfoOptionsViewController.mm b/macosx/InfoOptionsViewController.mm index 497f35b95..56986b9c2 100644 --- a/macosx/InfoOptionsViewController.mm +++ b/macosx/InfoOptionsViewController.mm @@ -5,6 +5,7 @@ #import "InfoOptionsViewController.h" #import "NSStringAdditions.h" #import "Torrent.h" +#import "Utils.h" typedef NS_ENUM(NSInteger, OptionPopupType) { OptionPopupTypeGlobal = 0, @@ -295,7 +296,7 @@ static CGFloat const kStackViewSpacing = 8.0; checkRatio = kInvalidValue; } - if (!multipleRatioLimits && ratioLimit != torrent.ratioLimit) + if (!multipleRatioLimits && isRatioEqual(ratioLimit, torrent.ratioLimit)) { multipleRatioLimits = YES; } diff --git a/macosx/InfoWindowController.mm b/macosx/InfoWindowController.mm index c6b102a76..bc056bf24 100644 --- a/macosx/InfoWindowController.mm +++ b/macosx/InfoWindowController.mm @@ -351,9 +351,9 @@ typedef NS_ENUM(NSUInteger, TabTag) { viewRect = [self.fOptionsViewController viewRect]; } - CGFloat const difference = NSHeight(viewRect) - oldHeight; - windowRect.origin.y -= difference; - windowRect.size.height += difference; + CGFloat const viewHeightDifference = NSHeight(viewRect) - oldHeight; + windowRect.origin.y -= viewHeightDifference; + windowRect.size.height += viewHeightDifference; windowRect.size.width = MAX(NSWidth(windowRect), minWindowWidth); if ([self.fViewController respondsToSelector:@selector(saveViewSize)]) //a little bit hacky, but avoids requiring an extra method @@ -363,11 +363,11 @@ typedef NS_ENUM(NSUInteger, TabTag) { CGFloat const screenHeight = NSHeight(window.screen.visibleFrame); if (NSHeight(windowRect) > screenHeight) { - CGFloat const difference = screenHeight - NSHeight(windowRect); - windowRect.origin.y -= difference; - windowRect.size.height += difference; + CGFloat const windowHeightDifference = screenHeight - NSHeight(windowRect); + windowRect.origin.y -= windowHeightDifference; + windowRect.size.height += windowHeightDifference; - viewRect.size.height += difference; + viewRect.size.height += windowHeightDifference; } } diff --git a/macosx/PortChecker.mm b/macosx/PortChecker.mm index 3184ccb9f..31e1ac6d5 100644 --- a/macosx/PortChecker.mm +++ b/macosx/PortChecker.mm @@ -72,7 +72,7 @@ static NSTimeInterval const kCheckFireInterval = 3.0; timeoutInterval:15.0]; _fTask = [_fSession dataTaskWithRequest:portProbeRequest - completionHandler:^(NSData* _Nullable data, NSURLResponse* _Nullable response, NSError* _Nullable error) { + completionHandler:^(NSData* _Nullable data, NSURLResponse* _Nullable, NSError* _Nullable error) { if (error) { NSLog(@"Unable to get port status: connection failed (%@)", error.localizedDescription); diff --git a/macosx/StatusBarController.mm b/macosx/StatusBarController.mm index 9d16d66c2..2102e58a3 100644 --- a/macosx/StatusBarController.mm +++ b/macosx/StatusBarController.mm @@ -4,6 +4,7 @@ #import "StatusBarController.h" #import "NSStringAdditions.h" +#import "Utils.h" typedef NSString* StatusRatioType NS_TYPED_EXTENSIBLE_ENUM; @@ -77,13 +78,13 @@ typedef NS_ENUM(NSUInteger, StatusTag) { - (void)updateWithDownload:(CGFloat)dlRate upload:(CGFloat)ulRate { //set rates - if (dlRate != self.fPreviousDownloadRate) + if (!isSpeedEqual(self.fPreviousDownloadRate, dlRate)) { self.fTotalDLField.stringValue = [NSString stringForSpeed:dlRate]; self.fPreviousDownloadRate = dlRate; } - if (ulRate != self.fPreviousUploadRate) + if (!isSpeedEqual(self.fPreviousUploadRate, ulRate)) { self.fTotalULField.stringValue = [NSString stringForSpeed:ulRate]; self.fPreviousUploadRate = ulRate; diff --git a/macosx/TorrentTableView.mm b/macosx/TorrentTableView.mm index 54af6cc07..44cb140cb 100644 --- a/macosx/TorrentTableView.mm +++ b/macosx/TorrentTableView.mm @@ -125,7 +125,7 @@ static NSTimeInterval const kToggleProgressSeconds = 0.175; NSIndexSet* fullIndexSet = [NSIndexSet indexSetWithIndexesInRange:fullRange]; NSMutableIndexSet* visibleIndexSet = [[NSMutableIndexSet alloc] init]; - [fullIndexSet enumerateIndexesUsingBlock:^(NSUInteger row, BOOL* stop) { + [fullIndexSet enumerateIndexesUsingBlock:^(NSUInteger row, BOOL*) { id rowView = [self rowViewAtRow:row makeIfNecessary:NO]; if ([rowView isGroupRowStyle]) { @@ -151,7 +151,7 @@ static NSTimeInterval const kToggleProgressSeconds = 0.175; //redraw fControlButton BOOL minimal = [self.fDefaults boolForKey:@"SmallView"]; - [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger row, BOOL* stop) { + [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger row, BOOL*) { id rowView = [self rowViewAtRow:row makeIfNecessary:NO]; if (![rowView isGroupRowStyle]) { diff --git a/macosx/Utils.h b/macosx/Utils.h new file mode 100644 index 000000000..311054c8c --- /dev/null +++ b/macosx/Utils.h @@ -0,0 +1,8 @@ +// This file Copyright © Transmission authors and contributors. +// It may be used under the MIT (SPDX: MIT) license. +// License text can be found in the licenses/ folder. + +#import + +bool isSpeedEqual(CGFloat old_speed, CGFloat new_speed); +bool isRatioEqual(CGFloat old_ratio, CGFloat new_ratio); diff --git a/macosx/Utils.mm b/macosx/Utils.mm new file mode 100644 index 000000000..b7130ca48 --- /dev/null +++ b/macosx/Utils.mm @@ -0,0 +1,19 @@ +// This file Copyright © Transmission authors and contributors. +// It may be used under the MIT (SPDX: MIT) license. +// License text can be found in the licenses/ folder. + +#include + +#import "Utils.h" + +bool isSpeedEqual(CGFloat old_speed, CGFloat new_speed) +{ + static CGFloat constexpr kSpeedCompareEps = 0.1 / 2; + return std::abs(new_speed - old_speed) < kSpeedCompareEps; +} + +bool isRatioEqual(CGFloat old_ratio, CGFloat new_ratio) +{ + static CGFloat constexpr kRatioCompareEps = 0.01 / 2; + return std::abs(new_ratio - old_ratio) < kRatioCompareEps; +}