diff --git a/GRDB/Core/Database+Statements.swift b/GRDB/Core/Database+Statements.swift index c3fabdeaf3..48d4ad74e0 100644 --- a/GRDB/Core/Database+Statements.swift +++ b/GRDB/Core/Database+Statements.swift @@ -373,7 +373,7 @@ extension SQLStatementCursor: Cursor { let baseAddress = buffer.baseAddress! // never nil because the buffer contains the trailing \0. // Compile next statement - var statementEnd: UnsafePointer? = nil + var statementEnd: UnsafePointer? = nil let statement = try Statement( database: database, statementStart: baseAddress + offset, diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 266155cbb0..858d6d955d 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -877,7 +877,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib _ mask: CInt, _ p: UnsafeMutableRawPointer?, _ x: UnsafeMutableRawPointer?, - _ sqlite3_expanded_sql: @escaping @convention(c) (OpaquePointer?) -> UnsafeMutablePointer?) + _ sqlite3_expanded_sql: @escaping @convention(c) (OpaquePointer?) -> UnsafeMutablePointer?) { guard let trace else { return } @@ -1896,7 +1896,7 @@ extension Database { public struct Statement: CustomStringConvertible { var sqliteStatement: SQLiteStatement var unexpandedSQL: UnsafePointer? - var sqlite3_expanded_sql: @convention(c) (OpaquePointer?) -> UnsafeMutablePointer? + var sqlite3_expanded_sql: @convention(c) (OpaquePointer?) -> UnsafeMutablePointer? var publicStatementArguments: Bool // See Configuration.publicStatementArguments /// The executed SQL, where bound parameters are not expanded. diff --git a/GRDB/Core/Statement.swift b/GRDB/Core/Statement.swift index ec11bfccb8..5bec60a162 100644 --- a/GRDB/Core/Statement.swift +++ b/GRDB/Core/Statement.swift @@ -119,8 +119,8 @@ public final class Statement { /// - throws: DatabaseError in case of compilation error. required init?( database: Database, - statementStart: UnsafePointer, - statementEnd: UnsafeMutablePointer?>, + statementStart: UnsafePointer, + statementEnd: UnsafeMutablePointer?>, prepFlags: CUnsignedInt) throws { SchedulingWatchdog.preconditionValidQueue(database) diff --git a/GRDB/Core/StatementAuthorizer.swift b/GRDB/Core/StatementAuthorizer.swift index 5fe6f9dbef..e20883049f 100644 --- a/GRDB/Core/StatementAuthorizer.swift +++ b/GRDB/Core/StatementAuthorizer.swift @@ -57,10 +57,10 @@ final class StatementAuthorizer { private func authorize( _ actionCode: CInt, - _ cString1: UnsafePointer?, - _ cString2: UnsafePointer?, - _ cString3: UnsafePointer?, - _ cString4: UnsafePointer?) + _ cString1: UnsafePointer?, + _ cString2: UnsafePointer?, + _ cString3: UnsafePointer?, + _ cString4: UnsafePointer?) -> CInt { // Uncomment when debugging diff --git a/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift b/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift index fd31c3724b..954edb350b 100644 --- a/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift +++ b/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift @@ -75,7 +75,7 @@ extension DatabaseDateComponents: StatementColumnConvertible { } let length = Int(sqlite3_column_bytes(sqliteStatement, index)) // avoid an strlen let components = cString.withMemoryRebound( - to: Int8.self, + to: CChar.self, capacity: length + 1 /* trailing \0 */) { cString in SQLiteDateParser().components(cString: cString, length: length) } diff --git a/GRDB/Core/TransactionObserver.swift b/GRDB/Core/TransactionObserver.swift index 99da62a60e..709acd667a 100644 --- a/GRDB/Core/TransactionObserver.swift +++ b/GRDB/Core/TransactionObserver.swift @@ -1095,7 +1095,7 @@ public struct DatabaseEvent { self.impl = impl } - init(kind: Kind, rowID: Int64, databaseNameCString: UnsafePointer?, tableNameCString: UnsafePointer?) { + init(kind: Kind, rowID: Int64, databaseNameCString: UnsafePointer?, tableNameCString: UnsafePointer?) { self.init( kind: kind, rowID: rowID, @@ -1131,8 +1131,8 @@ private protocol DatabaseEventImpl { /// Optimization: MetalDatabaseEventImpl does not create Swift strings from raw /// SQLite char* until actually asked for databaseName or tableName. private struct MetalDatabaseEventImpl: DatabaseEventImpl { - let databaseNameCString: UnsafePointer? - let tableNameCString: UnsafePointer? + let databaseNameCString: UnsafePointer? + let tableNameCString: UnsafePointer? var databaseName: String { String(cString: databaseNameCString!) } var tableName: String { String(cString: tableNameCString!) } @@ -1267,8 +1267,8 @@ public struct DatabasePreUpdateEvent { kind: Kind, initialRowID: Int64, finalRowID: Int64, - databaseNameCString: UnsafePointer?, - tableNameCString: UnsafePointer?) + databaseNameCString: UnsafePointer?, + tableNameCString: UnsafePointer?) { self.init( kind: kind, @@ -1324,8 +1324,8 @@ private struct MetalDatabasePreUpdateEventImpl: DatabasePreUpdateEventImpl { let connection: SQLiteConnection let kind: DatabasePreUpdateEvent.Kind - let databaseNameCString: UnsafePointer? - let tableNameCString: UnsafePointer? + let databaseNameCString: UnsafePointer? + let tableNameCString: UnsafePointer? var databaseName: String { String(cString: databaseNameCString!) } var tableName: String { String(cString: tableNameCString!) } diff --git a/GRDB/FTS/FTS5.swift b/GRDB/FTS/FTS5.swift index 333a2f2267..43daaf5dda 100644 --- a/GRDB/FTS/FTS5.swift +++ b/GRDB/FTS/FTS5.swift @@ -143,9 +143,9 @@ public struct FTS5 { private static func api_v2( _ db: Database, // swiftlint:disable:next line_length - _ sqlite3_prepare_v3: @convention(c) (OpaquePointer?, UnsafePointer?, CInt, CUnsignedInt, UnsafeMutablePointer?, UnsafeMutablePointer?>?) -> CInt, + _ sqlite3_prepare_v3: @convention(c) (OpaquePointer?, UnsafePointer?, CInt, CUnsignedInt, UnsafeMutablePointer?, UnsafeMutablePointer?>?) -> CInt, // swiftlint:disable:next line_length - _ sqlite3_bind_pointer: @convention(c) (OpaquePointer?, CInt, UnsafeMutableRawPointer?, UnsafePointer?, (@convention(c) (UnsafeMutableRawPointer?) -> Void)?) -> CInt) + _ sqlite3_bind_pointer: @convention(c) (OpaquePointer?, CInt, UnsafeMutableRawPointer?, UnsafePointer?, (@convention(c) (UnsafeMutableRawPointer?) -> Void)?) -> CInt) -> UnsafePointer { var statement: SQLiteStatement? = nil @@ -157,7 +157,7 @@ public struct FTS5 { fatalError("FTS5 is not available") } defer { sqlite3_finalize(statement) } - type.utf8Start.withMemoryRebound(to: Int8.self, capacity: type.utf8CodeUnitCount) { typePointer in + type.utf8Start.withMemoryRebound(to: CChar.self, capacity: type.utf8CodeUnitCount) { typePointer in _ = sqlite3_bind_pointer(statement, 1, &api, typePointer, nil) } sqlite3_step(statement) diff --git a/GRDB/FTS/FTS5CustomTokenizer.swift b/GRDB/FTS/FTS5CustomTokenizer.swift index b0a10a61a1..a294c35b3e 100644 --- a/GRDB/FTS/FTS5CustomTokenizer.swift +++ b/GRDB/FTS/FTS5CustomTokenizer.swift @@ -131,10 +131,10 @@ extension Database { tokenizerPointer: OpaquePointer?, context: UnsafeMutableRawPointer?, flags: CInt, - pText: UnsafePointer?, + pText: UnsafePointer?, nText: CInt, // swiftlint:disable:next line_length - tokenCallback: (@convention(c) (UnsafeMutableRawPointer?, CInt, UnsafePointer?, CInt, CInt, CInt) -> CInt)?) + tokenCallback: (@convention(c) (UnsafeMutableRawPointer?, CInt, UnsafePointer?, CInt, CInt, CInt) -> CInt)?) -> CInt { guard let tokenizerPointer else { diff --git a/GRDB/FTS/FTS5Tokenizer.swift b/GRDB/FTS/FTS5Tokenizer.swift index be19d6f591..02db061538 100644 --- a/GRDB/FTS/FTS5Tokenizer.swift +++ b/GRDB/FTS/FTS5Tokenizer.swift @@ -7,7 +7,7 @@ import Foundation public typealias FTS5TokenCallback = @convention(c) ( _ context: UnsafeMutableRawPointer?, _ flags: CInt, - _ pToken: UnsafePointer?, + _ pToken: UnsafePointer?, _ nToken: CInt, _ iStart: CInt, _ iEnd: CInt) @@ -77,7 +77,7 @@ public protocol FTS5Tokenizer: AnyObject { func tokenize( context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, - pText: UnsafePointer?, + pText: UnsafePointer?, nText: CInt, tokenCallback: @escaping FTS5TokenCallback) -> CInt @@ -143,7 +143,7 @@ extension FTS5Tokenizer { guard let addr = buffer.baseAddress else { return [] } - let pText = UnsafeMutableRawPointer(mutating: addr).assumingMemoryBound(to: Int8.self) + let pText = UnsafeMutableRawPointer(mutating: addr).assumingMemoryBound(to: CChar.self) let nText = CInt(buffer.count) var context = TokenizeContext() @@ -206,8 +206,8 @@ extension Database { } else { func withArrayOfCStrings( _ input: [String], - _ output: inout ContiguousArray>, - _ accessor: (ContiguousArray>) -> Result) + _ output: inout ContiguousArray>, + _ accessor: (ContiguousArray>) -> Result) -> Result { if output.count == input.count { @@ -219,7 +219,7 @@ extension Database { } } } - var cStrings = ContiguousArray>() + var cStrings = ContiguousArray>() cStrings.reserveCapacity(arguments.count) code = withArrayOfCStrings(arguments, &cStrings) { (cStrings) in cStrings.withUnsafeBufferPointer { azArg in @@ -252,7 +252,7 @@ extension Database { func tokenize( context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, - pText: UnsafePointer?, + pText: UnsafePointer?, nText: CInt, tokenCallback: @escaping FTS5TokenCallback) -> CInt diff --git a/GRDB/FTS/FTS5WrapperTokenizer.swift b/GRDB/FTS/FTS5WrapperTokenizer.swift index 7be012bf2a..8b9de904aa 100644 --- a/GRDB/FTS/FTS5WrapperTokenizer.swift +++ b/GRDB/FTS/FTS5WrapperTokenizer.swift @@ -87,7 +87,7 @@ extension FTS5WrapperTokenizer { public func tokenize( context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, - pText: UnsafePointer?, + pText: UnsafePointer?, nText: CInt, tokenCallback: @escaping FTS5TokenCallback) -> CInt @@ -138,7 +138,7 @@ extension FTS5WrapperTokenizer { return } let pToken = UnsafeMutableRawPointer(mutating: addr) - .assumingMemoryBound(to: Int8.self) + .assumingMemoryBound(to: CChar.self) let nToken = CInt(buffer.count) // Inject token bytes into SQLite diff --git a/Tests/GRDBTests/CompilationProtocolTests.swift b/Tests/GRDBTests/CompilationProtocolTests.swift index 25eebc7156..183fd89edb 100644 --- a/Tests/GRDBTests/CompilationProtocolTests.swift +++ b/Tests/GRDBTests/CompilationProtocolTests.swift @@ -52,7 +52,7 @@ private class UserDatabaseValueConvertible2 : DatabaseValueConvertible { #if SQLITE_ENABLE_FTS5 private class UserFTS5Tokenizer : FTS5Tokenizer { - func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: CInt, tokenCallback: @escaping FTS5TokenCallback) -> CInt { preconditionFailure() } + func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: CInt, tokenCallback: @escaping FTS5TokenCallback) -> CInt { preconditionFailure() } } #endif @@ -62,7 +62,7 @@ private class UserFTS5Tokenizer : FTS5Tokenizer { private class UserFTS5CustomTokenizer : FTS5CustomTokenizer { static let name: String = "UserFTS5CustomTokenizer" required init(db: Database, arguments: [String]) throws { preconditionFailure() } - func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: CInt, tokenCallback: @escaping FTS5TokenCallback) -> CInt { preconditionFailure() } + func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: CInt, tokenCallback: @escaping FTS5TokenCallback) -> CInt { preconditionFailure() } } #endif diff --git a/Tests/GRDBTests/FTS5CustomTokenizerTests.swift b/Tests/GRDBTests/FTS5CustomTokenizerTests.swift index 0c665b2b81..f5d76765d6 100644 --- a/Tests/GRDBTests/FTS5CustomTokenizerTests.swift +++ b/Tests/GRDBTests/FTS5CustomTokenizerTests.swift @@ -23,7 +23,7 @@ private final class StopWordsTokenizer : FTS5CustomTokenizer { // TODO: test that deinit is called } - func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: Int32, tokenCallback: @escaping FTS5TokenCallback) -> Int32 { + func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: Int32, tokenCallback: @escaping FTS5TokenCallback) -> Int32 { // The way we implement stop words is by letting wrappedTokenizer do its // job but intercepting its tokens before they feed SQLite. @@ -76,7 +76,7 @@ private final class NFKCTokenizer : FTS5CustomTokenizer { // TODO: test that deinit is called } - func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: Int32, tokenCallback: @escaping FTS5TokenCallback) -> Int32 { + func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: Int32, tokenCallback: @escaping FTS5TokenCallback) -> Int32 { // The way we implement NFKC conversion is by letting wrappedTokenizer // do its job, but intercepting its tokens before they feed SQLite. @@ -107,7 +107,7 @@ private final class NFKCTokenizer : FTS5CustomTokenizer { guard let addr = buffer.baseAddress else { return 0 // SQLITE_OK } - let pToken = UnsafeMutableRawPointer(mutating: addr).assumingMemoryBound(to: Int8.self) + let pToken = UnsafeMutableRawPointer(mutating: addr).assumingMemoryBound(to: CChar.self) let nToken = Int32(buffer.count) return customContext.tokenCallback(customContext.context, flags, pToken, nToken, iStart, iEnd) } @@ -135,7 +135,7 @@ private final class SynonymsTokenizer : FTS5CustomTokenizer { // TODO: test that deinit is called } - func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: Int32, tokenCallback: @escaping FTS5TokenCallback) -> Int32 { + func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: Int32, tokenCallback: @escaping FTS5TokenCallback) -> Int32 { // Don't look for synonyms when tokenizing queries, as advised by // https://www.sqlite.org/fts5.html#synonym_support if tokenization.contains(.query) { @@ -176,7 +176,7 @@ private final class SynonymsTokenizer : FTS5CustomTokenizer { guard let addr = buffer.baseAddress else { return 0 // SQLITE_OK } - let pToken = UnsafeMutableRawPointer(mutating: addr).assumingMemoryBound(to: Int8.self) + let pToken = UnsafeMutableRawPointer(mutating: addr).assumingMemoryBound(to: CChar.self) let nToken = Int32(buffer.count) // Set FTS5_TOKEN_COLOCATED for all but first token let synonymFlags = (index == 0) ? flags : flags | 1 // 1: FTS5_TOKEN_COLOCATED