From d0bbc1460756466acb45bf0d8f8a61e0f59b1d56 Mon Sep 17 00:00:00 2001 From: Nathan Memmott Date: Wed, 17 Jun 2026 11:53:17 -0700 Subject: [PATCH 4/7] Disable exceptions in darts.h under DARTS_DISABLE_EXCEPTIONS --- .../src/third_party/darts_clone/darts.h | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/third_party/sentencepiece/src/third_party/darts_clone/darts.h b/third_party/sentencepiece/src/third_party/darts_clone/darts.h index aeb5115662c41..fad75422bd280 100644 --- a/third_party/sentencepiece/src/third_party/darts_clone/darts.h +++ b/third_party/sentencepiece/src/third_party/darts_clone/darts.h @@ -6,6 +6,10 @@ #include #include +#if DARTS_DISABLE_EXCEPTIONS +#include "absl/log/absl_check.h" +#endif + #define DARTS_VERSION "0.32" // DARTS_THROW() throws a whose message starts with the @@ -16,8 +20,12 @@ #define DARTS_INT_TO_STR(value) #value #define DARTS_LINE_TO_STR(line) DARTS_INT_TO_STR(line) #define DARTS_LINE_STR DARTS_LINE_TO_STR(__LINE__) +#if DARTS_DISABLE_EXCEPTIONS +#define DARTS_THROW(msg) ABSL_CHECK(false) << (msg) +#else #define DARTS_THROW(msg) throw Darts::Details::Exception( \ __FILE__ ":" DARTS_LINE_STR ": exception: " msg) +#endif namespace Darts { @@ -387,15 +395,19 @@ int DoubleArrayImpl::open(const char *file_name, } unit_type *buf; +#if !DARTS_DISABLE_EXCEPTIONS try { +#endif buf = new unit_type[size]; for (id_type i = 0; i < 256; ++i) { buf[i] = units[i]; } +#if !DARTS_DISABLE_EXCEPTIONS } catch (const std::bad_alloc &) { std::fclose(file); DARTS_THROW("failed to open double-array: std::bad_alloc"); } +#endif if (size > 256) { if (std::fread(buf + 256, unit_size(), size - 256, file) != size - 256) { @@ -731,11 +743,15 @@ void AutoPool::resize_buf(std::size_t size) { } AutoArray buf; +#if !DARTS_DISABLE_EXCEPTIONS try { +#endif buf.reset(new char[sizeof(T) * capacity]); +#if !DARTS_DISABLE_EXCEPTIONS } catch (const std::bad_alloc &) { DARTS_THROW("failed to resize pool: std::bad_alloc"); } +#endif if (size_ > 0) { T *src = reinterpret_cast(&buf_[0]); @@ -870,11 +886,15 @@ class BitVector { }; inline void BitVector::build() { +#if !DARTS_DISABLE_EXCEPTIONS try { +#endif ranks_.reset(new id_type[units_.size()]); +#if !DARTS_DISABLE_EXCEPTIONS } catch (const std::bad_alloc &) { DARTS_THROW("failed to build rank index: std::bad_alloc"); } +#endif num_ones_ = 0; for (std::size_t i = 0; i < units_.size(); ++i) { -- 2.54.0.1189.g8c84645362-goog