From f20cd70a9afc28f785ef4a50c875ccf6c3729462 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 20 Apr 2013 20:45:32 +0100 Subject: [PATCH] Import Ardour's LocaleGuard to fix problems with saving decimals to metadata (#119). --- ChangeLog | 5 +++++ src/lib/film.cc | 3 +++ src/lib/util.cc | 19 +++++++++++++++++++ src/lib/util.h | 11 +++++++++++ 4 files changed, 38 insertions(+) diff --git a/ChangeLog b/ChangeLog index 85cdb48a6..0fbb73773 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-04-20 Carl Hetherington + + * Fix bad saving of metadata in locales which use + commas to separate decimals (#119). + 2013-04-19 Carl Hetherington * Add basic frame index and timecode to viewer, and previous/next diff --git a/src/lib/film.cc b/src/lib/film.cc index 227f8557b..b0785df34 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -204,6 +204,7 @@ string Film::video_state_identifier () const { assert (format ()); + LocaleGuard lg; pair f = Filter::ffmpeg_strings (filters()); @@ -428,6 +429,7 @@ void Film::write_metadata () const { boost::mutex::scoped_lock lm (_state_mutex); + LocaleGuard lg; boost::filesystem::create_directories (directory()); @@ -515,6 +517,7 @@ void Film::read_metadata () { boost::mutex::scoped_lock lm (_state_mutex); + LocaleGuard lg; _external_audio.clear (); _content_audio_streams.clear (); diff --git a/src/lib/util.cc b/src/lib/util.cc index 557e9a34b..e43b598ab 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1018,3 +1018,22 @@ FrameRateConversion::FrameRateConversion (float source, int dcp) } } } + +LocaleGuard::LocaleGuard () + : _old (0) +{ + char const * old = setlocale (LC_NUMERIC, 0); + + if (old) { + _old = strdup (old); + if (strcmp (_old, "POSIX")) { + setlocale (LC_NUMERIC, "POSIX"); + } + } +} + +LocaleGuard::~LocaleGuard () +{ + setlocale (LC_NUMERIC, _old); + free (_old); +} diff --git a/src/lib/util.h b/src/lib/util.h index 3d251cf06..31d0fc967 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -293,5 +293,16 @@ extern int64_t video_frames_to_audio_frames (SourceFrame v, float audio_sample_r extern bool still_image_file (std::string); extern std::pair cpu_info (); +class LocaleGuard +{ +public: + LocaleGuard (); + ~LocaleGuard (); + +private: + char* _old; +}; + + #endif -- 2.30.2