Skip to content

Commit

Permalink
Merge pull request #456 from mmd-osm/patch/issue_455_part1
Browse files Browse the repository at this point in the history
MacOS issues reported in #455
  • Loading branch information
mmd-osm authored Sep 10, 2024
2 parents 0df23d6 + a62ab3f commit 9d378ab
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 10 deletions.
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
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
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

0 comments on commit 9d378ab

Please sign in to comment.