Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Converted to ARC.

Merged, and more fixes added, by Jens.
  • Loading branch information...
commit de15dba1ee06bb373d01431f43c96ee92f989a7e 1 parent 2ad9cc8
@mz2 mz2 authored snej committed
Showing with 559 additions and 879 deletions.
  1. +10 −17 Demo-Mac/DemoAppController.m
  2. +1 −5 Demo-Mac/DemoQuery.m
  3. +1 −8 Demo-Mac/ShoppingItem.m
  4. +2 −2 Demo-iOS/EmptyAppDelegate.m
  5. +2 −3 Listener/TDHTTPConnection.m
  6. +4 −12 Listener/TDHTTPResponse.m
  7. +1 −7 Listener/TDListener.m
  8. +5 −5 Source/ChangeTracker/TDChangeTracker.h
  9. +2 −11 Source/ChangeTracker/TDChangeTracker.m
  10. +4 −7 Source/ChangeTracker/TDConnectionChangeTracker.m
  11. +16 −25 Source/ChangeTracker/TDSocketChangeTracker.m
  12. +0 −6 Source/TDAttachment.m
  13. +2 −2 Source/TDAuthorizer.h
  14. +9 −22 Source/TDAuthorizer.m
  15. +2 −2 Source/TDBase64.m
  16. +2 −7 Source/TDBatcher.m
  17. +1 −15 Source/TDBlobStore.m
  18. +2 −2 Source/TDBlobStore_Tests.m
  19. +3 −9 Source/TDBody.m
  20. +2 −11 Source/TDCanonicalJSON.m
  21. +29 −12 Source/TDChangeTracker_Tests.m
  22. +0 −2  Source/TDCollateJSON.m
  23. +12 −13 Source/TDDatabase+Attachments.m
  24. +8 −17 Source/TDDatabase+Insertion.m
  25. +2 −2 Source/TDDatabase+LocalDocs.m
  26. +0 −1  Source/TDDatabase+Replication.m
  27. +20 −27 Source/TDDatabase.m
  28. +3 −10 Source/TDDatabaseManager.m
  29. +31 −32 Source/TDDatabase_Tests.m
  30. +1 −8 Source/TDJSON.m
  31. +31 −11 Source/TDMisc.m
  32. +1 −1  Source/TDMultiStreamWriter.h
  33. +15 −22 Source/TDMultiStreamWriter.m
  34. +9 −19 Source/TDMultipartDocumentReader.m
  35. +2 −6 Source/TDMultipartDownloader.m
  36. +8 −28 Source/TDMultipartReader.m
  37. +1 −5 Source/TDMultipartUploader.m
  38. +5 −11 Source/TDMultipartWriter.m
  39. +6 −18 Source/TDOAuth1Authorizer.m
  40. +38 −38 Source/TDPuller.m
  41. +7 −7 Source/TDPusher.m
  42. +9 −10 Source/TDReachability.m
  43. +0 −82 Source/TDReachability_Stubs.m
  44. +1 −1  Source/TDRemoteRequest.h
  45. +20 −17 Source/TDRemoteRequest.m
  46. +4 −4 Source/TDReplicator.h
  47. +32 −37 Source/TDReplicator.m
  48. +4 −10 Source/TDReplicatorManager.m
  49. +6 −8 Source/TDReplicator_Tests.m
  50. +1 −1  Source/TDRevision.h
  51. +2 −16 Source/TDRevision.m
  52. +8 −12 Source/TDRouter+Handlers.m
  53. +2 −2 Source/TDRouter.h
  54. +16 −34 Source/TDRouter.m
  55. +5 −6 Source/TDRouter_Tests.m
  56. +1 −7 Source/TDSequenceMap.m
  57. +13 −21 Source/TDServer.m
  58. +17 −17 Source/TDStatus.m
  59. +19 −17 Source/TDURLProtocol.m
  60. +1 −1  Source/TDView.h
  61. +4 −19 Source/TDView.m
  62. +10 −9 Source/TDView_Tests.m
  63. +83 −79 TouchDB.xcodeproj/project.pbxproj
  64. +1 −1  vendor/MYUtilities
View
27 Demo-Mac/DemoAppController.m
@@ -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]) {
@@ -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:
@@ -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];
@@ -341,7 +334,7 @@ - (TDMapBlock) compileMapFunction: (NSString*)mapSource language:(NSString *)lan
emit(doc[@"foo"], nil);
};
}
- return [[mapBlock copy] autorelease];
+ return [mapBlock copy];
}
@@ -354,7 +347,7 @@ - (TDReduceBlock) compileReduceFunction: (NSString*)reduceSource language:(NSStr
return [TDView totalValues: values];
};
}
- return [[reduceBlock copy] autorelease];
+ return [reduceBlock copy];
}
#endif
View
6 Demo-Mac/DemoQuery.m
@@ -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];
@@ -45,10 +45,7 @@ - (id) initWithQuery: (CouchQuery*)query
- (void) dealloc
{
- [_entries release];
[_query removeObserver: self forKeyPath: @"rows"];
- [_query release];
- [super dealloc];
}
@@ -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"];
}
View
9 Demo-Mac/ShoppingItem.m
@@ -24,12 +24,6 @@
@implementation ShoppingItem
-- (void)dealloc {
- [_picture release];
- [super dealloc];
-}
-
-
@dynamic check, text, created_at;
@@ -58,8 +52,7 @@ - (void) setPicture:(NSImage *)picture {
[self createAttachmentWithName: @"picture"
type: @"image/jpeg"
body: ImageJPEGData(picture)];
- [_picture release];
- _picture = [picture retain];
+ _picture = picture;
}
View
4 Demo-iOS/EmptyAppDelegate.m
@@ -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;
View
5 Listener/TDHTTPConnection.m
@@ -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;
}
View
16 Listener/TDHTTPResponse.m
@@ -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];
@@ -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 {
@@ -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];
@@ -143,7 +140,6 @@ - (void) onDataAvailable: (NSData*)data finished: (BOOL)finished {
_dataMutable = NO;
} else {
if (!_dataMutable) {
- [_data autorelease];
_data = [_data mutableCopy];
_dataMutable = YES;
}
@@ -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);
@@ -207,7 +202,6 @@ - (void) cleanUp {
_router.onFinished = nil;
if (!_finished) {
_finished = true;
- [self autorelease];
}
}
@@ -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];
}
}
@@ -246,7 +239,6 @@ - (void) onFinished {
- (void)connectionDidClose {
@synchronized(self) {
_connection = nil;
- [_data release];
_data = nil;
[self cleanUp];
}
View
8 Listener/TDListener.m
@@ -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;
@@ -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];
}
@@ -79,7 +74,6 @@ - (UInt16) port {
- (void) setPasswords: (NSDictionary*)passwords {
- [_passwords autorelease];
_passwords = [passwords copy];
_requiresAuth = (_passwords != nil);
}
View
10 Source/ChangeTracker/TDChangeTracker.h
@@ -38,7 +38,7 @@ typedef enum TDChangeTrackerMode {
{
@protected
NSURL* _databaseURL;
- id<TDChangeTrackerClient> _client;
+ id<TDChangeTrackerClient> __weak _client;
TDChangeTrackerMode _mode;
id _lastSequenceID;
unsigned _limit;
@@ -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;
View
13 Source/ChangeTracker/TDChangeTracker.m
@@ -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;
@@ -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];
@@ -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 {
View
11 Source/ChangeTracker/TDConnectionChangeTracker.m
@@ -65,7 +65,7 @@ - (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;
@@ -73,9 +73,7 @@ - (BOOL) start {
- (void) clearConnection {
- [_connection autorelease];
_connection = nil;
- [_inputBuffer release];
_inputBuffer = nil;
}
@@ -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];
@@ -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 {
@@ -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;
@@ -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];
View
41 Source/ChangeTracker/TDSocketChangeTracker.m
@@ -40,13 +40,13 @@ - (BOOL) start {
[super start];
CFHTTPMessageRef request = CFHTTPMessageCreateRequest(NULL, CFSTR("GET"),
- (CFURLRef)self.changesFeedURL,
+ (__bridge CFURLRef)self.changesFeedURL,
kCFHTTPVersion1_1);
Assert(request);
// Add headers.
[self.requestHeaders enumerateKeysAndObjectsUsingBlock: ^(id key, id value, BOOL *stop) {
- CFHTTPMessageSetHeaderFieldValue(request, (CFStringRef)key, (CFStringRef)value);
+ CFHTTPMessageSetHeaderFieldValue(request, (__bridge CFStringRef)key, (__bridge CFStringRef)value);
}];
if (_unauthResponse && _credential) {
@@ -54,17 +54,18 @@ - (BOOL) start {
if (password) {
CFIndex unauthStatus = CFHTTPMessageGetResponseStatusCode(_unauthResponse);
Assert(CFHTTPMessageAddAuthentication(request, _unauthResponse,
- (CFStringRef)_credential.user,
- (CFStringRef)password,
+ (__bridge CFStringRef)_credential.user,
+ (__bridge CFStringRef)password,
kCFHTTPAuthenticationSchemeBasic,
unauthStatus == 407));
} else {
Warn(@"%@: Unable to get password of %@", self, _credential);
}
} else if (_authorizer) {
- CFStringRef authHeader = [_authorizer authorizeHTTPMessage: request forRealm: nil];
+ NSString* authHeader = [_authorizer authorizeHTTPMessage: request forRealm: nil];
if (authHeader)
- CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Authorization"), authHeader);
+ CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Authorization"),
+ (__bridge CFStringRef)(authHeader));
}
CFReadStreamRef cfInputStream = CFReadStreamCreateForHTTPRequest(NULL, request);
@@ -87,7 +88,7 @@ - (BOOL) start {
_inputBuffer = [[NSMutableData alloc] initWithCapacity: kReadLength];
- _trackingInput = (NSInputStream*)cfInputStream;
+ _trackingInput = (NSInputStream*)CFBridgingRelease(cfInputStream);
[_trackingInput setDelegate: self];
[_trackingInput scheduleInRunLoop: [NSRunLoop currentRunLoop] forMode: NSRunLoopCommonModes];
[_trackingInput open];
@@ -99,12 +100,8 @@ - (BOOL) start {
- (void) clearConnection {
[_trackingInput close];
- [_trackingInput release];
_trackingInput = nil;
-
- [_inputBuffer release];
_inputBuffer = nil;
- [_changeBuffer release];
_changeBuffer = nil;
}
@@ -123,8 +120,6 @@ - (void) stop {
- (void)dealloc
{
if (_unauthResponse) CFRelease(_unauthResponse);
- [_credential release];
- [super dealloc];
}
@@ -135,10 +130,9 @@ - (BOOL) checkSSLCert {
SecTrustRef sslTrust = (SecTrustRef) CFReadStreamCopyProperty((CFReadStreamRef)_trackingInput,
kCFStreamPropertySSLPeerTrust);
if (sslTrust) {
- CFURLRef cfURL = CFReadStreamCopyProperty((CFReadStreamRef)_trackingInput,
- kCFStreamPropertyHTTPFinalURL);
- BOOL trusted = [TDRemoteRequest checkTrust: sslTrust forHost: [(NSURL*)cfURL host]];
- CFRelease(cfURL);
+ NSURL* url = CFBridgingRelease(CFReadStreamCopyProperty((CFReadStreamRef)_trackingInput,
+ kCFStreamPropertyHTTPFinalURL));
+ BOOL trusted = [TDRemoteRequest checkTrust: sslTrust forHost: url.host];
CFRelease(sslTrust);
if (!trusted) {
//TODO: This error could be made more precise
@@ -157,8 +151,8 @@ - (NSURLCredential*) credentialForResponse: (CFHTTPMessageRef)response {
NSString* authenticationMethod;
// Basic & digest auth: http://www.ietf.org/rfc/rfc2617.txt
- CFStringRef str = CFHTTPMessageCopyHeaderFieldValue(response, CFSTR("WWW-Authenticate"));
- NSString* authHeader = [NSMakeCollectable(str) autorelease];
+ NSString* authHeader = CFBridgingRelease(CFHTTPMessageCopyHeaderFieldValue(response,
+ CFSTR("WWW-Authenticate")));
if (!authHeader)
return nil;
@@ -201,7 +195,7 @@ - (BOOL) readResponseHeader {
LogTo(ChangeTracker, @"%@ got status %ld", self, status);
if ((status == 401 || status == 407) && !_credential
&& ![_requestHeaders objectForKey: @"Authorization"]) {
- _credential = [[self credentialForResponse: response] retain];
+ _credential = [self credentialForResponse: response];
LogTo(ChangeTracker, @"%@: Auth challenge; credential = %@", self, _credential);
if (_credential) {
// Recoverable auth failure -- try again with _credential:
@@ -227,7 +221,7 @@ - (BOOL) readResponseHeader {
- (void) readEntireInput {
// After one-shot or longpoll response is complete, parse it as a single 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;
@@ -242,7 +236,6 @@ - (void) readEntireInput {
// 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];
@@ -269,7 +262,7 @@ - (BOOL) checkInvalidResponse: (NSData*)body {
Warn(@"%@: Unparseable response:\n%@", self, bodyStr);
} else {
Warn(@"%@: Response is invalid UTF-8; as CP1252:\n%@", self,
- [[[NSString alloc] initWithData: body encoding: NSWindowsCP1252StringEncoding] autorelease]);
+ [[NSString alloc] initWithData: body encoding: NSWindowsCP1252StringEncoding]);
}
return NO;
}
@@ -403,8 +396,6 @@ - (void) errorOccurred: (NSError*)error {
- (void) stream: (NSStream*)stream handleEvent: (NSStreamEvent)eventCode {
- [[self retain] autorelease]; // Delegate calling -stop might otherwise dealloc me
-
switch (eventCode) {
case NSStreamEventHasBytesAvailable: {
LogTo(ChangeTracker, @"%@: HasBytesAvailable %@", self, stream);
View
6 Source/TDAttachment.m
@@ -33,12 +33,6 @@ - (id) initWithName: (NSString*)name contentType: (NSString*)contentType {
}
-- (void)dealloc
-{
- [_name release];
- [_contentType release];
- [super dealloc];
-}
- (bool) isValid {
View
4 Source/TDAuthorizer.h
@@ -17,8 +17,8 @@
- (NSString*) authorizeURLRequest: (NSMutableURLRequest*)request
forRealm: (NSString*)realm;
-- (CFStringRef) authorizeHTTPMessage: (CFHTTPMessageRef)message
- forRealm: (NSString*)realm;
+- (NSString*) authorizeHTTPMessage: (CFHTTPMessageRef)message
+ forRealm: (NSString*)realm;
@end
View
31 Source/TDAuthorizer.m
@@ -25,16 +25,11 @@ - (id) initWithCredential: (NSURLCredential*)credential {
Assert(credential);
self = [super init];
if (self) {
- _credential = [credential retain];
+ _credential = credential;
}
return self;
}
-- (void)dealloc
-{
- [_credential release];
- [super dealloc];
-}
- (NSString*) authorizeURLRequest: (NSMutableURLRequest*)request
forRealm: (NSString*)realm
@@ -49,7 +44,7 @@ - (NSString*) authorizeURLRequest: (NSMutableURLRequest*)request
return nil;
}
-- (CFStringRef) authorizeHTTPMessage: (CFHTTPMessageRef)message
+- (NSString*) authorizeHTTPMessage: (CFHTTPMessageRef)message
forRealm: (NSString*)realm
{
NSString* username = _credential.user;
@@ -57,7 +52,7 @@ - (CFStringRef) authorizeHTTPMessage: (CFHTTPMessageRef)message
if (username && password) {
NSString* seekrit = $sprintf(@"%@:%@", username, password);
seekrit = [TDBase64 encode: [seekrit dataUsingEncoding: NSUTF8StringEncoding]];
- return (CFStringRef) [@"Basic " stringByAppendingString: seekrit];
+ return [@"Basic " stringByAppendingString: seekrit];
}
return nil;
}
@@ -86,7 +81,6 @@ - (id) initWithKey: (NSString*)key
else if ([algorithm isEqualToString: @"hmac-sha-256"])
_hmacFunction = &TDHMACSHA256;
else {
- [self release];
return nil;
}
}
@@ -94,13 +88,6 @@ - (id) initWithKey: (NSString*)key
}
-- (void)dealloc
-{
- [_key release];
- [_identifier release];
- [_issueTime release];
- [super dealloc];
-}
- (NSString*) authorizeMethod: (NSString*)httpMethod
@@ -145,15 +132,15 @@ - (NSString*) authorizeURLRequest: (NSMutableURLRequest*)request
}
-- (CFStringRef) authorizeHTTPMessage: (CFHTTPMessageRef)message
- forRealm: (NSString*)realm
+- (NSString*) authorizeHTTPMessage: (CFHTTPMessageRef)message
+ forRealm: (NSString*)realm
{
if (!message)
return nil;
- NSString* method = [(id)CFHTTPMessageCopyRequestMethod(message) autorelease];
- NSURL* url = [(id)CFHTTPMessageCopyRequestURL(message) autorelease];
- NSData* body = [(id)CFHTTPMessageCopyBody(message) autorelease];
- return (CFStringRef) [self authorizeMethod: method URL: url body: body];
+ NSString* method = CFBridgingRelease(CFHTTPMessageCopyRequestMethod(message));
+ NSURL* url = CFBridgingRelease(CFHTTPMessageCopyRequestURL(message));
+ NSData* body = CFBridgingRelease(CFHTTPMessageCopyBody(message));
+ return [self authorizeMethod: method URL: url body: body];
}
View
4 Source/TDBase64.m
@@ -58,8 +58,8 @@ + (NSString*) encode: (const void*)input length: (size_t)length {
output[index + 3] = (i + 2) < length ? kEncodingTable[(value >> 0) & 0x3F] : '=';
}
- return [[[NSString alloc] initWithData:data
- encoding:NSASCIIStringEncoding] autorelease];
+ return [[NSString alloc] initWithData:data
+ encoding:NSASCIIStringEncoding];
}
View
9 Source/TDBatcher.m
@@ -31,11 +31,6 @@ - (id) initWithCapacity: (NSUInteger)capacity
}
-- (void)dealloc {
- [_inbox release];
- [_processor release];
- [super dealloc];
-}
- (void) unschedule {
@@ -63,7 +58,7 @@ - (void) processNow {
if (count == 0) {
return;
} else if (count <= _capacity) {
- toProcess = [_inbox autorelease];
+ toProcess = _inbox;
_inbox = nil;
} else {
toProcess = [_inbox subarrayWithRange: NSMakeRange(0, _capacity)];
@@ -105,7 +100,7 @@ - (void) flush {
- (void) flushAll {
if (_inbox.count > 0) {
[self unschedule];
- NSArray* toProcess = [_inbox autorelease];
+ NSArray* toProcess = _inbox;
_inbox = nil;
_processor(toProcess);
}
View
16 Source/TDBlobStore.m
@@ -40,7 +40,6 @@ - (id) initWithPath: (NSString*)dir error: (NSError**)outError {
withIntermediateDirectories: NO
attributes: nil
error: outError]) {
- [self release];
return nil;
}
}
@@ -49,11 +48,6 @@ - (id) initWithPath: (NSString*)dir error: (NSError**)outError {
}
-- (void)dealloc {
- [_path release];
- [_tempDir release];
- [super dealloc];
-}
+ (TDBlobKey) keyForBlob: (NSData*)blob {
@@ -84,7 +78,6 @@ - (NSString*) pathForKey: (TDBlobKey)key {
strlcat(out, kFileExtension, sizeof(out));
NSString* name = [[NSString alloc] initWithCString: out encoding: NSASCIIStringEncoding];
NSString* path = [_path stringByAppendingPathComponent: name];
- [name release];
return path;
}
@@ -258,7 +251,6 @@ - (id) initWithStore: (TDBlobStore*)store {
NSString* filename = [TDCreateUUID() stringByAppendingPathExtension: @"blobtmp"];
_tempPath = [[_store.tempDir stringByAppendingPathComponent: filename] copy];
if (!_tempPath) {
- [self release];
return nil;
}
NSDictionary* attributes = nil;
@@ -268,12 +260,10 @@ - (id) initWithStore: (TDBlobStore*)store {
if (![[NSFileManager defaultManager] createFileAtPath: _tempPath
contents: nil
attributes: attributes]) {
- [self release];
return nil;
}
- _out = [[NSFileHandle fileHandleForWritingAtPath: _tempPath] retain];
+ _out = [NSFileHandle fileHandleForWritingAtPath: _tempPath];
if (!_out) {
- [self release];
return nil;
}
}
@@ -290,7 +280,6 @@ - (void) appendData: (NSData*)data {
- (void) closeFile {
[_out closeFile];
- [_out release];
_out = nil;
}
@@ -319,7 +308,6 @@ - (BOOL) install {
NSString* dstPath = [_store pathForKey: _blobKey];
if ([[NSFileManager defaultManager] moveItemAtPath: _tempPath
toPath: dstPath error:NULL]) {
- [_tempPath release];
_tempPath = nil;
} else {
// If the move fails, assume it means a file with the same name already exists; in that
@@ -333,14 +321,12 @@ - (void) cancel {
[self closeFile];
if (_tempPath) {
[[NSFileManager defaultManager] removeItemAtPath: _tempPath error: NULL];
- [_tempPath release];
_tempPath = nil;
}
}
- (void) dealloc {
[self cancel]; // Close file, and delete it if it hasn't been installed yet
- [super dealloc];
}
View
4 Source/TDBlobStore_Tests.m
@@ -16,7 +16,7 @@
NSError* error;
TDBlobStore* store = [[TDBlobStore alloc] initWithPath: path error: &error];
CAssert(store, @"Couldn't create TDBlobStore: %@", error);
- return [store autorelease];
+ return store;
}
static void deleteStore(TDBlobStore* store) {
@@ -40,7 +40,7 @@ static void deleteStore(TDBlobStore* store) {
TestCase(TDBlobStoreWriter) {
TDBlobStore* store = createStore();
- TDBlobStoreWriter* writer = [[[TDBlobStoreWriter alloc] initWithStore: store] autorelease];
+ TDBlobStoreWriter* writer = [[TDBlobStoreWriter alloc] initWithStore: store];
CAssert(writer);
[writer appendData: [@"part 1, " dataUsingEncoding: NSUTF8StringEncoding]];
View
12 Source/TDBody.m
@@ -39,17 +39,11 @@ - (id) initWithJSON: (NSData*)json {
return self;
}
-- (void)dealloc {
- [_object release];
- [_json release];
- [super dealloc];
-}
-
+ (TDBody*) bodyWithProperties: (NSDictionary*)properties {
- return [[[self alloc] initWithProperties: properties] autorelease];
+ return [[self alloc] initWithProperties: properties];
}
+ (TDBody*) bodyWithJSON: (NSData*)json {
- return [[[self alloc] initWithJSON: json] autorelease];
+ return [[self alloc] initWithJSON: json];
}
@synthesize error=_error;
@@ -83,7 +77,7 @@ - (NSData*) asPrettyJSON {
options: TDJSONWritingPrettyPrinted
error: NULL];
if (json) {
- NSMutableData* mjson = [[json mutableCopy] autorelease];
+ NSMutableData* mjson = [json mutableCopy];
[mjson appendBytes: "\n" length: 1];
return mjson;
}
View
13 Source/TDCanonicalJSON.m
@@ -28,19 +28,12 @@ @implementation TDCanonicalJSON
- (id) initWithObject: (id)object {
self = [super init];
if (self) {
- _input = [object retain];
+ _input = object;
}
return self;
}
-- (void)dealloc {
- [_ignoreKeyPrefix release];
- [_whitelistedKeys release];
- [_output release];
- [_input release];
- [super dealloc];
-}
@synthesize ignoreKeyPrefix=_ignoreKeyPrefix, whitelistedKeys=_whitelistedKeys;
@@ -189,7 +182,7 @@ - (void) encode {
- (NSString*) canonicalString {
[self encode];
- return [[_output copy] autorelease];
+ return [_output copy];
}
@@ -202,7 +195,6 @@ - (NSData*) canonicalData {
+ (NSString*) canonicalString: (id)rootObject {
TDCanonicalJSON* encoder = [[self alloc] initWithObject: rootObject];
NSString* result = encoder.canonicalString;
- [encoder release];
return result;
}
@@ -210,7 +202,6 @@ + (NSString*) canonicalString: (id)rootObject {
+ (NSData*) canonicalData: (id)rootObject {
TDCanonicalJSON* encoder = [[self alloc] initWithObject: rootObject];
NSData* result = encoder.canonicalData;
- [encoder release];
return result;
}
View
41 Source/TDChangeTracker_Tests.m
@@ -19,8 +19,30 @@
#import "MYURLUtils.h"
+void TestDictOf(void);
+void TestDictOf(void) {
+ NSDictionary *d = $dict({@"seq", @1},
+ {@"id", @"foo"},
+ {@"changes", @[@"hi"]});
+ CAssertEqual(d[@"seq"], @1);
+}
+
+
#if DEBUG
+TestCase(DictOf) {
+ NSDictionary* z = @{@"hi": @"there"};
+ NSLog(@"%@",z);
+ //typedef struct { __unsafe_unretained id key; __unsafe_unretained id value; } Pair;
+ typedef id Pair[2];
+ typedef Pair Pairs[];
+ Pairs pairs= {
+ {@"changes", @[@"hi"]}
+ };
+ NSLog(@"it's %@", pairs[0][1]);
+ //NSDictionary* d = _dictof(pairs,sizeof(pairs)/sizeof(struct _dictpair));
+ //CAssertEqual(d[@"changes"], @[@"hi"]);
+}
@interface TDChangeTrackerTester : NSObject <TDChangeTrackerClient>
{
@@ -49,7 +71,7 @@ - (void) run: (TDChangeTracker*)tracker expectingChanges: (NSArray*)expectedChan
Warn(@"Timeout contacting %@", tracker.databaseURL);
return;
}
- AssertNil(tracker.error);
+ Assert(!tracker.error, nil);
CAssertEqual(_changes, expectedChanges);
}
@@ -76,11 +98,6 @@ - (void) changeTrackerStopped:(TDChangeTracker *)tracker {
_running = NO;
}
-- (void)dealloc
-{
- [_changes release];
- [super dealloc];
-}
@end
@@ -99,9 +116,9 @@ static void addTemporaryCredential(NSURL* url, NSString* realm,
TestCase(TDChangeTracker_Simple) {
for (TDChangeTrackerMode mode = kOneShot; mode <= kContinuous; ++mode) {
Log(@"Mode = %d ...", mode);
- TDChangeTrackerTester* tester = [[[TDChangeTrackerTester alloc] init] autorelease];
+ TDChangeTrackerTester* tester = [[TDChangeTrackerTester alloc] init];
NSURL* url = [NSURL URLWithString: @"http://snej.iriscouch.com/tdpuller_test1"];
- TDChangeTracker* tracker = [[[TDChangeTracker alloc] initWithDatabaseURL: url mode: mode conflicts: NO lastSequence: nil client: tester] autorelease];
+ TDChangeTracker* tracker = [[TDChangeTracker alloc] initWithDatabaseURL: url mode: mode conflicts: NO lastSequence: nil client: tester];
NSArray* expected = $array($dict({@"seq", @1},
{@"id", @"foo"},
{@"changes", $array($dict({@"rev", @"5-ca289aa53cbbf35a5f5c799b64b1f16f"}))}),
@@ -122,9 +139,9 @@ static void addTemporaryCredential(NSURL* url, NSString* realm,
TestCase(TDChangeTracker_SSL) {
// The only difference here is the "https:" scheme in the URL.
- TDChangeTrackerTester* tester = [[[TDChangeTrackerTester alloc] init] autorelease];
+ TDChangeTrackerTester* tester = [[TDChangeTrackerTester alloc] init];
NSURL* url = [NSURL URLWithString: @"https://snej.iriscouch.com/tdpuller_test1"];
- TDChangeTracker* tracker = [[[TDChangeTracker alloc] initWithDatabaseURL: url mode: kOneShot conflicts: NO lastSequence: 0 client: tester] autorelease];
+ TDChangeTracker* tracker = [[TDChangeTracker alloc] initWithDatabaseURL: url mode: kOneShot conflicts: NO lastSequence: 0 client: tester];
NSArray* expected = $array($dict({@"seq", @1},
{@"id", @"foo"},
{@"changes", $array($dict({@"rev", @"5-ca289aa53cbbf35a5f5c799b64b1f16f"}))}),
@@ -144,11 +161,11 @@ static void addTemporaryCredential(NSURL* url, NSString* realm,
TestCase(TDChangeTracker_Auth) {
// This database requires authentication to access at all.
- TDChangeTrackerTester* tester = [[[TDChangeTrackerTester alloc] init] autorelease];
+ TDChangeTrackerTester* tester = [[TDChangeTrackerTester alloc] init];
NSURL* url = [NSURL URLWithString: @"https://dummy@snej.iriscouch.com/tdpuller_test2_auth"];
addTemporaryCredential(url, @"snejdom", @"dummy", @"dummy");
- TDChangeTracker* tracker = [[[TDChangeTracker alloc] initWithDatabaseURL: url mode: kOneShot conflicts: NO lastSequence: 0 client: tester] autorelease];
+ TDChangeTracker* tracker = [[TDChangeTracker alloc] initWithDatabaseURL: url mode: kOneShot conflicts: NO lastSequence: 0 client: tester];
NSArray* expected = $array($dict({@"seq", @1},
{@"id", @"something"},
{@"changes", $array($dict({@"rev", @"1-967a00dff5e02add41819138abb3284d"}))}) );
View
2  Source/TDCollateJSON.m
@@ -179,8 +179,6 @@ static int compareStringsUnicode(const char** in1, const char** in2) {
NSString* str1 = createStringFromJSON(in1);
NSString* str2 = createStringFromJSON(in2);
int result = (int)[str1 localizedCompare: str2];
- [str1 release];
- [str2 release];
return result;
}
View
25 Source/TDDatabase+Attachments.m
@@ -50,7 +50,7 @@ @implementation TDDatabase (Attachments)
- (TDBlobStoreWriter*) attachmentWriter {
- return [[[TDBlobStoreWriter alloc] initWithStore: _attachments] autorelease];
+ return [[TDBlobStoreWriter alloc] initWithStore: _attachments];
}
@@ -343,14 +343,13 @@ + (BOOL) mutateAttachmentsIn: (TDRevision*)rev
NSDictionary* attachment = attachments[name];
NSDictionary* editedAttachment = block(name, attachment);
if (!editedAttachment) {
- [editedProperties release];
return NO; // block canceled
}
if (editedAttachment != attachment) {
if (!editedProperties) {
// Make the document properties and _attachments dictionary mutable:
editedProperties = [properties mutableCopy];
- editedAttachments = [[attachments mutableCopy] autorelease];
+ editedAttachments = [attachments mutableCopy];
editedProperties[@"_attachments"] = editedAttachments;
}
editedAttachments[name] = editedAttachment;
@@ -358,7 +357,7 @@ + (BOOL) mutateAttachmentsIn: (TDRevision*)rev
}
}
if (editedProperties) {
- rev.properties = [editedProperties autorelease];
+ rev.properties = editedProperties;
return YES;
}
return NO;
@@ -383,7 +382,7 @@ + (void) stubOutAttachmentsIn: (TDRevision*)rev
if (!stubItOut && !addFollows)
return attachment; // no change
// Need to modify attachment entry:
- NSMutableDictionary* editedAttachment = [[attachment mutableCopy] autorelease];
+ NSMutableDictionary* editedAttachment = [attachment mutableCopy];
[editedAttachment removeObjectForKey: @"data"];
if (stubItOut) {
// ...then remove the 'data' and 'follows' key:
@@ -416,7 +415,7 @@ - (BOOL) inlineFollowingAttachmentsIn: (TDRevision*)rev error: (NSError**)outErr
error: &error];
if (!fileData)
return nil;
- NSMutableDictionary* editedAttachment = [[attachment mutableCopy] autorelease];
+ NSMutableDictionary* editedAttachment = [attachment mutableCopy];
[editedAttachment removeObjectForKey: @"follows"];
editedAttachment[@"data"] = [TDBase64 encode: fileData];
return editedAttachment;
@@ -444,8 +443,8 @@ - (NSDictionary*) attachmentsFromRevision: (TDRevision*)rev
// Create a TDAttachment object:
NSDictionary* attachInfo = revAttachments[name];
NSString* contentType = $castIf(NSString, attachInfo[@"content_type"]);
- TDAttachment* attachment = [[[TDAttachment alloc] initWithName: name
- contentType: contentType] autorelease];
+ TDAttachment* attachment = [[TDAttachment alloc] initWithName: name
+ contentType: contentType];
NSString* newContentsBase64 = $castIf(NSString, attachInfo[@"data"]);
if (newContentsBase64) {
@@ -557,7 +556,7 @@ - (TDMultipartWriter*) multipartWriterForRevision: (TDRevision*)rev
[writer addFileURL: [self fileForAttachmentDict: attachment]];
}
}
- return [writer autorelease];
+ return writer;
}
@@ -573,9 +572,9 @@ - (TDRevision*) updateAttachment: (NSString*)filename
if (filename.length == 0 || (body && !contentType) || (oldRevID && !docID) || (body && !docID))
return nil;
- TDRevision* oldRev = [[[TDRevision alloc] initWithDocID: docID
+ TDRevision* oldRev = [[TDRevision alloc] initWithDocID: docID
revID: oldRevID
- deleted: NO] autorelease];
+ deleted: NO];
if (oldRevID) {
// Load existing revision if this is a replacement:
*outStatus = [self loadRevisionBody: oldRev options: 0];
@@ -590,7 +589,7 @@ - (TDRevision*) updateAttachment: (NSString*)filename
}
// Update the _attachments dictionary:
- NSMutableDictionary* attachments = [[oldRev[@"_attachments"] mutableCopy] autorelease];
+ NSMutableDictionary* attachments = [oldRev[@"_attachments"] mutableCopy];
if (!attachments)
attachments = $mdict();
if (body) {
@@ -615,7 +614,7 @@ - (TDRevision*) updateAttachment: (NSString*)filename
}
[attachments removeObjectForKey: filename];
}
- NSMutableDictionary* properties = [[oldRev.properties mutableCopy] autorelease];
+ NSMutableDictionary* properties = [oldRev.properties mutableCopy];
properties[@"_attachments"] = attachments;
oldRev.properties = properties;
View
25 Source/TDDatabase+Insertion.m
@@ -176,7 +176,6 @@ - (NSData*) encodeDocumentJSON: (TDRevision*)rev {
properties[key] = origProps[key];
} else if (![sSpecialKeysToRemove member: key]) {
Log(@"TDDatabase: Invalid top-level key '%@' in document to be inserted", key);
- [properties release];
return nil;
}
}
@@ -185,7 +184,6 @@ - (NSData*) encodeDocumentJSON: (TDRevision*)rev {
// to create the new revision ID, and we need to guarantee that equivalent revision bodies
// result in equal revision IDs.
NSData* json = [TDCanonicalJSON canonicalData: properties];
- [properties release];
return json;
}
@@ -213,9 +211,9 @@ - (TDRevision*) winnerWithDocID: (SInt64)docNumericID
if ($equal(winningRevID, newRev.revID))
return newRev;
else {
- TDRevision* winningRev = [[[TDRevision alloc] initWithDocID: newRev.docID
+ TDRevision* winningRev = [[TDRevision alloc] initWithDocID: newRev.docID
revID: winningRevID
- deleted: NO] autorelease];
+ deleted: NO];
return winningRev;
}
}
@@ -317,7 +315,6 @@ - (TDRevision*) putRevision: (TDRevision*)rev
TDRevision* prevRev = [[TDRevision alloc] initWithDocID: docID revID: prevRevID
deleted: NO];
status = [self validateRevision: rev previousRevision: prevRev];
- [prevRev release];
if (TDStatusIsError(status)) {
*outStatus = status;
return nil;
@@ -411,7 +408,8 @@ - (TDRevision*) putRevision: (TDRevision*)rev
*outStatus = kTDStatusBadID; // invalid previous revID (no numeric prefix)
return nil;
}
- rev = [[rev copyWithDocID: docID revID: newRevID] autorelease];
+ Assert(docID);
+ rev = [rev copyWithDocID: docID revID: newRevID];
// Now insert the rev itself:
@@ -560,8 +558,7 @@ - (TDStatus) forceInsert: (TDRevision*)rev
current = YES;
} else {
// It's an intermediate parent, so insert a stub:
- newRev = [[[TDRevision alloc] initWithDocID: docID revID: revID deleted: NO]
- autorelease];
+ newRev = [[TDRevision alloc] initWithDocID: docID revID: revID deleted: NO];
}
// Insert it:
@@ -727,7 +724,7 @@ - (void) defineValidation: (NSString*)validationName asBlock: (TDValidationBlock
if (validationBlock) {
if (!_validations)
_validations = [[NSMutableDictionary alloc] init];
- [_validations setValue: [[validationBlock copy] autorelease] forKey: validationName];
+ [_validations setValue: [validationBlock copy] forKey: validationName];
} else {
[_validations removeObjectForKey: validationName];
}
@@ -745,14 +742,13 @@ - (TDStatus) validateRevision: (TDRevision*)newRev previousRevision: (TDRevision
revision: oldRev
newRevision: newRev];
TDStatus status = kTDStatusOK;
- for (TDValidationBlock validationName in _validations) {
+ for (NSString* validationName in _validations) {
TDValidationBlock validation = [self validationNamed: validationName];
if (!validation(newRev, context)) {
status = context.errorType;
break;
}
}
- [context release];
return status;
}
@@ -776,16 +772,11 @@ - (id) initWithDatabase: (TDDatabase*)db
_currentRevision = currentRevision;
_newRevision = newRevision;
_errorType = kTDStatusForbidden;
- _errorMessage = [@"invalid document" retain];
+ _errorMessage = @"invalid document";
}
return self;
}
-- (void)dealloc {
- [_changedKeys release];
- [_errorMessage release];
- [super dealloc];
-}
- (TDRevision*) currentRevision {
if (_currentRevision)
View
4 Source/TDDatabase+LocalDocs.m
@@ -46,7 +46,7 @@ - (TDRevision*) getLocalDocumentWithID: (NSString*)docID
}
properties[@"_id"] = docID;
properties[@"_rev"] = gotRevID;
- result = [[[TDRevision alloc] initWithDocID: docID revID: gotRevID deleted:NO] autorelease];
+ result = [[TDRevision alloc] initWithDocID: docID revID: gotRevID deleted:NO];
result.properties = properties;
}
[r close];
@@ -96,7 +96,7 @@ - (TDRevision*) putLocalRevision: (TDRevision*)revision
return nil;
}
*outStatus = kTDStatusCreated;
- return [[revision copyWithDocID: docID revID: newRevID] autorelease];
+ return [revision copyWithDocID: docID revID: newRevID];
} else {
// DELETE:
View
1  Source/TDDatabase+Replication.m
@@ -62,7 +62,6 @@ - (TDReplicator*) replicatorWithRemoteURL: (NSURL*)remote
object: nil];
}
[_activeReplicators addObject: repl];
- [repl release];
return repl;
}
View
47 Source/TDDatabase.m
@@ -48,7 +48,7 @@ - (NSString*) attachmentStorePath {
+ (TDDatabase*) createEmptyDBAtPath: (NSString*)path {
if (!removeItemIfExists(path, NULL))
return nil;
- TDDatabase *db = [[[self alloc] initWithPath: path] autorelease];
+ TDDatabase *db = [[self alloc] initWithPath: path];
if (!removeItemIfExists(db.attachmentStorePath, NULL))
return nil;
if (![db open])
@@ -70,6 +70,11 @@ - (id) initWithPath: (NSString*)path {
_fmdb.logsErrors = WillLogTo(TDDatabase);
#endif
_fmdb.traceExecution = WillLogTo(TDDatabaseVerbose);
+ if (0) {
+ // Appease the static analyzer by using these category ivars in this source file:
+ _validations = nil;
+ _pendingAttachmentsByDigest = nil;
+ }
}
return self;
}
@@ -284,10 +289,12 @@ - (BOOL) close {
object: self];
for (TDView* view in _views.allValues)
[view databaseClosing];
- setObj(&_views, nil);
- for (TDReplicator* repl in [_activeReplicators.copy autorelease])
+
+ _views = nil;
+ for (TDReplicator* repl in _activeReplicators.copy)
[repl databaseClosing];
- setObj(&_activeReplicators, nil);
+
+ _activeReplicators = nil;
if (![_fmdb close])
return NO;
@@ -315,17 +322,7 @@ - (void) dealloc {
//Warn(@"%@ dealloced without being closed first!", self);
[self close];
}
- [_fmdb release];
- [_path release];
- [_name release];
- [_views release];
- [_activeReplicators release];
- [_validations release];
- [_filters release];
- [_attachments release];
- [_pendingAttachmentsByDigest release];
[[NSNotificationCenter defaultCenter] removeObserver: self];
- [super dealloc];
}
@synthesize path=_path, name=_name, fmdb=_fmdb, attachmentStore=_attachments, readOnly=_readOnly;
@@ -490,7 +487,6 @@ - (NSDictionary*) documentPropertiesFromJSON: (NSData*)json
rev.sequence = sequence;
rev.missing = (json == nil);
NSDictionary* extra = [self extraPropertiesForRevision: rev options: options];
- [rev release];
if (json.length == 0 || (json.length==2 && memcmp(json.bytes, "{}", 2)==0))
return extra; // optimization, and workaround for issue #44
NSMutableDictionary* docProperties = [TDJSON JSONObjectWithData: json
@@ -533,7 +529,7 @@ - (TDRevision*) getDocumentWithID: (NSString*)docID
if (!revID)
revID = [r stringForColumnIndex: 0];
BOOL deleted = [r boolForColumnIndex: 1];
- result = [[[TDRevision alloc] initWithDocID: docID revID: revID deleted: deleted] autorelease];
+ result = [[TDRevision alloc] initWithDocID: docID revID: revID deleted: deleted];
result.sequence = [r longLongIntForColumnIndex: 2];
if (options != kTDNoBody) {
@@ -609,14 +605,13 @@ - (TDRevisionList*) getAllRevisionsOfDocumentID: (NSString*)docID
FMResultSet* r = [_fmdb executeQuery: sql, @(docNumericID)];
if (!r)
return nil;
- TDRevisionList* revs = [[[TDRevisionList alloc] init] autorelease];
+ TDRevisionList* revs = [[TDRevisionList alloc] init];
while ([r next]) {
TDRevision* rev = [[TDRevision alloc] initWithDocID: docID
revID: [r stringForColumnIndex: 1]
deleted: [r boolForColumnIndex: 2]];
rev.sequence = [r longLongIntForColumnIndex: 0];
[revs addRev: rev];
- [rev release];
}
[r close];
return revs;
@@ -629,7 +624,7 @@ - (TDRevisionList*) getAllRevisionsOfDocumentID: (NSString*)docID
if (docNumericID < 0)
return nil;
else if (docNumericID == 0)
- return [[[TDRevisionList alloc] init] autorelease]; // no such document
+ return [[TDRevisionList alloc] init]; // no such document
else
return [self getAllRevisionsOfDocumentID: docID
numericID: docNumericID
@@ -711,7 +706,6 @@ - (NSArray*) getRevisionHistory: (TDRevision*)rev {
rev.sequence = sequence;
rev.missing = [r boolForColumnIndex: 4];
[history addObject: rev];
- [rev release];
lastSequence = [r longLongIntForColumnIndex: 1];
if (lastSequence == 0)
break;
@@ -806,7 +800,7 @@ - (TDRevisionList*) changesSinceSequence: (SequenceNumber)lastSequence
FMResultSet* r = [_fmdb executeQuery: sql, @(lastSequence)];
if (!r)
return nil;
- TDRevisionList* changes = [[[TDRevisionList alloc] init] autorelease];
+ TDRevisionList* changes = [[TDRevisionList alloc] init];
int64_t lastDocID = 0;
while ([r next]) {
@autoreleasepool {
@@ -829,7 +823,6 @@ - (TDRevisionList*) changesSinceSequence: (SequenceNumber)lastSequence
}
if (!filter || filter(rev, filterParams))
[changes addRev: rev];
- [rev release];
}
}
[r close];
@@ -845,7 +838,7 @@ - (TDRevisionList*) changesSinceSequence: (SequenceNumber)lastSequence
- (void) defineFilter: (NSString*)filterName asBlock: (TDFilterBlock)filterBlock {
if (!_filters)
_filters = [[NSMutableDictionary alloc] init];
- [_filters setValue: [[filterBlock copy] autorelease] forKey: filterName];
+ [_filters setValue: [filterBlock copy] forKey: filterName];
}
- (TDFilterBlock) filterNamed: (NSString*)filterName {
@@ -870,7 +863,7 @@ - (TDView*) viewNamed: (NSString*)name {
TDView* view = _views[name];
if (view)
return view;
- return [self registerView: [[[TDView alloc] initWithDatabase: self name: name] autorelease]];
+ return [self registerView: [[TDView alloc] initWithDatabase: self name: name]];
}
@@ -878,7 +871,7 @@ - (TDView*) existingViewNamed: (NSString*)name {
TDView* view = _views[name];
if (view)
return view;
- view = [[[TDView alloc] initWithDatabase: self name: name] autorelease];
+ view = [[TDView alloc] initWithDatabase: self name: name];
if (!view.viewID)
return nil;
return [self registerView: view];
@@ -915,7 +908,7 @@ - (NSDictionary*) getDocsWithIDs: (NSArray*)docIDs options: (const TDQueryOption
update_seq = self.lastSequence; // TODO: needs to be atomic with the following SELECT
// Generate the SELECT statement, based on the options:
- NSMutableString* sql = [[@"SELECT revs.doc_id, docid, revid" mutableCopy] autorelease];
+ NSMutableString* sql = [@"SELECT revs.doc_id, docid, revid" mutableCopy];
if (options->includeDocs)
[sql appendString: @", json, sequence"];
if (options->includeDeletedDocs)
@@ -1044,7 +1037,7 @@ - (NSDictionary*) getAllDocs: (const TDQueryOptions*)options {
#if DEBUG
static TDRevision* mkrev(NSString* revID) {
- return [[[TDRevision alloc] initWithDocID: @"docid" revID: revID deleted: NO] autorelease];
+ return [[TDRevision alloc] initWithDocID: @"docid" revID: revID deleted: NO];
}
View
13 Source/TDDatabaseManager.m
@@ -34,8 +34,8 @@ @implementation TDDatabaseManager
+ (void) initialize {
if (self == [TDDatabaseManager class]) {
- kIllegalNameChars = [[[NSCharacterSet characterSetWithCharactersInString: kLegalChars]
- invertedSet] retain];
+ kIllegalNameChars = [[NSCharacterSet characterSetWithCharactersInString: kLegalChars]
+ invertedSet];
}
}
@@ -49,7 +49,7 @@ + (TDDatabaseManager*) createEmptyAtPath: (NSString*)path {
error: &error];
Assert(dbm, @"Failed to create db manager at %@: %@", path, error);
AssertEqual(dbm.directory, path);
- return [dbm autorelease];
+ return dbm;
}
+ (TDDatabaseManager*) createEmptyAtTemporaryPath: (NSString*)name {
@@ -77,7 +77,6 @@ - (id) initWithDirectory: (NSString*)dirPath
error: &error]) {
if (!TDIsFileExistsError(error)) {
if (outError) *outError = error;
- [self release];
return nil;
}
}
@@ -89,9 +88,6 @@ - (id) initWithDirectory: (NSString*)dirPath
- (void)dealloc {
LogTo(TDServer, @"DEALLOC %@", self);
[self close];
- [_dir release];
- [_databases release];
- [super dealloc];
}
@@ -128,12 +124,10 @@ - (TDDatabase*) databaseNamed: (NSString*)name create: (BOOL)create {
db = [[TDDatabase alloc] initWithPath: path];
db.readOnly = _options.readOnly;
if (!create && !db.exists) {
- [db release];
return nil;
}
db.name = name;
_databases[name] = db;
- [db release];
}
return db;
}
@@ -180,7 +174,6 @@ - (NSArray*) allOpenDatabases {
- (void) close {
LogTo(TDServer, @"CLOSE %@", self);
[_replicatorManager stop];
- [_replicatorManager release];
_replicatorManager = nil;
for (TDDatabase* db in _databases.allValues) {
[db close];
View
63 Source/TDDatabase_Tests.m
@@ -51,7 +51,7 @@
static TDRevision* putDoc(TDDatabase* db, NSDictionary* props) {
- TDRevision* rev = [[[TDRevision alloc] initWithProperties: props] autorelease];
+ TDRevision* rev = [[TDRevision alloc] initWithProperties: props];
TDStatus status;
TDRevision* result = [db putRevision: rev
prevRevisionID: props[@"_rev"]
@@ -87,8 +87,8 @@
// Create a document:
NSMutableDictionary* props = $mdict({@"foo", @1}, {@"bar", $false});
- TDBody* doc = [[[TDBody alloc] initWithProperties: props] autorelease];
- TDRevision* rev1 = [[[TDRevision alloc] initWithBody: doc] autorelease];
+ TDBody* doc = [[TDBody alloc] initWithProperties: props];
+ TDRevision* rev1 = [[TDRevision alloc] initWithBody: doc];
CAssert(rev1);
TDStatus status;
rev1 = [db putRevision: rev1 prevRevisionID: nil allowConflict: NO status: &status];
@@ -103,10 +103,10 @@
CAssertEqual(userProperties(readRev.properties), userProperties(doc.properties));
// Now update it:
- props = [[readRev.properties mutableCopy] autorelease];
+ props = [readRev.properties mutableCopy];
props[@"status"] = @"updated!";
doc = [TDBody bodyWithProperties: props];
- TDRevision* rev2 = [[[TDRevision alloc] initWithBody: doc] autorelease];
+ TDRevision* rev2 = [[TDRevision alloc] initWithBody: doc];
TDRevision* rev2Input = rev2;
rev2 = [db putRevision: rev2 prevRevisionID: rev1.revID allowConflict: NO status: &status];
CAssertEq(status, kTDStatusCreated);
@@ -142,8 +142,8 @@
CAssertEq(changes.count, 0u);
// Delete it:
- TDRevision* revD = [[[TDRevision alloc] initWithDocID: rev2.docID revID: nil deleted: YES] autorelease];
- CAssertEq([db putRevision: revD prevRevisionID: nil allowConflict: NO status: &status], nil);
+ TDRevision* revD = [[TDRevision alloc] initWithDocID: rev2.docID revID: nil deleted: YES];
+ CAssertEqual([db putRevision: revD prevRevisionID: nil allowConflict: NO status: &status], nil);
CAssertEq(status, kTDStatusConflict);
revD = [db putRevision: revD prevRevisionID: rev2.revID allowConflict: NO status: &status];
CAssertEq(status, kTDStatusOK);
@@ -151,7 +151,7 @@
CAssert([revD.revID hasPrefix: @"3-"]);
// Delete nonexistent doc:
- TDRevision* revFake = [[[TDRevision alloc] initWithDocID: @"fake" revID: nil deleted: YES] autorelease];
+ TDRevision* revFake = [[TDRevision alloc] initWithDocID: @"fake" revID: nil deleted: YES];
[db putRevision: revFake prevRevisionID: nil allowConflict: NO status: &status];
CAssertEq(status, kTDStatusNotFound);
@@ -229,7 +229,7 @@
// POST a valid new document:
NSMutableDictionary* props = $mdict({@"name", @"Zaphod Beeblebrox"}, {@"towel", @"velvet"});
- TDRevision* rev = [[[TDRevision alloc] initWithProperties: props] autorelease];
+ TDRevision* rev = [[TDRevision alloc] initWithProperties: props];
TDStatus status;
validationCalled = NO;
rev = [db putRevision: rev prevRevisionID: nil allowConflict: NO status: &status];
@@ -255,7 +255,7 @@
// POST an invalid new document:
props = $mdict({@"name", @"Vogon"}, {@"poetry", $true});
- rev = [[[TDRevision alloc] initWithProperties: props] autorelease];
+ rev = [[TDRevision alloc] initWithProperties: props];
validationCalled = NO;
rev = [db putRevision: rev prevRevisionID: nil allowConflict: NO status: &status];
CAssert(validationCalled);
@@ -263,7 +263,7 @@
// PUT a valid new document with an ID:
props = $mdict({@"_id", @"ford"}, {@"name", @"Ford Prefect"}, {@"towel", @"terrycloth"});
- rev = [[[TDRevision alloc] initWithProperties: props] autorelease];
+ rev = [[TDRevision alloc] initWithProperties: props];
validationCalled = NO;
rev = [db putRevision: rev prevRevisionID: nil allowConflict: NO status: &status];
CAssert(validationCalled);
@@ -271,7 +271,7 @@
CAssertEqual(rev.docID, @"ford");
// DELETE a document:
- rev = [[[TDRevision alloc] initWithDocID: rev.docID revID: rev.revID deleted: YES] autorelease];
+ rev = [[TDRevision alloc] initWithDocID: rev.docID revID: rev.revID deleted: YES];
CAssert(rev.deleted);
validationCalled = NO;
rev = [db putRevision: rev prevRevisionID: rev.revID allowConflict: NO status: &status];
@@ -280,7 +280,7 @@
// PUT an invalid new document:
props = $mdict({@"_id", @"petunias"}, {@"name", @"Pot of Petunias"});
- rev = [[[TDRevision alloc] initWithProperties: props] autorelease];
+ rev = [[TDRevision alloc] initWithProperties: props];
validationCalled = NO;
rev = [db putRevision: rev prevRevisionID: nil allowConflict: NO status: &status];
CAssert(validationCalled);
@@ -323,7 +323,7 @@ static void verifyHistory(TDDatabase* db, TDRevision* rev, NSArray* history, boo
noteInfo = n.userInfo;
}];
- TDRevision* rev = [[[TDRevision alloc] initWithDocID: @"MyDocID" revID: @"4-foxy" deleted: NO] autorelease];
+ TDRevision* rev = [[TDRevision alloc] initWithDocID: @"MyDocID" revID: @"4-foxy" deleted: NO];
rev.properties = $dict({@"_id", rev.docID}, {@"_rev", rev.revID}, {@"message", @"hi"});
NSArray* history = @[rev.revID, @"3-thrice", @"2-too", @"1-won"];
noteInfo = nil;
@@ -334,7 +334,7 @@ static void verifyHistory(TDDatabase* db, TDRevision* rev, NSArray* history, boo
CAssertEqual(noteInfo, (@{ @"rev" : rev, @"winner": rev }));
- TDRevision* conflict = [[[TDRevision alloc] initWithDocID: @"MyDocID" revID: @"5-epsilon" deleted: NO] autorelease];
+ TDRevision* conflict = [[TDRevision alloc] initWithDocID: @"MyDocID" revID: @"5-epsilon" deleted: NO];
conflict.properties = $dict({@"_id", conflict.docID}, {@"_rev", conflict.revID},
{@"message", @"yo"});
NSArray* conflictHistory = @[conflict.revID, @"4-delta", @"3-gamma", @"2-too", @"1-won"];
@@ -346,7 +346,7 @@ static void verifyHistory(TDDatabase* db, TDRevision* rev, NSArray* history, boo
CAssertEqual(noteInfo, (@{ @"rev" : conflict, @"winner": conflict }));
// Add an unrelated document:
- TDRevision* other = [[[TDRevision alloc] initWithDocID: @"AnotherDocID" revID: @"1-ichi" deleted: NO] autorelease];
+ TDRevision* other = [[TDRevision alloc] initWithDocID: @"AnotherDocID" revID: @"1-ichi" deleted: NO];
other.properties = $dict({@"language", @"jp"});
noteInfo = nil;
status = [db forceInsert: other revisionHistory: @[other.revID] source: nil];
@@ -381,7 +381,7 @@ static void verifyHistory(TDDatabase* db, TDRevision* rev, NSArray* history, boo
verifyHistory(db, conflict, conflictHistory, true);
// Delete the current winning rev, leaving the other one:
- TDRevision* del1 = [[[TDRevision alloc] initWithDocID: conflict.docID revID: nil deleted: YES] autorelease];
+ TDRevision* del1 = [[TDRevision alloc] initWithDocID: conflict.docID revID: nil deleted: YES];
noteInfo = nil;
del1 = [db putRevision: del1 prevRevisionID: conflict.revID
allowConflict: NO status: &status];
@@ -393,13 +393,13 @@ static void verifyHistory(TDDatabase* db, TDRevision* rev, NSArray* history, boo
verifyHistory(db, rev, history, true);
// Delete the remaining rev:
- TDRevision* del2 = [[[TDRevision alloc] initWithDocID: rev.docID revID: nil deleted: YES] autorelease];
+ TDRevision* del2 = [[TDRevision alloc] initWithDocID: rev.docID revID: nil deleted: YES];
noteInfo = nil;
del2 = [db putRevision: del2 prevRevisionID: rev.revID
allowConflict: NO status: &status];
CAssertEq(status, 200);
current = [db getDocumentWithID: rev.docID revisionID: nil];
- CAssertEq(current, nil);
+ CAssertEqual(current, nil);
TDRevision* maxDel = TDCompareRevIDs(del1.revID, del2.revID) > 0 ? del1 : nil;
CAssertEqual(noteInfo, (@{ @"rev" : del2, @"winner": maxDel }));
@@ -429,7 +429,7 @@ static void verifyHistory(TDDatabase* db, TDRevision* rev, NSArray* history, boo
{@"key", @"new-value"});
TDRevision* rev2a = putDoc(db, props);
- TDRevision* rev2b = [[[TDRevision alloc] initWithProperties: props] autorelease];
+ TDRevision* rev2b = [[TDRevision alloc] initWithProperties: props];
TDStatus status;
rev2b = [db putRevision: rev2b
prevRevisionID: rev1.revID
@@ -451,7 +451,6 @@ static void insertAttachment(TDDatabase* db, NSData* blob,
unsigned revpos)
{
TDAttachment* attachment = [[TDAttachment alloc] initWithName: name contentType: type];
- [attachment autorelease];
CAssert([db storeBlob: blob creatingKey: &attachment->blobKey], @"Failed to store blob");
attachment->encoding = encoding;
attachment->length = length;
@@ -799,8 +798,8 @@ static void insertAttachment(TDDatabase* db, NSData* blob,
// Create a document:
NSMutableDictionary* props = $mdict({@"_id", @"_local/doc1"},
{@"foo", @1}, {@"bar", $false});
- TDBody* doc = [[[TDBody alloc] initWithProperties: props] autorelease];
- TDRevision* rev1 = [[[TDRevision alloc] initWithBody: doc] autorelease];
+ TDBody* doc = [[TDBody alloc] initWithProperties: props];
+ TDRevision* rev1 = [[TDRevision alloc] initWithBody: doc];
TDStatus status;
rev1 = [db putLocalRevision: rev1 prevRevisionID: nil status: &status];
CAssertEq(status, kTDStatusCreated);
@@ -816,10 +815,10 @@ static void insertAttachment(TDDatabase* db, NSData* blob,
CAssertEqual(userProperties(readRev.properties), userProperties(doc.properties));
// Now update it:
- props = [[readRev.properties mutableCopy] autorelease];
+ props = [readRev.properties mutableCopy];
props[@"status"] = @"updated!";
doc = [TDBody bodyWithProperties: props];
- TDRevision* rev2 = [[[TDRevision alloc] initWithBody: doc] autorelease];
+ TDRevision* rev2 = [[TDRevision alloc] initWithBody: doc];
TDRevision* rev2Input = rev2;
rev2 = [db putLocalRevision: rev2 prevRevisionID: rev1.revID status: &status];
CAssertEq(status, kTDStatusCreated);
@@ -837,14 +836,14 @@ static void insertAttachment(TDDatabase* db, NSData* blob,
CAssertEq(status, kTDStatusConflict);
// Delete it:
- TDRevision* revD = [[[TDRevision alloc] initWithDocID: rev2.docID revID: nil deleted: YES] autorelease];
- CAssertEq([db putLocalRevision: revD prevRevisionID: nil status: &status], nil);
+ TDRevision* revD = [[TDRevision alloc] initWithDocID: rev2.docID revID: nil deleted: YES];
+ CAssertEqual([db putLocalRevision: revD prevRevisionID: nil status: &status], nil);
CAssertEq(status, kTDStatusConflict);
revD = [db putLocalRevision: revD prevRevisionID: rev2.revID status: &status];
CAssertEq(status, kTDStatusOK);
// Delete nonexistent doc:
- TDRevision* revFake = [[[TDRevision alloc] initWithDocID: @"_local/fake" revID: nil deleted: YES] autorelease];
+ TDRevision* revFake = [[TDRevision alloc] initWithDocID: @"_local/fake" revID: nil deleted: YES];
[db putLocalRevision: revFake prevRevisionID: nil status: &status];
CAssertEq(status, kTDStatusNotFound);
@@ -870,10 +869,10 @@ static void insertAttachment(TDDatabase* db, NSData* blob,
putDoc(db, $dict({@"_id", @"11111"}, {@"_rev", doc1r2.revID}, {@"_deleted", $true}));
// Now call -findMissingRevisions:
- TDRevision* revToFind1 = [[[TDRevision alloc] initWithDocID: @"11111" revID: @"3-bogus" deleted: NO] autorelease];
- TDRevision* revToFind2 = [[[TDRevision alloc] initWithDocID: @"22222" revID: doc2r2.revID deleted: NO] autorelease];
- TDRevision* revToFind3 = [[[TDRevision alloc] initWithDocID: @"99999" revID: @"9-huh" deleted: NO] autorelease];
- TDRevisionList* revs = [[[TDRevisionList alloc] initWithArray: @[revToFind1, revToFind2, revToFind3]] autorelease];
+ TDRevision* revToFind1 = [[TDRevision alloc] initWithDocID: @"11111" revID: @"3-bogus" deleted: NO];
+ TDRevision* revToFind2 = [[TDRevision alloc] initWithDocID: @"22222" revID: doc2r2.revID deleted: NO];
+ TDRevision* revToFind3 = [[TDRevision alloc] initWithDocID: @"99999" revID: @"9-huh" deleted: NO];
+ TDRevisionList* revs = [[TDRevisionList alloc] initWithArray: @[revToFind1, revToFind2, revToFind3]];
CAssert([db findMissingRevisions: revs]);
CAssertEqual(revs.allRevisions, (@[revToFind1, revToFind3]));
View
9 Source/TDJSON.m
@@ -38,7 +38,6 @@ + (NSData *)dataWithJSONObject:(id)object
NSData* json = [super dataWithJSONObject: object
options: (options & ~TDJSONWritingAllowFragments)
error: NULL];
- [object release];
return [json subdataWithRange: NSMakeRange(1, json.length - 2)];
} else {
return [super dataWithJSONObject: object options: options error: error];
@@ -114,17 +113,11 @@ @implementation TDLazyArrayOfJSON
- (id) initWithArray: (NSMutableArray*)array {
self = [super init];
if (self) {
- _array = [array retain];
+ _array = array;
}
return self;
}
-- (void)dealloc
-{
- [_array release];
- [super dealloc];
-}
-
- (NSUInteger)count {
return _array.count;
}
View
42 Source/TDMisc.m
@@ -36,10 +36,17 @@
uuid_unparse_lower(uuid, cstr);
return [[[NSString alloc] initWithCString: cstr encoding: NSASCIIStringEncoding] autorelease];
#else
+
CFUUIDRef uuid = CFUUIDCreate(NULL);
- NSString* str = NSMakeCollectable(CFUUIDCreateString(NULL, uuid));
+#ifdef __OBJC_GC__
+ CFStringRef uuidStrRef = CFUUIDCreateString(NULL, uuid);
+ NSString *uuidStr = (NSString *)uuidStrRef;
+ CFRelease(uuidStrRef);
+#else
+ NSString *uuidStr = (__bridge_transfer NSString *)CFUUIDCreateString(NULL, uuid);
+#endif
CFRelease(uuid);
- return [str autorelease];
+ return uuidStr;
#endif
}
@@ -77,9 +84,9 @@
char *dst = &hex[0];
for( size_t i=0; i<length; i+=1 )
dst += sprintf(dst,"%02x", ((const uint8_t*)bytes)[i]); // important: generates lowercase!
- return [[[NSString alloc] initWithBytes: hex
+ return [[NSString alloc] initWithBytes: hex
length: 2*length
- encoding: NSASCIIStringEncoding] autorelease];
+ encoding: NSASCIIStringEncoding];
}
@@ -113,7 +120,12 @@ NSComparisonResult TDSequenceCompare( SequenceNumber a, SequenceNumber b) {
(CFStringRef)docOrRevID,
NULL, (CFStringRef)@"&/",
kCFStringEncodingUTF8);
- return [NSMakeCollectable(escaped) autorelease];
+ #ifdef __OBJC_GC__
+ return NSMakeCollectable(escaped);
+ #else
+ return (__bridge_transfer NSString *)escaped;
+ #endif
+
#endif
}
@@ -128,13 +140,17 @@ NSComparisonResult TDSequenceCompare( SequenceNumber a, SequenceNumber b) {
(CFStringRef)param,
NULL, (CFStringRef)@"&",
kCFStringEncodingUTF8);
- return [NSMakeCollectable(escaped) autorelease];
+ #ifdef __OBJC_GC__
+ return NSMakeCollectable(escaped);
+ #else
+ return (__bridge_transfer NSString *)escaped;
+ #endif
#endif
}
NSString* TDQuoteString( NSString* param ) {
- NSMutableString* quoted = [[param mutableCopy] autorelease];
+ NSMutableString* quoted = [param mutableCopy];
[quoted replaceOccurrencesOfString: @"\\" withString: @"\\\\"
options: NSLiteralSearch
range: NSMakeRange(0, quoted.length)];
@@ -155,7 +171,7 @@ NSComparisonResult TDSequenceCompare( SequenceNumber a, SequenceNumber b) {
param = [param substringWithRange: NSMakeRange(1, param.length - 2)];
if ([param rangeOfString: @"\\"].length == 0)
return param;
- NSMutableString* unquoted = [[param mutableCopy] autorelease];
+ NSMutableString* unquoted = [param mutableCopy];
for (NSUInteger pos = 0; pos < unquoted.length; ) {
NSRange r = [unquoted rangeOfString: @"\\"
options: NSLiteralSearch
@@ -221,7 +237,7 @@ BOOL TDMayBeTransientError( NSError* error ) {
return [NSURL URLWithString: [str substringToIndex: q.location]];
#else
// Strip anything after the URL's path (i.e. the query string)
- CFURLRef cfURL = (CFURLRef)url;
+ CFURLRef cfURL = (__bridge CFURLRef)url;
CFRange range = CFURLGetByteRangeForComponent(cfURL, kCFURLComponentResourceSpecifier, NULL);
if (range.length == 0) {
return url;
@@ -231,8 +247,12 @@ BOOL TDMayBeTransientError( NSError* error ) {
return url; // give up
UInt8 bytes[size];
CFURLGetBytes(cfURL, bytes, size);
- cfURL = CFURLCreateWithBytes(NULL, bytes, range.location - 1, kCFStringEncodingUTF8, NULL);
- return [NSMakeCollectable(cfURL) autorelease];
+ NSURL *url = (__bridge_transfer NSURL *)CFURLCreateWithBytes(NULL, bytes, range.location - 1, kCFStringEncodingUTF8, NULL);
+ #ifdef __OBJC_GC__
+ return NSMakeCollectable(url);
+ #else
+ return url;
+ #endif
}
#endif
}
View
2  Source/TDMultiStreamWriter.h
@@ -51,7 +51,7 @@
@property (readonly) BOOL isOpen;
-@property (readonly, retain) NSError* error;
+@property (readonly, strong) NSError* error;
/** Convenience method that opens an output stream, collects all the data, and returns it. */
- (NSData*) allOutput;
View
37 Source/TDMultiStreamWriter.m
@@ -22,7 +22,7 @@
@interface TDMultiStreamWriter () <NSStreamDelegate>
-@property (readwrite, retain) NSError* error;
+@property (readwrite, strong) NSError* error;
@end
@@ -40,7 +40,6 @@ - (id)initWithBufferSize: (NSUInteger)bufferSize {