diff options
author | Max <dmoagx@users.noreply.github.com> | 2018-04-29 23:59:56 +0200 |
---|---|---|
committer | Max <dmoagx@users.noreply.github.com> | 2018-04-29 23:59:56 +0200 |
commit | 5bd7cde2e69991b5cd9bde424c45e2da5bb34292 (patch) | |
tree | 26d0fe949a2184339796eaef86bebc3b730b507a /Frameworks/SPMySQLFramework | |
parent | fc3e74c1e3f650e6efd3ddcce24d9e2c4d37c048 (diff) | |
download | sequelpro-5bd7cde2e69991b5cd9bde424c45e2da5bb34292.tar.gz sequelpro-5bd7cde2e69991b5cd9bde424c45e2da5bb34292.tar.bz2 sequelpro-5bd7cde2e69991b5cd9bde424c45e2da5bb34292.zip |
* Formatting and minor code changes
* Fixed a memory leak in CF code
Diffstat (limited to 'Frameworks/SPMySQLFramework')
13 files changed, 55 insertions, 41 deletions
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLArrayAdditions.h b/Frameworks/SPMySQLFramework/Source/SPMySQLArrayAdditions.h index 548c5e48..3605cdbc 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLArrayAdditions.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLArrayAdditions.h @@ -37,6 +37,26 @@ */ static inline void SPMySQLMutableArrayInsertObject(NSMutableArray *self, id anObject, NSUInteger anIndex) { + /* A note on CFArrayInsertValueAtIndex(): + * + * This function here does look similar to the CF function, however that is not neccesarily the + * case from a performance standpoint. + * + * CFArrayInsertValueAtIndex() is mostly a wrapper around either + * - _CFArrayReplaceValues(obj, …) *or* + * - objc_msgSend(obj, @selector(insertObject:atIndex:), …) + * + * The first case would be fast, but it will only be used if the object is a native CFArrayRef, not + * a toll-free bridged object. In our case however, we always pass in some object of the NSMutableArray cluster, + * so we would always end up in the slowest path (uncached objc method invocation). + * + * Determing the performance of the objc method is more difficult, because there are multiple implementations + * of NSMutableArray and the "real" -[NSMutableArray insertObject:atIndex:] (located in CoreFoundation.framework) + * is only an abstract stub that will raise an exception if called. + * + * NSCFArray's (for CFArrays bridged to objc) implementation will wind up in _CFArrayReplaceValues(). + * __NSArrayM's (for +[NSMutableArray array]) implementation is completely independent from the aforementioned ones. + */ typedef id (*SPMySQLMutableArrayInsertObjectPtr)(NSMutableArray*, SEL, id, NSUInteger); static SPMySQLMutableArrayInsertObjectPtr cachedMethodPointer; static SEL cachedSelector; diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m index 897df32f..57a40252 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m @@ -946,31 +946,28 @@ asm(".desc ___crashreporter_info__, 0x10"); */ - (BOOL)_waitForNetworkConnectionWithTimeout:(double)timeoutSeconds { - BOOL hostReachable; - Boolean flagsValid; - SCNetworkReachabilityRef reachabilityTarget; - SCNetworkConnectionFlags reachabilityStatus; - // Set up the reachability target - the host is not important, and is not connected to. - reachabilityTarget = SCNetworkReachabilityCreateWithName(NULL, "dev.mysql.com"); + SCNetworkReachabilityRef reachabilityTarget = SCNetworkReachabilityCreateWithName(NULL, "dev.mysql.com"); + BOOL hostReachable; // In a loop until success or the timeout, test reachability uint64_t loopStart_t = mach_absolute_time(); while (1) { + SCNetworkReachabilityFlags reachabilityStatus; // Check reachability - flagsValid = SCNetworkReachabilityGetFlags(reachabilityTarget, &reachabilityStatus); + Boolean flagsValid = SCNetworkReachabilityGetFlags(reachabilityTarget, &reachabilityStatus); hostReachable = flagsValid ? YES : NO; // Ensure that the network is reachable - if (hostReachable && !(reachabilityStatus & kSCNetworkFlagsReachable)) hostReachable = NO; + if (hostReachable && !(reachabilityStatus & kSCNetworkReachabilityFlagsReachable)) hostReachable = NO; // Ensure that Airport is up/connected if present - if (hostReachable && (reachabilityStatus & kSCNetworkFlagsConnectionRequired)) hostReachable = NO; + if (hostReachable && (reachabilityStatus & kSCNetworkReachabilityFlagsConnectionRequired)) hostReachable = NO; // If the host *is* reachable, return success - if (hostReachable) return YES; + if (hostReachable) break; // If the timeout has been exceeded, break out of the loop if (_elapsedSecondsSinceAbsoluteTime(loopStart_t) >= timeoutSeconds) break; @@ -979,8 +976,8 @@ asm(".desc ___crashreporter_info__, 0x10"); usleep(250000); } - // All checks failed - return failure - return NO; + CFRelease(reachabilityTarget); + return hostReachable; } /** diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLEmptyResult.m b/Frameworks/SPMySQLFramework/Source/SPMySQLEmptyResult.m index db63e12e..1b9892aa 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLEmptyResult.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLEmptyResult.m @@ -42,7 +42,7 @@ /** * Override the standard SPMySQLResult interface */ -- (id)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding +- (instancetype)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding { return [super init]; } diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLFastStreamingResult.m b/Frameworks/SPMySQLFramework/Source/SPMySQLFastStreamingResult.m index 53ab116f..76601779 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLFastStreamingResult.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLFastStreamingResult.m @@ -51,7 +51,7 @@ typedef struct st_spmysqlstreamingrowdata { struct st_spmysqlstreamingrowdata *nextRow; } SPMySQLStreamingRowData; -@interface SPMySQLFastStreamingResult (Private_API) +@interface SPMySQLFastStreamingResult () // Private API - (void) _downloadAllData; @@ -317,13 +317,9 @@ typedef struct st_spmysqlstreamingrowdata { return 1; } -@end - #pragma mark - #pragma mark Result set internals -@implementation SPMySQLFastStreamingResult (Private_API) - /** * Used internally to download results in a background thread */ diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLGeometryData.h b/Frameworks/SPMySQLFramework/Source/SPMySQLGeometryData.h index e886c1ca..7106b8c5 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLGeometryData.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLGeometryData.h @@ -28,7 +28,7 @@ // More info at <https://github.com/sequelpro/sequelpro> -@interface SPMySQLGeometryData : NSObject +@interface SPMySQLGeometryData : NSObject <NSCopying> { // Holds the WKB bytes coming from SQL server Byte *geoBuffer; @@ -38,8 +38,8 @@ } -- (id)initWithBytes:(const void *)geoData length:(NSUInteger)length; -+ (id)dataWithBytes:(const void *)geoData length:(NSUInteger)length; +- (instancetype)initWithBytes:(const void *)geoData length:(NSUInteger)length; ++ (instancetype)dataWithBytes:(const void *)geoData length:(NSUInteger)length; - (NSString *)description; - (NSUInteger)length; - (NSData *)data; diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLGeometryData.m b/Frameworks/SPMySQLFramework/Source/SPMySQLGeometryData.m index d617aebb..b7ced7ab 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLGeometryData.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLGeometryData.m @@ -28,6 +28,8 @@ // More info at <https://github.com/sequelpro/sequelpro> #import "SPMySQLGeometryData.h" +#include <stdlib.h> +#include <string.h> enum wkbType { @@ -57,7 +59,7 @@ typedef struct st_point_2d_ /** * Initialize the SPMySQLGeometryData object */ -- (id)init +- (instancetype)init { if ((self = [super init])) { geoBuffer = nil; @@ -69,7 +71,7 @@ typedef struct st_point_2d_ /** * Initialize the SPMySQLGeometryData object with the WKB data */ -- (id)initWithBytes:(const void *)geoData length:(NSUInteger)length +- (instancetype)initWithBytes:(const void *)geoData length:(NSUInteger)length { if ((self = [self init])) { bufferLength = length; @@ -82,7 +84,7 @@ typedef struct st_point_2d_ /** * Return an autorelease SPMySQLGeometryData object */ -+ (id)dataWithBytes:(const void *)geoData length:(NSUInteger)length ++ (instancetype)dataWithBytes:(const void *)geoData length:(NSUInteger)length { return [[[SPMySQLGeometryData alloc] initWithBytes:geoData length:length] autorelease]; } diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLKeepAliveTimer.h b/Frameworks/SPMySQLFramework/Source/SPMySQLKeepAliveTimer.h index c2581cca..1ed5fc56 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLKeepAliveTimer.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLKeepAliveTimer.h @@ -37,7 +37,9 @@ NSTimer *wrappedTimer; } -- (id)initWithInterval:(NSTimeInterval)anInterval target:(id)aTarget selector:(SEL)aSelector; +- (instancetype)initWithInterval:(NSTimeInterval)anInterval target:(id)aTarget selector:(SEL)aSelector NS_DESIGNATED_INITIALIZER; +- (instancetype)init NS_UNAVAILABLE; + - (void)invalidate; @end diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLKeepAliveTimer.m b/Frameworks/SPMySQLFramework/Source/SPMySQLKeepAliveTimer.m index a7520c2f..8103580b 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLKeepAliveTimer.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLKeepAliveTimer.m @@ -30,9 +30,8 @@ #import "SPMySQLKeepAliveTimer.h" -#import "SPMySQL Private APIs.h" -@interface SPMySQLKeepAliveTimer (Private_API) +@interface SPMySQLKeepAliveTimer () // Private API - (void)_initKeepAliveTimer; - (void)_forwardPing; @@ -46,7 +45,7 @@ /** * Prevent SPMySQLKeepAliveTimer from being init'd normally. */ -- (id)init +- (instancetype)init { [NSException raise:NSInternalInconsistencyException format:@"SPMySQLKeepAliveTimers should not be init'd directly; use initWithInterval:target:selector: instead."]; return nil; @@ -60,7 +59,7 @@ * After initialisation, the delegate should be set to ensure that the timer events * are received. */ -- (id)initWithInterval:(NSTimeInterval)anInterval target:(id)aTarget selector:(SEL)aSelector +- (instancetype)initWithInterval:(NSTimeInterval)anInterval target:(id)aTarget selector:(SEL)aSelector { if ((self = [super init])) { wrappedTimer = nil; @@ -96,13 +95,11 @@ - (void)dealloc { - [wrappedTimer dealloc]; + [wrappedTimer release]; [super dealloc]; } -@end - -@implementation SPMySQLKeepAliveTimer (Private_API) +#pragma mark - Private API /** * Set up the timer to tickle the target. This must be set up on the main thread diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLResult.h b/Frameworks/SPMySQLFramework/Source/SPMySQLResult.h index 1be7e859..ace4563b 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLResult.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLResult.h @@ -65,7 +65,7 @@ typedef enum { } // Master init method -- (id)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding; +- (instancetype)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding; // Result set information - (NSUInteger)numberOfFields; diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLResult.m b/Frameworks/SPMySQLFramework/Source/SPMySQLResult.m index 2e1cb2ba..88b27aad 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLResult.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLResult.m @@ -59,7 +59,7 @@ static id NSNullPointer; /** * Standard initialisation - not intended for external use. */ -- (id)init +- (instancetype)init { if ((self = [super init])) { stringEncoding = NSASCIIStringEncoding; @@ -83,7 +83,7 @@ static id NSNullPointer; * Standard init method, constructing the SPMySQLResult around a MySQL * result pointer and the encoding to use when working with the data. */ -- (id)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding +- (instancetype)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding { // If no result set was passed in, return nil. diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLStreamingResult.h b/Frameworks/SPMySQLFramework/Source/SPMySQLStreamingResult.h index 11ca417c..3f2f1873 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLStreamingResult.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLStreamingResult.h @@ -46,7 +46,8 @@ @property (readonly, assign) BOOL dataDownloaded; -- (id)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding connection:(SPMySQLConnection *)theConnection; +- (instancetype)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding connection:(SPMySQLConnection *)theConnection; +- (instancetype)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding NS_UNAVAILABLE; // Allow result fetching to be cancelled - (void)cancelResultLoad; diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLStreamingResult.m b/Frameworks/SPMySQLFramework/Source/SPMySQLStreamingResult.m index 79e6a9b0..230fe01a 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLStreamingResult.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLStreamingResult.m @@ -51,7 +51,7 @@ /** * Prevent SPMySQLStreamingResults from being init'd as SPMySQLResults. */ -- (id)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding +- (instancetype)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding { [NSException raise:NSInternalInconsistencyException format:@"SPMySQLFullStreamingResults should not be init'd as SPMySQLResults; use initWithMySQLResult:stringEncoding:connection:withFullStreaming: instead."]; return nil; @@ -63,7 +63,7 @@ * As opposed to SPMySQLResult, defaults to returning rows as arrays, as the result * sets are likely to be larger and processed in loops. */ -- (id)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding connection:(SPMySQLConnection *)theConnection +- (instancetype)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding connection:(SPMySQLConnection *)theConnection { // If no result set was passed in, return nil. diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLStreamingResultStore.m b/Frameworks/SPMySQLFramework/Source/SPMySQLStreamingResultStore.m index 29f83e0e..d3e2580d 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLStreamingResultStore.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLStreamingResultStore.m @@ -105,9 +105,8 @@ static inline void SPMySQLStreamingResultStoreFreeRowData(SPMySQLStreamingResult * The download of results is not started at once - instead, it must be triggered manually * via -startDownload, which allows assignment of a result set to replace before use. */ -- (id)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding connection:(SPMySQLConnection *)theConnection +- (instancetype)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding connection:(SPMySQLConnection *)theConnection { - // If no result set was passed in, return nil. if (!theResult) return nil; |