Title: [278647] trunk/Source
Revision
278647
Author
wei...@apple.com
Date
2021-06-08 22:03:32 -0700 (Tue, 08 Jun 2021)

Log Message

Adopt WTF::Span in SQLiteStatement
https://bugs.webkit.org/show_bug.cgi?id=226773

Reviewed by Alex Christensen.

Source/WebCore:

Do some initial adoption of WTF::Span by adopting it in SQLiteStatement.

- Removes class BlobView.
- Renames columnBlobView to columnBlobAsSpan() (mirrors columnBlobAsString() naming)
  and have it return a Span<const uint8_t>.
- Replace bindBlob(int index, const void* blob, int size) with bindBlob(int index, Span<const uint8_t>).

Due to implicit construction for types with data() and size() functions (actually anything
that std::data() and std::size() can reason about), Vector and SharedBuffer cleanly work
to convert to Span of the same underlying type. This means that many callers of bindBlob
are now simpler, as instead of doing:

    bindBlob(1, foo->data(), foo->size());

we instead do:

    bindBlob(1, *foo);

There is much much more to do to take advantage of this new type, but this is
kept intentionally small, as the pulling back the onion can go very deep.

* Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
(WebCore::IDBServer::SQLiteIDBBackingStore::migrateIndexInfoTableForIDUpdate):
(WebCore::IDBServer::SQLiteIDBBackingStore::migrateIndexRecordsTableForIDUpdate):
(WebCore::IDBServer::SQLiteIDBBackingStore::addExistingIndex):
(WebCore::IDBServer::SQLiteIDBBackingStore::extractExistingDatabaseInfo):
(WebCore::IDBServer::SQLiteIDBBackingStore::createObjectStore):
(WebCore::IDBServer::SQLiteIDBBackingStore::createIndex):
(WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedHasIndexRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedPutIndexRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::keyExistsInObjectStore):
(WebCore::IDBServer::SQLiteIDBBackingStore::deleteRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::addRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::getRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::getAllObjectStoreRecords):
(WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedGetIndexRecordForOneKey):
(WebCore::IDBServer::SQLiteIDBBackingStore::getCount):
* Modules/indexeddb/server/SQLiteIDBCursor.cpp:
(WebCore::IDBServer::SQLiteIDBCursor::bindArguments):
(WebCore::IDBServer::SQLiteIDBCursor::resetAndRebindPreIndexStatementIfNecessary):
(WebCore::IDBServer::SQLiteIDBCursor::internalFetchNextRecord):
* loader/appcache/ApplicationCacheStorage.cpp:
(WebCore::ApplicationCacheStorage::store):
* platform/sql/SQLiteStatement.cpp:
(WebCore::SQLiteStatement::bindBlob):
(WebCore::SQLiteStatement::columnBlob):
(WebCore::SQLiteStatement::columnBlobAsSpan):
(WebCore::SQLiteStatement::columnBlobView): Deleted.
* platform/sql/SQLiteStatement.h:
(WebCore::SQLiteStatement::BlobView::BlobView): Deleted.
(WebCore::SQLiteStatement::BlobView::data): Deleted.
(WebCore::SQLiteStatement::BlobView::size): Deleted.
(): Deleted.
* workers/service/server/RegistrationDatabase.cpp:
(WebCore::RegistrationDatabase::doPushChanges):
(WebCore::RegistrationDatabase::importRecords):

Source/WebKit:

* UIProcess/API/glib/IconDatabase.cpp:
(WebKit::IconDatabase::addIcon):
Adopt new bindBlob() signature.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (278646 => 278647)


--- trunk/Source/WebCore/ChangeLog	2021-06-09 04:38:35 UTC (rev 278646)
+++ trunk/Source/WebCore/ChangeLog	2021-06-09 05:03:32 UTC (rev 278647)
@@ -1,3 +1,67 @@
+2021-06-08  Sam Weinig  <wei...@apple.com>
+
+        Adopt WTF::Span in SQLiteStatement
+        https://bugs.webkit.org/show_bug.cgi?id=226773
+
+        Reviewed by Alex Christensen.
+
+        Do some initial adoption of WTF::Span by adopting it in SQLiteStatement.
+        
+        - Removes class BlobView.
+        - Renames columnBlobView to columnBlobAsSpan() (mirrors columnBlobAsString() naming)
+          and have it return a Span<const uint8_t>.
+        - Replace bindBlob(int index, const void* blob, int size) with bindBlob(int index, Span<const uint8_t>).
+
+        Due to implicit construction for types with data() and size() functions (actually anything
+        that std::data() and std::size() can reason about), Vector and SharedBuffer cleanly work
+        to convert to Span of the same underlying type. This means that many callers of bindBlob
+        are now simpler, as instead of doing:
+
+            bindBlob(1, foo->data(), foo->size());
+
+        we instead do:
+
+            bindBlob(1, *foo);
+
+        There is much much more to do to take advantage of this new type, but this is
+        kept intentionally small, as the pulling back the onion can go very deep. 
+
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
+        (WebCore::IDBServer::SQLiteIDBBackingStore::migrateIndexInfoTableForIDUpdate):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::migrateIndexRecordsTableForIDUpdate):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::addExistingIndex):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::extractExistingDatabaseInfo):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::createObjectStore):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::createIndex):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedHasIndexRecord):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedPutIndexRecord):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::keyExistsInObjectStore):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::deleteRecord):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::addRecord):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::getRecord):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::getAllObjectStoreRecords):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedGetIndexRecordForOneKey):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::getCount):
+        * Modules/indexeddb/server/SQLiteIDBCursor.cpp:
+        (WebCore::IDBServer::SQLiteIDBCursor::bindArguments):
+        (WebCore::IDBServer::SQLiteIDBCursor::resetAndRebindPreIndexStatementIfNecessary):
+        (WebCore::IDBServer::SQLiteIDBCursor::internalFetchNextRecord):
+        * loader/appcache/ApplicationCacheStorage.cpp:
+        (WebCore::ApplicationCacheStorage::store):
+        * platform/sql/SQLiteStatement.cpp:
+        (WebCore::SQLiteStatement::bindBlob):
+        (WebCore::SQLiteStatement::columnBlob):
+        (WebCore::SQLiteStatement::columnBlobAsSpan):
+        (WebCore::SQLiteStatement::columnBlobView): Deleted.
+        * platform/sql/SQLiteStatement.h:
+        (WebCore::SQLiteStatement::BlobView::BlobView): Deleted.
+        (WebCore::SQLiteStatement::BlobView::data): Deleted.
+        (WebCore::SQLiteStatement::BlobView::size): Deleted.
+        (): Deleted.
+        * workers/service/server/RegistrationDatabase.cpp:
+        (WebCore::RegistrationDatabase::doPushChanges):
+        (WebCore::RegistrationDatabase::importRecords):
+
 2021-06-08  Jean-Yves Avenard  <j...@apple.com>
 
         MediaPlayerPrivateRemote::didLoadingProgress should not send synchronous message to GPU process

Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp (278646 => 278647)


--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp	2021-06-09 04:38:35 UTC (rev 278646)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp	2021-06-09 05:03:32 UTC (rev 278647)
@@ -550,7 +550,7 @@
             String name = statement->columnText(1);
             uint64_t objectStoreID = statement->columnInt64(2);
             uint64_t newID = indexIDMap.get({ objectStoreID, id });
-            auto keyPathBufferView = statement->columnBlobView(3);
+            auto keyPathBufferSpan = statement->columnBlobAsSpan(3);
             bool unique = statement->columnInt(4);
             bool multiEntry = statement->columnInt(5);
 
@@ -559,7 +559,7 @@
                 || sql->bindInt64(1, newID) != SQLITE_OK
                 || sql->bindText(2, name) != SQLITE_OK
                 || sql->bindInt64(3, objectStoreID) != SQLITE_OK
-                || sql->bindBlob(4, keyPathBufferView.data(), keyPathBufferView.size()) != SQLITE_OK
+                || sql->bindBlob(4, keyPathBufferSpan) != SQLITE_OK
                 || sql->bindInt(5, unique) != SQLITE_OK
                 || sql->bindInt(6, multiEntry) != SQLITE_OK
                 || sql->step() != SQLITE_DONE) {
@@ -613,8 +613,8 @@
             uint64_t id = statement->columnInt64(0);
             uint64_t objectStoreID = statement->columnInt64(1);
             uint64_t newID = indexIDMap.get({ objectStoreID, id });
-            auto keyBufferView = statement->columnBlobView(2);
-            auto valueBufferView = statement->columnBlobView(3);
+            auto keyBufferSpan = statement->columnBlobAsSpan(2);
+            auto valueBufferSpan = statement->columnBlobAsSpan(3);
             uint64_t recordID = statement->columnInt64(4);
 
             auto sql = cachedStatement(SQL::PutTempIndexRecord, "INSERT INTO _Temp_IndexRecords VALUES (?, ?, CAST(? AS TEXT), CAST(? AS TEXT), ?);"_s);
@@ -621,8 +621,8 @@
             if (!sql
                 || sql->bindInt64(1, newID) != SQLITE_OK
                 || sql->bindInt64(2, objectStoreID) != SQLITE_OK
-                || sql->bindBlob(3, keyBufferView.data(), keyBufferView.size()) != SQLITE_OK
-                || sql->bindBlob(4, valueBufferView.data(), valueBufferView.size()) != SQLITE_OK
+                || sql->bindBlob(3, keyBufferSpan) != SQLITE_OK
+                || sql->bindBlob(4, valueBufferSpan) != SQLITE_OK
                 || sql->bindInt64(5, recordID) != SQLITE_OK
                 || sql->step() != SQLITE_DONE) {
                 LOG_ERROR("Error adding index record to _Temp_IndexRecords table (%i) - %s", database.lastError(), database.lastErrorMsg());
@@ -698,7 +698,7 @@
             || sql->bindInt64(1, info.identifier()) != SQLITE_OK
             || sql->bindText(2, info.name()) != SQLITE_OK
             || sql->bindInt64(3, info.objectStoreIdentifier()) != SQLITE_OK
-            || sql->bindBlob(4, keyPathBlob->data(), keyPathBlob->size()) != SQLITE_OK
+            || sql->bindBlob(4, *keyPathBlob) != SQLITE_OK
             || sql->bindInt(5, info.unique()) != SQLITE_OK
             || sql->bindInt(6, info.multiEntry()) != SQLITE_OK
             || sql->step() != SQLITE_DONE) {
@@ -717,9 +717,9 @@
 
         int result = sql->step();
         while (result == SQLITE_ROW) {
-            auto keyBufferView = sql->columnBlobView(0);
+            auto keyBufferSpan = sql->columnBlobAsSpan(0);
             IDBKeyData keyData;
-            if (!deserializeIDBKeyData(keyBufferView.data(), keyBufferView.size(), keyData)) {
+            if (!deserializeIDBKeyData(keyBufferSpan.data(), keyBufferSpan.size(), keyData)) {
                 LOG_ERROR("Unable to deserialize key data from database while getting all records");
                 return false;
             }
@@ -818,10 +818,10 @@
         while (result == SQLITE_ROW) {
             uint64_t objectStoreID = sql->columnInt64(0);
             String objectStoreName = sql->columnText(1);
-            auto keyPathBufferView = sql->columnBlobView(2);
+            auto keyPathBufferSpan = sql->columnBlobAsSpan(2);
 
             std::optional<IDBKeyPath> objectStoreKeyPath;
-            if (!deserializeIDBKeyPath(keyPathBufferView.data(), keyPathBufferView.size(), objectStoreKeyPath)) {
+            if (!deserializeIDBKeyPath(keyPathBufferSpan.data(), keyPathBufferSpan.size(), objectStoreKeyPath)) {
                 LOG_ERROR("Unable to extract key path from database");
                 return nullptr;
             }
@@ -854,10 +854,10 @@
             uint64_t indexID = sql->columnInt64(0);
             String indexName = sql->columnText(1);
             uint64_t objectStoreID = sql->columnInt64(2);
-            auto keyPathBufferView = sql->columnBlobView(3);
+            auto keyPathBufferSpan = sql->columnBlobAsSpan(3);
 
             std::optional<IDBKeyPath> indexKeyPath;
-            if (!deserializeIDBKeyPath(keyPathBufferView.data(), keyPathBufferView.size(), indexKeyPath)) {
+            if (!deserializeIDBKeyPath(keyPathBufferSpan.data(), keyPathBufferSpan.size(), indexKeyPath)) {
                 LOG_ERROR("Unable to extract key path from database");
                 return nullptr;
             }
@@ -1182,7 +1182,7 @@
         if (!sql
             || sql->bindInt64(1, info.identifier()) != SQLITE_OK
             || sql->bindText(2, info.name()) != SQLITE_OK
-            || sql->bindBlob(3, keyPathBlob->data(), keyPathBlob->size()) != SQLITE_OK
+            || sql->bindBlob(3, *keyPathBlob) != SQLITE_OK
             || sql->bindInt(4, info.autoIncrement()) != SQLITE_OK
             || sql->step() != SQLITE_DONE) {
             LOG_ERROR("Could not add object store '%s' to ObjectStoreInfo table (%i) - %s", info.name().utf8().data(), m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
@@ -1396,7 +1396,7 @@
             || sql->bindInt64(1, info.identifier()) != SQLITE_OK
             || sql->bindText(2, info.name()) != SQLITE_OK
             || sql->bindInt64(3, info.objectStoreIdentifier()) != SQLITE_OK
-            || sql->bindBlob(4, keyPathBlob->data(), keyPathBlob->size()) != SQLITE_OK
+            || sql->bindBlob(4, *keyPathBlob) != SQLITE_OK
             || sql->bindInt(5, info.unique()) != SQLITE_OK
             || sql->bindInt(6, info.multiEntry()) != SQLITE_OK
             || sql->step() != SQLITE_DONE) {
@@ -1470,7 +1470,7 @@
     auto sql = cachedStatement(SQL::HasIndexRecord, "SELECT rowid FROM IndexRecords WHERE indexID = ? AND key = CAST(? AS TEXT);"_s);
     if (!sql
         || sql->bindInt64(1, info.identifier()) != SQLITE_OK
-        || sql->bindBlob(2, indexKeyBuffer->data(), indexKeyBuffer->size()) != SQLITE_OK) {
+        || sql->bindBlob(2, *indexKeyBuffer) != SQLITE_OK) {
         LOG_ERROR("Error checking for index record in database");
         return IDBError { UnknownError, "Error checking for index record in database"_s };
     }
@@ -1547,8 +1547,8 @@
         if (!sql
             || sql->bindInt64(1, indexID) != SQLITE_OK
             || sql->bindInt64(2, objectStoreID) != SQLITE_OK
-            || sql->bindBlob(3, indexKeyBuffer->data(), indexKeyBuffer->size()) != SQLITE_OK
-            || sql->bindBlob(4, valueBuffer->data(), valueBuffer->size()) != SQLITE_OK
+            || sql->bindBlob(3, *indexKeyBuffer) != SQLITE_OK
+            || sql->bindBlob(4, *valueBuffer) != SQLITE_OK
             || sql->bindInt64(5, recordID) != SQLITE_OK
             || sql->step() != SQLITE_DONE) {
             LOG_ERROR("Could not put index record for index %" PRIi64 " in object store %" PRIi64 " in Records table (%i) - %s", indexID, objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
@@ -1666,7 +1666,7 @@
     auto sql = cachedStatement(SQL::KeyExistsInObjectStore, "SELECT key FROM Records WHERE objectStoreID = ? AND key = CAST(? AS TEXT) LIMIT 1;"_s);
     if (!sql
         || sql->bindInt64(1, objectStoreID) != SQLITE_OK
-        || sql->bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLITE_OK) {
+        || sql->bindBlob(2, *keyBuffer) != SQLITE_OK) {
         LOG_ERROR("Could not get record from object store %" PRIi64 " from Records table (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
         return IDBError { UnknownError, "Unable to check for existence of IDBKey in object store"_s };
     }
@@ -1752,7 +1752,7 @@
 
         if (!sql
             || sql->bindInt64(1, objectStoreID) != SQLITE_OK
-            || sql->bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLITE_OK) {
+            || sql->bindBlob(2, *keyBuffer) != SQLITE_OK) {
             LOG_ERROR("Could not delete record from object store %" PRIi64 " (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
             return IDBError { UnknownError, "Failed to delete record from object store"_s };
         }
@@ -1799,7 +1799,7 @@
 
         if (!sql
             || sql->bindInt64(1, objectStoreID) != SQLITE_OK
-            || sql->bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLITE_OK
+            || sql->bindBlob(2, *keyBuffer) != SQLITE_OK
             || sql->step() != SQLITE_DONE) {
             LOG_ERROR("Could not delete record from object store %" PRIi64 " (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
             return IDBError { UnknownError, "Failed to delete record from object store"_s };
@@ -1970,8 +1970,8 @@
         auto sql = cachedStatement(SQL::AddObjectStoreRecord, "INSERT INTO Records VALUES (?, CAST(? AS TEXT), ?, NULL);"_s);
         if (!sql
             || sql->bindInt64(1, objectStoreInfo.identifier()) != SQLITE_OK
-            || sql->bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLITE_OK
-            || sql->bindBlob(3, value.data().data()->data(), value.data().data()->size()) != SQLITE_OK
+            || sql->bindBlob(2, *keyBuffer) != SQLITE_OK
+            || sql->bindBlob(3, *value.data().data()) != SQLITE_OK
             || sql->step() != SQLITE_DONE) {
             LOG_ERROR("Could not put record for object store %" PRIi64 " in Records table (%i) - %s", objectStoreInfo.identifier(), m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
             return IDBError { UnknownError, "Unable to store record in object store"_s };
@@ -1986,7 +1986,7 @@
         auto sql = cachedStatement(SQL::DeleteObjectStoreRecord, "DELETE FROM Records WHERE objectStoreID = ? AND key = CAST(? AS TEXT);"_s);
         if (!sql
             || sql->bindInt64(1, objectStoreInfo.identifier()) != SQLITE_OK
-            || sql->bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLITE_OK
+            || sql->bindBlob(2, *keyBuffer) != SQLITE_OK
             || sql->step() != SQLITE_DONE) {
             LOG_ERROR("Indexing new object store record failed, but unable to remove the object store record itself");
             return IDBError { UnknownError, "Indexing new object store record failed, but unable to remove the object store record itself"_s };
@@ -2171,8 +2171,8 @@
 
         if (!sql
             || sql->bindInt64(1, objectStoreID) != SQLITE_OK
-            || sql->bindBlob(2, lowerBuffer->data(), lowerBuffer->size()) != SQLITE_OK
-            || sql->bindBlob(3, upperBuffer->data(), upperBuffer->size()) != SQLITE_OK) {
+            || sql->bindBlob(2, *lowerBuffer) != SQLITE_OK
+            || sql->bindBlob(3, *upperBuffer) != SQLITE_OK) {
             LOG_ERROR("Could not get key range record from object store %" PRIi64 " from Records table (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
             return IDBError { UnknownError, "Failed to look up record in object store by key range"_s };
         }
@@ -2288,8 +2288,8 @@
     auto sql = cachedStatementForGetAllObjectStoreRecords(getAllRecordsData);
     if (!sql
         || sql->bindInt64(1, getAllRecordsData.objectStoreIdentifier) != SQLITE_OK
-        || sql->bindBlob(2, lowerBuffer->data(), lowerBuffer->size()) != SQLITE_OK
-        || sql->bindBlob(3, upperBuffer->data(), upperBuffer->size()) != SQLITE_OK) {
+        || sql->bindBlob(2, *lowerBuffer) != SQLITE_OK
+        || sql->bindBlob(3, *upperBuffer) != SQLITE_OK) {
         LOG_ERROR("Could not get key range record from object store %" PRIi64 " from Records table (%i) - %s", getAllRecordsData.objectStoreIdentifier, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
         return IDBError { UnknownError, "Failed to look up record in object store by key range"_s };
     }
@@ -2308,9 +2308,9 @@
     uint32_t returnedResults = 0;
 
     while (sqlResult == SQLITE_ROW && returnedResults < targetResults) {
-        auto keyBufferView = sql->columnBlobView(0);
+        auto keyBufferSpan = sql->columnBlobAsSpan(0);
         IDBKeyData keyData;
-        if (!deserializeIDBKeyData(keyBufferView.data(), keyBufferView.size(), keyData)) {
+        if (!deserializeIDBKeyData(keyBufferSpan.data(), keyBufferSpan.size(), keyData)) {
             LOG_ERROR("Unable to deserialize key data from database while getting all records");
             return IDBError { UnknownError, "Unable to deserialize key data while getting all records"_s };
         }
@@ -2450,7 +2450,7 @@
 
     if (!sql
         || sql->bindInt64(1, indexID) != SQLITE_OK
-        || sql->bindBlob(2, buffer->data(), buffer->size()) != SQLITE_OK) {
+        || sql->bindBlob(2, *buffer) != SQLITE_OK) {
         LOG_ERROR("Unable to lookup index record in database");
         return IDBError { UnknownError, "Unable to lookup index record in database"_s };
     }
@@ -2465,9 +2465,9 @@
         return IDBError { };
 
     IDBKeyData objectStoreKey;
-    auto keyView = sql->columnBlobView(0);
+    auto keySpan = sql->columnBlobAsSpan(0);
 
-    if (!deserializeIDBKeyData(keyView.data(), keyView.size(), objectStoreKey)) {
+    if (!deserializeIDBKeyData(keySpan.data(), keySpan.size(), objectStoreKey)) {
         LOG_ERROR("Unable to deserialize key looking up index record in database");
         return IDBError { UnknownError, "Unable to deserialize key looking up index record in database"_s };
     }
@@ -2532,8 +2532,8 @@
         
         if (!statement
             || statement->bindInt64(1, objectStoreIdentifier) != SQLITE_OK
-            || statement->bindBlob(2, lowerBuffer->data(), lowerBuffer->size()) != SQLITE_OK
-            || statement->bindBlob(3, upperBuffer->data(), upperBuffer->size()) != SQLITE_OK) {
+            || statement->bindBlob(2, *lowerBuffer) != SQLITE_OK
+            || statement->bindBlob(3, *upperBuffer) != SQLITE_OK) {
             LOG_ERROR("Could not count records in object store %" PRIi64 " from Records table (%i) - %s", objectStoreIdentifier, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
             return IDBError { UnknownError, "Unable to count records in object store due to binding failure"_s };
         }
@@ -2549,8 +2549,8 @@
 
         if (!statement
             || statement->bindInt64(1, indexIdentifier) != SQLITE_OK
-            || statement->bindBlob(2, lowerBuffer->data(), lowerBuffer->size()) != SQLITE_OK
-            || statement->bindBlob(3, upperBuffer->data(), upperBuffer->size()) != SQLITE_OK) {
+            || statement->bindBlob(2, *lowerBuffer) != SQLITE_OK
+            || statement->bindBlob(3, *upperBuffer) != SQLITE_OK) {
             LOG_ERROR("Could not count records with index %" PRIi64 " from IndexRecords table (%i) - %s", indexIdentifier, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
             return IDBError { UnknownError, "Unable to count records for index due to binding failure"_s };
         }

Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp (278646 => 278647)


--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp	2021-06-09 04:38:35 UTC (rev 278646)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp	2021-06-09 05:03:32 UTC (rev 278647)
@@ -270,13 +270,13 @@
     }
 
     RefPtr<SharedBuffer> buffer = serializeIDBKeyData(m_currentLowerKey);
-    if (m_statement->bindBlob(currentBindArgument++, buffer->data(), buffer->size()) != SQLITE_OK) {
+    if (m_statement->bindBlob(currentBindArgument++, *buffer) != SQLITE_OK) {
         LOG_ERROR("Could not create cursor statement (lower key)");
         return false;
     }
 
     buffer = serializeIDBKeyData(m_currentUpperKey);
-    if (m_statement->bindBlob(currentBindArgument++, buffer->data(), buffer->size()) != SQLITE_OK) {
+    if (m_statement->bindBlob(currentBindArgument++, *buffer) != SQLITE_OK) {
         LOG_ERROR("Could not create cursor statement (upper key)");
         return false;
     }
@@ -316,13 +316,13 @@
     }
 
     RefPtr<SharedBuffer> buffer = serializeIDBKeyData(key);
-    if (m_preIndexStatement->bindBlob(currentBindArgument++, buffer->data(), buffer->size()) != SQLITE_OK) {
+    if (m_preIndexStatement->bindBlob(currentBindArgument++, *buffer) != SQLITE_OK) {
         LOG_ERROR("Could not bind id argument to pre statement (key)");
         return false;
     }
 
     buffer = serializeIDBKeyData(m_currentIndexRecordValue);
-    if (m_preIndexStatement->bindBlob(currentBindArgument++, buffer->data(), buffer->size()) != SQLITE_OK) {
+    if (m_preIndexStatement->bindBlob(currentBindArgument++, *buffer) != SQLITE_OK) {
         LOG_ERROR("Could not bind id argument to pre statement (value)");
         return false;
     }
@@ -507,9 +507,9 @@
 
     record.rowID = statement->columnInt64(0);
     ASSERT(record.rowID);
-    auto keyDataView = statement->columnBlobView(1);
+    auto keyDataSpan = statement->columnBlobAsSpan(1);
 
-    if (!deserializeIDBKeyData(keyDataView.data(), keyDataView.size(), record.record.key)) {
+    if (!deserializeIDBKeyData(keyDataSpan.data(), keyDataSpan.size(), record.record.key)) {
         LOG_ERROR("Unable to deserialize key data from database while advancing cursor");
         markAsErrored(record);
         return FetchResult::Failure;
@@ -544,7 +544,7 @@
         }
 
         if (!m_cachedObjectStoreStatement
-            || m_cachedObjectStoreStatement->bindBlob(1, keyData.data(), keyData.size()) != SQLITE_OK
+            || m_cachedObjectStoreStatement->bindBlob(1, keyData) != SQLITE_OK
             || m_cachedObjectStoreStatement->bindInt64(2, m_objectStoreID) != SQLITE_OK) {
             LOG_ERROR("Could not create index cursor statement into object store records (%i) '%s'", database.lastError(), database.lastErrorMsg());
             markAsErrored(record);

Modified: trunk/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp (278646 => 278647)


--- trunk/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp	2021-06-09 04:38:35 UTC (rev 278646)
+++ trunk/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp	2021-06-09 05:03:32 UTC (rev 278647)
@@ -815,7 +815,7 @@
         dataStatement->bindText(2, path);
     } else {
         if (resource->data().size())
-            dataStatement->bindBlob(1, resource->data().data(), resource->data().size());
+            dataStatement->bindBlob(1, resource->data());
     }
     
     if (!dataStatement->executeCommand()) {

Modified: trunk/Source/WebCore/platform/sql/SQLiteStatement.cpp (278646 => 278647)


--- trunk/Source/WebCore/platform/sql/SQLiteStatement.cpp	2021-06-09 04:38:35 UTC (rev 278646)
+++ trunk/Source/WebCore/platform/sql/SQLiteStatement.cpp	2021-06-09 05:03:32 UTC (rev 278647)
@@ -85,14 +85,14 @@
     return step() == SQLITE_DONE;
 }
 
-int SQLiteStatement::bindBlob(int index, const void* blob, int size)
+int SQLiteStatement::bindBlob(int index, Span<const uint8_t> blob)
 {
     ASSERT(index > 0);
     ASSERT(static_cast<unsigned>(index) <= bindParameterCount());
-    ASSERT(blob || !size);
-    ASSERT(size >= 0);
+    ASSERT(blob.data() || !blob.size());
+    ASSERT(blob.size() >= 0);
 
-    return sqlite3_bind_blob(m_statement, index, blob, size, SQLITE_TRANSIENT);
+    return sqlite3_bind_blob(m_statement, index, blob.data(), blob.size(), SQLITE_TRANSIENT);
 }
 
 int SQLiteStatement::bindBlob(int index, const String& text)
@@ -107,7 +107,7 @@
     else
         characters = upconvertedCharacters;
 
-    return bindBlob(index, characters, text.length() * sizeof(UChar));
+    return bindBlob(index, Span { reinterpret_cast<const uint8_t*>(characters), text.length() * sizeof(UChar) });
 }
 
 int SQLiteStatement::bindText(int index, StringView text)
@@ -282,11 +282,11 @@
 
 Vector<uint8_t> SQLiteStatement::columnBlob(int col)
 {
-    auto blobView = columnBlobView(col);
-    return { blobView.data(), blobView.size() };
+    auto span = columnBlobAsSpan(col);
+    return { span.data(), span.size() };
 }
 
-auto SQLiteStatement::columnBlobView(int col) -> BlobView
+Span<const uint8_t> SQLiteStatement::columnBlobAsSpan(int col)
 {
     ASSERT(col >= 0);
 

Modified: trunk/Source/WebCore/platform/sql/SQLiteStatement.h (278646 => 278647)


--- trunk/Source/WebCore/platform/sql/SQLiteStatement.h	2021-06-09 04:38:35 UTC (rev 278646)
+++ trunk/Source/WebCore/platform/sql/SQLiteStatement.h	2021-06-09 05:03:32 UTC (rev 278647)
@@ -27,6 +27,7 @@
 
 #include "SQLValue.h"
 #include "SQLiteDatabase.h"
+#include <wtf/Span.h>
 
 struct sqlite3_stmt;
 
@@ -38,7 +39,7 @@
     WEBCORE_EXPORT ~SQLiteStatement();
     WEBCORE_EXPORT SQLiteStatement(SQLiteStatement&&);
     
-    WEBCORE_EXPORT int bindBlob(int index, const void* blob, int size);
+    WEBCORE_EXPORT int bindBlob(int index, Span<const uint8_t>);
     WEBCORE_EXPORT int bindBlob(int index, const String&);
     WEBCORE_EXPORT int bindText(int index, StringView);
     WEBCORE_EXPORT int bindInt(int index, int);
@@ -72,24 +73,9 @@
     WEBCORE_EXPORT String columnBlobAsString(int col);
     WEBCORE_EXPORT Vector<uint8_t> columnBlob(int col);
 
-    class BlobView {
-    public:
-        BlobView() = default;
-        BlobView(const uint8_t* data, size_t size)
-            : m_data(data)
-            , m_size(size)
-        { }
+    // The returned Span stays valid until the next step() / reset() or destruction of the statement.
+    Span<const uint8_t> columnBlobAsSpan(int col);
 
-        const uint8_t* data() { return m_data; }
-        size_t size() { return m_size; }
-
-    private:
-        const uint8_t* m_data { nullptr };
-        const size_t m_size { 0 };
-    };
-    // The returned BlobView stays valid until the next step() / reset() or destruction of the statement.
-    BlobView columnBlobView(int col);
-
     SQLiteDatabase& database() { return m_database; }
     
 private:

Modified: trunk/Source/WebCore/workers/service/server/RegistrationDatabase.cpp (278646 => 278647)


--- trunk/Source/WebCore/workers/service/server/RegistrationDatabase.cpp	2021-06-09 04:38:35 UTC (rev 278646)
+++ trunk/Source/WebCore/workers/service/server/RegistrationDatabase.cpp	2021-06-09 05:03:32 UTC (rev 278647)
@@ -459,10 +459,10 @@
             || insertStatement->bindText(6, updateViaCacheToString(data.registration.updateViaCache)) != SQLITE_OK
             || insertStatement->bindText(7, data.scriptURL.string()) != SQLITE_OK
             || insertStatement->bindText(8, workerTypeToString(data.workerType)) != SQLITE_OK
-            || insertStatement->bindBlob(9, cspEncoder.buffer(), cspEncoder.bufferSize()) != SQLITE_OK
+            || insertStatement->bindBlob(9, Span { cspEncoder.buffer(), cspEncoder.bufferSize() }) != SQLITE_OK
             || insertStatement->bindText(10, data.referrerPolicy) != SQLITE_OK
-            || insertStatement->bindBlob(11, scriptResourceMapEncoder.buffer(), scriptResourceMapEncoder.bufferSize()) != SQLITE_OK
-            || insertStatement->bindBlob(12, certificateInfoEncoder.buffer(), certificateInfoEncoder.bufferSize()) != SQLITE_OK
+            || insertStatement->bindBlob(11, Span { scriptResourceMapEncoder.buffer(), scriptResourceMapEncoder.bufferSize() }) != SQLITE_OK
+            || insertStatement->bindBlob(12, Span { certificateInfoEncoder.buffer(), certificateInfoEncoder.bufferSize() }) != SQLITE_OK
             || insertStatement->step() != SQLITE_DONE) {
             RELEASE_LOG_ERROR(ServiceWorker, "Failed to store registration data into records table (%i) - %s", m_database->lastError(), m_database->lastErrorMsg());
             return false;
@@ -515,9 +515,9 @@
         auto workerType = stringToWorkerType(sql->columnText(7));
 
         std::optional<ContentSecurityPolicyResponseHeaders> contentSecurityPolicy;
-        auto contentSecurityPolicyDataView = sql->columnBlobView(8);
-        if (contentSecurityPolicyDataView.size()) {
-            WTF::Persistence::Decoder cspDecoder(contentSecurityPolicyDataView.data(), contentSecurityPolicyDataView.size());
+        auto contentSecurityPolicyDataSpan = sql->columnBlobAsSpan(8);
+        if (contentSecurityPolicyDataSpan.size()) {
+            WTF::Persistence::Decoder cspDecoder(contentSecurityPolicyDataSpan.data(), contentSecurityPolicyDataSpan.size());
             cspDecoder >> contentSecurityPolicy;
             if (!contentSecurityPolicy) {
                 RELEASE_LOG_ERROR(ServiceWorker, "RegistrationDatabase::importRecords: Failed to decode contentSecurityPolicy");
@@ -528,9 +528,9 @@
         auto referrerPolicy = sql->columnText(9);
 
         HashMap<URL, ServiceWorkerContextData::ImportedScript> scriptResourceMap;
-        auto scriptResourceMapDataView = sql->columnBlobView(10);
-        if (scriptResourceMapDataView.size()) {
-            WTF::Persistence::Decoder scriptResourceMapDecoder(scriptResourceMapDataView.data(), scriptResourceMapDataView.size());
+        auto scriptResourceMapDataSpan = sql->columnBlobAsSpan(10);
+        if (scriptResourceMapDataSpan.size()) {
+            WTF::Persistence::Decoder scriptResourceMapDecoder(scriptResourceMapDataSpan.data(), scriptResourceMapDataSpan.size());
             std::optional<HashMap<URL, ImportedScriptAttributes>> scriptResourceMapWithoutScripts;
             scriptResourceMapDecoder >> scriptResourceMapWithoutScripts;
             if (!scriptResourceMapWithoutScripts) {
@@ -540,10 +540,10 @@
             scriptResourceMap = populateScriptSourcesFromDisk(scriptStorage(), *key, WTFMove(*scriptResourceMapWithoutScripts));
         }
 
-        auto certificateInfoDataView = sql->columnBlobView(11);
+        auto certificateInfoDataSpan = sql->columnBlobAsSpan(11);
         std::optional<CertificateInfo> certificateInfo;
 
-        WTF::Persistence::Decoder certificateInfoDecoder(certificateInfoDataView.data(), certificateInfoDataView.size());
+        WTF::Persistence::Decoder certificateInfoDecoder(certificateInfoDataSpan.data(), certificateInfoDataSpan.size());
         certificateInfoDecoder >> certificateInfo;
         if (!certificateInfo) {
             RELEASE_LOG_ERROR(ServiceWorker, "RegistrationDatabase::importRecords: Failed to decode certificateInfo");

Modified: trunk/Source/WebKit/ChangeLog (278646 => 278647)


--- trunk/Source/WebKit/ChangeLog	2021-06-09 04:38:35 UTC (rev 278646)
+++ trunk/Source/WebKit/ChangeLog	2021-06-09 05:03:32 UTC (rev 278647)
@@ -1,3 +1,14 @@
+2021-06-08  Sam Weinig  <wei...@apple.com>
+
+        Adopt WTF::Span in SQLiteStatement
+        https://bugs.webkit.org/show_bug.cgi?id=226773
+
+        Reviewed by Alex Christensen.
+
+        * UIProcess/API/glib/IconDatabase.cpp:
+        (WebKit::IconDatabase::addIcon):
+        Adopt new bindBlob() signature.
+
 2021-06-08  Jean-Yves Avenard  <j...@apple.com>
 
         MediaPlayerPrivateRemote::didLoadingProgress should not send synchronous message to GPU process

Modified: trunk/Source/WebKit/UIProcess/API/glib/IconDatabase.cpp (278646 => 278647)


--- trunk/Source/WebKit/UIProcess/API/glib/IconDatabase.cpp	2021-06-09 04:38:35 UTC (rev 278646)
+++ trunk/Source/WebKit/UIProcess/API/glib/IconDatabase.cpp	2021-06-09 05:03:32 UTC (rev 278647)
@@ -398,7 +398,7 @@
     m_addIconStatement->reset();
 
     auto iconID = m_db.lastInsertRowID();
-    if (m_addIconDataStatement->bindInt64(1, iconID) != SQLITE_OK || m_addIconDataStatement->bindBlob(2, iconData.data(), iconData.size()) != SQLITE_OK) {
+    if (m_addIconDataStatement->bindInt64(1, iconID) != SQLITE_OK || m_addIconDataStatement->bindBlob(2, iconData) != SQLITE_OK) {
         LOG_ERROR("IconDatabase::addIcon failed: %s", m_db.lastErrorMsg());
         return std::nullopt;
     }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to