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

feat: add windows support #119

Merged
merged 5 commits into from May 20, 2024
Merged

feat: add windows support #119

merged 5 commits into from May 20, 2024

Conversation

dmehala
Copy link
Collaborator

@dmehala dmehala commented May 6, 2024

Description

This PR add support for windows. It is a prerequisite for #85.

Contains:

  • refactor: the codebase to use substr instead of range.
  • refactor: CMake targets.
  • refactor: add bazelrc to build using either abseil or std::string STD.
  • ci: build and run on windows using CMake and bazel.
  • update: add platform support section and update building instructions.

@dmehala dmehala force-pushed the dmehala/windows-support-2 branch from e98f1b7 to a98849c Compare May 6, 2024 11:51
@pr-commenter
Copy link

pr-commenter bot commented May 6, 2024

Benchmarks

Benchmark execution time: 2024-05-20 21:14:39

Comparing candidate commit 7355dcc in PR branch dmehala/windows-support-2 with baseline commit f8cacf4 in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics.

@dmehala dmehala marked this pull request as ready for review May 6, 2024 11:57
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/datadog/expected.h Outdated Show resolved Hide resolved
test/system-tests/main.cpp Outdated Show resolved Hide resolved
@dmehala dmehala requested review from a team and cataphract and removed request for a team and cataphract May 7, 2024 13:57
Copy link

@pablomartinezbernardo pablomartinezbernardo left a comment

Choose a reason for hiding this comment

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

Small comment, LGTM

Comment on lines 90 to 100
bool starts_with(StringView subject, StringView prefix) {
if (prefix.size() > subject.size()) {
return false;
auto s = subject.data();
auto p = prefix.data();
const auto prefix_end = p + prefix.size();
while (*s == *p) {
++s;
++p;
}

return std::mismatch(subject.begin(), subject.end(), prefix.begin()).second ==
prefix.end();
return p == prefix_end;
}

Choose a reason for hiding this comment

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

This will cause problems when subject is equal to prefix, right? Not that important, but should also not be difficult to fix

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

[question] why?

Choose a reason for hiding this comment

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

There's nothing stopping s and p from going over the end of the string_view, so it would be undefined behavior, but even if nothing breaks the condition p == prefix_end will be false. Did a small example to reproduce it

image

To avoid that, the function could be written like this for example

bool starts_with(StringView subject, StringView prefix) {
  auto s = subject.data();
  auto p = prefix.data();
  const auto prefix_end = p + prefix.size();
  while (p < prefix_end) {
    if (*s++ != *p++) {
        return false;
    }
  }

  return true;
}

Copy link
Collaborator Author

@dmehala dmehala May 17, 2024

Choose a reason for hiding this comment

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

There's nothing stopping s and p from going over the end of the string_view, so it would be undefined behavior

Indeed, thanks to Github awful diff I thought if (prefix.size() > subject.size()) { ... } was part of the implementation, which reduce the area of the UB. However, as you mentioned, if prefix.size() == subject.size() then it's undefined behaviour and plain wrong. Thank you.

  • Fix implementation + add unit tests.

- refactor: the codebase to use `substr` instead of `range`.
- refactor: CMake targets.
- refactor: add bazelrc to build using either abseil or std::string STD.
- ci: build and run on windows using CMake and bazel.
- update: add platform support section and update building instructions.
@dmehala dmehala force-pushed the dmehala/windows-support-2 branch from a98849c to d7bb00e Compare May 20, 2024 17:43
@dmehala dmehala merged commit fad4e8d into main May 20, 2024
22 checks passed
@dmehala dmehala deleted the dmehala/windows-support-2 branch May 20, 2024 21:19
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.

None yet

2 participants