Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS issues reported in #455 #456

Merged
merged 12 commits into from
Sep 10, 2024
26 changes: 26 additions & 0 deletions .github/workflows/macos_14.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build on macOS 14

on: [push, pull_request]

jobs:
build:
runs-on: macos-14

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install dependencies
run: |
brew install boost cryptopp fmt fcgi yajl libmemcached libpqxx postgresql

- name: build
run: |
mkdir build && cd build && \
CXXFLAGS="-Wall -Wextra -Wpedantic -Wno-unused-parameter" cmake .. -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release && \
make -j${nproc} && \
ctest --output-on-failure -E "db"

- name: Running openstreetmap-cgimap
run: |
./build/openstreetmap-cgimap --help
9 changes: 3 additions & 6 deletions contrib/sjparser/library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
find_library(YAJL_LIB yajl)
if(NOT YAJL_LIB)
message(FATAL_ERROR "Can't find yajl library")
endif()
find_package(YAJL 2 REQUIRED)

add_library(sjparser STATIC
sjparser/parsing_error.cpp
Expand Down Expand Up @@ -42,7 +39,7 @@ set_target_properties(sjparser PROPERTIES OUTPUT_NAME sjparser_static)

setup_compilation_options(sjparser)

target_link_libraries(sjparser PUBLIC ${YAJL_LIB})
target_link_libraries(sjparser PUBLIC YAJL::YAJL)

target_include_directories(sjparser PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
Expand All @@ -60,7 +57,7 @@ if(SJPARSER_BUILD_SHARED_LIBRARY)

setup_compilation_options(sjparser_shared)

target_link_libraries(sjparser_shared PUBLIC ${YAJL_LIB})
target_link_libraries(sjparser_shared PUBLIC YAJL::YAJL)

target_include_directories(sjparser_shared PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
Expand Down
29 changes: 29 additions & 0 deletions include/cgimap/api06/changeset_upload/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Node : public OSMObject {

double _lat;

#if !defined(__APPLE__)
auto [_, ec] = std::from_chars(lat.data(), lat.data() + lat.size(), _lat);

if (ec == std::errc())
Expand All @@ -42,12 +43,26 @@ class Node : public OSMObject {
throw payload_error("Latitude value is too large");
else
throw payload_error("Unexpected parsing error");

#else

try {
_lat = std::stod(lat);
} catch (std::invalid_argument &e) {
throw payload_error("Latitude is not numeric");
} catch (std::out_of_range &e) {
throw payload_error("Latitude value is too large");
}
set_lat(_lat);

#endif
}

void set_lon(const std::string &lon) {

double _lon;

#if !defined(__APPLE__)
auto [_, ec] = std::from_chars(lon.data(), lon.data() + lon.size(), _lon);

if (ec == std::errc())
Expand All @@ -58,6 +73,20 @@ class Node : public OSMObject {
throw payload_error("Longitude value is too large");
else
throw payload_error("Unexpected parsing error");

#else

try {
_lon = std::stod(lon);
} catch (std::invalid_argument &e) {
throw payload_error("Longitude is not numeric");
} catch (std::out_of_range &e) {
throw payload_error("Longitude value is too large");
}

set_lon(_lon);

#endif
}

void set_lat(double lat) {
Expand Down
3 changes: 1 addition & 2 deletions include/cgimap/backend/apidb/pqxx_string_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct array_string_traits
template<> \
struct string_traits<type> : cgimap::array_string_traits<type> {}; \
\
template<> std::string const type_name<type>{#type}; \
template<> inline std::string const type_name<type>{#type}; \


#endif
Expand All @@ -127,7 +127,6 @@ PQXX_ARRAY_STRING_TRAITS(std::vector<tile_id_t>);
PQXX_ARRAY_STRING_TRAITS(std::vector<osm_changeset_id_t>);
PQXX_ARRAY_STRING_TRAITS(std::set<osm_changeset_id_t>);
PQXX_ARRAY_STRING_TRAITS(std::vector<std::string>);
PQXX_ARRAY_STRING_TRAITS(std::vector<bool>);

} // namespace pqxx

Expand Down
27 changes: 27 additions & 0 deletions include/cgimap/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,33 @@

#include <fmt/core.h>
#include <fmt/format.h>
#include <fmt/ranges.h>


#if __APPLE__
// NOTE: <codecvt> is deprecated in C++17 and removed in C++26 (see P2871R3).

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"

#include <codecvt>
#include <iomanip>
#include <stdexcept>

inline std::size_t unicode_strlen(const std::string& utf8)
{

try {
return std::wstring_convert< std::codecvt_utf8<char32_t>, char32_t >{}.from_bytes(utf8).size();
} catch(std::range_error) {
throw http::bad_request("Invalid UTF-8 string encountered");
}
}

#pragma clang diagnostic pop

#else

inline size_t unicode_strlen(const std::string & s)
{
const char* mbstr = s.c_str();
Expand All @@ -43,6 +68,8 @@ inline size_t unicode_strlen(const std::string & s)
return len;
}

#endif

inline std::string escape(std::string_view input) {

int n = 0;
Expand Down
11 changes: 4 additions & 7 deletions src/backend/apidb/changeset_upload/relation_updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1239,17 +1239,16 @@ void ApiDB_Relation_Updater::update_current_relations(

m.prepare("update_current_relations",
R"(
WITH u(id, changeset_id, visible, version) AS (
WITH u(id, changeset_id, version) AS (
SELECT * FROM
UNNEST( CAST($1 AS bigint[]),
CAST($2 AS bigint[]),
CAST($3 AS boolean[]),
CAST($4 AS bigint[])
CAST($3 AS bigint[])
)
)
UPDATE current_relations AS r
SET changeset_id = u.changeset_id,
visible = u.visible,
visible = CAST($4 as boolean),
timestamp = (now() at time zone 'utc'),
version = u.version + 1
FROM u
Expand All @@ -1260,20 +1259,18 @@ void ApiDB_Relation_Updater::update_current_relations(

std::vector<osm_nwr_signed_id_t> ids;
std::vector<osm_changeset_id_t> cs;
std::vector<bool> visibles;
std::vector<osm_version_t> versions;
std::map<osm_nwr_id_t, osm_nwr_signed_id_t> id_to_old_id;

for (const auto &relation : relations) {
ids.emplace_back(relation.id);
cs.emplace_back(relation.changeset_id);
visibles.push_back(visible);
versions.emplace_back(relation.version);
id_to_old_id[relation.id] = relation.old_id;
}

pqxx::result r =
m.exec_prepared("update_current_relations", ids, cs, visibles, versions);
m.exec_prepared("update_current_relations", ids, cs, versions, visible);

if (r.affected_rows() != relations.size())
throw http::server_error("Could not update all current relations");
Expand Down
11 changes: 4 additions & 7 deletions src/backend/apidb/changeset_upload/way_updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,17 +642,16 @@ void ApiDB_Way_Updater::update_current_ways(const std::vector<way_t> &ways,
return;

m.prepare("update_current_ways", R"(
WITH u(id, changeset_id, visible, version) AS (
WITH u(id, changeset_id, version) AS (
SELECT * FROM
UNNEST( CAST($1 AS bigint[]),
CAST($2 AS bigint[]),
CAST($3 AS boolean[]),
CAST($4 AS bigint[])
CAST($3 AS bigint[])
)
)
UPDATE current_ways AS w
SET changeset_id = u.changeset_id,
visible = u.visible,
visible = CAST($4 as boolean),
timestamp = (now() at time zone 'utc'),
version = u.version + 1
FROM u
Expand All @@ -663,20 +662,18 @@ void ApiDB_Way_Updater::update_current_ways(const std::vector<way_t> &ways,

std::vector<osm_nwr_signed_id_t> ids;
std::vector<osm_changeset_id_t> cs;
std::vector<bool> visibles;
std::vector<osm_version_t> versions;
std::map<osm_nwr_id_t, osm_nwr_signed_id_t> id_to_old_id;

for (const auto &way : ways) {
ids.emplace_back(way.id);
cs.emplace_back(way.changeset_id);
visibles.push_back(visible);
versions.emplace_back(way.version);
id_to_old_id[way.id] = way.old_id;
}

pqxx::result r =
m.exec_prepared("update_current_ways", ids, cs, visibles, versions);
m.exec_prepared("update_current_ways", ids, cs, versions, visible);

if (r.affected_rows() != ways.size())
throw http::server_error("Could not update all current ways");
Expand Down
2 changes: 1 addition & 1 deletion src/backend/apidb/pgsql_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ uint64_t pgsql_update::get_bbox_size_limit(osm_user_id_t uid)
auto row = res[0];
auto bbox_size_limit = row[0].as<int64_t>();

return std::max(bbox_size_limit, 0L);
return (bbox_size_limit < 0 ? 0 : bbox_size_limit);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/fcgi_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ int fcgi_request::accept_r() {
} else {
char err_buf[1024];
out << "error accepting request: ";
if (strerror_r(errno, err_buf, sizeof err_buf) == nullptr) {
if (strerror_r(errno, err_buf, sizeof err_buf) == 0) { // NOLINT(modernize-use-nullptr)
out << err_buf;
} else {
out << "error encountered while getting error message";
Expand Down
6 changes: 6 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ void reload(int) {
reload_requested = true;
}

#if __APPLE__
#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 255
#endif
#endif

/**
* make a string to be used as the generator header
* attribute of output files. includes some instance
Expand Down
4 changes: 2 additions & 2 deletions src/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ void request::check_workflow(workflow_status this_stage) {
} else if (m_workflow_status > this_stage) {
// oops - workflow is more advanced than the function which called
// this, so a workflow violation has occurred.
throw std::runtime_error(fmt::format("Can't move backwards in the request workflow from {} to {}.",
m_workflow_status, this_stage));
throw std::runtime_error(fmt::format("Can't move backwards in the request workflow from {:d} to {:d}.",
static_cast<int>(m_workflow_status), static_cast<int>(this_stage)));
}
}

Expand Down
Loading