aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMSQLite.m
diff options
context:
space:
mode:
authorGravatar dmaclach <dmaclach@google.com>2016-10-07 12:10:23 -0400
committerGravatar Thomas Van Lenten <thomasvl@google.com>2016-10-07 12:21:06 -0400
commit42124b3691197c3c4f52f069775fa0390a8ff942 (patch)
treeebd373d398ea64b45bdc1d196fa0a2c5f57cabfd /Foundation/GTMSQLite.m
parent57eeab4193210df8ab0c81e9d3f1ee1ad3e24492 (diff)
First cut at pruning things/updating things.
Remove a bunch of code that Google stopped using/maintaining rather than trying to update it it. Some would be hard to update, some actually has system provided replacements; others are patterns that just don't seem as common now. Prune out the code related to macOS <= 10.5, start pruning some of the really old iOS support also. Get the projects mostly limping again with modern Xcodes so tests can be run. If someone ends up on this commit via history for something they still find as useful, feel free to do a pull request to bring the snippet of code back to life and update it for current SDKs.
Diffstat (limited to 'Foundation/GTMSQLite.m')
-rw-r--r--Foundation/GTMSQLite.m91
1 files changed, 13 insertions, 78 deletions
diff --git a/Foundation/GTMSQLite.m b/Foundation/GTMSQLite.m
index 502a5cc..aa5d5f5 100644
--- a/Foundation/GTMSQLite.m
+++ b/Foundation/GTMSQLite.m
@@ -20,9 +20,6 @@
#import <Foundation/Foundation.h>
-#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
-#import <dlfcn.h>
-#endif
#import "GTMSQLite.h"
#import "GTMMethodCheck.h"
#import "GTMDefines.h"
@@ -44,22 +41,6 @@ typedef struct {
int textRep;
} LikeGlobUserArgs;
-#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
-// While we want to be compatible with Tiger, some operations are more
-// efficient when implemented with Leopard APIs. We look those up dynamically.
-// CFStringCreateWithBytesNoCopy
-static const char* const kCFStringCreateWithBytesNoCopySymbolName =
- "CFStringCreateWithBytesNoCopy";
-
-typedef CFStringRef (*CFStringCreateWithBytesNoCopyPtrType)(CFAllocatorRef,
- const UInt8 *,
- CFIndex,
- CFStringEncoding,
- Boolean,
- CFAllocatorRef);
-static CFStringCreateWithBytesNoCopyPtrType gCFStringCreateWithBytesNoCopySymbol = NULL;
-#endif // MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
-
// Helper inline for SQLite text type to CF endcoding
GTM_INLINE CFStringEncoding SqliteTextEncodingToCFStringEncoding(int enc) {
// Default should never happen, but assume UTF 8
@@ -87,14 +68,12 @@ GTM_INLINE CFOptionFlags FilteredStringCompareFlags(CFOptionFlags inOptions) {
if (inOptions & kCFCompareNonliteral) outOptions |= kCFCompareNonliteral;
if (inOptions & kCFCompareLocalized) outOptions |= kCFCompareLocalized;
if (inOptions & kCFCompareNumerically) outOptions |= kCFCompareNumerically;
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
if (inOptions & kCFCompareDiacriticInsensitive) {
outOptions |= kCFCompareDiacriticInsensitive;
}
if (inOptions & kCFCompareWidthInsensitive) {
outOptions |= kCFCompareWidthInsensitive;
}
-#endif
return outOptions;
}
@@ -141,14 +120,6 @@ static CFLocaleRef gCurrentLocale = NULL;
+ (void)initialize {
// Need the locale for some CFString enhancements
gCurrentLocale = CFLocaleCopyCurrent();
-
-#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
- // Compiling pre-Leopard try to find some symbols dynamically
- gCFStringCreateWithBytesNoCopySymbol =
- (CFStringCreateWithBytesNoCopyPtrType)dlsym(
- RTLD_DEFAULT,
- kCFStringCreateWithBytesNoCopySymbolName);
-#endif // MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
}
+ (int)sqliteVersionNumber {
@@ -176,7 +147,7 @@ static CFLocaleRef gCurrentLocale = NULL;
#else
cfEncoding = kCFStringEncodingUTF16LE;
#endif
- NSStringEncoding nsEncoding
+ NSStringEncoding nsEncoding
= CFStringConvertEncodingToNSStringEncoding(cfEncoding);
NSData *data = [path dataUsingEncoding:nsEncoding];
// Using -[NSString cStringUsingEncoding] causes sqlite3_open16
@@ -420,7 +391,7 @@ static CFLocaleRef gCurrentLocale = NULL;
- (CFOptionFlags)likeComparisonOptions {
CFOptionFlags flags = 0;
- if (hasCFAdditions_)
+ if (hasCFAdditions_)
flags = likeOptions_;
return flags;
}
@@ -510,7 +481,7 @@ static CFLocaleRef gCurrentLocale = NULL;
}
- (NSString *)description {
- return [NSString stringWithFormat:@"<%@: %p - %@>",
+ return [NSString stringWithFormat:@"<%@: %p - %@>",
[self class], self, path_];
}
@end
@@ -787,7 +758,7 @@ static void CollateNeeded(void *userContext, sqlite3 *db, int textRep,
[collationName componentsSeparatedByString:@"_"];
NSString *collationFlag = nil;
BOOL atLeastOneValidFlag = NO;
- GTM_FOREACH_OBJECT(collationFlag, collationComponents) {
+ for (collationFlag in collationComponents) {
if ([collationFlag isEqualToString:@"reverse"]) {
userArgs->reverse = YES;
atLeastOneValidFlag = YES;
@@ -803,19 +774,12 @@ static void CollateNeeded(void *userContext, sqlite3 *db, int textRep,
} else if ([collationFlag isEqualToString:@"numeric"]) {
userArgs->compareOptions |= kCFCompareNumerically;
atLeastOneValidFlag = YES;
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
} else if ([collationFlag isEqualToString:@"nodiacritic"]) {
userArgs->compareOptions |= kCFCompareDiacriticInsensitive;
atLeastOneValidFlag = YES;
} else if ([collationFlag isEqualToString:@"widthinsensitive"]) {
userArgs->compareOptions |= kCFCompareWidthInsensitive;
atLeastOneValidFlag = YES;
-#else
- } else if (([collationFlag isEqualToString:@"nodiacritic"]) ||
- ([collationFlag isEqualToString:@"widthinsensitive"])) {
- _GTMDevLog(@"GTMSQLiteDatabase 10.5 collating not "
- @"available on 10.4 or earlier");
-#endif
}
}
@@ -874,34 +838,6 @@ static int Collate8(void *userContext, int length1, const void *str1,
// creation function, we'll use it when we can but we want to stay compatible
// with Tiger.
CFStringRef string1 = NULL, string2 = NULL;
-#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
- if (gCFStringCreateWithBytesNoCopySymbol) {
- string1 = gCFStringCreateWithBytesNoCopySymbol(kCFAllocatorDefault,
- str1,
- length1,
- kCFStringEncodingUTF8,
- false,
- kCFAllocatorNull);
- string2 = gCFStringCreateWithBytesNoCopySymbol(kCFAllocatorDefault,
- str2,
- length2,
- kCFStringEncodingUTF8,
- false,
- kCFAllocatorNull);
- } else {
- // Have to use the copy-based variants
- string1 = CFStringCreateWithBytes(kCFAllocatorDefault,
- str1,
- length1,
- kCFStringEncodingUTF8,
- false);
- string2 = CFStringCreateWithBytes(kCFAllocatorDefault,
- str2,
- length2,
- kCFStringEncodingUTF8,
- false);
- }
-#else // MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
string1 = CFStringCreateWithBytesNoCopy(kCFAllocatorDefault,
str1,
length1,
@@ -914,7 +850,6 @@ static int Collate8(void *userContext, int length1, const void *str1,
kCFStringEncodingUTF8,
false,
kCFAllocatorNull);
-#endif // MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
GTMCFAutorelease(string1);
GTMCFAutorelease(string2);
// Allocation failures can't really be sanely handled from a collator
@@ -937,7 +872,7 @@ static int Collate8(void *userContext, int length1, const void *str1,
if (userArgs->reverse && sqliteResult) {
sqliteResult = -sqliteResult;
}
-
+
}
return sqliteResult;
}
@@ -1025,7 +960,7 @@ static int Collate16(void *userContext, int length1, const void *str1,
string2,
userArgs->compareOptions);
- sqliteResult = (int)result;
+ sqliteResult = (int)result;
//Reverse
if (userArgs->reverse && sqliteResult) {
sqliteResult = -sqliteResult;
@@ -1052,8 +987,8 @@ static void LikeGlobCompare(sqlite3_context *context,
// Setup for pattern walk
CFIndex patternLength = CFStringGetLength(pattern);
CFStringInlineBuffer patternBuffer;
- CFStringInitInlineBuffer(pattern,
- &patternBuffer,
+ CFStringInitInlineBuffer(pattern,
+ &patternBuffer,
CFRangeMake(0, patternLength));
UniChar patternChar;
CFIndex patternIndex = 0;
@@ -1128,7 +1063,7 @@ static void LikeGlobCompare(sqlite3_context *context,
}
// There's at least one character, try to match the remainder of the
// string using a CFCharacterSet
- CFMutableCharacterSetRef charSet
+ CFMutableCharacterSetRef charSet
= CFCharacterSetCreateMutable(kCFAllocatorDefault);
GTMCFAutorelease(charSet);
if (!charSet) {
@@ -1776,8 +1711,8 @@ static void Glob16(sqlite3_context *context, int argc, sqlite3_value **argv) {
- (int)bindBlobAtPosition:(int)position data:(NSData *)data {
if (!statement_ || !data || !position) return SQLITE_MISUSE;
int blobLength = (int)[data length];
- _GTMDevAssert((blobLength < INT_MAX),
- @"sqlite methods do not support data lengths "
+ _GTMDevAssert((blobLength < INT_MAX),
+ @"sqlite methods do not support data lengths "
@"exceeding 32 bit sizes");
return [self bindBlobAtPosition:position
bytes:(void *)[data bytes]
@@ -1822,8 +1757,8 @@ static void Glob16(sqlite3_context *context, int argc, sqlite3_value **argv) {
}
return sqlite3_bind_text(statement_,
position,
- [string UTF8String],
- -1,
+ [string UTF8String],
+ -1,
SQLITE_TRANSIENT);
}