Skip to content

Commit

Permalink
feat: fix build warnings for all targets (#236)
Browse files Browse the repository at this point in the history
fix: CMake import issues

fix: virtual destructor warning

chore: removed auto generated files
  • Loading branch information
EmperorYP7 authored Sep 5, 2023
1 parent 3e42413 commit f6561a4
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 179 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ MigrationBackup/
cmake-build/
xcode-build/
cmake-build*/
build_support/

# pip
*.egg-info
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ endif()

project(
casbin
VERSION 1.44.0
VERSION 1.53.2
DESCRIPTION "An authorization library that supports access control models like ACL, RBAC, ABAC in C/C++"
HOMEPAGE_URL https://github.com/casbin/casbin-cpp
LANGUAGES CXX C
Expand Down
Empty file.
131 changes: 0 additions & 131 deletions build_support/run_clang_format.py

This file was deleted.

5 changes: 2 additions & 3 deletions casbin/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ void Config::ParseBuffer(std::istream* buf) {
else {
std::vector<std::string> option_val = Split(line, "=", 2);
if (option_val.size() != 2) {
char* error = new char;
sprintf(error, "parse the content error : line %d , %s = ? ", line_num, option_val[0].c_str());
throw IllegalArgumentException(std::string(error));
std::string error = "parse the content error : line " + std::to_string(line_num) + " , " + option_val[0] + " = ?";
throw IllegalArgumentException(error);
}
std::string option = Trim(option_val[0]);
std::string value = Trim(option_val[1]);
Expand Down
8 changes: 4 additions & 4 deletions casbin/enforcer_cached.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ CachedEnforcer::CachedEnforcer(const CachedEnforcer& ce)
this->enableCache = ce.enableCache;
}

CachedEnforcer::CachedEnforcer(CachedEnforcer&& ce)
CachedEnforcer::CachedEnforcer(CachedEnforcer&& ce) noexcept
: Enforcer(ce) {
this->m = move(ce.m);
this->m = std::move(ce.m);
this->enableCache = ce.enableCache;
}

void CachedEnforcer::EnableCache(const bool& enableCache) {
this->enableCache = enableCache;
void CachedEnforcer::EnableCache(const bool& shouldEnableCache) {
this->enableCache = shouldEnableCache;
}

std::pair<bool, bool> CachedEnforcer::getCachedResult(const std::string& key) {
Expand Down
2 changes: 1 addition & 1 deletion casbin/enforcer_synced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void SyncedEnforcer ::SetWatcher(std::shared_ptr<Watcher> w) {

// LoadModel reloads the model from the model CONF file.
void SyncedEnforcer ::LoadModel() {
std::unique_lock<std::shared_mutex>(policyMutex);
std::unique_lock<std::shared_mutex> lock(policyMutex);
Enforcer::LoadModel();
}

Expand Down
5 changes: 1 addition & 4 deletions casbin/management_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ bool Enforcer ::AddNamedPolicy(const std::string& p_type, const std::vector<std:
return this->addPolicy("p", p_type, str_slice);
}

std::vector<std::string> policy;
for (int i = 0; i < params.size(); i++)
policy.push_back(params[i]);
return this->addPolicy("p", p_type, policy);
return this->addPolicy("p", p_type, params);
}

// AddNamedPolicies adds authorization rules to the current named policy.
Expand Down
4 changes: 2 additions & 2 deletions casbin/persist/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
namespace casbin {

// LoadPolicyLine loads a text line as a policy rule to model.
void LoadPolicyLine(std::string line, const std::shared_ptr<Model>& model) {
if (line == "" || line.find("#") == 0)
void LoadPolicyLine(const std::string& line, const std::shared_ptr<Model>& model) {
if (line.empty() || line.find('#') == 0)
return;

std::vector<std::string> tokens = Split(line, ",", -1);
Expand Down
4 changes: 3 additions & 1 deletion casbin/persist/adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
namespace casbin {

// LoadPolicyLine loads a text line as a policy rule to model.
void LoadPolicyLine(std::string line, const std::shared_ptr<Model>& model);
void LoadPolicyLine(const std::string& line, const std::shared_ptr<Model>& model);

/**
* Adapter is the interface for Casbin adapters.
Expand All @@ -34,6 +34,8 @@ class Adapter {
public:
bool filtered;

virtual ~Adapter() = default;

/**
* LoadPolicy loads all policy rules from the storage.
*
Expand Down
4 changes: 3 additions & 1 deletion cmake/modules/Findbenchmark.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ include(FetchContent)

FetchContent_Declare(
benchmark
URL https://github.com/google/benchmark/archive/refs/tags/v1.5.5.zip
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.8.3
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
)

set(BENCHMARK_ENABLE_TESTING OFF)
Expand Down
3 changes: 2 additions & 1 deletion cmake/modules/Findgoogletest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.11.0
GIT_TAG v1.14.0
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
)

# For Windows: Prevent overriding the parent project's compiler/linker settings
Expand Down
7 changes: 6 additions & 1 deletion cmake/modules/Findjson.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ include(FetchContent)

set(JSON_Install ON)

FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz)
FetchContent_Declare(
json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.2
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
)

FetchContent_MakeAvailable(json)
3 changes: 2 additions & 1 deletion cmake/modules/Findpybind11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ include(FetchContent)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.8.0
GIT_TAG v2.11.1
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
)

FetchContent_MakeAvailable(pybind11)
Expand Down
4 changes: 2 additions & 2 deletions include/casbin/enforcer_cached.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class CachedEnforcer : public Enforcer {
std::mutex locker;

CachedEnforcer(const CachedEnforcer& ce);
CachedEnforcer(CachedEnforcer&& ce);
CachedEnforcer(CachedEnforcer&& ce) noexcept;

void EnableCache(const bool& enableCache);
void EnableCache(const bool& shouldEnableCache);
std::pair<bool, bool> getCachedResult(const std::string& key);
void setCachedResult(const std::string& key, const bool& res);
void InvalidateCache();
Expand Down
2 changes: 1 addition & 1 deletion include/casbin/model/evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ExprtkEvaluator : public IEvaluator {

float GetFloat() override;

std::string GetString();
std::string GetString() override;

void Clean(AssertionMap& section, bool after_enforce = true) override;

Expand Down
4 changes: 3 additions & 1 deletion include/casbin/persist/adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
namespace casbin {

// LoadPolicyLine loads a text line as a policy rule to model.
void LoadPolicyLine(std::string line, const std::shared_ptr<Model>& model);
void LoadPolicyLine(const std::string& line, const std::shared_ptr<Model>& model);

/**
* Adapter is the interface for Casbin adapters.
Expand All @@ -34,6 +34,8 @@ class Adapter {
public:
bool filtered;

virtual ~Adapter() = default;

/**
* LoadPolicy loads all policy rules from the storage.
*
Expand Down
45 changes: 21 additions & 24 deletions tests/benchmarks/model_b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,30 @@ static void BenchmarkRBACModel(benchmark::State& state) {
BENCHMARK(BenchmarkRBACModel);

static void BenchmarkRBACModelSizesSmall(benchmark::State& state) {
// 100, 10, 1000
int num_roles = 100, num_resources = 10, num_users = 1000;
int num_roles = 100, num_resources = 10, num_users = 1000;

casbin::Enforcer e(rbac_model_path, "", false);

for (int i = 0; i < num_roles; ++i) e.AddPolicy({"group-has-a-very-long-name-" + std::to_string(i), "data-has-a-very-long-name-" + std::to_string(i % num_resources), "read"});

for (int i = 0; i < num_users; ++i) {
e.AddGroupingPolicy({"user-has-a-very-long-name-" + std::to_string(i), "group-has-a-very-long-name-" + std::to_string(i % num_roles)});
}

int num_request = 17;
std::vector<casbin::DataList> requests(num_request);

for (int i = 0; i < num_request; ++i) {
int id_user = num_users / num_request * i,
id_role = id_user / num_roles,
id_resource = id_role % num_resources;
if (i&2 == 0)
id_resource = (id_resource + 1) % num_resources;

requests[i] = {"user-has-a-very-long-name-" + std::to_string(id_user), "data-has-a-very-long-name-" + std::to_string(id_resource), "read"};
}

for (auto _ : state)
for (auto& req: requests)
e.Enforce(req);
for (int i = 0; i < num_roles; ++i)
e.AddPolicy({
"group-has-a-very-long-name-" + std::to_string(i),
"data-has-a-very-long-name-" + std::to_string(i % num_resources),
"read"
});

for (int i = 0; i < num_users; ++i)
e.AddGroupingPolicy({
"user-has-a-very-long-name-" + std::to_string(i),
"group-has-a-very-long-name-" + std::to_string(i % num_roles)
});

int itr = 0;
for (auto _ : state)
e.Enforce({
"user-has-a-very-long-name-" + std::to_string(itr % num_users),
"data-has-a-very-long-name-" + std::to_string(itr % num_resources),
"read"
}), ++itr;
}

BENCHMARK(BenchmarkRBACModelSizesSmall);
Expand Down

0 comments on commit f6561a4

Please sign in to comment.