-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dso_demo] Add some non-trivial constructions (e.g. using TLS)
The use of TLS from DSOs presents particularly interesting technical challenges. The use of TLS in general triggers a certain problem in Bazel on MacOS at this point, which can be avoided by compiling with --dynamic_mode=off or by disabling the dynamic mode feature entirely (see bazelbuild/bazel#4341 (comment)).
- Loading branch information
Showing
3 changed files
with
27 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,23 @@ | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <string> | ||
#include <string_view> | ||
|
||
extern "C" void demo_function() { | ||
std::puts("I am a function."); | ||
#include "absl/strings/string_view.h" | ||
#include "absl/container/flat_hash_map.h" | ||
|
||
extern "C" void demo_function(std::size_t n, const char* args[]) { | ||
std::puts("I am a function. Here come my arguments."); | ||
|
||
absl::flat_hash_map<std::string, std::vector<std::string>> m; | ||
|
||
for (std::size_t i = 0; i != n; ++i) { | ||
absl::string_view arg = args[i]; | ||
m[arg].emplace_back().assign(arg); | ||
} | ||
|
||
for (const auto& [k, v] : m) { | ||
std::printf("Argument '%*s' appears %zu times.\n", | ||
static_cast<int>(k.size()), k.data(), v.size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters