Skip to content

Commit

Permalink
Merge pull request #2239 from joto/more-anon-ns
Browse files Browse the repository at this point in the history
Refactors final cases of use of "static"
  • Loading branch information
lonvia authored Sep 1, 2024
2 parents 0ccce1d + d2e58a0 commit 21f7e00
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
5 changes: 1 addition & 4 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
Checks: '*,-abseil-*,-altera-*,-android-cloexec-*,-bugprone-easily-swappable-parameters,-cert-err58-cpp,-cppcoreguidelines-avoid-do-while,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-cstyle-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-static-cast-downcast,-cppcoreguidelines-pro-type-vararg,-fuchsia-*,-google-readability-casting,-google-readability-todo,-hicpp-named-parameter,-hicpp-no-array-decay,-hicpp-vararg,-llvm-include-order,-llvm-header-guard,-llvmlibc-*,-misc-include-cleaner,-misc-no-recursion,-misc-use-anonymous-namespace,-modernize-use-nodiscard,-modernize-use-trailing-return-type,-readability-identifier-length,-readability-implicit-bool-conversion,-readability-named-parameter,-readability-magic-numbers'
Checks: '*,-abseil-*,-altera-*,-android-cloexec-*,-bugprone-easily-swappable-parameters,-cert-err58-cpp,-cppcoreguidelines-avoid-do-while,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-cstyle-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-static-cast-downcast,-cppcoreguidelines-pro-type-vararg,-fuchsia-*,-google-readability-casting,-google-readability-todo,-hicpp-named-parameter,-hicpp-no-array-decay,-hicpp-vararg,-llvm-include-order,-llvm-header-guard,-llvmlibc-*,-misc-include-cleaner,-misc-no-recursion,-modernize-use-nodiscard,-modernize-use-trailing-return-type,-readability-identifier-length,-readability-implicit-bool-conversion,-readability-named-parameter,-readability-magic-numbers'
#
# cppcoreguidelines-pro-type-cstyle-cast
# google-build-using-namespace
Expand Down Expand Up @@ -65,9 +65,6 @@ Checks: '*,-abseil-*,-altera-*,-android-cloexec-*,-bugprone-easily-swappable-par
# misc-no-recursion
# Nothing wrong with recursion
#
# misc-use-anonymous-namespace (new in clang-tidy-16)
# Lots of these, need some time to fix. (TODO)
#
# modernize-use-nodiscard
# Doesn't really make the code clearer if it is all littered with
# [[nodiscard]]. Looks like this warning is more suited for a library
Expand Down
2 changes: 1 addition & 1 deletion src/gen/osm2pgsql-gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
// context object.
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define TRAMPOLINE(func_name, lua_name) \
static int lua_trampoline_##func_name(lua_State *lua_state) \
int lua_trampoline_##func_name(lua_State *lua_state) \
{ \
try { \
return static_cast<genproc_t *>(luaX_get_context(lua_state)) \
Expand Down
6 changes: 5 additions & 1 deletion src/lua-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ void *luaX_get_context(lua_State *lua_state) noexcept

#else

namespace {

// Unique key for lua registry
static char const *osm2pgsql_output_flex = "osm2pgsql_output_flex";
constexpr char const *const osm2pgsql_output_flex = "osm2pgsql_output_flex";

} // anonymous namespace

void luaX_set_context(lua_State *lua_state, void *ptr) noexcept
{
Expand Down
8 changes: 6 additions & 2 deletions src/output-flex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,18 @@
#include <string>
#include <string_view>

namespace {

// Mutex used to coordinate access to Lua code
static std::mutex lua_mutex;
std::mutex lua_mutex;

// Lua can't call functions on C++ objects directly. This macro defines simple
// C "trampoline" functions which are called from Lua which get the current
// context (the output_flex_t object) and call the respective function on the
// context object.
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define TRAMPOLINE(func_name, lua_name) \
static int lua_trampoline_##func_name(lua_State *lua_state) \
int lua_trampoline_##func_name(lua_State *lua_state) \
{ \
try { \
return static_cast<output_flex_t *>(luaX_get_context(lua_state)) \
Expand Down Expand Up @@ -99,6 +101,8 @@ TRAMPOLINE(expire_output_schema, schema)
TRAMPOLINE(expire_output_table, table)
TRAMPOLINE(expire_output_tostring, __tostring)

} // anonymous namespace

prepared_lua_function_t::prepared_lua_function_t(lua_State *lua_state,
calling_context context,
char const *name, int nresults)
Expand Down
6 changes: 5 additions & 1 deletion src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
#include <cassert>
#include <cstdlib>

static constexpr char const *const properties_table = "osm2pgsql_properties";
namespace {

constexpr char const *const properties_table = "osm2pgsql_properties";

} // anonymous namespace

properties_t::properties_t(connection_params_t connection_params,
std::string schema)
Expand Down
6 changes: 5 additions & 1 deletion src/wkb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,9 @@ geom::geometry_t ewkb_to_geom(std::string_view wkb)
return geom;
}

static constexpr std::array<char, 256> const hex_table = {
namespace {

constexpr std::array<char, 256> const hex_table = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand All @@ -587,6 +589,8 @@ static constexpr std::array<char, 256> const hex_table = {
0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};

} // anonymous namespace

unsigned char decode_hex_char(char c) noexcept
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index)
Expand Down

0 comments on commit 21f7e00

Please sign in to comment.