Skip to content

BUG: Fix number encoding to use C locale#2297

Merged
dzenanz merged 2 commits intoInsightSoftwareConsortium:masterfrom
okaerin:fix-vtk-io-float-encoding
Feb 15, 2021
Merged

BUG: Fix number encoding to use C locale#2297
dzenanz merged 2 commits intoInsightSoftwareConsortium:masterfrom
okaerin:fix-vtk-io-float-encoding

Conversation

@okaerin
Copy link
Contributor

@okaerin okaerin commented Feb 12, 2021

The floating point number encoding defaults to the C locale on the standard C++ std IO. The sscanf uses the OS dependent LC_NUMERIC value. This fixes that behavior
EDIT
Closes #2067

PR Checklist

  • No API changes were made (or the changes have been approved)
  • No major design changes were made (or the changes have been approved)
  • Added test (or behavior not changed)
  • Updated API documentation (or API not changed)
  • Added license to new files (if any)
  • Added Python wrapping to new files (if any) as described in ITK Software Guide Section 9.5
  • Added ITK examples for all new major features (if any)

Refer to the ITK Software Guide for
further development details if necessary.

The floating point number encoding defaults to the C locale on the standard C++ std IO. The sscanf uses the OS dependent LC_NUMERIC value. This fixes that behavior
@okaerin okaerin mentioned this pull request Feb 12, 2021
Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good. Minor style issue: there should be a space between statement and a comment. The in-line suggestion should be applied to all the cases.

fixed a missing locale reset. fixed the mentioned styling issues.
@okaerin okaerin changed the title BUG: Fix number encoding to use C locale BUG: Fix number encoding to use C locale Closes #2067 Feb 12, 2021
@okaerin okaerin changed the title BUG: Fix number encoding to use C locale Closes #2067 BUG: Fix number encoding to use C locale Feb 12, 2021
@dzenanz dzenanz merged commit c01cd4b into InsightSoftwareConsortium:master Feb 15, 2021
thewtex added a commit that referenced this pull request Dec 17, 2025
Avoid locale-dependent of floating-point metadata re: #5683, #3375, #2297

Implement locale handling in
Modules/IO/NRRD/src/itkNrrdImageIO.cxx using RAII pattern.

- Add ScopedCNumericLocale class for automatic locale save/restore
- Apply locale protection around nrrdLoad/nrrdSave calls
- Add test coverage (itkNrrdLocaleTest.cxx)

Co-authored-by: Matt McCormick <matt@fideus.io>
hjmjohnson pushed a commit that referenced this pull request Jan 23, 2026
Avoid locale-dependent of floating-point metadata re: #5683, #3375, #2297

Implement locale handling in
Modules/IO/NRRD/src/itkNrrdImageIO.cxx using RAII pattern.

- Add ScopedCNumericLocale class for automatic locale save/restore
- Apply locale protection around nrrdLoad/nrrdSave calls
- Add test coverage (itkNrrdLocaleTest.cxx)

Co-authored-by: Matt McCormick <matt@fideus.io>
hjmjohnson pushed a commit that referenced this pull request Jan 23, 2026
Avoid locale-dependent of floating-point metadata re: #5683, #3375, #2297

Implement locale handling in
Modules/IO/NRRD/src/itkNrrdImageIO.cxx using RAII pattern.

- Add ScopedCNumericLocale class for automatic locale save/restore
- Add thread-safe NumericLocale utility class.  This addresses
  thread-safety concerns raised in code review. Thread safety implementation:
   - Windows: Uses _configthreadlocale() for thread-local locale
   - POSIX (Linux/macOS): Uses newlocale()/uselocale() for thread-local locale
   - Fallback: Mutex-protected global locale as last resort
- Apply locale protection around nrrdLoad/nrrdSave calls
- Add test coverage (itkNrrdLocaleTest.cxx)

Create thread-safe locale handling in ITKCommon to replace non-thread-safe
setlocale() calls. Update NRRD reader to use the new utility.

Co-authored-by: Matt McCormick <matt@fideus.io>
Co-authored-by: Bradley Lowekamp <blowekamp@mail.nih.gov>
hjmjohnson pushed a commit that referenced this pull request Jan 23, 2026
Avoid locale-dependent of floating-point metadata re: #5683, #3375, #2297

Implement locale handling in
Modules/IO/NRRD/src/itkNrrdImageIO.cxx using RAII pattern.

- Add ScopedCNumericLocale class for automatic locale save/restore
- Add thread-safe NumericLocale utility class.  This addresses
  thread-safety concerns raised in code review. Thread safety implementation:
   - Windows: Uses _configthreadlocale() for thread-local locale
   - POSIX (Linux/macOS): Uses newlocale()/uselocale() for thread-local locale
   - Fallback: Mutex-protected global locale as last resort
- Apply locale protection around nrrdLoad/nrrdSave calls
- Add test coverage (itkNrrdLocaleTest.cxx)

Create thread-safe locale handling in ITKCommon to replace non-thread-safe
setlocale() calls. Update NRRD reader to use the new utility.

Co-authored-by: Matt McCormick <matt@fideus.io>
Co-authored-by: Bradley Lowekamp <blowekamp@mail.nih.gov>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MacOS itk vtk glue

4 participants