Richard Heck wrote:

> It has been a few months since 2.1.2, and we have fixed a number of bugs
> since then. So I'm thinking about freezing strings in maybe a week.
> 
> What bugs need to be fixed for this release? I'd like to try to fix the
> recent outliner bug #9375 for 2.1.3 and should be able to do so this
> week, and it shouldn't involve any string changes, anyway. Others?

I'd like to put in a minimal workaround for the export threading problems of 
bug 9336 (see attachment). OK?


Georg
diff --git a/src/Language.cpp b/src/Language.cpp
index e6f7f9e..6b624fc 100644
--- a/src/Language.cpp
+++ b/src/Language.cpp
@@ -38,6 +38,12 @@ Language const * latex_language = 0;
 Language const * reset_language = 0;
 
 
+std::string const Language::babel() const
+{
+	return deep_copy(babel_);
+}
+
+
 bool Language::isPolyglossiaExclusive() const
 {
 	return babel().empty() && !polyglossia().empty() && requires().empty();
diff --git a/src/Language.h b/src/Language.h
index c912326..79b4098 100644
--- a/src/Language.h
+++ b/src/Language.h
@@ -35,7 +35,7 @@ public:
 	/// LyX language name
 	std::string const & lang() const { return lang_; }
 	/// Babel language name
-	std::string const & babel() const { return babel_; }
+	std::string const babel();
 	/// polyglossia language name
 	std::string const & polyglossia() const { return polyglossia_name_; }
 	/// polyglossia language options
diff --git a/src/support/lstrings.h b/src/support/lstrings.h
index 20a73c4..3a69df4 100644
--- a/src/support/lstrings.h
+++ b/src/support/lstrings.h
@@ -24,6 +24,19 @@
 namespace lyx {
 namespace support {
 
+/// Helper to enforce creating a deep copy of lyx::docstring or std::string
+/// even if std::basic_string uses copy-on-write as in GNU libstdc++.
+/// \sa https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21334
+template<typename Char, typename Traits, typename Alloc>
+typename std::basic_string<Char, Traits, Alloc>
+deep_copy(typename std::basic_string<Char, Traits, Alloc> const & src)
+{
+	typedef typename std::basic_string<Char, Traits, Alloc> String;
+	// Use constructor with two arguments to support strings with embedded
+	// \0 characters
+	return String(src.c_str(), src.length());
+}
+
 /// Compare \p s and \p s2, ignoring the case.
 /// Does not depend on the locale.
 int compare_no_case(docstring const & s, docstring const & s2);

Reply via email to