Skip to content

Commit

Permalink
Remove unnecessary setting of locale::global (AcademySoftwareFoundati…
Browse files Browse the repository at this point in the history
…on#1636)

Signed-off-by: Daniel Dresser <danield@image-engine.com>
  • Loading branch information
danieldresser-ie authored and lgritz committed Jan 12, 2023
1 parent b20183d commit 6f9c907
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 33 deletions.
12 changes: 0 additions & 12 deletions src/liboslcomp/osllex.l
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,6 @@ OSLCompilerImpl::osl_parse_buffer (const std::string &preprocessed_buffer)
// Thread safety with the lexer/parser
std::lock_guard<std::mutex> lock(oslcompiler_mutex);

#ifndef OIIO_STRUTIL_HAS_STOF
// Force classic "C" locale for correct '.' decimal parsing.
// N.B. This is not safe in a multi-threaded program where another
// application thread is expecting the native locale to work properly.
// This is not necessary for versions of OIIO that have Strutil::stof,
// and we can remove it entirely when OIIO 1.9 is the minimum.
std::locale oldlocale = std::locale::global (std::locale::classic());
#endif

yyscan_t scanner;
yylex_init(&scanner);
YY_BUFFER_STATE buffer = yy_scan_string(preprocessed_buffer.c_str(), scanner);
Expand All @@ -415,9 +406,6 @@ OSLCompilerImpl::osl_parse_buffer (const std::string &preprocessed_buffer)
yy_delete_buffer (buffer, scanner);
yylex_destroy(scanner);

#ifndef OIIO_STRUTIL_HAS_STOF
std::locale::global (oldlocale); // Restore the original locale.
#endif
return parseerr;
}

Expand Down
23 changes: 2 additions & 21 deletions src/liboslexec/osolex.l
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ public:
}
// TODO: This is really the only part of parsing that needs the lock still.
// But the calling code setting locale complicates this.
// The calling code no longer sets the global locale, so it would
// likely be simple to clean this up.
//
bool parse(OSOReader* reader, const char* what) {
yy_switch_to_buffer(m_buffer, m_scanner);
Expand All @@ -310,12 +311,6 @@ OSOReader::parse_file (const std::string &filename)
// can actually be reading a .oso file at a time.
std::lock_guard<std::mutex> guard (osoread_mutex);
// Force classic "C" locale for correct '.' decimal parsing.
// N.B. This is not safe in a multi-threaded program where another
// application thread is expecting the native locale to work properly.
std::locale oldlocale; // save the previous native locale
std::locale::global (std::locale::classic());
FILE* osoin = OIIO::Filesystem::fopen (filename, "r");
if (! osoin) {
m_err.errorfmt("File {} not found", filename);
Expand All @@ -326,7 +321,6 @@ OSOReader::parse_file (const std::string &filename)
bool ok = scope.parse(this, filename.c_str());
fclose (osoin);
std::locale::global (oldlocale); // Restore the original locale.
return ok;
}
Expand All @@ -339,22 +333,9 @@ OSOReader::parse_memory (const std::string &buffer)
// can actually be reading a .oso file at a time.
std::lock_guard<std::mutex> guard (osoread_mutex);
#ifndef OIIO_STRUTIL_HAS_STOF
// Force classic "C" locale for correct '.' decimal parsing.
// N.B. This is not safe in a multi-threaded program where another
// application thread is expecting the native locale to work properly.
// This is not necessary for versions of OIIO that have Strutil::stof,
// and we can remove it entirely when OIIO 1.9 is the minimum.
std::locale oldlocale = std::locale::global (std::locale::classic());
#endif
Scope scope(buffer);
bool ok = scope.parse(this, "preloaded OSO code");
#ifndef OIIO_STRUTIL_HAS_STOF
std::locale::global (oldlocale); // Restore the original locale.
#endif
return ok;
}
Expand Down

0 comments on commit 6f9c907

Please sign in to comment.