From d5a9c0c937b65b7bec58fed4432fd97e16bc716a Mon Sep 17 00:00:00 2001 From: Niklas Fiekas Date: Mon, 10 Apr 2023 12:19:40 -0700 Subject: [PATCH] C-API: Constify cache functions where possible (#11243) Summary: Makes it easier to use generated Rust bindings. Constness of these is already part of the C++ API. Pull Request resolved: https://github.com/facebook/rocksdb/pull/11243 Reviewed By: hx235 Differential Revision: D44840394 Pulled By: ajkr fbshipit-source-id: bcd1aeb8c959c304148d25b00043bb8c4cd3e0a4 --- db/c.cc | 10 +++++----- include/rocksdb/c.h | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/db/c.cc b/db/c.cc index ab5bfe057..d817f5b17 100644 --- a/db/c.cc +++ b/db/c.cc @@ -4679,7 +4679,7 @@ rocksdb_cache_t* rocksdb_cache_create_lru_with_strict_capacity_limit( } rocksdb_cache_t* rocksdb_cache_create_lru_opts( - rocksdb_lru_cache_options_t* opt) { + const rocksdb_lru_cache_options_t* opt) { rocksdb_cache_t* c = new rocksdb_cache_t; c->rep = NewLRUCache(opt->rep); return c; @@ -4726,7 +4726,7 @@ rocksdb_cache_t* rocksdb_cache_create_hyper_clock( } rocksdb_cache_t* rocksdb_cache_create_hyper_clock_opts( - rocksdb_hyper_clock_cache_options_t* opts) { + const rocksdb_hyper_clock_cache_options_t* opts) { rocksdb_cache_t* c = new rocksdb_cache_t; c->rep = opts->rep.MakeSharedCache(); return c; @@ -4742,15 +4742,15 @@ void rocksdb_cache_set_capacity(rocksdb_cache_t* cache, size_t capacity) { cache->rep->SetCapacity(capacity); } -size_t rocksdb_cache_get_capacity(rocksdb_cache_t* cache) { +size_t rocksdb_cache_get_capacity(const rocksdb_cache_t* cache) { return cache->rep->GetCapacity(); } -size_t rocksdb_cache_get_usage(rocksdb_cache_t* cache) { +size_t rocksdb_cache_get_usage(const rocksdb_cache_t* cache) { return cache->rep->GetUsage(); } -size_t rocksdb_cache_get_pinned_usage(rocksdb_cache_t* cache) { +size_t rocksdb_cache_get_pinned_usage(const rocksdb_cache_t* cache) { return cache->rep->GetPinnedUsage(); } diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h index 809275891..aac55638a 100644 --- a/include/rocksdb/c.h +++ b/include/rocksdb/c.h @@ -2006,7 +2006,7 @@ extern ROCKSDB_LIBRARY_API rocksdb_cache_t* rocksdb_cache_create_lru( extern ROCKSDB_LIBRARY_API rocksdb_cache_t* rocksdb_cache_create_lru_with_strict_capacity_limit(size_t capacity); extern ROCKSDB_LIBRARY_API rocksdb_cache_t* rocksdb_cache_create_lru_opts( - rocksdb_lru_cache_options_t*); + const rocksdb_lru_cache_options_t*); extern ROCKSDB_LIBRARY_API void rocksdb_cache_destroy(rocksdb_cache_t* cache); extern ROCKSDB_LIBRARY_API void rocksdb_cache_disown_data( @@ -2014,11 +2014,11 @@ extern ROCKSDB_LIBRARY_API void rocksdb_cache_disown_data( extern ROCKSDB_LIBRARY_API void rocksdb_cache_set_capacity( rocksdb_cache_t* cache, size_t capacity); extern ROCKSDB_LIBRARY_API size_t -rocksdb_cache_get_capacity(rocksdb_cache_t* cache); +rocksdb_cache_get_capacity(const rocksdb_cache_t* cache); extern ROCKSDB_LIBRARY_API size_t -rocksdb_cache_get_usage(rocksdb_cache_t* cache); +rocksdb_cache_get_usage(const rocksdb_cache_t* cache); extern ROCKSDB_LIBRARY_API size_t -rocksdb_cache_get_pinned_usage(rocksdb_cache_t* cache); +rocksdb_cache_get_pinned_usage(const rocksdb_cache_t* cache); extern ROCKSDB_LIBRARY_API size_t rocksdb_cache_get_table_address_count(const rocksdb_cache_t* cache); extern ROCKSDB_LIBRARY_API size_t @@ -2046,7 +2046,8 @@ rocksdb_hyper_clock_cache_options_set_memory_allocator( extern ROCKSDB_LIBRARY_API rocksdb_cache_t* rocksdb_cache_create_hyper_clock( size_t capacity, size_t estimated_entry_charge); extern ROCKSDB_LIBRARY_API rocksdb_cache_t* -rocksdb_cache_create_hyper_clock_opts(rocksdb_hyper_clock_cache_options_t*); +rocksdb_cache_create_hyper_clock_opts( + const rocksdb_hyper_clock_cache_options_t*); /* DBPath */