Fixed a memory leak during locales switching on macOS and
removed frequent locales switching during gcode processing
This commit is contained in:
parent
d8ac2ceaf6
commit
d2874f2e34
4 changed files with 11 additions and 10 deletions
|
@ -720,6 +720,8 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessor::Result* re
|
||||||
{
|
{
|
||||||
PROFILE_CLEAR();
|
PROFILE_CLEAR();
|
||||||
|
|
||||||
|
CNumericLocalesSetter locales_setter;
|
||||||
|
|
||||||
// Does the file exist? If so, we hope that it is still valid.
|
// Does the file exist? If so, we hope that it is still valid.
|
||||||
if (print->is_step_done(psGCodeExport) && boost::filesystem::exists(boost::filesystem::path(path)))
|
if (print->is_step_done(psGCodeExport) && boost::filesystem::exists(boost::filesystem::path(path)))
|
||||||
return;
|
return;
|
||||||
|
@ -750,7 +752,6 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessor::Result* re
|
||||||
std::string path_tmp(path);
|
std::string path_tmp(path);
|
||||||
path_tmp += ".tmp";
|
path_tmp += ".tmp";
|
||||||
|
|
||||||
CNumericLocalesSetter c_locales_setter;
|
|
||||||
FILE *file = boost::nowide::fopen(path_tmp.c_str(), "wb");
|
FILE *file = boost::nowide::fopen(path_tmp.c_str(), "wb");
|
||||||
if (file == nullptr)
|
if (file == nullptr)
|
||||||
throw Slic3r::RuntimeError(std::string("G-code export to ") + path + " failed.\nCannot open the file for writing.\n");
|
throw Slic3r::RuntimeError(std::string("G-code export to ") + path + " failed.\nCannot open the file for writing.\n");
|
||||||
|
|
|
@ -1257,6 +1257,8 @@ void GCodeProcessor::process_file(const std::string& filename, bool apply_postpr
|
||||||
{
|
{
|
||||||
auto last_cancel_callback_time = std::chrono::high_resolution_clock::now();
|
auto last_cancel_callback_time = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
CNumericLocalesSetter locales_setter;
|
||||||
|
|
||||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
auto start_time = std::chrono::high_resolution_clock::now();
|
auto start_time = std::chrono::high_resolution_clock::now();
|
||||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
|
|
|
@ -27,7 +27,8 @@ void GCodeReader::apply_config(const DynamicPrintConfig &config)
|
||||||
const char* GCodeReader::parse_line_internal(const char *ptr, GCodeLine &gline, std::pair<const char*, const char*> &command)
|
const char* GCodeReader::parse_line_internal(const char *ptr, GCodeLine &gline, std::pair<const char*, const char*> &command)
|
||||||
{
|
{
|
||||||
PROFILE_FUNC();
|
PROFILE_FUNC();
|
||||||
CNumericLocalesSetter locales_setter; // for strtod
|
|
||||||
|
assert(is_decimal_separator_point());
|
||||||
|
|
||||||
// command and args
|
// command and args
|
||||||
const char *c = ptr;
|
const char *c = ptr;
|
||||||
|
@ -153,7 +154,7 @@ bool GCodeReader::GCodeLine::has(char axis) const
|
||||||
|
|
||||||
bool GCodeReader::GCodeLine::has_value(char axis, float &value) const
|
bool GCodeReader::GCodeLine::has_value(char axis, float &value) const
|
||||||
{
|
{
|
||||||
CNumericLocalesSetter locales_setter; // for strtod
|
assert(is_decimal_separator_point());
|
||||||
const char *c = m_raw.c_str();
|
const char *c = m_raw.c_str();
|
||||||
// Skip the whitespaces.
|
// Skip the whitespaces.
|
||||||
c = skip_whitespaces(c);
|
c = skip_whitespaces(c);
|
||||||
|
|
|
@ -11,11 +11,14 @@ CNumericLocalesSetter::CNumericLocalesSetter()
|
||||||
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
|
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
|
||||||
m_orig_numeric_locale = std::setlocale(LC_NUMERIC, nullptr);
|
m_orig_numeric_locale = std::setlocale(LC_NUMERIC, nullptr);
|
||||||
std::setlocale(LC_NUMERIC, "C");
|
std::setlocale(LC_NUMERIC, "C");
|
||||||
#else
|
#elif __linux__
|
||||||
m_original_locale = uselocale((locale_t)0);
|
m_original_locale = uselocale((locale_t)0);
|
||||||
m_new_locale = duplocale(m_original_locale);
|
m_new_locale = duplocale(m_original_locale);
|
||||||
m_new_locale = newlocale(LC_NUMERIC_MASK, "C", m_new_locale);
|
m_new_locale = newlocale(LC_NUMERIC_MASK, "C", m_new_locale);
|
||||||
uselocale(m_new_locale);
|
uselocale(m_new_locale);
|
||||||
|
#else // APPLE
|
||||||
|
m_original_locale = uselocale((locale_t)0);
|
||||||
|
m_new_locale = newlocale(LC_NUMERIC_MASK, "C", m_original_locale);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +61,6 @@ double string_to_double_decimal_point(const std::string& str, size_t* pos /* = n
|
||||||
|
|
||||||
std::string float_to_string_decimal_point(double value, int precision/* = -1*/)
|
std::string float_to_string_decimal_point(double value, int precision/* = -1*/)
|
||||||
{
|
{
|
||||||
assert(is_decimal_separator_point());
|
|
||||||
std::stringstream buf;
|
std::stringstream buf;
|
||||||
if (precision >= 0)
|
if (precision >= 0)
|
||||||
buf << std::fixed << std::setprecision(precision);
|
buf << std::fixed << std::setprecision(precision);
|
||||||
|
@ -66,11 +68,6 @@ std::string float_to_string_decimal_point(double value, int precision/* = -1*/)
|
||||||
return buf.str();
|
return buf.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
//std::string float_to_string_decimal_point(float value, int precision/* = -1*/)
|
|
||||||
//{
|
|
||||||
// return float_to_string_decimal_point(double(value), precision);
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Slic3r
|
} // namespace Slic3r
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue