From e90f0d31a6d06bc9ff886d68d72df3bfcc9c9fba Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Tue, 20 Dec 2016 14:08:43 +0200 Subject: [PATCH] Cache: Pass argument as reference when it must be non-NULL --- .../storage_inmemory/inmemorystorage.cc | 20 +++++++++---------- .../storage_inmemory/inmemorystorage.hh | 6 +++--- .../storage_inmemory/inmemorystoragemt.cc | 4 ++-- .../storage_inmemory/inmemorystoragemt.hh | 2 +- .../storage_inmemory/inmemorystoragest.cc | 4 ++-- .../storage_inmemory/inmemorystoragest.hh | 2 +- .../storage/storage_rocksdb/rocksdbstorage.cc | 16 +++++++-------- .../storage/storage_rocksdb/rocksdbstorage.hh | 4 ++-- .../filter/cache/storage/storagemodule.hh | 4 ++-- 9 files changed, 31 insertions(+), 31 deletions(-) diff --git a/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.cc b/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.cc index bcb5d6453..0a28a06ec 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.cc +++ b/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.cc @@ -97,13 +97,13 @@ InMemoryStorage* InMemoryStorage::Create_instance(const char* zName, return sStorage.release(); } -cache_result_t InMemoryStorage::Get_key(const char* zDefault_db, const GWBUF* pQuery, CACHE_KEY* pKey) +cache_result_t InMemoryStorage::Get_key(const char* zDefault_db, const GWBUF& query, CACHE_KEY* pKey) { - ss_dassert(GWBUF_IS_CONTIGUOUS(pQuery)); + ss_dassert(GWBUF_IS_CONTIGUOUS(&query)); int n; bool fullnames = true; - char** pzTables = qc_get_table_names(const_cast(pQuery), &n, fullnames); + char** pzTables = qc_get_table_names(const_cast(&query), &n, fullnames); set dbs; // Elements in set are sorted. @@ -149,7 +149,7 @@ cache_result_t InMemoryStorage::Get_key(const char* zDefault_db, const GWBUF* pQ char *pSql; int length; - modutil_extract_SQL(const_cast(pQuery), &pSql, &length); + modutil_extract_SQL(const_cast(&query), &pSql, &length); // Then we store the query itself in the second half of the key. pData = reinterpret_cast(pSql); @@ -248,11 +248,11 @@ cache_result_t InMemoryStorage::do_get_value(const CACHE_KEY& key, uint32_t flag return result; } -cache_result_t InMemoryStorage::do_put_value(const CACHE_KEY& key, const GWBUF* pValue) +cache_result_t InMemoryStorage::do_put_value(const CACHE_KEY& key, const GWBUF& value) { - ss_dassert(GWBUF_IS_CONTIGUOUS(pValue)); + ss_dassert(GWBUF_IS_CONTIGUOUS(&value)); - size_t size = GWBUF_LENGTH(pValue); + size_t size = GWBUF_LENGTH(&value); Entries::iterator i = m_entries.find(key); Entry* pEntry; @@ -276,8 +276,8 @@ cache_result_t InMemoryStorage::do_put_value(const CACHE_KEY& key, const GWBUF* { // If the needed value is less than what is currently stored, // we shrink the buffer so as not to waste space. - Value value(size); - pEntry->value.swap(value); + Value entry_value(size); + pEntry->value.swap(entry_value); } else { @@ -287,7 +287,7 @@ cache_result_t InMemoryStorage::do_put_value(const CACHE_KEY& key, const GWBUF* m_stats.size += size; - const uint8_t* pData = GWBUF_DATA(pValue); + const uint8_t* pData = GWBUF_DATA(&value); copy(pData, pData + size, pEntry->value.begin()); pEntry->time = time(NULL); diff --git a/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.hh b/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.hh index 76e0384c1..2eb3613f9 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.hh +++ b/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.hh @@ -30,12 +30,12 @@ public: const CACHE_STORAGE_CONFIG& config, int argc, char* argv[]); - static cache_result_t Get_key(const char* zDefault_db, const GWBUF* pQuery, CACHE_KEY* pKey); + static cache_result_t Get_key(const char* zDefault_db, const GWBUF& query, CACHE_KEY* pKey); void get_config(CACHE_STORAGE_CONFIG* pConfig); virtual cache_result_t get_info(uint32_t what, json_t** ppInfo) const = 0; virtual cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppResult) = 0; - virtual cache_result_t put_value(const CACHE_KEY& key, const GWBUF* pValue) = 0; + virtual cache_result_t put_value(const CACHE_KEY& key, const GWBUF& value) = 0; virtual cache_result_t del_value(const CACHE_KEY& key) = 0; cache_result_t get_head(CACHE_KEY* pKey, GWBUF** ppHead) const; @@ -49,7 +49,7 @@ protected: cache_result_t do_get_info(uint32_t what, json_t** ppInfo) const; cache_result_t do_get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppResult); - cache_result_t do_put_value(const CACHE_KEY& key, const GWBUF* pValue); + cache_result_t do_put_value(const CACHE_KEY& key, const GWBUF& value); cache_result_t do_del_value(const CACHE_KEY& key); private: diff --git a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.cc b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.cc index d38b2da4b..1fe3164da 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.cc +++ b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.cc @@ -49,11 +49,11 @@ cache_result_t InMemoryStorageMT::get_value(const CACHE_KEY& key, uint32_t flags return do_get_value(key, flags, ppResult); } -cache_result_t InMemoryStorageMT::put_value(const CACHE_KEY& key, const GWBUF* pValue) +cache_result_t InMemoryStorageMT::put_value(const CACHE_KEY& key, const GWBUF& value) { SpinLockGuard guard(lock_); - return do_put_value(key, pValue); + return do_put_value(key, value); } cache_result_t InMemoryStorageMT::del_value(const CACHE_KEY& key) diff --git a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.hh b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.hh index 7213ce741..40ab89691 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.hh +++ b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragemt.hh @@ -29,7 +29,7 @@ public: cache_result_t get_info(uint32_t what, json_t** ppInfo) const; cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppResult); - cache_result_t put_value(const CACHE_KEY& key, const GWBUF* pValue); + cache_result_t put_value(const CACHE_KEY& key, const GWBUF& value); cache_result_t del_value(const CACHE_KEY& key); private: diff --git a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.cc b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.cc index 9975e89bc..3e8afd586 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.cc +++ b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.cc @@ -43,9 +43,9 @@ cache_result_t InMemoryStorageST::get_value(const CACHE_KEY& key, uint32_t flags return do_get_value(key, flags, ppResult); } -cache_result_t InMemoryStorageST::put_value(const CACHE_KEY& key, const GWBUF* pValue) +cache_result_t InMemoryStorageST::put_value(const CACHE_KEY& key, const GWBUF& value) { - return do_put_value(key, pValue); + return do_put_value(key, value); } cache_result_t InMemoryStorageST::del_value(const CACHE_KEY& key) diff --git a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.hh b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.hh index 9188d0e27..177f3157d 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.hh +++ b/server/modules/filter/cache/storage/storage_inmemory/inmemorystoragest.hh @@ -28,7 +28,7 @@ public: cache_result_t get_info(uint32_t what, json_t** ppInfo) const; cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppResult); - cache_result_t put_value(const CACHE_KEY& key, const GWBUF* pValue); + cache_result_t put_value(const CACHE_KEY& key, const GWBUF& pValue); cache_result_t del_value(const CACHE_KEY& key); private: diff --git a/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.cc b/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.cc index 30f9605ce..c72a33139 100644 --- a/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.cc +++ b/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.cc @@ -360,13 +360,13 @@ RocksDBStorage* RocksDBStorage::Create(const char* zName, return sStorage.release(); } -cache_result_t RocksDBStorage::Get_key(const char* zDefault_db, const GWBUF* pQuery, CACHE_KEY* pKey) +cache_result_t RocksDBStorage::Get_key(const char* zDefault_db, const GWBUF& query, CACHE_KEY* pKey) { - ss_dassert(GWBUF_IS_CONTIGUOUS(pQuery)); + ss_dassert(GWBUF_IS_CONTIGUOUS(&query)); int n; bool fullnames = true; - char** pzTables = qc_get_table_names(const_cast(pQuery), &n, fullnames); + char** pzTables = qc_get_table_names(const_cast(&query), &n, fullnames); set dbs; // Elements in set are sorted. @@ -409,7 +409,7 @@ cache_result_t RocksDBStorage::Get_key(const char* zDefault_db, const GWBUF* pQu char *pSql; int length; - modutil_extract_SQL(const_cast(pQuery), &pSql, &length); + modutil_extract_SQL(const_cast(&query), &pSql, &length); // Then we store the query itself in the second half of the key. pData = reinterpret_cast(pSql); @@ -510,14 +510,14 @@ cache_result_t RocksDBStorage::get_value(const CACHE_KEY& key, uint32_t flags, G return result; } -cache_result_t RocksDBStorage::put_value(const CACHE_KEY& key, const GWBUF* pValue) +cache_result_t RocksDBStorage::put_value(const CACHE_KEY& key, const GWBUF& value) { - ss_dassert(GWBUF_IS_CONTIGUOUS(pValue)); + ss_dassert(GWBUF_IS_CONTIGUOUS(&value)); rocksdb::Slice rocksdb_key(key.data, ROCKSDB_KEY_LENGTH); - rocksdb::Slice value((char*)GWBUF_DATA(pValue), GWBUF_LENGTH(pValue)); + rocksdb::Slice rocksdb_value((char*)GWBUF_DATA(&value), GWBUF_LENGTH(&value)); - rocksdb::Status status = m_sDb->Put(Write_options(), rocksdb_key, value); + rocksdb::Status status = m_sDb->Put(Write_options(), rocksdb_key, rocksdb_value); return status.ok() ? CACHE_RESULT_OK : CACHE_RESULT_ERROR; } diff --git a/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.hh b/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.hh index b31be4f51..34f10dc33 100644 --- a/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.hh +++ b/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.hh @@ -30,12 +30,12 @@ public: int argc, char* argv[]); ~RocksDBStorage(); - static cache_result_t Get_key(const char* zDefault_db, const GWBUF* pQuery, CACHE_KEY* pKey); + static cache_result_t Get_key(const char* zDefault_db, const GWBUF& query, CACHE_KEY* pKey); void get_config(CACHE_STORAGE_CONFIG* pConfig); cache_result_t get_info(uint32_t flags, json_t** ppInfo) const; cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppResult); - cache_result_t put_value(const CACHE_KEY& key, const GWBUF* pValue); + cache_result_t put_value(const CACHE_KEY& key, const GWBUF& value); cache_result_t del_value(const CACHE_KEY& key); cache_result_t get_head(CACHE_KEY* pKey, GWBUF** ppHead) const; diff --git a/server/modules/filter/cache/storage/storagemodule.hh b/server/modules/filter/cache/storage/storagemodule.hh index e134e5b2a..df35d79e3 100644 --- a/server/modules/filter/cache/storage/storagemodule.hh +++ b/server/modules/filter/cache/storage/storagemodule.hh @@ -47,7 +47,7 @@ public: cache_result_t result = CACHE_RESULT_ERROR; - MXS_EXCEPTION_GUARD(result = StorageType::Get_key(zDefault_db, pQuery, pKey)); + MXS_EXCEPTION_GUARD(result = StorageType::Get_key(zDefault_db, *pQuery, pKey)); return result; } @@ -113,7 +113,7 @@ public: StorageType* pStorage = reinterpret_cast(pCache_storage); - MXS_EXCEPTION_GUARD(result = pStorage->put_value(*pKey, pValue)); + MXS_EXCEPTION_GUARD(result = pStorage->put_value(*pKey, *pValue)); return result; }