Commit 91340efd for tesseract
commit 91340efdaac3fe1394752aab0e6de48fb4cb0301
Author: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Date: Sun Aug 9 20:48:36 2026 +0000
Refine fix: move env override to file scope to avoid recursive block-scope static init
GetDetector() now contains only the function-local static. The DOTPRODUCT
env var override is applied via a file-scope IIFE placed after detector_init,
guaranteeing the detector is fully constructed before Update() is called and
eliminating all recursive re-entry of GetDetector() during initialization.
Co-authored-by: stweil <6734573+stweil@users.noreply.github.com>
diff --git a/src/arch/simddetect.cpp b/src/arch/simddetect.cpp
index 324bba18..132ef8e4 100644
--- a/src/arch/simddetect.cpp
+++ b/src/arch/simddetect.cpp
@@ -92,18 +92,6 @@ const SIMDDetect &SIMDDetect::GetDetector() {
// A function local static variable is initialized when the function is
// first called, so there is no problem with the order of initialization.
static const SIMDDetect detector;
- // Apply DOTPRODUCT environment variable override after construction.
- // Using a static flag ensures this only runs once, and defers the override
- // until after the detector is fully constructed to avoid recursive
- // re-entry of GetDetector() during static initialization.
- [[maybe_unused]] static bool env_override_applied = []() -> bool {
- const char *dotproduct_env = getenv("DOTPRODUCT");
- if (dotproduct_env != nullptr) {
- dotproduct = dotproduct_env;
- Update();
- }
- return true;
- }();
return detector;
}
@@ -112,6 +100,18 @@ const SIMDDetect &SIMDDetect::GetDetector() {
// SIMDDetect::Update() or any of the Is*Available() functions.
static const SIMDDetect &detector_init = SIMDDetect::GetDetector();
+// Apply DOTPRODUCT environment variable override after detector construction.
+// Placed here (after detector_init) so the detector is fully constructed
+// before Update() is called, avoiding recursive re-entry of GetDetector().
+[[maybe_unused]] static bool env_override_applied = []() -> bool {
+ const char *dotproduct_env = getenv("DOTPRODUCT");
+ if (dotproduct_env != nullptr) {
+ dotproduct = dotproduct_env;
+ SIMDDetect::Update();
+ }
+ return true;
+}();
+
#if defined(__aarch64__)
// ARMv8 always has NEON.
bool SIMDDetect::neon_available_ = true;