Skip to content

Commit 4c0b3e4

Browse files
committed
Cleared some compiler warnings which appeared with Xcode 12.
1 parent a871544 commit 4c0b3e4

File tree

2 files changed

+99
-88
lines changed

2 files changed

+99
-88
lines changed

SSYPathObserver.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ extern NSString* const SSYPathObserverUserInfoKey ;
127127
@brief A Cocoa wrapper around the kqueue path-watching
128128
notification system which will watch a set of filesystem items.
129129
130-
@details
131-
130+
@details
132131
* Background
133132
134133
Although File system events (FSEvents) became available
@@ -218,7 +217,7 @@ extern NSString* const SSYPathObserverUserInfoKey ;
218217
*/
219218
- (BOOL)addPath:(NSString*)path
220219
watchFlags:(uint32_t)watchFlags
221-
notifyThread:(NSThread*)notifeeThread
220+
notifyThread:(NSThread*)notifyThread
222221
userInfo:(id)userInfo
223222
error_p:(NSError**)error_p ;
224223

SSYPathObserver.m

+97-85
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ @interface SSYPathWatch : NSObject {
1919
NSString* m_path ;
2020
id m_userInfo ;
2121
uint32_t m_fileDescriptor ;
22-
NSThread* m_notifyThread ;
22+
__unsafe_unretained NSThread* m_notifyThread ;
2323
}
2424

2525
@property (retain) NSString* path ;
@@ -53,12 +53,14 @@ - (BOOL)isEqual:(SSYPathWatch*)otherPathWatch {
5353
return ([[otherPathWatch path] isEqualToString:[self path]]) ;
5454
}
5555

56+
#if !__has_feature(objc_arc)
5657
- (void)dealloc {
5758
[m_path release] ;
5859
[m_userInfo release] ;
5960

6061
[super dealloc] ;
6162
}
63+
#endif
6264

6365
@end
6466

@@ -76,6 +78,7 @@ @implementation SSYPathObserver
7678
@synthesize pathWatches = m_pathWatches ;
7779
@synthesize kqueueFileDescriptor = m_kqueueFileDescriptor ; // file descriptor for the kqueue
7880

81+
#if !__has_feature(objc_arc)
7982
/*
8083
Note that this method is always invoked by the watcher
8184
thread, not the main thread. See commments in -release.
@@ -85,6 +88,7 @@ - (void)dealloc {
8588

8689
[super dealloc] ;
8790
}
91+
#endif
8892

8993
- (void)watchAndWait {
9094
/* Note that, in macOS 10.5, we may kill this thread in -release.
@@ -105,13 +109,11 @@ camping on kevent(), outside of these two blocks of code, but,
105109

106110
int fileDescriptor ;
107111
@synchronized(self) {
108-
NSAutoreleasePool* pool1 = [[NSAutoreleasePool alloc] init] ;
109-
110-
[[NSThread currentThread] setName:SSYPathObserverWatcherThread] ;
111-
112-
fileDescriptor = [self kqueueFileDescriptor] ;
113-
114-
[pool1 release] ;
112+
@autoreleasepool {
113+
[[NSThread currentThread] setName:SSYPathObserverWatcherThread] ;
114+
115+
fileDescriptor = [self kqueueFileDescriptor] ;
116+
}
115117
}
116118

117119

@@ -128,63 +130,66 @@ camping on kevent(), outside of these two blocks of code, but,
128130
) ;
129131
if (result != -1) {
130132
if(event.filter == EVFILT_VNODE ) {
131-
SSYPathWatch* pathWatch = (SSYPathWatch*)event.udata ;
133+
SSYPathWatch* pathWatch = (__bridge SSYPathWatch*)event.udata ;
132134

133135
@synchronized(self) {
134-
NSAutoreleasePool* pool2 = [[NSAutoreleasePool alloc] init] ;
135-
// Retain pathWatch here, in case of the unlikely event that
136-
// pathWatch has just been removed on another thread
137-
[pathWatch retain] ;
138-
NSString* path = [pathWatch path];
139-
NSDictionary* pathWatchUserInfo = [pathWatch userInfo];
140-
NSThread* notifyThread = [pathWatch notifyThread];
141-
if ([self isWatching]) {
142-
NSNumber* filterFlags = [NSNumber numberWithInteger:event.fflags] ;
143-
NSDictionary* userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
144-
filterFlags, SSYPathObserverChangeFlagsKey,
145-
path, SSYPathObserverPathKey,
146-
[NSNumber numberWithInteger:[pathWatch fileDescriptor]], SSYPathObserverFileDescriptorKey,
147-
pathWatchUserInfo, SSYPathObserverUserInfoKey, // may be nil
148-
nil] ;
149-
NSNotification* note = [NSNotification notificationWithName:SSYPathObserverChangeNotification
150-
object:self
151-
userInfo:userInfo] ;
152-
[[NSNotificationCenter defaultCenter] performSelector:@selector(postNotification:)
153-
onThread:notifyThread
154-
withObject:note
155-
waitUntilDone:NO] ;
156-
}
157-
158-
/* In some cases, I think if the event we re no processing was
159-
caused by an external actor *replacing* the file at the watched
160-
path with a new file, our path watch will be watching the old file
161-
which no longer exists, and therefore we will not get any subsequent
162-
events when the *new* file at the watched path is touched. Although I
163-
have not verified that such file replacement is the cause, I have
164-
definitely seen kqueues "die" like this. I think it's a good theory,
165-
and in at least one reproducible case, the following code, which
166-
removes the "used" path watch adds back a new one) fixed the problem.
167-
I theorize this is due to the fact that destroying the path watch
168-
closes its (watched) file descriptor, and creating a new path
169-
watch opens a new file descriptor. I did verify that the new file
170-
descriptor integer value is the same as the old one; presumably
171-
the system uses the lowest unused file descriptor which is the old
172-
one that was just released. */
173-
BOOL ok;
174-
NSError* error = nil;
175-
ok = [self removePath:path
176-
error_p:&error];
177-
NSAssert(ok, @"Error removing used path from kqueue : %@", error);
178-
uint32_t watchFlags = pathWatch.watchFlags;
179-
[pathWatch release] ;
180-
[self addPath:path
181-
watchFlags:watchFlags
182-
notifyThread:notifyThread
183-
userInfo:pathWatchUserInfo
184-
error_p:&error];
185-
NSAssert(ok, @"Error renewing used path from kqueue : %@", error);
186-
187-
[pool2 release] ;
136+
@autoreleasepool {
137+
// Retain pathWatch here, in case of the unlikely event that
138+
// pathWatch has just been removed on another thread
139+
#if !__has_feature(objc_arc)
140+
[pathWatch retain] ;
141+
#endif
142+
NSString* path = [pathWatch path];
143+
NSDictionary* pathWatchUserInfo = [pathWatch userInfo];
144+
NSThread* notifyThread = [pathWatch notifyThread];
145+
if ([self isWatching]) {
146+
NSNumber* filterFlags = [NSNumber numberWithInteger:event.fflags] ;
147+
NSDictionary* userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
148+
filterFlags, SSYPathObserverChangeFlagsKey,
149+
path, SSYPathObserverPathKey,
150+
[NSNumber numberWithInteger:[pathWatch fileDescriptor]], SSYPathObserverFileDescriptorKey,
151+
pathWatchUserInfo, SSYPathObserverUserInfoKey, // may be nil
152+
nil] ;
153+
NSNotification* note = [NSNotification notificationWithName:SSYPathObserverChangeNotification
154+
object:self
155+
userInfo:userInfo] ;
156+
[[NSNotificationCenter defaultCenter] performSelector:@selector(postNotification:)
157+
onThread:notifyThread
158+
withObject:note
159+
waitUntilDone:NO] ;
160+
}
161+
162+
/* In some cases, I think if the event we re no processing was
163+
caused by an external actor *replacing* the file at the watched
164+
path with a new file, our path watch will be watching the old file
165+
which no longer exists, and therefore we will not get any subsequent
166+
events when the *new* file at the watched path is touched. Although I
167+
have not verified that such file replacement is the cause, I have
168+
definitely seen kqueues "die" like this. I think it's a good theory,
169+
and in at least one reproducible case, the following code, which
170+
removes the "used" path watch adds back a new one) fixed the problem.
171+
I theorize this is due to the fact that destroying the path watch
172+
closes its (watched) file descriptor, and creating a new path
173+
watch opens a new file descriptor. I did verify that the new file
174+
descriptor integer value is the same as the old one; presumably
175+
the system uses the lowest unused file descriptor which is the old
176+
one that was just released. */
177+
BOOL ok;
178+
NSError* error = nil;
179+
ok = [self removePath:path
180+
error_p:&error];
181+
NSAssert(ok, @"Error removing used path from kqueue : %@", error);
182+
uint32_t watchFlags = pathWatch.watchFlags;
183+
#if !__has_feature(objc_arc)
184+
[pathWatch release] ;
185+
#endif
186+
[self addPath:path
187+
watchFlags:watchFlags
188+
notifyThread:notifyThread
189+
userInfo:pathWatchUserInfo
190+
error_p:&error];
191+
NSAssert(ok, @"Error renewing used path from kqueue : %@", error);
192+
}
188193
}
189194
}
190195
}
@@ -211,7 +216,9 @@ -(id)init {
211216
if (kqueueFileDescriptor == -1) {
212217
NSLog(@"Internal Error 153-9092. Failed creating kqueue") ;
213218
// See http://lists.apple.com/archives/Objc-language/2008/Sep/msg00133.html ...
219+
#if !__has_feature(objc_arc)
214220
[super dealloc] ;
221+
#endif
215222
self = nil ;
216223
}
217224
else {
@@ -302,7 +309,7 @@ - (BOOL)kqueueRegisterPathWatch:(SSYPathWatch*)pathWatch
302309
actionFlags, // flags
303310
fflags, // fflags
304311
0, // data
305-
pathWatch // udata, user data, aka "context info"
312+
(__bridge void *)pathWatch // udata, user data, aka "context info"
306313
) ;
307314

308315
#if DEBUG_LOG_KQUEUE_SETTINGS
@@ -347,6 +354,7 @@ - (BOOL)kqueueRegisterPathWatch:(SSYPathWatch*)pathWatch
347354
return ok ;
348355
}
349356

357+
#if !__has_feature(objc_arc)
350358
- (oneway void)release {
351359
// The default behavior of -release is to decrement retainCount if
352360
// retainCount is greater than 1, and otherwise invoke -dealloc.
@@ -396,6 +404,7 @@ - (oneway void)release {
396404
[super release] ;
397405
return ;
398406
}
407+
#endif
399408

400409
#if 0
401410
- (id)autorelease {
@@ -431,28 +440,29 @@ - (BOOL)addPath:(NSString*)path
431440
}
432441

433442
ok = NO ;
434-
goto end ;
435443
}
436444

437-
// Create pathWatch
438-
SSYPathWatch* pathWatch = [[SSYPathWatch alloc] init] ;
439-
[pathWatch setPath:path] ;
440-
[pathWatch setUserInfo:userInfo] ;
441-
[pathWatch setFileDescriptor:fileDescriptor] ;
442-
[pathWatch setNotifyThread:(notifyThread ? notifyThread : [NSThread mainThread])] ;
443-
@synchronized(self) {
444-
[[self pathWatches] addObject:pathWatch] ;
445-
[pathWatch release] ;
446-
447-
// Register kqueue for it
448-
ok = [self kqueueRegisterPathWatch:pathWatch
449-
doAdd:YES
450-
flags:watchFlags
451-
error_p:error_p] ;
452-
}
453-
454-
end:
455-
return ok ;
445+
if (ok) {
446+
// Create pathWatch
447+
SSYPathWatch* pathWatch = [[SSYPathWatch alloc] init] ;
448+
[pathWatch setPath:path] ;
449+
[pathWatch setUserInfo:userInfo] ;
450+
[pathWatch setFileDescriptor:fileDescriptor] ;
451+
[pathWatch setNotifyThread:(notifyThread ? notifyThread : [NSThread mainThread])] ;
452+
@synchronized(self) {
453+
[[self pathWatches] addObject:pathWatch] ;
454+
#if !__has_feature(objc_arc)
455+
[pathWatch release] ;
456+
#endif
457+
// Register kqueue for it
458+
ok = [self kqueueRegisterPathWatch:pathWatch
459+
doAdd:YES
460+
flags:watchFlags
461+
error_p:error_p] ;
462+
}
463+
}
464+
465+
return ok ;
456466
}
457467

458468
- (BOOL)removePath:(NSString*)path
@@ -499,9 +509,11 @@ - (NSSet*)currentlyWatchedPaths {
499509
}
500510

501511
NSSet* answer = [paths copy];
512+
#if !__has_feature(objc_arc)
502513
[paths release];
503514
[answer autorelease];
504-
515+
#endif
516+
505517
return answer;
506518
}
507519

0 commit comments

Comments
 (0)