Bug 1638256 - Some casts and fixes in mozStorage to make clang-tidy happy. r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D181551
This commit is contained in:
Marco Bonardo 2023-06-24 10:11:28 +00:00
parent 95fe144ede
commit 016cc78dda
4 changed files with 33 additions and 22 deletions

View file

@ -10,6 +10,7 @@
#include "nsIFileURL.h"
#include "nsIXPConnect.h"
#include "mozilla/AppShutdown.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/Telemetry.h"
#include "mozilla/Mutex.h"
#include "mozilla/CondVar.h"
@ -138,15 +139,22 @@ int sqlite3_T_double(sqlite3_context* aCtx, double aValue) {
}
int sqlite3_T_text(sqlite3_context* aCtx, const nsCString& aValue) {
::sqlite3_result_text(aCtx, aValue.get(), aValue.Length(), SQLITE_TRANSIENT);
CheckedInt<int32_t> length(aValue.Length());
if (!length.isValid()) {
return SQLITE_MISUSE;
}
::sqlite3_result_text(aCtx, aValue.get(), length.value(), SQLITE_TRANSIENT);
return SQLITE_OK;
}
int sqlite3_T_text16(sqlite3_context* aCtx, const nsString& aValue) {
::sqlite3_result_text16(
aCtx, aValue.get(),
aValue.Length() * sizeof(char16_t), // Number of bytes.
SQLITE_TRANSIENT);
CheckedInt<int32_t> n_bytes =
CheckedInt<int32_t>(aValue.Length()) * sizeof(char16_t);
if (!n_bytes.isValid()) {
return SQLITE_MISUSE;
}
::sqlite3_result_text16(aCtx, aValue.get(), n_bytes.value(),
SQLITE_TRANSIENT);
return SQLITE_OK;
}
@ -1395,8 +1403,9 @@ int Connection::stepStatement(sqlite3* aNativeConnection,
: Telemetry::kSlowSQLThresholdForHelperThreads;
if (duration.ToMilliseconds() >= threshold) {
nsDependentCString statementString(::sqlite3_sql(aStatement));
Telemetry::RecordSlowSQLStatement(statementString, mTelemetryFilename,
duration.ToMilliseconds());
Telemetry::RecordSlowSQLStatement(
statementString, mTelemetryFilename,
static_cast<uint32_t>(duration.ToMilliseconds()));
}
(void)::sqlite3_extended_result_codes(aNativeConnection, 0);
@ -1474,8 +1483,9 @@ int Connection::executeSql(sqlite3* aNativeConnection, const char* aSqlString) {
: Telemetry::kSlowSQLThresholdForHelperThreads;
if (duration.ToMilliseconds() >= threshold) {
nsDependentCString statementString(aSqlString);
Telemetry::RecordSlowSQLStatement(statementString, mTelemetryFilename,
duration.ToMilliseconds());
Telemetry::RecordSlowSQLStatement(
statementString, mTelemetryFilename,
static_cast<uint32_t>(duration.ToMilliseconds()));
}
return srv;

View file

@ -147,7 +147,7 @@ Service::CollectReports(nsIHandleReportCallback* aHandleReport,
#endif
}
int64_t other = ::sqlite3_memory_used() - totalConnSize;
int64_t other = static_cast<int64_t>(::sqlite3_memory_used() - totalConnSize);
MOZ_COLLECT_REPORT("explicit/storage/sqlite/other", KIND_HEAP, UNITS_BYTES,
other, "All unclassified sqlite memory.");
@ -202,7 +202,8 @@ Service::AutoVFSRegistration::~AutoVFSRegistration() {
Service::Service()
: mMutex("Service::mMutex"),
mRegistrationMutex("Service::mRegistrationMutex"),
mConnections() {}
mConnections(),
mLastSensitivity(mozilla::intl::Collator::Sensitivity::Base) {}
Service::~Service() {
mozilla::UnregisterWeakMemoryReporter(this);
@ -375,8 +376,8 @@ nsresult Service::initialize() {
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
NS_ENSURE_TRUE(os, NS_ERROR_FAILURE);
for (size_t i = 0; i < ArrayLength(sObserverTopics); ++i) {
nsresult rv = os->AddObserver(this, sObserverTopics[i], false);
for (auto& sObserverTopic : sObserverTopics) {
nsresult rv = os->AddObserver(this, sObserverTopic, false);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -740,8 +741,8 @@ Service::Observe(nsISupports*, const char* aTopic, const char16_t*) {
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
for (size_t i = 0; i < ArrayLength(sObserverTopics); ++i) {
(void)os->RemoveObserver(this, sObserverTopics[i]);
for (auto& sObserverTopic : sObserverTopics) {
(void)os->RemoveObserver(this, sObserverTopic);
}
SpinEventLoopUntil("storage::Service::Observe(xpcom-shutdown-threads)"_ns,

View file

@ -24,8 +24,7 @@ namespace mozilla::intl {
class Collator;
}
namespace mozilla {
namespace storage {
namespace mozilla::storage {
class Connection;
class Service : public mozIStorageService,
@ -179,7 +178,6 @@ class Service : public mozIStorageService,
mozilla::intl::Collator::Sensitivity mLastSensitivity;
};
} // namespace storage
} // namespace mozilla
} // namespace mozilla::storage
#endif /* MOZSTORAGESERVICE_H */

View file

@ -186,16 +186,18 @@ nsIThread* last_non_watched_thread = nullptr;
* call the real mutex function.
*/
extern "C" void wrapped_MutexEnter(sqlite3_mutex* mutex) {
if (PR_GetCurrentThread() == watched_thread)
if (PR_GetCurrentThread() == watched_thread) {
mutex_used_on_watched_thread = true;
else
} else {
last_non_watched_thread = NS_GetCurrentThread();
}
orig_mutex_methods.xMutexEnter(mutex);
}
extern "C" int wrapped_MutexTry(sqlite3_mutex* mutex) {
if (::PR_GetCurrentThread() == watched_thread)
if (::PR_GetCurrentThread() == watched_thread) {
mutex_used_on_watched_thread = true;
}
return orig_mutex_methods.xMutexTry(mutex);
}