wolph / numpy-stl

Simple library to make working with STL files (and 3D objects in general) fast and easy.
http://numpy-stl.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
624 stars 105 forks source link

_speedups.ascii_read() causing locale change in linux env #169

Closed gogela closed 3 years ago

gogela commented 3 years ago

Running functions that use _speedups.ascii_read() - ie. Mesh.from_file() causes change of locale settings: typically:

from stl import mesh
import locale

print(locale.CODESET, locale.nl_langinfo(locale.CODESET))
x= return mesh.Mesh.from_file(filename)
print(locale.CODESET, locale.nl_langinfo(locale.CODESET))

OUTPUTS:
14 UTF-8
14 ANSI_X3.4-1968

The problem apparently lies in:

IF UNAME_SYSNAME == 'Linux':
        cdef locale_t new_locale = newlocale(LC_NUMERIC_MASK, 'C',
                                             <locale_t>NULL)
        cdef locale_t old_locale = uselocale(new_locale)
        freelocale(new_locale)

where the old_locale var gets populated from new_locale and furthermore never changed back

Suggested change: LINE #21 (add): locale_t LC_GLOBAL_LOCALE LINES #109,110

cdef locale_t old_locale = uselocale(LC_GLOBAL_LOCALE)
uselocale(new_locale)
wolph commented 3 years ago

Wow... good catch. It never occurred to me that the change would affect other bits of code but that's indeed problematic.

This change was caused by a fix for this issue because some people had issues otherwise: https://github.com/WoLpH/numpy-stl/issues/52 I'll add this to my todo list :)

gogela commented 3 years ago

sorry, closed by mistake.

wolph commented 3 years ago

I found the issue... it was rather subtle. The code that was supposed to restore the locale was actually broken but nobody ever noticed because it was never executed. The code had a return a bit higher up and the restoring of the locale was not part of the finally clause.

In any case, I'll create a new release fixing this :)