1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-21 23:32:35 +00:00

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 <nevack.d@gmail.com>

* chore: fix warning about shadowed variable

CGFloat const difference was used twice in the same scope

Signed-off-by: Dzmitry Neviadomski <nevack.d@gmail.com>

* chore: fix unused block parameter warnings

Signed-off-by: Dzmitry Neviadomski <nevack.d@gmail.com>

* chore: disable GCC_WARN_64_TO_32_BIT_CONVERSION for libtransmission

This warnings are not reported with CMake build.

Signed-off-by: Dzmitry Neviadomski <nevack.d@gmail.com>

* 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 <nevack.d@gmail.com>

* 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 <nevack.d@gmail.com>

---------

Signed-off-by: Dzmitry Neviadomski <nevack.d@gmail.com>
This commit is contained in:
Dzmitry Neviadomski 2024-03-15 08:16:26 +03:00 committed by GitHub
parent 45d3c678bc
commit 8e35e526c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 58 additions and 15 deletions

View file

@ -630,7 +630,6 @@ else()
-Wextra
-Wcast-align
-Wduplicated-cond
-Wexit-time-destructors
-Wextra-semi
-Wextra-semi-stmt
-Wextra-tokens

View file

@ -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 = "<group>"; };
ED8A163D2735A8AA000D61F9 /* peer-mgr-wishlist.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = "peer-mgr-wishlist.h"; sourceTree = "<group>"; };
ED8A163E2735A8AA000D61F9 /* peer-mgr-wishlist.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "peer-mgr-wishlist.cc"; sourceTree = "<group>"; };
ED9862952B979AA2002F3035 /* Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Utils.h; sourceTree = "<group>"; };
ED9862962B979AA2002F3035 /* Utils.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Utils.mm; sourceTree = "<group>"; };
EDBAAC8B29E486BC00D9495F /* global-ip-cache.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = "global-ip-cache.h"; sourceTree = "<group>"; };
EDBAAC8D29E486C200D9495F /* global-ip-cache.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "global-ip-cache.cc"; sourceTree = "<group>"; };
EDBDFA9D25AFCCA60093D9C1 /* evutil_time.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = evutil_time.c; sourceTree = "<group>"; };
@ -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",

View file

@ -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;
}

View file

@ -191,6 +191,8 @@ target_sources(${TR_NAME}-mac
TrackerTableView.mm
URLSheetWindowController.h
URLSheetWindowController.mm
Utils.h
Utils.mm
WebSeedTableView.h
WebSeedTableView.mm)

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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;

View file

@ -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])
{

8
macosx/Utils.h Normal file
View file

@ -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 <CoreFoundation/CoreFoundation.h>
bool isSpeedEqual(CGFloat old_speed, CGFloat new_speed);
bool isRatioEqual(CGFloat old_ratio, CGFloat new_ratio);

19
macosx/Utils.mm Normal file
View file

@ -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 <cmath>
#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;
}