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

baldr: Adjusting code to C++17 #4011

Merged
merged 35 commits into from
Apr 11, 2023
Merged

Conversation

cvvergara
Copy link
Contributor

@cvvergara cvvergara commented Mar 7, 2023

Issue

baldr part of #4018

TODO

  • removing the superfluous try catch from the new edgeinfo function
  • correcting the docstrings for the edgeinfo functions
  • making a sentinel invalid function that is properly typed to replace uses of -1 (probably goes in midgard/util headers or somewhere everything can use it)
  • fixing the system include directive to work in the valhalla_module so we can keep date stuff in baldr

@cvvergara
Copy link
Contributor Author

cvvergara commented Mar 9, 2023

In this commit:
9440737
all files on sources_with_warnings are moved to sources
No warning on baldr should appear on the CI when this PR is ready for review.

@cvvergara cvvergara marked this pull request as ready for review March 9, 2023 22:32
@cvvergara cvvergara changed the title Adjusting code to C++17 baldr: Adjusting code to C++17 Mar 10, 2023
@cvvergara cvvergara mentioned this pull request Mar 10, 2023
16 tasks
CMakeLists.txt Outdated Show resolved Hide resolved
src/baldr/edgeinfo.cc Outdated Show resolved Hide resolved
src/baldr/admin.cc Outdated Show resolved Hide resolved
src/baldr/connectivity_map.cc Outdated Show resolved Hide resolved
src/baldr/datetime.cc Show resolved Hide resolved
src/baldr/edgeinfo.cc Outdated Show resolved Hide resolved
src/baldr/edgeinfo.cc Outdated Show resolved Hide resolved
@cvvergara
Copy link
Contributor Author

@kevinkreiser I think this is ready.

@kevinkreiser
Copy link
Member

sounds good! ill take another look hopefully this evening, sorry again for the delay and thanks again for grinding th rough it!

@cvvergara
Copy link
Contributor Author

@kevinkreiser made the changes

Comment on lines 562 to 564
uint32_t max_id = tile_level.tiles.ncolumns() > 0 && tile_level.tiles.nrows() > 0
? tile_level.tiles.ncolumns() * tile_level.tiles.nrows() - 1
: 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same casting here for same reason

strncpy(version_, version.c_str(), kMaxVersionSize);
// reinitializing the version array before copying
version_ = {};
std::copy(version.begin(), version.begin() + std::min(kMaxVersionSize, sizeof(version.c_str())),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the previous code was a bug because someone could screw with the version string and make it shorter than kMaxVersionSize and strncpy would have read past the end, so its good you are fixing it however i think you have a new bug here, this should be:

Suggested change
std::copy(version.begin(), version.begin() + std::min(kMaxVersionSize, sizeof(version.c_str())),
std::copy(version.begin(), version.begin() + std::min(kMaxVersionSize, version.size()),

otherwise it will only ever copy 8 bytes because c_str() is a pointer which is 64bits wide (these days)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch :-)

@cvvergara
Copy link
Contributor Author

@kevinkreiser made the changes

@kevinkreiser
Copy link
Member

ok i made it to the bottom of the diff! the only changes i would request are:

  1. removing the superfluous try catch from the new edgeinfo function
  2. correcting the docstrings for the edgeinfo functions
  3. making a sentinel invalid function that is properly typed to replace uses of -1 (probably goes in midgard/util headers or somewhere everything can use it)
  4. fixing the system include directive to work in the valhalla_module so we can keep date stuff in baldr

@kevinkreiser
Copy link
Member

kevinkreiser commented Mar 19, 2023

regarding number 4, i tried it out myself and it just worked for me, this was my diff with master:

diff --git a/src/baldr/CMakeLists.txt b/src/baldr/CMakeLists.txt
index 1ce31ea6d..306646f26 100644
--- a/src/baldr/CMakeLists.txt
+++ b/src/baldr/CMakeLists.txt
@@ -30,7 +30,6 @@ set(includes
      ${VALHALLA_SOURCE_DIR}/valhalla
      $<$<BOOL:${WIN32}>:${VALHALLA_SOURCE_DIR}/third_party/dirent/include>
      ${VALHALLA_SOURCE_DIR}/third_party/rapidjson/include
-     ${VALHALLA_SOURCE_DIR}/third_party/date/include
      ${CMAKE_CURRENT_BINARY_DIR}/src/baldr
      )
 
@@ -114,6 +113,8 @@ valhalla_module(NAME baldr
       ${includes}
     PRIVATE
       ${CMAKE_CURRENT_BINARY_DIR}
+  SYSTEM
+      ${VALHALLA_SOURCE_DIR}/third_party/date/include
 
   DEPENDS
     valhalla::midgard

now in reality it should be slightly more complicated because of the ios includes i guess but only very slightly more complicated. also, did you know that clion now lets you debug cmake scripts!? its awesome you can litterally step through a cmake run in the debugger and watch varaibles and general flow through the script, pretty awesome!

@cvvergara
Copy link
Contributor Author

cvvergara commented Mar 19, 2023

regarding number 4, i tried it out myself and it just worked for me, this was my diff with master:

diff --git a/src/baldr/CMakeLists.txt b/src/baldr/CMakeLists.txt
index 1ce31ea6d..306646f26 100644
--- a/src/baldr/CMakeLists.txt
+++ b/src/baldr/CMakeLists.txt
@@ -30,7 +30,6 @@ set(includes
      ${VALHALLA_SOURCE_DIR}/valhalla
      $<$<BOOL:${WIN32}>:${VALHALLA_SOURCE_DIR}/third_party/dirent/include>
      ${VALHALLA_SOURCE_DIR}/third_party/rapidjson/include
-     ${VALHALLA_SOURCE_DIR}/third_party/date/include
      ${CMAKE_CURRENT_BINARY_DIR}/src/baldr
      )
 
@@ -114,6 +113,8 @@ valhalla_module(NAME baldr
       ${includes}
     PRIVATE
       ${CMAKE_CURRENT_BINARY_DIR}
+  SYSTEM
+      ${VALHALLA_SOURCE_DIR}/third_party/date/include
 
   DEPENDS
     valhalla::midgard

now in reality it should be slightly more complicated because of the ios includes i guess but only very slightly more complicated. also, did you know that clion now lets you debug cmake scripts!? its awesome you can litterally step through a cmake run in the debugger and watch varaibles and general flow through the script, pretty awesome!

Doing that is leading to this in my computer (doing make VERBOSE=ON):

-I/home/vicky/valhalla/cvvergara/src/baldr/SYSTEM -I/home/vicky/valhalla/cvvergara/third_party/date/include

instead of:

-isystem /home/vicky/valhalla/cvvergara/third_party/date/include

Update, I didnt see the indentation, does not work :-(

src/baldr/edgeinfo.cc Outdated Show resolved Hide resolved
valhalla/baldr/edgeinfo.h Outdated Show resolved Hide resolved
@cvvergara cvvergara force-pushed the range-for-loops branch 4 times, most recently from 0fb92a8 to 6a8c6ae Compare April 5, 2023 22:52
@cvvergara
Copy link
Contributor Author

ok i left a fresh round of review comments after going over the whole thing again. all of them are trivial so i suspect we can merge this soon?

Yes

kevinkreiser
kevinkreiser previously approved these changes Apr 11, 2023
@kevinkreiser
Copy link
Member

kevinkreiser commented Apr 11, 2023

we missed the one update to the docstring so i just commited it and since its only a comment i will just merge no need to wait for build

@kevinkreiser kevinkreiser merged commit f79a4a4 into valhalla:master Apr 11, 2023
@cvvergara cvvergara deleted the range-for-loops branch April 11, 2023 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants