diff --git a/Sources/CSQLite/sqlite3.c b/Sources/CSQLite/sqlite3.c index 536e9b1..01a3eb8 100644 --- a/Sources/CSQLite/sqlite3.c +++ b/Sources/CSQLite/sqlite3.c @@ -1,3 +1,5 @@ +#pragma clang diagnostic ignored "-Wambiguous-macro" +#pragma clang diagnostic ignored "-Wshorten-64-to-32" /****************************************************************************** ** This file is an amalgamation of many separate C source files from SQLite ** version 3.41.2. By combining all the individual C code files into this @@ -165427,7 +165429,10 @@ SQLITE_API sqlite_int64 sqlite_nio_sqlite3_last_insert_rowid(sqlite3 *db){ return 0; } #endif - return db->lastRowid; + sqlite_nio_sqlite3_mutex_enter(db->mutex); + i64 lastRowId = db->lastRowid; + sqlite_nio_sqlite3_mutex_leave(db->mutex); + return lastRowId; } /* ** Set the value returned by the sqlite_nio_sqlite3_last_insert_rowid() API function. diff --git a/scripts/001-warnings-and-data-race.patch b/scripts/001-warnings-and-data-race.patch new file mode 100644 index 0000000..1ea7631 --- /dev/null +++ b/scripts/001-warnings-and-data-race.patch @@ -0,0 +1,23 @@ +diff --git a/Sources/CSQLite/sqlite3.c b/Sources/CSQLite/sqlite3.c +index 536e9b1..01a3eb8 100644 +--- a/Sources/CSQLite/sqlite3.c ++++ b/Sources/CSQLite/sqlite3.c +@@ -1,3 +1,5 @@ ++#pragma clang diagnostic ignored "-Wambiguous-macro" ++#pragma clang diagnostic ignored "-Wshorten-64-to-32" + /****************************************************************************** + ** This file is an amalgamation of many separate C source files from SQLite + ** version 3.41.2. By combining all the individual C code files into this +@@ -165427,7 +165429,10 @@ SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){ + return 0; + } + #endif +- return db->lastRowid; ++ sqlite3_mutex_enter(db->mutex); ++ i64 lastRowId = db->lastRowid; ++ sqlite3_mutex_leave(db->mutex); ++ return lastRowId; + } + /* + ** Set the value returned by the sqlite_nio_sqlite3_last_insert_rowid() API function. + diff --git a/scripts/vendor-sqlite3.swift b/scripts/vendor-sqlite3.swift index 38d2afc..1c82dc7 100644 --- a/scripts/vendor-sqlite3.swift +++ b/scripts/vendor-sqlite3.swift @@ -57,6 +57,7 @@ let sha3sum: URL! let swift: URL! let ar: URL! let nm: URL! +let patch: URL! do { unzip = try await ensureExecutable("unzip") sqlite3 = try await ensureExecutable("sqlite3") @@ -64,6 +65,7 @@ do { swift = try await ensureExecutable("swift") ar = try await ensureExecutable("ar") nm = try await ensureExecutable("nm") + patch = try await ensureExecutable("patch") try await main() } catch let error as String { @@ -130,6 +132,7 @@ func bumpVersion(_ args: ArraySlice) async throws { expectedSize: product.sizeInBytes, expectedSha3Sum: product.sha3Hash ) + try await applySQLitePatches() try await addVendorPrefixToSQLite() try product.version.stamp(from: product.downloadURL) print("Upgraded from \(String(describing: currentVersion)) to \(product.version)") @@ -185,6 +188,7 @@ func updateVersion(_ args: ArraySlice) async throws { let filename = "sqlite-amalgamation-\(version.asDownloadVersion).zip" let sqliteDownloadURL = URL(string: "\(sqliteURL)/\(year)/\(filename)")! try await downloadAndUnzipSQLite(from: sqliteDownloadURL, to: filename, expectedSize: nil, expectedSha3Sum: nil) + try await applySQLitePatches() try await addVendorPrefixToSQLite() try version.stamp(from: sqliteDownloadURL) print("Upgraded from \(String(describing: currentVersion)) to \(version)") @@ -440,6 +444,19 @@ func getSymbolsToPrefix() async throws -> [String] { return sortedSymbolsToRewrite.filter { !exclude.contains($0) } } +func applySQLitePatches() async throws { + try await subprocess(patch, [ + "-d", root.path, + "-p1", + "-u", + "-V", "none", + "-i", root + .appendingPathComponent("scripts", isDirectory: true) + .appendingPathComponent("001-warnings-and-data-race.patch", isDirectory: false) + .path, + ], captureStdout: false) +} + @discardableResult func subprocess(_ executable: URL, _ arguments: [String], captureStdout: Bool) async throws -> String? { let stdout = Pipe()