Skip to content
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

CBL-4658: Enable CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF #3190

Merged
merged 5 commits into from
Sep 13, 2023
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
4 changes: 2 additions & 2 deletions CouchbaseLite.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5566,7 +5566,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "source \"$SCRIPT_INPUT_FILE_0\"\n";
shellScript = "source \"$SCRIPT_INPUT_FILE_0\"\necho \"Private headers removed\"\n";
};
93CED8D52048B3D600E6F0A4 /* Remove private headers */ = {
isa = PBXShellScriptBuildPhase;
Expand All @@ -5581,7 +5581,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "source \"$SCRIPT_INPUT_FILE_0\"";
shellScript = "source \"$SCRIPT_INPUT_FILE_0\"\necho \"Private headers removed\"\n";
};
93D118ED1F560232000F6D3E /* Check Git Commit */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
2 changes: 1 addition & 1 deletion Objective-C/CBLDocument.mm
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ - (void) updateDictionary {
}
_root.reset(new MRoot<id>(new cbl::DocContext(db, _c4Doc), Dict(_fleeceData), self.isMutable));
[db safeBlock:^{
_dict = _root->asNative();
self->_dict = self->_root->asNative();
}];
} else {
// New document:
Expand Down
18 changes: 9 additions & 9 deletions Objective-C/CBLQuery.mm
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ - (instancetype) initWithSelect: (NSArray<CBLQuerySelectResult*>*)select

- (void) dealloc {
[self.database safeBlock:^{
c4query_release(_c4Query);
c4query_release(self->_c4Query);
}];
}

Expand Down Expand Up @@ -236,7 +236,7 @@ - (void) setParameters: (CBLQueryParameters*)parameters {

_parameters = [[CBLQueryParameters alloc] initWithParameters: parameters readonly: YES];
[self.database safeBlock:^{
c4query_setParameters(_c4Query, {params.bytes, params.length});
c4query_setParameters(self->_c4Query, {params.bytes, params.length});
}];
}
else
Expand All @@ -247,7 +247,7 @@ - (void) setParameters: (CBLQueryParameters*)parameters {
- (NSString*) explain: (NSError**)outError {
__block NSString* result;
[self.database safeBlock: ^{
result = sliceResult2string(c4query_explain(_c4Query));
result = sliceResult2string(c4query_explain(self->_c4Query));
}];

return result;
Expand All @@ -258,7 +258,7 @@ - (nullable CBLQueryResultSet*) execute: (NSError**)outError {
__block C4QueryEnumerator* e;
__block C4Error c4Err;
[self.database safeBlock:^{
e = c4query_run(_c4Query, kC4SliceNull, &c4Err);
e = c4query_run(self->_c4Query, kC4SliceNull, &c4Err);
}];

if (!e) {
Expand Down Expand Up @@ -352,13 +352,13 @@ - (BOOL) compile: (NSError**)outError {
__block C4Error c4Err;
__block C4Query* query;
[self.database safeBlock:^{
if (_language == kC4JSONQuery) {
assert(_json);
if (self->_language == kC4JSONQuery) {
assert(self->_json);
query = c4query_new2(self.database.c4db,
kC4JSONQuery, {_json.bytes, _json.length}, nullptr, &c4Err);
kC4JSONQuery, {self->_json.bytes, self->_json.length}, nullptr, &c4Err);
} else {
assert(_expressions);
CBLStringBytes exp(_expressions);
assert(self->_expressions);
CBLStringBytes exp(self->_expressions);
query = c4query_new2(self.database.c4db, kC4N1QLQuery, exp, nullptr, &c4Err);
}
}];
Expand Down
2 changes: 1 addition & 1 deletion Objective-C/CBLQueryResult.mm
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ - (id) fleeceValueToObjectAtIndex: (NSUInteger)index {

__block id result;
[_rs.database safeBlock:^{
MRoot<id> root(_context, value, false);
MRoot<id> root(self->_context, value, false);
result = root.asNative();
}];
return result;
Expand Down
18 changes: 9 additions & 9 deletions Objective-C/CBLQueryResultSet.mm
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ - (void) dealloc {
- (id) nextObject {
__block id row = nil;
[self.database safeBlock: ^{
if (_isAllEnumerated)
if (self->_isAllEnumerated)
return;

if (c4queryenum_next(_c4enum, &_error)) {
if (c4queryenum_next(self->_c4enum, &self->_error)) {
row = self.currentObject;
} else if (_error.code) {
CBLWarnError(Query, @"%@[%p] error: %d/%d", [self class], self, _error.domain, _error.code);
} else if (self->_error.code) {
CBLWarnError(Query, @"%@[%p] error: %d/%d", [self class], self, self->_error.domain, self->_error.code);
} else {
_isAllEnumerated = YES;
CBLLogInfo(Query, @"End of query enumeration (%p)", _c4enum);
self->_isAllEnumerated = YES;
CBLLogInfo(Query, @"End of query enumeration (%p)", self->_c4enum);
}
}];
return row;
Expand Down Expand Up @@ -144,8 +144,8 @@ - (id) objectAtIndex: (NSUInteger)index {

__block id result;
[db safeBlock: ^{
if (!c4queryenum_seek(_c4enum, index, &_error)) {
NSString* message = sliceResult2string(c4error_getMessage(_error));
if (!c4queryenum_seek(self->_c4enum, index, &self->_error)) {
NSString* message = sliceResult2string(c4error_getMessage(self->_error));
[NSException raise: NSInternalInconsistencyException
format: @"CBLQueryEnumerator couldn't get a value: %@", message];
}
Expand All @@ -172,7 +172,7 @@ - (CBLQueryResultSet*) refresh: (NSError**)outError {

CBLDatabase* db = self.database;
[db safeBlock: ^{
newEnum = c4queryenum_refresh(_c4enum, &c4error);
newEnum = c4queryenum_refresh(self->_c4enum, &c4error);
}];
if (!newEnum) {
if (c4error.code)
Expand Down
14 changes: 7 additions & 7 deletions Objective-C/CBLReplicator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,17 @@ - (bool) _setupC4Replicator: (C4Error*)outErr {

// Create a C4Replicator:
[_config.database safeBlock: ^{
[_config.database mustBeOpenLocked];
[self->_config.database mustBeOpenLocked];

if (remoteURL || !otherDB)
_repl = c4repl_new(_config.database.c4db, addr, dbName, params, outErr);
self->_repl = c4repl_new(self->_config.database.c4db, addr, dbName, params, outErr);
else {
#ifdef COUCHBASE_ENTERPRISE
if (otherDB) {
[otherDB safeBlock: ^{
[otherDB mustBeOpenLocked];

_repl = c4repl_newLocal(_config.database.c4db, otherDB.c4db, params, outErr);
self->_repl = c4repl_newLocal(self->_config.database.c4db, otherDB.c4db, params, outErr);
}];
}
#else
Expand Down Expand Up @@ -718,13 +718,13 @@ - (void) resolveConflict: (CBLReplicatedDocument*)doc {
dispatch_async(_conflictQueue, ^{
[self _resolveConflict: doc];
CBL_LOCK(self) {
if (--_conflictCount == 0 && _deferReplicatorNotification) {
if (_rawStatus.level == kC4Stopped) {
Assert(_state == kCBLStateStopping);
if (--self->_conflictCount == 0 && self->_deferReplicatorNotification) {
if (self->_rawStatus.level == kC4Stopped) {
Assert(self->_state == kCBLStateStopping);
[self stopped];
}

_deferReplicatorNotification = NO;
self->_deferReplicatorNotification = NO;
[self updateAndPostStatus];
}
}
Expand Down
4 changes: 2 additions & 2 deletions Objective-C/Internal/Replicator/CBLDNSService.mm
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ - (void) start {
if (!_timeoutBlock) {
_timeoutBlock = dispatch_block_create(DISPATCH_BLOCK_ASSIGN_CURRENT, ^{
@synchronized (self) {
CBLWarnError(WebSocket, @"%@: Looking up '%@' timeout", self, _host);
CBLWarnError(WebSocket, @"%@: Looking up '%@' timeout", self, self->_host);
[self notifyError: kDNSServiceErr_Timeout];
}
});
Expand Down Expand Up @@ -215,7 +215,7 @@ - (BOOL) checkAlreadyIPAddress {

if (info) {
dispatch_async(_dnsQueue, ^{
[_delegate didResolveSuccessWithAddress: info];
[self->_delegate didResolveSuccessWithAddress: info];
});
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ - (void) endBackgrounding {
- (void) endCurrentBackgroundTask {
dispatch_async(dispatch_get_main_queue(), ^{
if ([self.bgMonitor hasBackgroundTask]) {
_deepBackground = YES;
self->_deepBackground = YES;
[self updateSuspended];
CBLLogInfo(Sync, @"%@: ending background task as idle.", self);
[self.bgMonitor endBackgroundTask]; // will probably suspend the process immediately
Expand Down
24 changes: 12 additions & 12 deletions Objective-C/Internal/Replicator/CBLWebSocket.mm
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ - (void) callC4Socket: (void (^)(C4Socket*))callback {

- (void) start {
dispatch_async(_queue, ^{
if (_logic.error) {
if (self->_logic.error) {
// PAC resolution must have failed. Give up.
[self closeWithError: _logic.error];
[self closeWithError: self->_logic.error];
return;
}
[self _connect];
Expand Down Expand Up @@ -389,7 +389,7 @@ - (void) connectToHostWithName: (NSString*)hostname

- (void) didResolveSuccessWithAddress: (AddressInfo*)info {
dispatch_async(_queue, ^{
if (_dnsService) {
if (self->_dnsService) {
CBLLogVerbose(WebSocket, @"%@: Host '%@' was resolved as ip=%@, family=%d",
self, info.host, info.addrstr, info.addr->sa_family);
[self _socketConnect: info];
Expand All @@ -399,7 +399,7 @@ - (void) didResolveSuccessWithAddress: (AddressInfo*)info {

- (void) didResolveFailWithError: (NSError*)error {
dispatch_async(_queue, ^{
if (_dnsService) {
if (self->_dnsService) {
CBLWarnError(WebSocket, @"%@: Host was failed to resolve with error '%@'",
self, error.my_compactDescription);
[self closeWithError: error];
Expand Down Expand Up @@ -453,13 +453,13 @@ - (void) _socketConnect: (AddressInfo*)info {
CBLLogVerbose(WebSocket, @"%@: Connect to IP address %@", self, info.addrstr);
int status = connect(sockfd, info.addr, info.length);
if (status == 0) {
dispatch_async(_queue, ^{
if (_sockfd < 0)
dispatch_async(self->_queue, ^{
if (self->_sockfd < 0)
return; // Already disconnected

// Enable non-blocking mode on the socket:
int flags = fcntl(_sockfd, F_GETFL);
if (fcntl(_sockfd, F_SETFL, flags | O_NONBLOCK) < 0) {
int flags = fcntl(self->_sockfd, F_GETFL);
if (fcntl(self->_sockfd, F_SETFL, flags | O_NONBLOCK) < 0) {
int errNo = errno;
NSString* msg = $sprintf(@"Failed to enable non-blocking mode with errno %d", errNo);
CBLWarnError(WebSocket, @"%@: %@", self, msg);
Expand All @@ -470,7 +470,7 @@ - (void) _socketConnect: (AddressInfo*)info {
// Create a pair steam with the socket:
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocket(kCFAllocatorDefault, _sockfd, &readStream, &writeStream);
CFStreamCreatePairWithSocket(kCFAllocatorDefault, self->_sockfd, &readStream, &writeStream);

CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
Expand All @@ -487,7 +487,7 @@ - (void) _socketConnect: (AddressInfo*)info {
info.interface, errNo);
CBLWarnError(WebSocket, @"%@: %@", self, msg);
NSError* error = posixError(errNo, msg);
dispatch_async(_queue, ^{
dispatch_async(self->_queue, ^{
[self closeWithError: error];
});
}
Expand Down Expand Up @@ -845,7 +845,7 @@ - (void) completedReceive: (size_t)byteCount {
dispatch_async(_queue, ^{
bool wasThrottled = self.readThrottled;
self->_receivedBytesPending -= byteCount;
if (_hasBytes && wasThrottled && !self.readThrottled)
if (self->_hasBytes && wasThrottled && !self.readThrottled)
[self doRead];
});
}
Expand All @@ -854,7 +854,7 @@ - (void) completedReceive: (size_t)byteCount {
- (void) closeSocket {
CBLLogInfo(WebSocket, @"%@: CBLWebSocket closeSocket requested", self);
dispatch_async(_queue, ^{
if (_in || _out || _sockfd >= 0) {
if (self->_in || self->_out || self->_sockfd >= 0) {
[self closeWithError: nil];
}
});
Expand Down
2 changes: 1 addition & 1 deletion Swift/Tests/URLEndpointListenerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ class URLEndpointListenerTest_Main: URLEndpointListenerTest {
let urls = self.listener!.urls!

/// Link local addresses cannot be assigned via network interface because they don't map to any given interface.
let notLinkLocal: [URL] = urls.filter { !$0.host!.contains("fe80::") && !$0.host!.contains(".local")}
let notLinkLocal: [URL] = urls.filter { !$0.host!.contains(":") && !$0.host!.contains(".local")}

for (i, url) in notLinkLocal.enumerated() {
// separate db instance!
Expand Down
2 changes: 1 addition & 1 deletion vendor/MYUtilities
2 changes: 1 addition & 1 deletion xcconfigs/Project.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ CLANG_WARN_ENUM_CONVERSION = YES
CLANG_WARN_INFINITE_RECURSION = YES
CLANG_WARN_INT_CONVERSION = YES
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = NO // TODO: Switch this to YES
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR
Expand Down
Loading