Skip to content

Commit

Permalink
Use anonymous namespace instead of static in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
joto committed Aug 19, 2024
1 parent 6a15ebd commit 0e0590f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
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 @@ -49,16 +49,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 @@ -98,6 +100,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 0e0590f

Please sign in to comment.