GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — key_selector: compile with clang and -fno-exceptions (#2913) · simdjson/simdjson@e9cdb87

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • cmake
    • developer-options.cmake
  • include/simdjson/generic/ondemand
    • key_selector.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎cmake/developer-options.cmake‎

Copy file name to clipboardExpand all lines: cmake/developer-options.cmake
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ else()
175175
if(CMAKE_CXX_STANDARD VERSION_GREATER_EQUAL 20)
176176
target_compile_options(simdjson-internal-flags INTERFACE -Wctad-maybe-unsupported)
177177
endif()
178+
if(NOT SIMDJSON_EXCEPTIONS)
179+
# Compile the tests without exceptions too, so that the headers are
180+
# checked the way users with -fno-exceptions consume them.
181+
target_compile_options(simdjson-internal-flags INTERFACE -fno-exceptions)
182+
endif()
178183

179184
endif()
180185

Collapse file

‎include/simdjson/generic/ondemand/key_selector.h‎

Copy file name to clipboardExpand all lines: include/simdjson/generic/ondemand/key_selector.h
+13-8Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ namespace ondemand {
4646

4747
namespace key_selector_detail {
4848

49+
// Since not constexpr, triggers compile-time error.
50+
inline void compile_time_error(const char* message) noexcept { (void)message; }
51+
4952
// ============================================================================
5053
// Compile-time perfect-hash generator.
5154
// It scales to ~100 keys at compile time by determining association values one (position, character)
@@ -265,7 +268,8 @@ consteval std::size_t select_positions(
265268
if (positions_distinguish<N>(keys, positions.data(), num_pos, modulus)) { return num_pos; }
266269
}
267270

268-
throw "Failed to find distinguishing positions for perfect hash";
271+
compile_time_error("Failed to find distinguishing positions for perfect hash");
272+
return 0;
269273
}
270274

271275
// Result of PHF computation. A max-sized slot_to_key array lets the same struct
@@ -614,7 +618,8 @@ consteval phf_result<N> compute_phf_hd_po2(const std::array<std::string_view, N>
614618
if constexpr (NextM <= phf_result<N>::MAX_TABLE_SIZE) {
615619
return compute_phf_hd_po2<N, NextM>(keys);
616620
} else {
617-
throw "Hash-and-Displace: failed to find valid table size";
621+
compile_time_error("Hash-and-Displace: failed to find valid table size");
622+
return result;
618623
}
619624
}
620625

@@ -661,15 +666,15 @@ template <std::size_t N, std::size_t TableSize, std::size_t MaxKeyLen>
661666
consteval phf_data<N, TableSize, MaxKeyLen>
662667
build_phf_data(const std::array<std::string_view, N>& keys, const phf_result<N>& result) {
663668
for (std::size_t i = 0; i < N; ++i) {
664-
if (keys[i].empty()) { throw "empty keys are not allowed in key_selector"; }
665-
if (keys[i].size() > MaxKeyLen) { throw "key length exceeds MaxKeyLen"; }
669+
if (keys[i].empty()) { compile_time_error("empty keys are not allowed in key_selector"); }
670+
if (keys[i].size() > MaxKeyLen) { compile_time_error("key length exceeds MaxKeyLen"); }
666671
for (char c : keys[i]) {
667-
if (c == '\\') { throw "backslash not allowed in key_selector keys"; }
668-
if (c == '"') { throw "quote not allowed in key_selector keys"; }
669-
if (c == '\0') { throw "null byte not allowed in key_selector keys"; }
672+
if (c == '\\') { compile_time_error("backslash not allowed in key_selector keys"); }
673+
if (c == '"') { compile_time_error("quote not allowed in key_selector keys"); }
674+
if (c == '\0') { compile_time_error("null byte not allowed in key_selector keys"); }
670675
}
671676
for (std::size_t j = i + 1; j < N; ++j) {
672-
if (keys[i] == keys[j]) { throw "duplicate keys in key_selector"; }
677+
if (keys[i] == keys[j]) { compile_time_error("duplicate keys in key_selector"); }
673678
}
674679
}
675680

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.