Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gogela opened this issue Mar 19, 2021 · 3 comments
Closed

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

gogela opened this issue Mar 19, 2021 · 3 comments

Comments

@gogela
Copy link

gogela commented Mar 19, 2021

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
Copy link
Owner

wolph commented Mar 22, 2021

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: #52
I'll add this to my todo list :)

@gogela gogela closed this as completed Mar 23, 2021
@gogela gogela reopened this Mar 23, 2021
@gogela
Copy link
Author

gogela commented Mar 23, 2021

sorry, closed by mistake.

@wolph
Copy link
Owner

wolph commented Mar 27, 2021

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 :)

@wolph wolph closed this as completed in 4dac446 Mar 27, 2021
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

No branches or pull requests

2 participants