From: Carl Hetherington Date: Thu, 16 Apr 2015 22:10:28 +0000 (+0100) Subject: Add our own raw_convert that uses SafeStringStream. X-Git-Tag: v2.0.48~153 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=769c71b5c3e050ccfc1c13771d24328fbf76a495 Add our own raw_convert that uses SafeStringStream. --- diff --git a/ChangeLog b/ChangeLog index cc41dab42..1d659518d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-04-16 Carl Hetherington + + * Fix potential OS X crashes due to another incarnation + of the bizarre multi-thread stringstream bug. + 2015-04-15 c.hetherington * Hand-apply 94998e12d117f3f1781dfb1318939debfbf34546 from master; diff --git a/src/lib/audio_content.cc b/src/lib/audio_content.cc index 9909e3a08..53160fdb0 100644 --- a/src/lib/audio_content.cc +++ b/src/lib/audio_content.cc @@ -25,8 +25,8 @@ #include "config.h" #include "frame_rate_change.h" #include "audio_processor.h" +#include "raw_convert.h" #include -#include #include "i18n.h" @@ -38,7 +38,6 @@ using std::fixed; using std::setprecision; using boost::shared_ptr; using boost::dynamic_pointer_cast; -using dcp::raw_convert; int const AudioContentProperty::AUDIO_CHANNELS = 200; int const AudioContentProperty::AUDIO_LENGTH = 201; diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc index 35e4c036c..4e5a8afa2 100644 --- a/src/lib/audio_mapping.cc +++ b/src/lib/audio_mapping.cc @@ -20,8 +20,8 @@ #include "audio_mapping.h" #include "util.h" #include "md5_digester.h" +#include "raw_convert.h" #include -#include #include using std::list; @@ -33,7 +33,6 @@ using std::min; using std::vector; using boost::shared_ptr; using boost::dynamic_pointer_cast; -using dcp::raw_convert; AudioMapping::AudioMapping () : _content_channels (0) diff --git a/src/lib/colour_conversion.cc b/src/lib/colour_conversion.cc index eea6f77cf..4bf84281d 100644 --- a/src/lib/colour_conversion.cc +++ b/src/lib/colour_conversion.cc @@ -21,8 +21,8 @@ #include "colour_conversion.h" #include "util.h" #include "md5_digester.h" +#include "raw_convert.h" #include -#include #include #include #include @@ -37,7 +37,6 @@ using std::vector; using boost::shared_ptr; using boost::optional; using boost::dynamic_pointer_cast; -using dcp::raw_convert; ColourConversion::ColourConversion () : dcp::ColourConversion (dcp::ColourConversion::srgb_to_xyz ()) diff --git a/src/lib/config.cc b/src/lib/config.cc index cc0edd4a5..c75eaa0f5 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -27,8 +27,8 @@ #include "cinema.h" #include "util.h" #include "cross.h" +#include "raw_convert.h" #include -#include #include #include #include @@ -52,7 +52,6 @@ using std::cerr; using boost::shared_ptr; using boost::optional; using boost::algorithm::trim; -using dcp::raw_convert; Config* Config::_instance = 0; diff --git a/src/lib/content.cc b/src/lib/content.cc index 550a8cd05..fcc658717 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -29,8 +29,8 @@ #include "film.h" #include "safe_stringstream.h" #include "job.h" +#include "raw_convert.h" #include -#include #include #include @@ -42,7 +42,6 @@ using std::cout; using std::vector; using std::max; using boost::shared_ptr; -using dcp::raw_convert; int const ContentProperty::PATH = 400; int const ContentProperty::POSITION = 401; @@ -145,7 +144,7 @@ Content::examine (shared_ptr job) digest here: a MD5 of the first and last 1e6 bytes with the size of the first file tacked on the end as a string. */ - string const d = md5_digest_head_tail (p, 1000000) + dcp::raw_convert (boost::filesystem::file_size (p.front ())); + string const d = md5_digest_head_tail (p, 1000000) + raw_convert (boost::filesystem::file_size (p.front ())); lm.lock (); _digest = d; diff --git a/src/lib/dcp_subtitle_content.cc b/src/lib/dcp_subtitle_content.cc index 9f2ff61c5..f3198c58d 100644 --- a/src/lib/dcp_subtitle_content.cc +++ b/src/lib/dcp_subtitle_content.cc @@ -19,17 +19,16 @@ #include "font.h" #include "dcp_subtitle_content.h" +#include "raw_convert.h" #include #include #include -#include #include "i18n.h" using std::string; using std::list; using boost::shared_ptr; -using dcp::raw_convert; DCPSubtitleContent::DCPSubtitleContent (shared_ptr film, boost::filesystem::path path) : Content (film, path) diff --git a/src/lib/dcp_video.cc b/src/lib/dcp_video.cc index a2668c4a7..f2d765f7d 100644 --- a/src/lib/dcp_video.cc +++ b/src/lib/dcp_video.cc @@ -37,12 +37,12 @@ #include "log.h" #include "cross.h" #include "player_video.h" +#include "raw_convert.h" #include "encoded_data.h" #include #include #include #include -#include #include #include #include @@ -67,7 +67,6 @@ using std::cout; using boost::shared_ptr; using boost::lexical_cast; using dcp::Size; -using dcp::raw_convert; #define DCI_COEFFICENT (48.0 / 52.37) diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc index c39ad8aab..08349fba4 100644 --- a/src/lib/ffmpeg.cc +++ b/src/lib/ffmpeg.cc @@ -22,20 +22,19 @@ extern "C" { #include #include } -#include #include "ffmpeg.h" #include "ffmpeg_content.h" #include "ffmpeg_audio_stream.h" #include "ffmpeg_subtitle_stream.h" #include "exceptions.h" #include "util.h" +#include "raw_convert.h" #include "i18n.h" using std::string; using std::cout; using boost::shared_ptr; -using dcp::raw_convert; boost::mutex FFmpeg::_mutex; diff --git a/src/lib/ffmpeg_audio_stream.cc b/src/lib/ffmpeg_audio_stream.cc index d8666e89e..6300958e0 100644 --- a/src/lib/ffmpeg_audio_stream.cc +++ b/src/lib/ffmpeg_audio_stream.cc @@ -17,13 +17,12 @@ */ +#include "ffmpeg_audio_stream.h" +#include "raw_convert.h" #include #include -#include -#include "ffmpeg_audio_stream.h" using std::string; -using dcp::raw_convert; FFmpegAudioStream::FFmpegAudioStream (cxml::ConstNodePtr node, int version) : FFmpegStream (node) diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 9e9473935..3a42b169f 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -17,11 +17,6 @@ */ -extern "C" { -#include -} -#include -#include #include "ffmpeg_content.h" #include "ffmpeg_examiner.h" #include "ffmpeg_subtitle_stream.h" @@ -35,6 +30,11 @@ extern "C" { #include "exceptions.h" #include "frame_rate_change.h" #include "safe_stringstream.h" +#include "raw_convert.h" +#include +extern "C" { +#include +} #include "i18n.h" @@ -47,7 +47,6 @@ using std::cout; using std::pair; using boost::shared_ptr; using boost::dynamic_pointer_cast; -using dcp::raw_convert; int const FFmpegContentProperty::SUBTITLE_STREAMS = 100; int const FFmpegContentProperty::SUBTITLE_STREAM = 101; diff --git a/src/lib/ffmpeg_stream.cc b/src/lib/ffmpeg_stream.cc index f28a2f14e..dfd6f718c 100644 --- a/src/lib/ffmpeg_stream.cc +++ b/src/lib/ffmpeg_stream.cc @@ -19,14 +19,13 @@ #include "ffmpeg_stream.h" #include "dcpomatic_assert.h" -#include +#include "raw_convert.h" #include extern "C" { #include } using std::string; -using dcp::raw_convert; FFmpegStream::FFmpegStream (cxml::ConstNodePtr node) : name (node->string_child ("Name")) diff --git a/src/lib/film.cc b/src/lib/film.cc index 297193f83..a7be8aea7 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -41,12 +41,12 @@ #include "cinema.h" #include "safe_stringstream.h" #include "environment_info.h" +#include "raw_convert.h" #include #include #include #include #include -#include #include #include #include @@ -86,8 +86,6 @@ using boost::optional; using boost::is_any_of; using dcp::Size; using dcp::Signer; -using dcp::raw_convert; -using dcp::raw_convert; #define LOG_GENERAL(...) log()->log (String::compose (__VA_ARGS__), Log::TYPE_GENERAL); #define LOG_GENERAL_NC(...) log()->log (__VA_ARGS__, Log::TYPE_GENERAL); diff --git a/src/lib/image_filename_sorter.cc b/src/lib/image_filename_sorter.cc index 7bb1b4c37..805c469b0 100644 --- a/src/lib/image_filename_sorter.cc +++ b/src/lib/image_filename_sorter.cc @@ -17,10 +17,10 @@ */ -#include +#include "raw_convert.h" #include #include -#include +#include class ImageFilenameSorter { @@ -57,6 +57,6 @@ private: return boost::optional (); } - return dcp::raw_convert (number); + return raw_convert (number); } }; diff --git a/src/lib/image_proxy.cc b/src/lib/image_proxy.cc index f72a6c3e4..c803e6bd0 100644 --- a/src/lib/image_proxy.cc +++ b/src/lib/image_proxy.cc @@ -25,7 +25,6 @@ #include "exceptions.h" #include "cross.h" #include -#include #include #include "i18n.h" diff --git a/src/lib/isdcf_metadata.cc b/src/lib/isdcf_metadata.cc index e9d2e313e..a9d7d939e 100644 --- a/src/lib/isdcf_metadata.cc +++ b/src/lib/isdcf_metadata.cc @@ -17,16 +17,15 @@ */ -#include -#include -#include #include "isdcf_metadata.h" +#include "raw_convert.h" +#include +#include #include "i18n.h" using std::string; using boost::shared_ptr; -using dcp::raw_convert; ISDCFMetadata::ISDCFMetadata (cxml::ConstNodePtr node) : content_version (node->number_child ("ContentVersion")) diff --git a/src/lib/j2k_image_proxy.cc b/src/lib/j2k_image_proxy.cc index 99e4dddab..16b886169 100644 --- a/src/lib/j2k_image_proxy.cc +++ b/src/lib/j2k_image_proxy.cc @@ -21,7 +21,7 @@ #include "dcpomatic_socket.h" #include "image.h" #include "encoded_data.h" -#include +#include "raw_convert.h" #include #include #include @@ -94,14 +94,14 @@ void J2KImageProxy::add_metadata (xmlpp::Node* node) const { node->add_child("Type")->add_child_text (N_("J2K")); - node->add_child("Width")->add_child_text (dcp::raw_convert (_size.width)); - node->add_child("Height")->add_child_text (dcp::raw_convert (_size.height)); + node->add_child("Width")->add_child_text (raw_convert (_size.width)); + node->add_child("Height")->add_child_text (raw_convert (_size.height)); if (_stereo) { - node->add_child("Eye")->add_child_text (dcp::raw_convert (_eye.get ())); - node->add_child("LeftSize")->add_child_text (dcp::raw_convert (_stereo->left_j2k_size ())); - node->add_child("RightSize")->add_child_text (dcp::raw_convert (_stereo->right_j2k_size ())); + node->add_child("Eye")->add_child_text (raw_convert (_eye.get ())); + node->add_child("LeftSize")->add_child_text (raw_convert (_stereo->left_j2k_size ())); + node->add_child("RightSize")->add_child_text (raw_convert (_stereo->right_j2k_size ())); } else { - node->add_child("Size")->add_child_text (dcp::raw_convert (_mono->j2k_size ())); + node->add_child("Size")->add_child_text (raw_convert (_mono->j2k_size ())); } } diff --git a/src/lib/player_video.cc b/src/lib/player_video.cc index f9f06f63a..aad75889f 100644 --- a/src/lib/player_video.cc +++ b/src/lib/player_video.cc @@ -17,16 +17,15 @@ */ -#include #include "player_video.h" #include "image.h" #include "image_proxy.h" #include "j2k_image_proxy.h" #include "film.h" +#include "raw_convert.h" using std::string; using std::cout; -using dcp::raw_convert; using boost::shared_ptr; using boost::dynamic_pointer_cast; using boost::optional; diff --git a/src/lib/raw_convert.h b/src/lib/raw_convert.h new file mode 100644 index 000000000..2e5d1373c --- /dev/null +++ b/src/lib/raw_convert.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2014-2015 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include "safe_stringstream.h" + +/** A sort-of version of boost::lexical_cast that does uses the "C" + * locale (i.e. no thousands separators and a . for the decimal separator). + */ +template +P +raw_convert (Q v, int precision = 16) +{ + SafeStringStream s; + s.imbue (std::locale::classic ()); + s << std::setprecision (precision); + s << v; + P r; + s >> r; + return r; +} diff --git a/src/lib/raw_image_proxy.cc b/src/lib/raw_image_proxy.cc index 8f05f5455..e73a1543d 100644 --- a/src/lib/raw_image_proxy.cc +++ b/src/lib/raw_image_proxy.cc @@ -17,14 +17,14 @@ */ +#include "raw_image_proxy.h" +#include "image.h" +#include "raw_convert.h" +#include extern "C" { #include } #include -#include -#include -#include "raw_image_proxy.h" -#include "image.h" #include "i18n.h" @@ -58,9 +58,9 @@ void RawImageProxy::add_metadata (xmlpp::Node* node) const { node->add_child("Type")->add_child_text (N_("Raw")); - node->add_child("Width")->add_child_text (dcp::raw_convert (_image->size().width)); - node->add_child("Height")->add_child_text (dcp::raw_convert (_image->size().height)); - node->add_child("PixelFormat")->add_child_text (dcp::raw_convert (_image->pixel_format ())); + node->add_child("Width")->add_child_text (raw_convert (_image->size().width)); + node->add_child("Height")->add_child_text (raw_convert (_image->size().height)); + node->add_child("PixelFormat")->add_child_text (raw_convert (_image->pixel_format ())); } void diff --git a/src/lib/server.cc b/src/lib/server.cc index ba8580732..9b3b3808b 100644 --- a/src/lib/server.cc +++ b/src/lib/server.cc @@ -31,7 +31,7 @@ #include "player_video.h" #include "encoded_data.h" #include "safe_stringstream.h" -#include +#include "raw_convert.h" #include #include #include @@ -62,7 +62,6 @@ using boost::bind; using boost::scoped_array; using boost::optional; using dcp::Size; -using dcp::raw_convert; Server::Server (shared_ptr log, bool verbose) : _terminate (false) diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc index d62531d9f..979046dab 100644 --- a/src/lib/server_finder.cc +++ b/src/lib/server_finder.cc @@ -24,8 +24,8 @@ #include "cross.h" #include "ui_signaller.h" #include "dcpomatic_socket.h" +#include "raw_convert.h" #include -#include #include #include "i18n.h" @@ -37,7 +37,6 @@ using std::cout; using boost::shared_ptr; using boost::scoped_array; using boost::weak_ptr; -using dcp::raw_convert; ServerFinder* ServerFinder::_instance = 0; diff --git a/src/lib/single_stream_audio_content.cc b/src/lib/single_stream_audio_content.cc index 521597606..4547ae600 100644 --- a/src/lib/single_stream_audio_content.cc +++ b/src/lib/single_stream_audio_content.cc @@ -17,15 +17,14 @@ */ -#include #include "single_stream_audio_content.h" #include "audio_examiner.h" #include "film.h" +#include "raw_convert.h" using std::string; using std::cout; using boost::shared_ptr; -using dcp::raw_convert; SingleStreamAudioContent::SingleStreamAudioContent (shared_ptr f) : Content (f) diff --git a/src/lib/sndfile_content.cc b/src/lib/sndfile_content.cc index e757c77c5..9f9ea351e 100644 --- a/src/lib/sndfile_content.cc +++ b/src/lib/sndfile_content.cc @@ -18,7 +18,6 @@ */ #include -#include #include "sndfile_content.h" #include "sndfile_decoder.h" #include "film.h" @@ -32,7 +31,6 @@ using std::string; using std::cout; using boost::shared_ptr; -using dcp::raw_convert; SndfileContent::SndfileContent (shared_ptr f, boost::filesystem::path p) : Content (f, p) diff --git a/src/lib/subrip_content.cc b/src/lib/subrip_content.cc index fc0637bfd..f9d184b9d 100644 --- a/src/lib/subrip_content.cc +++ b/src/lib/subrip_content.cc @@ -22,13 +22,12 @@ #include "subrip.h" #include "film.h" #include "font.h" -#include +#include "raw_convert.h" #include "i18n.h" using std::string; using std::cout; -using dcp::raw_convert; using boost::shared_ptr; using boost::lexical_cast; diff --git a/src/lib/subtitle_content.cc b/src/lib/subtitle_content.cc index 2bed5413c..f42f3db37 100644 --- a/src/lib/subtitle_content.cc +++ b/src/lib/subtitle_content.cc @@ -17,13 +17,13 @@ */ -#include -#include #include "subtitle_content.h" #include "util.h" #include "exceptions.h" #include "safe_stringstream.h" #include "font.h" +#include "raw_convert.h" +#include #include "i18n.h" @@ -33,7 +33,6 @@ using std::cout; using std::list; using boost::shared_ptr; using boost::dynamic_pointer_cast; -using dcp::raw_convert; int const SubtitleContentProperty::SUBTITLE_X_OFFSET = 500; int const SubtitleContentProperty::SUBTITLE_Y_OFFSET = 501; diff --git a/src/lib/types.cc b/src/lib/types.cc index 54a8cb492..6ab4d56f2 100644 --- a/src/lib/types.cc +++ b/src/lib/types.cc @@ -17,16 +17,15 @@ */ +#include "types.h" +#include "raw_convert.h" #include #include -#include -#include "types.h" using std::max; using std::min; using std::string; using boost::shared_ptr; -using dcp::raw_convert; bool operator== (Crop const & a, Crop const & b) { diff --git a/src/lib/update.cc b/src/lib/update.cc index b41d8bb66..a05df8ef3 100644 --- a/src/lib/update.cc +++ b/src/lib/update.cc @@ -17,17 +17,17 @@ */ -#include -#include -#include -#include -#include #include "update.h" #include "version.h" #include "ui_signaller.h" #include "safe_stringstream.h" #include "config.h" #include "util.h" +#include "raw_convert.h" +#include +#include +#include +#include #define BUFFER_SIZE 1024 @@ -35,7 +35,6 @@ using std::cout; using std::min; using std::string; using std::vector; -using dcp::raw_convert; using boost::is_any_of; using boost::ends_with; diff --git a/src/lib/util.cc b/src/lib/util.cc index 6ebdc85d4..ab991e76b 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -37,7 +37,6 @@ #include "safe_stringstream.h" #include #include -#include #include #include #include @@ -81,7 +80,6 @@ using boost::shared_ptr; using boost::thread; using boost::optional; using dcp::Size; -using dcp::raw_convert; /** Path to our executable, required by the stacktrace stuff and filled * in during App::onInit(). diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index 64c51be99..bfbcef9bf 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -29,9 +29,9 @@ #include "frame_rate_change.h" #include "log.h" #include "safe_stringstream.h" +#include "raw_convert.h" #include #include -#include #include #include "i18n.h" @@ -59,7 +59,6 @@ using std::setprecision; using boost::shared_ptr; using boost::optional; using boost::dynamic_pointer_cast; -using dcp::raw_convert; VideoContent::VideoContent (shared_ptr f) : Content (f) diff --git a/src/wx/audio_mapping_view.cc b/src/wx/audio_mapping_view.cc index 8e92400bd..c61ce7f06 100644 --- a/src/wx/audio_mapping_view.cc +++ b/src/wx/audio_mapping_view.cc @@ -21,16 +21,16 @@ * @brief AudioMappingView class and helpers. */ -#include -#include -#include -#include -#include #include "lib/audio_mapping.h" #include "lib/util.h" +#include "lib/raw_convert.h" #include "audio_mapping_view.h" #include "wx_util.h" #include "audio_gain_dialog.h" +#include +#include +#include +#include #include using std::cout; @@ -247,7 +247,7 @@ AudioMappingView::update_cells () _grid->SetCellValue (i, 0, wxString::Format (wxT("%d"), i + 1)); for (int j = 1; j < _grid->GetNumberCols(); ++j) { - _grid->SetCellValue (i, j, std_to_wx (dcp::raw_convert (_map.get (i, static_cast (j - 1))))); + _grid->SetCellValue (i, j, std_to_wx (raw_convert (_map.get (i, static_cast (j - 1))))); } } diff --git a/src/wx/colour_conversion_editor.cc b/src/wx/colour_conversion_editor.cc index 4658716c6..3ea144e1d 100644 --- a/src/wx/colour_conversion_editor.cc +++ b/src/wx/colour_conversion_editor.cc @@ -19,11 +19,11 @@ #include "lib/colour_conversion.h" #include "lib/safe_stringstream.h" +#include "lib/raw_convert.h" #include "wx_util.h" #include "colour_conversion_editor.h" #include #include -#include #include #include #include @@ -33,7 +33,6 @@ using std::cout; using boost::shared_ptr; using boost::dynamic_pointer_cast; using boost::lexical_cast; -using dcp::raw_convert; ColourConversionEditor::ColourConversionEditor (wxWindow* parent) : wxPanel (parent, wxID_ANY) diff --git a/src/wx/image_sequence_dialog.cc b/src/wx/image_sequence_dialog.cc index 02602267c..48af6afa1 100644 --- a/src/wx/image_sequence_dialog.cc +++ b/src/wx/image_sequence_dialog.cc @@ -17,11 +17,9 @@ */ -#include #include "wx_util.h" #include "image_sequence_dialog.h" - -using dcp::raw_convert; +#include "lib/raw_convert.h" ImageSequenceDialog::ImageSequenceDialog (wxWindow* parent) : TableDialog (parent, _("Add image sequence"), 2, true) diff --git a/src/wx/timing_panel.cc b/src/wx/timing_panel.cc index b466da842..55c53e79d 100644 --- a/src/wx/timing_panel.cc +++ b/src/wx/timing_panel.cc @@ -19,11 +19,11 @@ #include "lib/content.h" #include "lib/image_content.h" +#include "lib/raw_convert.h" #include "timing_panel.h" #include "wx_util.h" #include "timecode.h" #include "content_panel.h" -#include #include using std::cout; @@ -31,7 +31,6 @@ using std::string; using std::set; using boost::shared_ptr; using boost::dynamic_pointer_cast; -using dcp::raw_convert; TimingPanel::TimingPanel (ContentPanel* p) /* horrid hack for apparent lack of context support with wxWidgets i18n code */