Skip to content

Commit 835c21a

Browse files
committed
BUG: Locale-independent itk::StringToDouble/Float; remove NumericLocale
itk::StringToDouble and itk::StringToFloat (itkStringConvert.h) used std::stod/std::stof, which follow the ambient LC_NUMERIC locale: under a decimal-comma locale "0.878906" parsed as 0 at every IO call site that was migrated to these helpers. Parse with strtod_l/strtof_l against a cached "C" locale, keeping the itk::ExceptionObject contract. Only overflow throws; ERANGE underflow yields a valid subnormal or zero and is accepted (std::stod rejected those valid inputs on some platforms). An unobtainable "C" locale throws instead of silently parsing under the ambient locale. Remove the NumericLocale RAII class (never in a release): switching the thread-local locale via uselocale() is a no-op for the non-_l std::strtod on macOS 13 and earlier libc, so the class cannot honor its contract; its last users are gone (NrrdIO is locale-independent by construction and DCMTKTransformIO now parses DICOM Decimal Strings via itk::StringToDouble, gaining itk::ExceptionObject wrapping). The newlocale/_configthreadlocale try_compile checks remain for itkStringConvert.
1 parent e015fde commit 835c21a

10 files changed

Lines changed: 148 additions & 421 deletions

File tree

Modules/Core/Common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ try_compile(
158158
${CMAKE_CURRENT_SOURCE_DIR}/CMake/itkCheckHasSchedGetAffinity.cxx
159159
)
160160

161-
# Check for thread-local locale functions for NumericLocale
161+
# Check for thread-safe locale functions (locale-independent parsing in itkStringConvert)
162162
try_compile(
163163
ITK_HAS_NEWLOCALE
164164
${ITK_BINARY_DIR}

Modules/Core/Common/include/itkNumericLocale.h

Lines changed: 0 additions & 84 deletions
This file was deleted.

Modules/Core/Common/include/itkStringConvert.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ namespace itk
4343
* `context` describing what was being parsed (e.g.
4444
* ``"NRRD header field 'sizes'"``) plus the offending input string.
4545
*
46+
* The floating-point helpers parse with an explicit "C" locale
47+
* (`strtod_l`-family), so `.` is the decimal separator regardless of
48+
* the ambient `LC_NUMERIC` locale — unlike `std::stod`/`std::stof`,
49+
* which follow the ambient locale. Underflow to a subnormal or zero is
50+
* accepted as a valid value; only overflow throws.
51+
*
4652
* **Fixed-width integer return types** are used (`int32_t`, `int64_t`,
4753
* `uint32_t`, `uint64_t`) rather than the platform-dependent C++
4854
* spellings (`int`, `long`, `unsigned long`). The C++ Standard only

Modules/Core/Common/src/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ set(
106106
itkMultipleLogOutput.cxx
107107
itkMultiThreaderBase.cxx
108108
itkNumberToString.cxx
109-
itkNumericLocale.cxx
110109
itkNumericTraits.cxx
111110
itkNumericTraitsCovariantVectorPixel.cxx
112111
itkNumericTraitsDiffusionTensor3DPixel.cxx

Modules/Core/Common/src/itkNumericLocale.cxx

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)