Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Converted to ARC.
Browse files Browse the repository at this point in the history
Merged, and more fixes added, by Jens.
  • Loading branch information
mz2 authored and snej committed Nov 2, 2012
1 parent 2ad9cc8 commit de15dba
Show file tree
Hide file tree
Showing 64 changed files with 559 additions and 879 deletions.
27 changes: 10 additions & 17 deletions Demo-Mac/DemoAppController.m
Expand Up @@ -59,7 +59,7 @@ - (void) applicationDidFinishLaunching: (NSNotification*)n {
CouchTouchDBServer* server = [CouchTouchDBServer sharedInstance];
NSAssert(!server.error, @"Error initializing TouchDB: %@", server.error);

_database = [[server databaseNamed: dbName] retain];
_database = [server databaseNamed: dbName];

RESTOperation* op = [_database create];
if (![op wait]) {
Expand Down Expand Up @@ -94,7 +94,7 @@ - (void) applicationDidFinishLaunching: (NSNotification*)n {

CouchQuery* q = [design queryViewNamed: @"byDate"];
q.descending = YES;
self.query = [[[DemoQuery alloc] initWithQuery: q] autorelease];
self.query = [[DemoQuery alloc] initWithQuery: q];
self.query.modelClass =_tableController.objectClass;

// Start watching any persistent replications already configured:
Expand Down Expand Up @@ -220,22 +220,15 @@ - (void) stopObservingReplication: (CouchPersistentReplication*)repl {
[repl removeObserver: self forKeyPath: @"mode"];
}

- (void) forgetReplication: (CouchPersistentReplication**)repl {
if (*repl) {
[self stopObservingReplication: *repl];
[*repl release];
*repl = nil;
}
}


- (void) startContinuousSyncWith: (NSURL*)otherDbURL {
[self forgetReplication: &_pull];
[self forgetReplication: &_push];

if (_pull)
[self stopObservingReplication: _pull];
if (_push)
[self stopObservingReplication: _push];
NSArray* repls = [_database replicateWithURL: otherDbURL exclusively: YES];
_pull = [repls[0] retain];
_push = [repls[1] retain];
_pull = repls[0];
_push = repls[1];
[self observeReplication: _pull];
[self observeReplication: _push];

Expand Down Expand Up @@ -341,7 +334,7 @@ - (TDMapBlock) compileMapFunction: (NSString*)mapSource language:(NSString *)lan
emit(doc[@"foo"], nil);
};
}
return [[mapBlock copy] autorelease];
return [mapBlock copy];
}


Expand All @@ -354,7 +347,7 @@ - (TDReduceBlock) compileReduceFunction: (NSString*)reduceSource language:(NSStr
return [TDView totalValues: values];
};
}
return [[reduceBlock copy] autorelease];
return [reduceBlock copy];
}

#endif
Expand Down
6 changes: 1 addition & 5 deletions Demo-Mac/DemoQuery.m
Expand Up @@ -31,7 +31,7 @@ - (id) initWithQuery: (CouchQuery*)query
self = [super init];
if (self != nil) {
_modelClass = [CouchModel class];
_query = [[query asLiveQuery] retain];
_query = [query asLiveQuery];

_query.prefetch = YES; // for efficiency, include docs on first load
[_query start];
Expand All @@ -45,10 +45,7 @@ - (id) initWithQuery: (CouchQuery*)query

- (void) dealloc
{
[_entries release];
[_query removeObserver: self forKeyPath: @"rows"];
[_query release];
[super dealloc];
}


Expand Down Expand Up @@ -78,7 +75,6 @@ - (void) loadEntriesFrom: (CouchQueryEnumerator*)rows {
NSLog(@" ...entries changed! (was %u, now %u)",
(unsigned)_entries.count, (unsigned)entries.count);
[self willChangeValueForKey: @"entries"];
[_entries release];
_entries = [entries mutableCopy];
[self didChangeValueForKey: @"entries"];
}
Expand Down
9 changes: 1 addition & 8 deletions Demo-Mac/ShoppingItem.m
Expand Up @@ -24,12 +24,6 @@
@implementation ShoppingItem


- (void)dealloc {
[_picture release];
[super dealloc];
}


@dynamic check, text, created_at;


Expand Down Expand Up @@ -58,8 +52,7 @@ - (void) setPicture:(NSImage *)picture {
[self createAttachmentWithName: @"picture"
type: @"image/jpeg"
body: ImageJPEGData(picture)];
[_picture release];
_picture = [picture retain];
_picture = picture;
}


Expand Down
4 changes: 2 additions & 2 deletions Demo-iOS/EmptyAppDelegate.m
Expand Up @@ -15,8 +15,8 @@ @implementation EmptyAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSError* error;
TDServer* tdServer = [[[TDServer alloc] initWithDirectory: @"/tmp/touchdb_empty_app"
error: &error] autorelease];
TDServer* tdServer = [[TDServer alloc] initWithDirectory: @"/tmp/touchdb_empty_app"
error: &error];
NSAssert(tdServer, @"Couldn't create server: %@", error);
[TDURLProtocol setServer: tdServer];
return YES;
Expand Down
5 changes: 2 additions & 3 deletions Listener/TDHTTPConnection.m
Expand Up @@ -75,10 +75,9 @@ - (BOOL)supportsMethod:(NSString *)method atPath:(NSString *)path {
request: urlRequest
isLocal: NO];
router.processRanges = NO; // The HTTP server framework does this already
TDHTTPResponse* response = [[[TDHTTPResponse alloc] initWithRouter: router
forConnection: self] autorelease];
TDHTTPResponse* response = [[TDHTTPResponse alloc] initWithRouter: router
forConnection: self];

[router release];
return response;
}

Expand Down
16 changes: 4 additions & 12 deletions Listener/TDHTTPResponse.m
Expand Up @@ -38,7 +38,7 @@ - (id) initWithRouter: (TDRouter*)router forConnection:(TDHTTPConnection*)connec
if (self) {
//EnableLog(YES);
//EnableLogTo(TDListenerVerbose, YES);
_router = [router retain];
_router = router;
_connection = connection;
router.onResponseReady = ^(TDResponse* r) {
[self onResponseReady: r];
Expand Down Expand Up @@ -68,19 +68,16 @@ - (id) initWithRouter: (TDRouter*)router forConnection:(TDHTTPConnection*)connec
// Run the router, asynchronously:
LogTo(TDListenerVerbose, @"%@: Starting...", self);
[router start];
[self retain]; // will be released in -cleanUp
LogTo(TDListenerVerbose, @"%@: Returning from -init", self);
}
return self;
}

#if 0
- (void)dealloc {
LogTo(TDListenerVerbose, @"DEALLOC %@", self);
[_router release];
[_response release];
[_data release];
[super dealloc];
}
#endif


- (NSString*) description {
Expand Down Expand Up @@ -116,7 +113,7 @@ - (BOOL) delayResponseHeaders {

- (void) onResponseReady: (TDResponse*)response {
@synchronized(self) {
_response = [response retain];
_response = response;
LogTo(TDListener, @" %@ --> %i", self, _response.status);
if (_delayedHeaders)
[_connection responseHasAvailableData: self];
Expand All @@ -143,7 +140,6 @@ - (void) onDataAvailable: (NSData*)data finished: (BOOL)finished {
_dataMutable = NO;
} else {
if (!_dataMutable) {
[_data autorelease];
_data = [_data mutableCopy];
_dataMutable = YES;
}
Expand Down Expand Up @@ -185,7 +181,6 @@ - (NSData*) readDataOfLength: (NSUInteger)length {
if (range.length == bytesAvailable) {
// Client has read all of the available data, so we can discard it
_dataOffset += _data.length;
[_data autorelease];
_data = nil;
}
LogTo(TDListenerVerbose, @"%@ sending %u bytes", self, (unsigned)result.length);
Expand All @@ -207,7 +202,6 @@ - (void) cleanUp {
_router.onFinished = nil;
if (!_finished) {
_finished = true;
[self autorelease];
}
}

Expand All @@ -233,7 +227,6 @@ - (void) onFinished {
if (pretty) {
NSString* contentType = (_response.headers)[@"Content-Type"];
if ([contentType hasPrefix: @"application/json"] && _data.length < 100000) {
[_data release];
_data = [_response.body.asPrettyJSON mutableCopy];
}
}
Expand All @@ -246,7 +239,6 @@ - (void) onFinished {
- (void)connectionDidClose {
@synchronized(self) {
_connection = nil;
[_data release];
_data = nil;
[self cleanUp];
}
Expand Down
8 changes: 1 addition & 7 deletions Listener/TDListener.m
Expand Up @@ -30,7 +30,7 @@ @implementation TDListener
- (id) initWithTDServer: (TDServer*)server port: (UInt16)port {
self = [super init];
if (self) {
_tdServer = [server retain];
_tdServer = server;
_httpServer = [[TDHTTPServer alloc] init];
_httpServer.listener = self;
_httpServer.tdServer = _tdServer;
Expand All @@ -45,11 +45,6 @@ - (id) initWithTDServer: (TDServer*)server port: (UInt16)port {
- (void)dealloc
{
[self stop];
[_tdServer release];
[_httpServer release];
[_realm release];
[_passwords release];
[super dealloc];
}


Expand Down Expand Up @@ -79,7 +74,6 @@ - (UInt16) port {


- (void) setPasswords: (NSDictionary*)passwords {
[_passwords autorelease];
_passwords = [passwords copy];
_requiresAuth = (_passwords != nil);
}
Expand Down
10 changes: 5 additions & 5 deletions Source/ChangeTracker/TDChangeTracker.h
Expand Up @@ -38,7 +38,7 @@ typedef enum TDChangeTrackerMode {
{
@protected
NSURL* _databaseURL;
id<TDChangeTrackerClient> _client;
id<TDChangeTrackerClient> __weak _client;
TDChangeTrackerMode _mode;
id _lastSequenceID;
unsigned _limit;
Expand All @@ -62,10 +62,10 @@ typedef enum TDChangeTrackerMode {
@property (readonly, nonatomic) NSString* databaseName;
@property (readonly) NSURL* changesFeedURL;
@property (readonly, copy, nonatomic) id lastSequenceID;
@property (retain, nonatomic) NSError* error;
@property (assign, nonatomic) id<TDChangeTrackerClient> client;
@property (retain, nonatomic) NSDictionary *requestHeaders;
@property (retain, nonatomic) id<TDAuthorizer> authorizer;
@property (nonatomic) NSError* error;
@property (weak, nonatomic) id<TDChangeTrackerClient> client;
@property (strong, nonatomic) NSDictionary *requestHeaders;
@property (strong, nonatomic) id<TDAuthorizer> authorizer;

@property (nonatomic) TDChangeTrackerMode mode;
@property (copy) NSString* filterName;
Expand Down
13 changes: 2 additions & 11 deletions Source/ChangeTracker/TDChangeTracker.m
Expand Up @@ -51,14 +51,13 @@ - (id)initWithDatabaseURL: (NSURL*)databaseURL
if (self) {
if([self class] == [TDChangeTracker class]) {
// TDChangeTracker is abstract; instantiate a concrete subclass instead.
[self release];
return [[TDSocketChangeTracker alloc] initWithDatabaseURL: databaseURL
mode: mode
conflicts: includeConflicts
lastSequence: lastSequenceID
client: client];
}
_databaseURL = [databaseURL retain];
_databaseURL = databaseURL;
_client = client;
_mode = mode;
_heartbeat = kDefaultHeartbeat;
Expand Down Expand Up @@ -96,7 +95,7 @@ - (NSString*) changesFeedPath {
}

- (NSURL*) changesFeedURL {
NSMutableString* urlStr = [[_databaseURL.absoluteString mutableCopy] autorelease];
NSMutableString* urlStr = [_databaseURL.absoluteString mutableCopy];
if (![urlStr hasSuffix: @"/"])
[urlStr appendString: @"/"];
[urlStr appendString: self.changesFeedPath];
Expand All @@ -109,14 +108,6 @@ - (NSString*) description {

- (void) dealloc {
[self stop];
[_filterName release];
[_filterParameters release];
[_databaseURL release];
[_lastSequenceID release];
[_error release];
[_requestHeaders release];
[_authorizer release];
[super dealloc];
}

- (void) setUpstreamError: (NSString*)message {
Expand Down
11 changes: 4 additions & 7 deletions Source/ChangeTracker/TDConnectionChangeTracker.m
Expand Up @@ -65,17 +65,15 @@ - (BOOL) start {
[request setValue: value forHTTPHeaderField: key];
}];

_connection = [[NSURLConnection connectionWithRequest: request delegate: self] retain];
_connection = [NSURLConnection connectionWithRequest: request delegate: self];
_startTime = CFAbsoluteTimeGetCurrent();
LogTo(ChangeTracker, @"%@: Started... <%@>", self, request.URL);
return YES;
}


- (void) clearConnection {
[_connection autorelease];
_connection = nil;
[_inputBuffer release];
_inputBuffer = nil;
}

Expand Down Expand Up @@ -106,7 +104,7 @@ - (bool) retryWithCredential {
}

[_connection cancel];
self.authorizer = [[[TDBasicAuthorizer alloc] initWithCredential: cred] autorelease];
self.authorizer = [[TDBasicAuthorizer alloc] initWithCredential: cred];
LogTo(ChangeTracker, @"Got 401 but retrying with %@", _authorizer);
[self clearConnection];
[self start];
Expand Down Expand Up @@ -135,7 +133,7 @@ - (void)connection:(NSURLConnection *)connection
if (challengeIsForDottedHost) {
// Update the policy with the correct original hostname (without the "." suffix):
host = _databaseURL.host;
SecPolicyRef policy = SecPolicyCreateSSL(YES, (CFStringRef)host);
SecPolicyRef policy = SecPolicyCreateSSL(YES, (__bridge CFStringRef)host);
trust = CopyTrustWithPolicy(trust, policy);
CFRelease(policy);
} else {
Expand Down Expand Up @@ -235,7 +233,7 @@ - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// Now parse the entire response as a JSON document:
NSData* input = [_inputBuffer retain];
NSData* input = _inputBuffer;
LogTo(ChangeTracker, @"%@: Got entire body, %u bytes", self, (unsigned)input.length);
BOOL restart = NO;
NSString* errorMessage = nil;
Expand All @@ -250,7 +248,6 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// ran out of changes due to a _limit rather than because we hit the end.
restart = _mode == kLongPoll || numChanges == (NSInteger)_limit;
}
[input release];

[self clearConnection];

Expand Down

0 comments on commit de15dba

Please sign in to comment.