Commit 02b6c343 authored by Marco Bonardo's avatar Marco Bonardo
Browse files

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

parent 48ecbc8f
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -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,14 +139,21 @@ 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.
  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;
+7 −6
Original line number Diff line number Diff line
@@ -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,
+2 −4
Original line number Diff line number Diff line
@@ -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 */
+5 −3
Original line number Diff line number Diff line
@@ -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);
}