Uses clang-format for C/C++ code

Uses the same configuration as RocksDB
pull/398/head
Tpt 2 years ago committed by Thomas Tanon
parent 03df957427
commit c8caf805fa
  1. 7
      .github/workflows/tests.yml
  2. 3
      oxrocksdb-sys/api/.clang-format
  3. 12
      oxrocksdb-sys/api/build_version.cc
  4. 103
      oxrocksdb-sys/api/c.cc
  5. 50
      oxrocksdb-sys/api/c.h

@ -250,6 +250,13 @@ jobs:
- run: cargo install typos-cli || true
- run: typos
clang_fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: sudo apt install -y clang-format
- run: clang-format --Werror --dry-run oxrocksdb-sys/api/*
fuzz_changes:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest

@ -0,0 +1,3 @@
---
BasedOnStyle: Google
...

@ -2,20 +2,21 @@
#include <memory>
#include "rocksdb/version.h"
#include "rocksdb/utilities/object_registry.h"
#include "rocksdb/version.h"
namespace ROCKSDB_NAMESPACE {
std::unordered_map<std::string, RegistrarFunc> ObjectRegistry::builtins_ = {};
const std::unordered_map<std::string, std::string>& GetRocksBuildProperties() {
static std::unique_ptr<std::unordered_map<std::string, std::string>> props(new std::unordered_map<std::string, std::string>());
static std::unique_ptr<std::unordered_map<std::string, std::string>> props(
new std::unordered_map<std::string, std::string>());
return *props;
}
std::string GetRocksVersionAsString(bool with_patch) {
std::string version = std::to_string(ROCKSDB_MAJOR) + "." + std::to_string(ROCKSDB_MINOR);
std::string version =
std::to_string(ROCKSDB_MAJOR) + "." + std::to_string(ROCKSDB_MINOR);
if (with_patch) {
return version + "." + std::to_string(ROCKSDB_PATCH);
} else {
@ -23,7 +24,8 @@ namespace ROCKSDB_NAMESPACE {
}
}
std::string GetRocksBuildInfoAsString(const std::string& program, bool verbose) {
std::string GetRocksBuildInfoAsString(const std::string& program,
bool verbose) {
std::string info = program + " (RocksDB) " + GetRocksVersionAsString(true);
if (verbose) {
for (const auto& it : GetRocksBuildProperties()) {

@ -1,4 +1,5 @@
#include "../rocksdb/db/c.cc"
#include "c.h"
static bool SaveStatus(rocksdb_status_t* target, const Status source) {
@ -43,17 +44,17 @@ rocksdb_t* rocksdb_open_for_read_only_column_families_with_status(
unsigned char error_if_wal_file_exists, rocksdb_status_t* statusptr) {
std::vector<ColumnFamilyDescriptor> column_families;
for (int i = 0; i < num_column_families; i++) {
column_families.push_back(ColumnFamilyDescriptor(
column_families.emplace_back(ColumnFamilyDescriptor(
std::string(column_family_names[i]),
ColumnFamilyOptions(column_family_options[i]->rep)));
}
DB* db;
std::vector<ColumnFamilyHandle*> handles;
if (SaveStatus(statusptr,
DB::OpenForReadOnly(DBOptions(db_options->rep),
std::string(name), column_families,
&handles, &db, error_if_wal_file_exists))) {
if (SaveStatus(statusptr, DB::OpenForReadOnly(DBOptions(db_options->rep),
std::string(name),
column_families, &handles, &db,
error_if_wal_file_exists))) {
return nullptr;
}
@ -88,10 +89,10 @@ rocksdb_t* rocksdb_open_as_secondary_column_families_with_status(
}
DB* db;
std::vector<ColumnFamilyHandle*> handles;
if (SaveStatus(statusptr, DB::OpenAsSecondary(DBOptions(db_options->rep),
std::string(name),
std::string(secondary_path),
column_families, &handles, &db))) {
if (SaveStatus(statusptr, DB::OpenAsSecondary(
DBOptions(db_options->rep), std::string(name),
std::string(secondary_path), column_families,
&handles, &db))) {
return nullptr;
}
for (size_t i = 0; i != handles.size(); ++i) {
@ -110,17 +111,19 @@ rocksdb_transactiondb_t* rocksdb_transactiondb_open_column_families_with_status(
const rocksdb_transactiondb_options_t* txn_db_options, const char* name,
int num_column_families, const char* const* column_family_names,
const rocksdb_options_t* const* column_family_options,
rocksdb_column_family_handle_t** column_family_handles, rocksdb_status_t* statusptr) {
rocksdb_column_family_handle_t** column_family_handles,
rocksdb_status_t* statusptr) {
std::vector<ColumnFamilyDescriptor> column_families;
for (int i = 0; i < num_column_families; i++) {
column_families.push_back(ColumnFamilyDescriptor(
column_families.emplace_back(ColumnFamilyDescriptor(
std::string(column_family_names[i]),
ColumnFamilyOptions(column_family_options[i]->rep)));
}
TransactionDB* txn_db;
std::vector<ColumnFamilyHandle*> handles;
if (SaveStatus(statusptr, TransactionDB::Open(options->rep, txn_db_options->rep,
if (SaveStatus(statusptr,
TransactionDB::Open(options->rep, txn_db_options->rep,
std::string(name), column_families,
&handles, &txn_db))) {
return nullptr;
@ -154,32 +157,31 @@ rocksdb_pinnableslice_t* rocksdb_transactiondb_get_pinned_cf_with_status(
return v;
}
void rocksdb_transactiondb_put_cf_with_status(rocksdb_transactiondb_t* txn_db,
const rocksdb_writeoptions_t* options,
rocksdb_column_family_handle_t* column_family,
const char* key, size_t keylen,
const char* val, size_t vallen,
void rocksdb_transactiondb_put_cf_with_status(
rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options,
rocksdb_column_family_handle_t* column_family, const char* key,
size_t keylen, const char* val, size_t vallen,
rocksdb_status_t* statusptr) {
SaveStatus(statusptr, txn_db->rep->Put(options->rep, column_family->rep,
SaveStatus(statusptr,
txn_db->rep->Put(options->rep, column_family->rep,
Slice(key, keylen), Slice(val, vallen)));
}
void rocksdb_transactiondb_flush_cf_with_status(
rocksdb_transactiondb_t* db,
const rocksdb_flushoptions_t* options,
rocksdb_transactiondb_t* db, const rocksdb_flushoptions_t* options,
rocksdb_column_family_handle_t* column_family,
rocksdb_status_t* statusptr) {
SaveStatus(statusptr, db->rep->Flush(options->rep, column_family->rep));
}
void rocksdb_transactiondb_compact_range_cf_opt_with_status(rocksdb_transactiondb_t* db,
rocksdb_column_family_handle_t* column_family,
rocksdb_compactoptions_t* opt,
const char* start_key, size_t start_key_len,
const char* limit_key, size_t limit_key_len,
rocksdb_status_t* statusptr) {
void rocksdb_transactiondb_compact_range_cf_opt_with_status(
rocksdb_transactiondb_t* db, rocksdb_column_family_handle_t* column_family,
rocksdb_compactoptions_t* opt, const char* start_key, size_t start_key_len,
const char* limit_key, size_t limit_key_len, rocksdb_status_t* statusptr) {
Slice a, b;
SaveStatus(statusptr, db->rep->CompactRange(
SaveStatus(
statusptr,
db->rep->CompactRange(
opt->rep, column_family->rep,
// Pass nullptr Slice if corresponding "const char*" is nullptr
(start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr),
@ -211,16 +213,18 @@ void rocksdb_transactiondb_create_checkpoint_with_status(
SaveStatus(statusptr, s);
return;
}
SaveStatus(statusptr, checkpoint->CreateCheckpoint(std::string(checkpoint_dir)));
SaveStatus(statusptr,
checkpoint->CreateCheckpoint(std::string(checkpoint_dir)));
delete checkpoint;
}
void rocksdb_transaction_commit_with_status(rocksdb_transaction_t* txn, rocksdb_status_t* statusptr) {
void rocksdb_transaction_commit_with_status(rocksdb_transaction_t* txn,
rocksdb_status_t* statusptr) {
SaveStatus(statusptr, txn->rep->Commit());
}
void rocksdb_transaction_rollback_with_status(rocksdb_transaction_t* txn, rocksdb_status_t* statusptr) {
void rocksdb_transaction_rollback_with_status(rocksdb_transaction_t* txn,
rocksdb_status_t* statusptr) {
SaveStatus(statusptr, txn->rep->Rollback());
}
@ -241,13 +245,14 @@ rocksdb_pinnableslice_t* rocksdb_transaction_get_pinned_cf_with_status(
return v;
}
rocksdb_pinnableslice_t* rocksdb_transaction_get_for_update_pinned_cf_with_status(
rocksdb_pinnableslice_t*
rocksdb_transaction_get_for_update_pinned_cf_with_status(
rocksdb_transaction_t* txn, const rocksdb_readoptions_t* options,
rocksdb_column_family_handle_t* column_family, const char* key,
size_t keylen, rocksdb_status_t* statusptr) {
rocksdb_pinnableslice_t* v = new rocksdb_pinnableslice_t;
Status s = txn->rep->GetForUpdate(options->rep, column_family->rep, Slice(key, keylen),
&v->rep);
Status s = txn->rep->GetForUpdate(options->rep, column_family->rep,
Slice(key, keylen), &v->rep);
if (!s.ok()) {
delete v;
if (!s.IsNotFound()) {
@ -258,10 +263,10 @@ rocksdb_pinnableslice_t* rocksdb_transaction_get_for_update_pinned_cf_with_statu
return v;
}
void rocksdb_transaction_put_cf_with_status(rocksdb_transaction_t* txn,
rocksdb_column_family_handle_t* column_family,
const char* key, size_t klen, const char* val,
size_t vlen, rocksdb_status_t* statusptr) {
void rocksdb_transaction_put_cf_with_status(
rocksdb_transaction_t* txn, rocksdb_column_family_handle_t* column_family,
const char* key, size_t klen, const char* val, size_t vlen,
rocksdb_status_t* statusptr) {
SaveStatus(statusptr, txn->rep->Put(column_family->rep, Slice(key, klen),
Slice(val, vlen)));
}
@ -272,17 +277,18 @@ void rocksdb_transaction_delete_cf_with_status(
SaveStatus(statusptr, txn->rep->Delete(column_family->rep, Slice(key, klen)));
}
void rocksdb_sstfilewriter_open_with_status(rocksdb_sstfilewriter_t* writer,
const char* name, rocksdb_status_t* statusptr) {
const char* name,
rocksdb_status_t* statusptr) {
SaveStatus(statusptr, writer->rep->Open(std::string(name)));
}
void rocksdb_sstfilewriter_put_with_status(rocksdb_sstfilewriter_t* writer, const char* key,
size_t keylen, const char* val, size_t vallen,
void rocksdb_sstfilewriter_put_with_status(rocksdb_sstfilewriter_t* writer,
const char* key, size_t keylen,
const char* val, size_t vallen,
rocksdb_status_t* statusptr) {
SaveStatus(statusptr, writer->rep->Put(Slice(key, keylen), Slice(val, vallen)));
SaveStatus(statusptr,
writer->rep->Put(Slice(key, keylen), Slice(val, vallen)));
}
void rocksdb_sstfilewriter_finish_with_status(rocksdb_sstfilewriter_t* writer,
@ -290,14 +296,13 @@ void rocksdb_sstfilewriter_finish_with_status(rocksdb_sstfilewriter_t* writer,
SaveStatus(statusptr, writer->rep->Finish(nullptr));
}
void rocksdb_iter_get_status(const rocksdb_iterator_t* iter, rocksdb_status_t* statusptr) {
void rocksdb_iter_get_status(const rocksdb_iterator_t* iter,
rocksdb_status_t* statusptr) {
SaveStatus(statusptr, iter->rep->status());
}
rocksdb_readoptions_t* rocksdb_readoptions_create_copy(rocksdb_readoptions_t* options) {
rocksdb_readoptions_t* rocksdb_readoptions_create_copy(
rocksdb_readoptions_t* options) {
return new rocksdb_readoptions_t(*options);
}
}

@ -70,9 +70,8 @@ rocksdb_pinnableslice_t* rocksdb_get_pinned_cf_with_status(
rocksdb_column_family_handle_t* column_family, const char* key,
size_t keylen, rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API rocksdb_t* rocksdb_open_for_read_only_column_families_with_status(
extern ROCKSDB_LIBRARY_API rocksdb_t*
rocksdb_open_for_read_only_column_families_with_status(
const rocksdb_options_t* db_options, const char* name,
int num_column_families, const char* const* column_family_names,
const rocksdb_options_t* const* column_family_options,
@ -82,7 +81,8 @@ extern ROCKSDB_LIBRARY_API rocksdb_t* rocksdb_open_for_read_only_column_families
extern ROCKSDB_LIBRARY_API void rocksdb_try_catch_up_with_primary_with_status(
rocksdb_t* db, rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API rocksdb_t* rocksdb_open_as_secondary_column_families_with_status(
extern ROCKSDB_LIBRARY_API rocksdb_t*
rocksdb_open_as_secondary_column_families_with_status(
const rocksdb_options_t* options, const char* name,
const char* secondary_path, int num_column_families,
const char* const* column_family_names,
@ -90,15 +90,17 @@ extern ROCKSDB_LIBRARY_API rocksdb_t* rocksdb_open_as_secondary_column_families_
rocksdb_column_family_handle_t** column_family_handles,
rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API rocksdb_transactiondb_t* rocksdb_transactiondb_open_column_families_with_status(
extern ROCKSDB_LIBRARY_API rocksdb_transactiondb_t*
rocksdb_transactiondb_open_column_families_with_status(
const rocksdb_options_t* options,
const rocksdb_transactiondb_options_t* txn_db_options, const char* name,
int num_column_families, const char* const* column_family_names,
const rocksdb_options_t* const* column_family_options,
rocksdb_column_family_handle_t** column_family_handles, rocksdb_status_t* statusptr);
rocksdb_column_family_handle_t** column_family_handles,
rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API rocksdb_pinnableslice_t* rocksdb_transactiondb_get_pinned_cf_with_status(
extern ROCKSDB_LIBRARY_API rocksdb_pinnableslice_t*
rocksdb_transactiondb_get_pinned_cf_with_status(
rocksdb_transactiondb_t* db, const rocksdb_readoptions_t* options,
rocksdb_column_family_handle_t* column_family, const char* key,
size_t keylen, rocksdb_status_t* statusptr);
@ -112,18 +114,21 @@ extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_flush_cf_with_status(
rocksdb_transactiondb_t* db, const rocksdb_flushoptions_t* options,
rocksdb_column_family_handle_t* column_family, rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_compact_range_cf_opt_with_status(
extern ROCKSDB_LIBRARY_API void
rocksdb_transactiondb_compact_range_cf_opt_with_status(
rocksdb_transactiondb_t* db, rocksdb_column_family_handle_t* column_family,
rocksdb_compactoptions_t* opt, const char* start_key, size_t start_key_len,
const char* limit_key, size_t limit_key_len, rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_ingest_external_files_with_status(
extern ROCKSDB_LIBRARY_API void
rocksdb_transactiondb_ingest_external_files_with_status(
rocksdb_transactiondb_t* db, const rocksdb_ingestexternalfilearg_t* list,
const size_t list_len, rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_create_checkpoint_with_status(
rocksdb_transactiondb_t* db, const char* checkpoint_dir, rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API void
rocksdb_transactiondb_create_checkpoint_with_status(
rocksdb_transactiondb_t* db, const char* checkpoint_dir,
rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_commit_with_status(
rocksdb_transaction_t* txn, rocksdb_status_t* statusptr);
@ -131,27 +136,30 @@ extern ROCKSDB_LIBRARY_API void rocksdb_transaction_commit_with_status(
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_rollback_with_status(
rocksdb_transaction_t* txn, rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API rocksdb_pinnableslice_t* rocksdb_transaction_get_pinned_cf_with_status(
extern ROCKSDB_LIBRARY_API rocksdb_pinnableslice_t*
rocksdb_transaction_get_pinned_cf_with_status(
rocksdb_transaction_t* txn, const rocksdb_readoptions_t* options,
rocksdb_column_family_handle_t* column_family, const char* key,
size_t keylen, rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API rocksdb_pinnableslice_t* rocksdb_transaction_get_for_update_pinned_cf_with_status(
extern ROCKSDB_LIBRARY_API rocksdb_pinnableslice_t*
rocksdb_transaction_get_for_update_pinned_cf_with_status(
rocksdb_transaction_t* txn, const rocksdb_readoptions_t* options,
rocksdb_column_family_handle_t* column_family, const char* key,
size_t keylen, rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_put_cf_with_status(
rocksdb_transaction_t* txn, rocksdb_column_family_handle_t* column_family,
const char* key, size_t klen, const char* val, size_t vlen, rocksdb_status_t* statusptr);
const char* key, size_t klen, const char* val, size_t vlen,
rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_delete_cf_with_status(
rocksdb_transaction_t* txn, rocksdb_column_family_handle_t* column_family,
const char* key, size_t klen, rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API void rocksdb_sstfilewriter_open_with_status(
rocksdb_sstfilewriter_t* writer, const char* name, rocksdb_status_t* statusptr);
rocksdb_sstfilewriter_t* writer, const char* name,
rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API void rocksdb_sstfilewriter_put_with_status(
rocksdb_sstfilewriter_t* writer, const char* key, size_t keylen,
@ -160,13 +168,11 @@ extern ROCKSDB_LIBRARY_API void rocksdb_sstfilewriter_put_with_status(
extern ROCKSDB_LIBRARY_API void rocksdb_sstfilewriter_finish_with_status(
rocksdb_sstfilewriter_t* writer, rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API void rocksdb_iter_get_status(
const rocksdb_iterator_t*, rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API rocksdb_readoptions_t* rocksdb_readoptions_create_copy(
rocksdb_readoptions_t*);
extern ROCKSDB_LIBRARY_API rocksdb_readoptions_t*
rocksdb_readoptions_create_copy(rocksdb_readoptions_t*);
#ifdef __cplusplus
}

Loading…
Cancel
Save