[LyX/master] Make WordList noncopyable

2014-07-05 Thread Georg Baum
commit 7baaeb3fd2d12928f79e32821b6c01784b99b2a6
Author: Georg Baum b...@lyx.org
Date:   Fri Jul 4 21:15:21 2014 +0200

Make WordList noncopyable

To avoid unwanted double deletion of d.

diff --git a/src/WordList.h b/src/WordList.h
index f57f20b..d21f9c8 100644
--- a/src/WordList.h
+++ b/src/WordList.h
@@ -17,6 +17,9 @@
 namespace lyx {
 
 class WordList {
+   // noncopyable because of pimpl
+   WordList(WordList const );
+   WordList  operator=(WordList const );
 public:
///
WordList();


[LyX/master] Don't guess whether autosave succeeded

2014-07-05 Thread Georg Baum
commit 50467f3f554129b6ff532f4433da27e9b76aff55
Author: Georg Baum b...@lyx.org
Date:   Fri Jul 4 21:06:49 2014 +0200

Don't guess whether autosave succeeded

writeFile() tells whether it could save the file, so use the return value
instead of guessing.

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 10e7a27..4331309 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -3738,9 +3738,9 @@ int AutoSaveBuffer::generateChild()
tempfile.setAutoRemove(false);
FileName const tmp_ret = tempfile.name();
if (!tmp_ret.empty()) {
-   buffer_.writeFile(tmp_ret);
-   // assume successful write of tmp_ret
-   if (!tmp_ret.moveTo(fname_))
+   if (!buffer_.writeFile(tmp_ret))
+   failed = true;
+   else if (!tmp_ret.moveTo(fname_))
failed = true;
} else
failed = true;


[LyX/master] Fix bug #9162: Missing \use_indices

2014-07-05 Thread Georg Baum
commit 22dcdd6d8ff39206bcb627ea6ce4de8c6c07417f
Author: Georg Baum b...@lyx.org
Date:   Fri Jul 4 19:55:44 2014 +0200

Fix bug #9162: Missing \use_indices

The lyx2lyx conversion for format 352 was incomplete: It should have been
added the \use_indices setting, but it relied on the fact that the default 
in
LyX for missing \use_indices is the same as the old format without that
setting used. However, the default might change in the future, and later
lyx2lyx conversions rely on that setting as well.

diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py
index 5ee8d5f..eb0b079 100644
--- a/lib/lyx2lyx/LyX.py
+++ b/lib/lyx2lyx/LyX.py
@@ -720,6 +720,7 @@ class File(LyX_base):
 self.read()
 
 
+# FIXME: header settings are completely outdated, don't use like this
 #class NewFile(LyX_base):
 # This class is to create new LyX files.
 #def set_header(self, **params):
@@ -748,6 +749,7 @@ class File(LyX_base):
 #\\use_amsmath 1,
 #\\cite_engine basic,
 #\\use_bibtopic false,
+#\\use_indices false,
 #\\paperorientation portrait,
 #\\secnumdepth 3,
 #\\tocdepth 3,
diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py
index 2756418..7914cc4 100644
--- a/lib/lyx2lyx/lyx_2_0.py
+++ b/lib/lyx2lyx/lyx_2_0.py
@@ -317,11 +317,33 @@ def revert_backgroundcolor(document):
 '\\pagecolor{page_backgroundcolor}'])
 
 
-def revert_splitindex(document):
- Reverts splitindex-aware documents 
+def add_use_indices(document):
+ Add \\use_indices if it is missing 
 i = find_token(document.header, '\\use_indices', 0)
+if i != -1:
+return i
+i = find_token(document.header, '\\use_bibtopic', 0)
+if i == -1:
+i = find_token(document.header, '\\cite_engine', 0)
+if i == -1:
+i = find_token(document.header, '\\use_mathdots', 0)
+if i == -1:
+i = find_token(document.header, '\\use_mhchem', 0)
+if i == -1:
+i = find_token(document.header, '\\use_esint', 0)
+if i == -1:
+i = find_token(document.header, '\\use_amsmath', 0)
 if i == -1:
 document.warning(Malformed LyX document: Missing \\use_indices.)
+return -1
+document.header.insert(i + 1, '\\use_indices 0')
+return i + 1
+
+
+def revert_splitindex(document):
+ Reverts splitindex-aware documents 
+i = add_use_indices(document)
+if i == -1:
 return
 useindices = str2bool(get_value(document.header, \\use_indices, i))
 del document.header[i]
@@ -398,6 +420,7 @@ def revert_splitindex(document):
 
 def convert_splitindex(document):
  Converts index and printindex insets to splitindex-aware format 
+add_use_indices(document)
 i = 0
 while True:
 i = find_token(document.body, \\begin_inset Index, i)
@@ -422,9 +445,8 @@ def convert_splitindex(document):
 
 def revert_subindex(document):
  Reverts \\printsubindex CommandInset types 
-i = find_token(document.header, '\\use_indices', 0)
+i = add_use_indices(document)
 if i == -1:
-document.warning(Malformed LyX document: Missing \\use_indices.)
 return
 useindices = str2bool(get_value(document.header, \\use_indices, i))
 i = 0
@@ -448,9 +470,8 @@ def revert_subindex(document):
 
 def revert_printindexall(document):
  Reverts \\print[sub]index* CommandInset types 
-i = find_token(document.header, '\\use_indices', 0)
+i = add_use_indices(document)
 if i == -1:
-document.warning(Malformed LyX document: Missing \\use_indices.)
 return
 useindices = str2bool(get_value(document.header, \\use_indices, i))
 i = 0
diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py
index ae95841..f9b1e32 100644
--- a/lib/lyx2lyx/lyx_2_1.py
+++ b/lib/lyx2lyx/lyx_2_1.py
@@ -409,9 +409,15 @@ def revert_japanese_encodings(document):
 
 def convert_justification(document):
  Add the \\justification buffer param
-i = find_token(document.header, \\use_indices , 0)
+i = find_token(document.header, \\suppress_date , 0)
 if i == -1:
-document.warning(Malformed LyX document: Missing \\use_indices.)
+i = find_token(document.header, \\paperorientation , 0)
+if i == -1:
+i = find_token(document.header, \\use_indices , 0)
+if i == -1:
+i = find_token(document.header, \\use_bibtopic , 0)
+if i == -1:
+document.warning(Malformed LyX document: Missing \\suppress_date.)
 return
 document.header.insert(i + 1, \\justification true)
 


[LyX/master] Make theWordList() thread safe.

2014-07-05 Thread Georg Baum
commit cf89851374163be2e8a390dd917d7ef435978979
Author: Georg Baum b...@lyx.org
Date:   Fri Jul 4 22:19:43 2014 +0200

Make theWordList() thread safe.

Without this, you get crashes in a few second when you set the autosave
interval to one second and edit quickly (typing new words etc). The reason
is that the cloned buffer wants to insert words into the word list and
remove them again, but it lives in a different thread.

diff --git a/src/WordList.cpp b/src/WordList.cpp
index 3a095af..16f3b92 100644
--- a/src/WordList.cpp
+++ b/src/WordList.cpp
@@ -18,6 +18,8 @@
 #include support/lassert.h
 #include support/weighted_btree.h
 
+#include QThreadStorage
+
 #include map
 
 using namespace std;
@@ -26,26 +28,37 @@ namespace lyx {
 
 ///
 typedef mapstring, WordList * GlobalWordList;
-GlobalWordList theGlobalWordList;
+// Each thread uses its own word list, but only the one of the GUI thread is
+// used to do real work. The others are only neded to prevent simultanous
+// write access e.g. from a cloned buffer and a true document buffer.
+QThreadStorageGlobalWordList * theGlobalWordList;
 
 
 WordList * theWordList(string const  lang)
 {
-   GlobalWordList::iterator it = theGlobalWordList.find(lang);
-   if (it != theGlobalWordList.end())
+   if (!theGlobalWordList.hasLocalData())
+   theGlobalWordList.setLocalData(new GlobalWordList);
+   GlobalWordList * globalWordList = theGlobalWordList.localData();
+   GlobalWordList::iterator it = globalWordList-find(lang);
+   if (it != globalWordList-end())
return it-second;
-   else
-   theGlobalWordList[lang] = new WordList;
-   return theGlobalWordList[lang];
+   else {
+   WordList * wl = new WordList;
+   (*globalWordList)[lang] = wl;
+   return wl;
+   }
 }
 
 
 void WordList::cleanupWordLists()
 {
-   GlobalWordList::const_iterator it = theGlobalWordList.begin();
-   for (; it != theGlobalWordList.end(); ++it)
+   if (!theGlobalWordList.hasLocalData())
+   return;
+   GlobalWordList * globalWordList = theGlobalWordList.localData();
+   GlobalWordList::const_iterator it = globalWordList-begin();
+   for (; it != globalWordList-end(); ++it)
delete it-second;
-   theGlobalWordList.clear();
+   globalWordList-clear();
 }
 
 


[LyX/master] Make preview filename generation threadsafe

2014-07-05 Thread Georg Baum
commit 79e79ed5480883ac1fd77c11a24e1185690f4354
Author: Georg Baum b...@lyx.org
Date:   Sat Jul 5 11:19:34 2014 +0200

Make preview filename generation threadsafe

Threadsafety is ensured by the atomic file name generation in TempFile.

diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp
index 1c17226..a6c2c68 100644
--- a/src/graphics/PreviewLoader.cpp
+++ b/src/graphics/PreviewLoader.cpp
@@ -38,6 +38,7 @@
 #include support/lstrings.h
 
 #include support/bind.h
+#include support/TempFile.h
 
 #include sstream
 #include fstream
@@ -59,12 +60,11 @@ typedef liststring PendingSnippets;
 typedef vectorSnippetPair BitmapFile;
 
 
-string const unique_filename(string const  bufferpath)
+FileName const unique_tex_filename(FileName const  bufferpath)
 {
-   // FIXME THREAD
-   static int theCounter = 0;
-   string const filename = lyx::convertstring(theCounter++) + 
lyxpreview;
-   return addName(bufferpath, filename);
+   TempFile tempfile(bufferpath, lyxpreviewXX.tex);
+   tempfile.setAutoRemove(false);
+   return tempfile.name();
 }
 
 
@@ -531,9 +531,10 @@ void PreviewLoader::Impl::startLoading(bool wait)
LYXERR(Debug::GRAPHICS, PreviewLoader::startLoading());
 
// As used by the LaTeX file and by the resulting image files
-   string const directory = buffer_.temppath();
+   FileName const directory(buffer_.temppath());
 
-   string const filename_base = unique_filename(directory);
+   FileName const latexfile = unique_tex_filename(directory);
+   string const filename_base = removeExtension(latexfile.absFileName());
 
// Create an InProgress instance to place in the map of all
// such processes if it starts correctly.
@@ -543,8 +544,6 @@ void PreviewLoader::Impl::startLoading(bool wait)
pending_.clear();
 
// Output the LaTeX file.
-   FileName const latexfile(filename_base + .tex);
-
// we use the encoding of the buffer
Encoding const  enc = buffer_.params().encoding();
ofdocstream of;


[LyX/master] Fix Tabular::CellData::operator=()

2014-07-05 Thread Georg Baum
commit 0092b523c7d3c1735b6854bcbdb4e65ec782f092
Author: Georg Baum b...@lyx.org
Date:   Sat Jul 5 11:44:13 2014 +0200

Fix Tabular::CellData::operator=()

Don't create an intermediate copy (found by Jean-Marc).
I doubt that this has anything to do with the mystery crash, but it works, 
and
following the standard patterns is better anyway.

diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index 1a84c8e..433fe19 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -602,9 +602,29 @@ Tabular::CellData::CellData(CellData const  cs)
 {
 }
 
-Tabular::CellData  Tabular::CellData::operator=(CellData cs)
-{
-   swap(cs);
+Tabular::CellData  Tabular::CellData::operator=(CellData const  cs)
+{
+   if (cs == this)
+   return *this;
+   cellno = cs.cellno;
+   width = cs.width;
+   multicolumn = cs.multicolumn;
+   multirow = cs.multirow;
+   mroffset = cs.mroffset;
+   alignment = cs.alignment;
+   valignment = cs.valignment;
+   decimal_hoffset = cs.decimal_hoffset;
+   decimal_width = cs.decimal_width;
+   voffset = cs.voffset;
+   top_line = cs.top_line;
+   bottom_line = cs.bottom_line;
+   left_line = cs.left_line;
+   right_line = cs.right_line;
+   usebox = cs.usebox;
+   rotate = cs.rotate;
+   align_special = cs.align_special;
+   p_width = cs.p_width;
+   inset.reset(static_castInsetTableCell *(cs.inset-clone()));
return *this;
 }
 
diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h
index be1a67f..8941a83 100644
--- a/src/insets/InsetTabular.h
+++ b/src/insets/InsetTabular.h
@@ -610,7 +610,7 @@ public:
///
CellData(CellData const );
///
-   CellData  operator=(CellData);
+   CellData  operator=(CellData const );
///
void swap(CellData  rhs);
///


[LyX/master] Make Formats::isZippedFile() threadsafe

2014-07-05 Thread Georg Baum
commit 4a2250a5d1dd551f43f75e54942ecbf0d5702080
Author: Georg Baum b...@lyx.org
Date:   Sat Jul 5 11:55:35 2014 +0200

Make Formats::isZippedFile() threadsafe

In this case I use a mutex, so the zip status of files is shared between
threads. This is possible because a deadlock can't happen, and it should 
give
better performance.

diff --git a/src/Format.cpp b/src/Format.cpp
index 063b683..82712af 100644
--- a/src/Format.cpp
+++ b/src/Format.cpp
@@ -22,6 +22,7 @@
 #include support/filetools.h
 #include support/gettext.h
 #include support/lstrings.h
+#include support/mutex.h
 #include support/os.h
 #include support/PathChanger.h
 #include support/Systemcall.h
@@ -503,14 +504,15 @@ struct ZippedInfo {
 };
 
 
-// FIXME THREAD
 /// Mapping absolute pathnames of files to their ZippedInfo metadata.
 static std::mapstd::string, ZippedInfo zipped_;
+static Mutex zipped_mutex;
 
 
 bool Formats::isZippedFile(support::FileName const  filename) const {
string const  fname = filename.absFileName();
time_t timestamp = filename.lastModified();
+   Mutex::Locker lock(zipped_mutex);
mapstring, ZippedInfo::iterator it = zipped_.find(fname);
if (it != zipped_.end()  it-second.timestamp == timestamp)
return it-second.zipped;


[LyX/master] Make include and bibitem insets threadsafe

2014-07-05 Thread Georg Baum
commit 50929b5b8a294079de7b81617a119a51dcb3142c
Author: Georg Baum b...@lyx.org
Date:   Sat Jul 5 12:09:49 2014 +0200

Make include and bibitem insets threadsafe

Using a mutex to ensure that the generated filenames and ids are still 
unique.

diff --git a/src/insets/InsetBibitem.cpp b/src/insets/InsetBibitem.cpp
index 4f263e9..d0a28e7 100644
--- a/src/insets/InsetBibitem.cpp
+++ b/src/insets/InsetBibitem.cpp
@@ -41,6 +41,7 @@
 #include support/docstream.h
 #include support/gettext.h
 #include support/lstrings.h
+#include support/mutex.h
 
 using namespace std;
 using namespace lyx::support;
@@ -48,8 +49,8 @@ using namespace lyx::support;
 namespace lyx {
 
 
-// FIXME THREAD
 int InsetBibitem::key_counter = 0;
+static Mutex counter_mutex;
 docstring const key_prefix = from_ascii(key-);
 
 
@@ -57,8 +58,10 @@ InsetBibitem::InsetBibitem(Buffer * buf, InsetCommandParams 
const  p)
: InsetCommand(buf, p)
 {
buffer().invalidateBibinfoCache();
-   if (getParam(key).empty())
+   if (getParam(key).empty()) {
+   Mutex::Locker lock(counter_mutex);
setParam(key, key_prefix + convertdocstring(++key_counter));
+   }
 }
 
 
@@ -196,6 +199,7 @@ void InsetBibitem::read(Lexer  lex)
 
if (prefixIs(getParam(key), key_prefix)) {
int const key = 
convertint(getParam(key).substr(key_prefix.length()));
+   Mutex::Locker lock(counter_mutex);
key_counter = max(key_counter, key);
}
 }
diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp
index ff4a329..7494650 100644
--- a/src/insets/InsetInclude.cpp
+++ b/src/insets/InsetInclude.cpp
@@ -60,6 +60,7 @@
 #include support/lassert.h
 #include support/lstrings.h // contains
 #include support/lyxalgo.h
+#include support/mutex.h
 
 #include support/bind.h
 
@@ -75,8 +76,9 @@ namespace {
 
 docstring const uniqueID()
 {
-   // FIXME THREAD
static unsigned int seed = 1000;
+   static Mutex mutex;
+   Mutex::Locker lock(mutex);
return file + convertdocstring(++seed);
 }
 


[LyX/master] Make DocFileName::mangledFileName() threadsafe

2014-07-05 Thread Georg Baum
commit 0de4bc224af34b6f519afb7ab38f190e634b4c7c
Author: Georg Baum b...@lyx.org
Date:   Sat Jul 5 12:22:08 2014 +0200

Make DocFileName::mangledFileName() threadsafe

diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp
index 95880a0..05492f6 100644
--- a/src/support/FileName.cpp
+++ b/src/support/FileName.cpp
@@ -17,6 +17,7 @@
 #include support/filetools.h
 #include support/lassert.h
 #include support/lstrings.h
+#include support/mutex.h
 #include support/qstring_helpers.h
 #include support/os.h
 #include support/Package.h
@@ -910,13 +911,15 @@ string DocFileName::outputFileName(string const  path) 
const
 
 string DocFileName::mangledFileName(string const  dir) const
 {
-   // FIXME THREAD
// Concurrent access to these variables is possible.
 
// We need to make sure that every DocFileName instance for a given
// filename returns the same mangled name.
typedef mapstring, string MangledMap;
static MangledMap mangledNames;
+   static Mutex mangledMutex;
+   // this locks both access to mangledNames and counter below 
+   Mutex::Locker lock(mangledMutex);
MangledMap::const_iterator const it = mangledNames.find(absFileName());
if (it != mangledNames.end())
return (*it).second;
@@ -942,7 +945,6 @@ string DocFileName::mangledFileName(string const  dir) 
const
// Add the extension back on
mname = support::changeExtension(mname, getExtension(name));
 
-   // FIXME THREAD
// Prepend a counter to the filename. This is necessary to make
// the mangled name unique.
static int counter = 0;


[LyX/master] Make createBufferTmpDir() threadsafe

2014-07-05 Thread Georg Baum
commit 4bfca60359825cf51b09f0a6b35a91e2858df374
Author: Georg Baum b...@lyx.org
Date:   Sat Jul 5 12:31:12 2014 +0200

Make createBufferTmpDir() threadsafe

This must not use thread local storage, since the generated directories are
all in the same parent directory which is unique per running LyX instance.

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 4331309..0a362c3 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -97,6 +97,7 @@
 #include support/gzstream.h
 #include support/lstrings.h
 #include support/lyxalgo.h
+#include support/mutex.h
 #include support/os.h
 #include support/Package.h
 #include support/PathChanger.h
@@ -353,13 +354,20 @@ private:
 /// Creates the per buffer temporary directory
 static FileName createBufferTmpDir()
 {
-   // FIXME THREAD
-   static int count;
+   // FIXME This would be the ideal application for a TempDir class (like
+   //   TempFile but for directories) 
+   string counter;
+   {
+   static int count;
+   static Mutex mutex;
+   Mutex::Locker locker(mutex);
+   counter = convertstring(count++);
+   }
// We are in our own directory.  Why bother to mangle name?
// In fact I wrote this code to circumvent a problematic behaviour
// (bug?) of EMX mkstemp().
FileName tmpfl(package().temp_dir().absFileName() + /lyx_tmpbuf +
-   convertstring(count++));
+   counter);
 
if (!tmpfl.createDirectory(0777)) {
throw ExceptionMessage(WarningException, _(Disk Error: ), 
bformat(


[LyX/master] Make BufferParams::auto_packages() threadsafe

2014-07-05 Thread Georg Baum
commit e7c41b5f56e48670ed6415edac1811167a1e177b
Author: Georg Baum b...@lyx.org
Date:   Sat Jul 5 12:39:59 2014 +0200

Make BufferParams::auto_packages() threadsafe

diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 49c55aa..792f148 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -52,6 +52,7 @@
 #include support/filetools.h
 #include support/gettext.h
 #include support/Messages.h
+#include support/mutex.h
 #include support/Translator.h
 #include support/lstrings.h
 
@@ -446,10 +447,16 @@ void BufferParams::use_package(std::string const  p, 
BufferParams::Package u)
 
 mapstring, string const  BufferParams::auto_packages()
 {
-   // FIXME THREAD
-   // It is extremely unlikely that there could be a problem here, but...
static mapstring, string packages;
if (packages.empty()) {
+   // We could have a race condition here that two threads
+   // discover an empty map at the same time and want to fill
+   // it, but that is no problem, since the same contents is
+   // filled in twice then. Having the locker inside the
+   // packages.empty() condition has the advantage that we
+   // don't need the mutex overhead for simple reading.
+   static Mutex mutex;
+   Mutex::Locker locker(mutex);
// adding a package here implies a file format change!
packages[amsmath] =
N_(The LaTeX package amsmath is only used if AMS 
formula types or symbols from the AMS math toolbars are inserted into 
formulas);


[LyX/master] Make BufferList::fileNames() threadsafe

2014-07-05 Thread Georg Baum
commit 922d48da27b4371a089fabc5bc1b6c660ad0f598
Author: Georg Baum b...@lyx.org
Date:   Sat Jul 5 12:51:40 2014 +0200

Make BufferList::fileNames() threadsafe

Using a static variable here was premature optimization: fileNames() is only
called from GuiRef (directly or indirectly), and since this is a dialog the
copying of a FileNameList is not noticeable at all.

diff --git a/src/BufferList.cpp b/src/BufferList.cpp
index de5a7ab..c253282 100644
--- a/src/BufferList.cpp
+++ b/src/BufferList.cpp
@@ -154,11 +154,9 @@ void BufferList::closeAll()
 }
 
 
-FileNameList const  BufferList::fileNames() const
+FileNameList BufferList::fileNames() const
 {
-   // FIXME THREAD
-   static FileNameList nvec;
-   nvec.clear();
+   FileNameList nvec;
BufferStorage::const_iterator it = bstore.begin();
BufferStorage::const_iterator end = bstore.end();
for (; it != end; ++it) {
@@ -348,7 +346,7 @@ void BufferList::recordCurrentAuthor(Author const  author)
 
 int BufferList::bufferNum(FileName const  fname) const
 {
-   FileNameList const  buffers = fileNames();
+   FileNameList const buffers(fileNames());
FileNameList::const_iterator cit =
find(buffers.begin(), buffers.end(), fname);
if (cit == buffers.end())
diff --git a/src/BufferList.h b/src/BufferList.h
index 95df26a..4f9cb95 100644
--- a/src/BufferList.h
+++ b/src/BufferList.h
@@ -66,7 +66,7 @@ public:
void closeAll();
 
/// returns a vector with all the buffers filenames
-   support::FileNameList const  fileNames() const;
+   support::FileNameList fileNames() const;
 
/// return true if no buffers loaded
bool empty() const;
diff --git a/src/frontends/qt4/GuiRef.cpp b/src/frontends/qt4/GuiRef.cpp
index 141c67b..c0e6842 100644
--- a/src/frontends/qt4/GuiRef.cpp
+++ b/src/frontends/qt4/GuiRef.cpp
@@ -251,7 +251,7 @@ void GuiRef::updateContents()
 
// insert buffer list
bufferCO-clear();
-   FileNameList const  buffers = theBufferList().fileNames();
+   FileNameList const buffers(theBufferList().fileNames());
for (FileNameList::const_iterator it = buffers.begin();
 it != buffers.end(); ++it) {
bufferCO-addItem(toqstr(makeDisplayPath(it-absFileName(;
@@ -455,7 +455,8 @@ void GuiRef::updateRefs()
refs_.clear();
int const the_buffer = bufferCO-currentIndex();
if (the_buffer != -1) {
-   FileName const  name = theBufferList().fileNames()[the_buffer];
+   FileNameList const names(theBufferList().fileNames());
+   FileName const  name = names[the_buffer];
Buffer const * buf = theBufferList().getBuffer(name);
buf-getLabelList(refs_);
}


[LyX/master] Make newUnnamedFile() threadsafe

2014-07-05 Thread Georg Baum
commit 5c431b9335e7e698f866f516665a2c604e7be396
Author: Georg Baum b...@lyx.org
Date:   Sat Jul 5 12:58:22 2014 +0200

Make newUnnamedFile() threadsafe

diff --git a/src/buffer_funcs.cpp b/src/buffer_funcs.cpp
index 3f64b90..03ecc90 100644
--- a/src/buffer_funcs.cpp
+++ b/src/buffer_funcs.cpp
@@ -47,6 +47,7 @@
 #include support/filetools.h
 #include support/gettext.h
 #include support/lstrings.h
+#include support/mutex.h
 #include support/textutils.h
 
 using namespace std;
@@ -172,9 +173,10 @@ Buffer * newFile(string const  filename, string const  
templatename,
 Buffer * newUnnamedFile(FileName const  path, string const  prefix,
string const  templatename)
 {
-   // FIXME THREAD
static mapstring, int file_number;
+   static Mutex mutex;
 
+   Mutex::Locker locker(mutex);
FileName filename;
 
do {


[LyX/master] Support for Swiss German (old spelling)

2014-07-05 Thread Juergen Spitzmueller
commit 0c3b88e3cb817cd030163c534db91ec94f886953
Author: Juergen Spitzmueller sp...@lyx.org
Date:   Sat Jul 5 13:38:55 2014 +0200

Support for Swiss German (old spelling)

diff --git a/lib/languages b/lib/languages
index 92387a9..e4c0dd5 100644
--- a/lib/languages
+++ b/lib/languages
@@ -491,17 +491,18 @@ Language german-ch
LangCode de_CH
 End
 
-# This is now supported, but requires a file format change
-# Language german-ch-old
-#  GuiName  German (Switzerland, old spelling)
-#  BabelNameswissgerman
-#  PolyglossiaName  german
-#  PolyglossiaOpts  spelling=old,babelshorthands=true
-## PolyglossiaOpts  variant=swiss,spelling=old,babelshorthands=true
-#  QuoteStyle   danish
-#  Encoding iso8859-15
-#  LangCode de_CH
-# End
+# In Babel, this is supported since release 2.7 of babel-german (Dec 2013)
+# Polyglossia does not yet support Swiss German. We use german for now.
+Language german-ch-old
+   GuiName  German (Switzerland, old spelling)
+   BabelNameswissgerman
+   PolyglossiaName  german
+   PolyglossiaOpts  spelling=old,babelshorthands=true
+#  PolyglossiaOpts  variant=swiss,spelling=old,babelshorthands=true
+   QuoteStyle   danish
+   Encoding iso8859-15
+   LangCode de_CH
+End
 
 Language greek
GuiName   Greek
diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py
index eb0b079..6364524 100644
--- a/lib/lyx2lyx/LyX.py
+++ b/lib/lyx2lyx/LyX.py
@@ -85,7 +85,7 @@ format_relation = [(0_06,[200], minor_versions(0.6 , 
4)),
(1_6, range(277,346), minor_versions(1.6 , 10)),
(2_0, range(346,414), minor_versions(2.0, 8)),
(2_1, range(414,475), minor_versions(2.1, 0)),
-   (2_2, range(475,477), minor_versions(2.2, 0))
+   (2_2, range(475,478), minor_versions(2.2, 0))
   ]
 
 
diff --git a/lib/lyx2lyx/lyx_2_2.py b/lib/lyx2lyx/lyx_2_2.py
index c263c83..f15b0c6 100644
--- a/lib/lyx2lyx/lyx_2_2.py
+++ b/lib/lyx2lyx/lyx_2_2.py
@@ -275,6 +275,23 @@ def revert_smash(document):
 j = k
 
 
+def revert_swissgerman(document):
+ Set language german-ch-old to german 
+i = 0
+if document.language == german-ch-old:
+document.language = german
+i = find_token(document.header, \\language, 0)
+if i != -1:
+document.header[i] = \\language german
+j = 0
+while True:
+j = find_token(document.body, \\lang german-ch-old, j)
+if j == -1:
+return
+document.body[j] = document.body[j].replace(\\lang german-ch-old, 
\\lang german)
+j = j + 1
+
+
 ##
 # Conversion hub
 #
@@ -286,9 +303,11 @@ convert = [
# did not load amsmath automatically for these commands, and do not
# want to hardcode amsmath off.
[476, []],
+   [477, []],
   ]
 
 revert =  [
+   [476, [revert_swissgerman]],
[475, [revert_smash]],
[474, [revert_separator]]
   ]
diff --git a/src/version.h b/src/version.h
index 22713f6..f7eb1e1 100644
--- a/src/version.h
+++ b/src/version.h
@@ -30,8 +30,8 @@ extern char const * const lyx_version_info;
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 476 // gb: \smash[t], \smash[b] and \notag
-#define LYX_FORMAT_TEX2LYX 476
+#define LYX_FORMAT_LYX 477 // spitz: support for swissgerman
+#define LYX_FORMAT_TEX2LYX 477
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER


[LyX/master] Make LaTeX export threadsafe.

2014-07-05 Thread Georg Baum
commit 5a8b8ba8e11360a716465b9c6c7c0dc48f37f552
Author: Georg Baum b...@lyx.org
Date:   Sat Jul 5 14:23:43 2014 +0200

Make LaTeX export threadsafe.

This is one of the more important threadsafety issues because of export in
thread and simultanous view source. The solution is ugly, but a better one
(see FIXME) would require major rework. These static variables should not
have been used in the first place IMHO.

diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index 735b898..ed46c05 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -35,6 +35,8 @@
 #include support/lstrings.h
 #include support/textutils.h
 
+#include QThreadStorage
+
 #include algorithm
 #include boost/next_prior.hpp
 #include list
@@ -53,13 +55,28 @@ enum OpenEncoding {
CJK
 };
 
-// FIXME THREAD
-// There could easily be a conflict here, with the export process
-// setting this one way, and a ViewSource process (possbily for
-// another Buffer) resetting it.
-static int open_encoding_ = none;
-static int cjk_inherited_ = 0;
-Language const * prev_env_language_ = 0;
+
+struct OutputState
+{
+   OutputState() : open_encoding_(none), cjk_inherited_(0),
+   prev_env_language_(0)
+   {
+   }
+   int open_encoding_;
+   int cjk_inherited_;
+   Language const * prev_env_language_;
+};
+
+
+OutputState * getOutputState()
+{
+   // FIXME An instance of OutputState should be kept around for each 
export
+   //   instead of using local thread storage
+   static QThreadStorageOutputState * outputstate;
+   if (!outputstate.hasLocalData())
+   outputstate.setLocalData(new OutputState);
+   return outputstate.localData();
+}
 
 
 string const getPolyglossiaEnvName(Language const * lang)
@@ -101,7 +118,8 @@ static TeXEnvironmentData prepareEnvironment(Buffer const  
buf,
ParagraphList::const_iterator const priorpit =
pit == paragraphs.begin() ? pit : boost::prior(pit);
 
-   bool const use_prev_env_language = prev_env_language_ != 0
+   OutputState * state = getOutputState();
+   bool const use_prev_env_language = state-prev_env_language_ != 0
 priorpit-layout().isEnvironment()
 (priorpit-getDepth()  pit-getDepth()
|| (priorpit-getDepth() == pit-getDepth()
@@ -112,7 +130,7 @@ static TeXEnvironmentData prepareEnvironment(Buffer const  
buf,
Language const * const doc_language = bparams.language;
Language const * const prev_par_language =
(pit != paragraphs.begin())
-   ? (use_prev_env_language ? prev_env_language_
+   ? (use_prev_env_language ? state-prev_env_language_
 : priorpit-getParLanguage(bparams))
: doc_language;
 
@@ -191,11 +209,11 @@ static TeXEnvironmentData prepareEnvironment(Buffer const 
 buf,
// in multilingual environments, the CJK tags have to be nested properly
data.cjk_nested = false;
if (data.par_language-encoding()-package() == Encoding::CJK 
-   open_encoding_ != CJK  pit-isMultiLingual(bparams)) {
+   state-open_encoding_ != CJK  pit-isMultiLingual(bparams)) {
if (prev_par_language-encoding()-package() == Encoding::CJK)
os  \\begin{CJK}{  
from_ascii(data.par_language-encoding()-latexName())
}{  from_ascii(bparams.fonts_cjk)  }%\n;
-   open_encoding_ = CJK;
+   state-open_encoding_ = CJK;
data.cjk_nested = true;
}
return data;
@@ -205,17 +223,18 @@ static TeXEnvironmentData prepareEnvironment(Buffer const 
 buf,
 static void finishEnvironment(otexstream  os, OutputParams const  runparams,
  TeXEnvironmentData const  data)
 {
-   if (open_encoding_ == CJK  data.cjk_nested) {
+   OutputState * state = getOutputState();
+   if (state-open_encoding_ == CJK  data.cjk_nested) {
// We need to close the encoding even if it does not change
// to do correct environment nesting
os  \\end{CJK}\n;
-   open_encoding_ = none;
+   state-open_encoding_ = none;
}
 
if (data.style-isEnvironment()) {
os  breakln
\\end{  from_ascii(data.style-latexname())  }\n;
-   prev_env_language_ = data.par_language;
+   state-prev_env_language_ = data.par_language;
if (runparams.encoding != data.prev_encoding) {
runparams.encoding = data.prev_encoding;
if (!runparams.isFullUnicode())
@@ -225,7 +244,7 @@ static void finishEnvironment(otexstream  os, OutputParams 
const  runparams,
 
if (data.leftindent_open) {
os  breakln  \\end{LyXParagraphLeftIndent}\n;
-   

[LyX/master] Fix LaTeXFeatures::useLayout() recursion test

2014-07-05 Thread Georg Baum
commit 5093893b59938ab3cb59612a90580d4b7956cfec
Author: Georg Baum b...@lyx.org
Date:   Sat Jul 5 14:37:55 2014 +0200

Fix LaTeXFeatures::useLayout() recursion test

It was broken in two ways: It was not threadsafe, and it did never detect
any recursion, since the counter was decremented for each non-recursive call
and never incremented again.

diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index cb35fdf..506af18 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -427,9 +427,13 @@ void LaTeXFeatures::require(setstring const  names)
 
 void LaTeXFeatures::useLayout(docstring const  layoutname)
 {
+   useLayout(layoutname, 0);
+}
+
+
+void LaTeXFeatures::useLayout(docstring const  layoutname, int level)
+{
// Some code to avoid loops in dependency definition
-   // FIXME THREAD
-   static int level = 0;
const int maxlevel = 30;
if (level  maxlevel) {
lyxerr  LaTeXFeatures::useLayout: maximum level of 
@@ -449,9 +453,7 @@ void LaTeXFeatures::useLayout(docstring const  layoutname)
require(layout.requires());
 
if (!layout.depends_on().empty()) {
-   ++level;
-   useLayout(layout.depends_on());
-   --level;
+   useLayout(layout.depends_on(), level + 1);
}
usedLayouts_.push_back(layoutname);
} else {
@@ -459,8 +461,6 @@ void LaTeXFeatures::useLayout(docstring const  layoutname)
to_utf8(layoutname)  ' does not exist in this 
class
endl;
}
-
-   --level;
 }
 
 
diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h
index 71004be..be00847 100644
--- a/src/LaTeXFeatures.h
+++ b/src/LaTeXFeatures.h
@@ -158,6 +158,8 @@ public:
 
 private:
///
+   void useLayout(docstring const , int);
+   ///
std::listdocstring usedLayouts_;
///
std::listdocstring usedInsetLayouts_;


[LyX/master] Fix uncodable author warning

2014-07-05 Thread Georg Baum
commit 2a677592a5fbbc369dc4199b1c4b3a0c84fb068a
Author: Georg Baum b...@lyx.org
Date:   Sat Jul 5 14:49:51 2014 +0200

Fix uncodable author warning

The old code was not threadsafe, and the restriction to one message box per
author name did not work if more than two authors were uncodable.

diff --git a/src/Changes.cpp b/src/Changes.cpp
index 39f2a8e..29471f2 100644
--- a/src/Changes.cpp
+++ b/src/Changes.cpp
@@ -27,6 +27,7 @@
 #include support/gettext.h
 #include support/lassert.h
 #include support/lstrings.h
+#include support/mutex.h
 
 #include frontends/alert.h
 
@@ -348,9 +349,7 @@ docstring getLaTeXMarkup(docstring const  macro, docstring 
const  author,
if (macro.empty())
return docstring();
 
-   // FIXME THREAD
-   static docstring warned_author = docstring();
-   docstring uncodable_author = warned_author;
+   docstring uncodable_author;
odocstringstream ods;
 
ods  macro;
@@ -367,8 +366,12 @@ docstring getLaTeXMarkup(docstring const  macro, 
docstring const  author,
ods  author_latexed.first  }{  chgTime  }{;
 
// warn user (once) if we found uncodable glyphs.
-   if (uncodable_author != warned_author) {
-   frontend::Alert::warning(_(Uncodable character in author 
name),
+   if (!uncodable_author.empty()) {
+   static std::setdocstring warned_authors;
+   static Mutex warned_mutex;
+   Mutex::Locker locker(warned_mutex);
+   if (warned_authors.find(uncodable_author) == 
warned_authors.end()) {
+   frontend::Alert::warning(_(Uncodable character in 
author name),
support::bformat(_(The author name '%1$s',\n
  used for change tracking, contains the 
following glyphs that\n
  cannot be represented in the current 
encoding: %2$s.\n
@@ -376,7 +379,8 @@ docstring getLaTeXMarkup(docstring const  macro, docstring 
const  author,
  Choose an appropriate document encoding 
(such as utf8)\n
  or change the spelling of the author name.),
uncodable_author, author_latexed.second));
-   warned_author = uncodable_author;
+   warned_authors.insert(uncodable_author);
+   }
}
 
return ods.str();


[LyX/master] Make GraphicsConverter threadsafe

2014-07-05 Thread Georg Baum
commit 5a01424bf0dbb939cbff1c72ecd99359803a4675
Author: Georg Baum b...@lyx.org
Date:   Sat Jul 5 15:11:24 2014 +0200

Make GraphicsConverter threadsafe

build_script() was already threadsafe, since it used a TempFile, and the
counter was basically not needed, but the new solution makes this obvious
and has the additional advantage that TempFile constructs the real output
file, not a dummy without extension which is not needed.

diff --git a/src/graphics/GraphicsConverter.cpp 
b/src/graphics/GraphicsConverter.cpp
index e833a35..83d895e 100644
--- a/src/graphics/GraphicsConverter.cpp
+++ b/src/graphics/GraphicsConverter.cpp
@@ -143,10 +143,9 @@ Converter::Impl::Impl(FileName const  from_file, string 
const  to_file_base,
 \n--\n);
 
// Output the script to file.
-   // FIXME THREAD
-   static int counter = 0;
-   script_file_ = FileName(onlyPath(to_file_base) + lyxconvert +
-   convertstring(counter++) + .py);
+   TempFile tempfile(to_file_.onlyPath(), lyxconvertXX.py);
+   tempfile.setAutoRemove(false);
+   script_file_ = tempfile.name();
 
ofstream fs(script_file_.toFilesystemEncoding().c_str());
if (!fs.good()) {
@@ -289,19 +288,16 @@ static void build_script(string const  from_file,
theConverters().getPath(from_format, to_format);
 
// Create a temporary base file-name for all intermediate steps.
-   // Remember to remove the temp file because we only want the name...
-   // FIXME THREAD
-   static int counter = 0;
-   string const tmp = gconvert + convertstring(counter++);
-   TempFile tempfile(tmp);
+   string const from_ext = getExtension(from_file);
+   TempFile tempfile(addExtension(gconvertXX, from_ext));
tempfile.setAutoRemove(false);
-   string const to_base = tempfile.name().toFilesystemEncoding();
+   string outfile = tempfile.name().toFilesystemEncoding();
+   string const to_base = from_ext.empty() ? outfile : 
removeExtension(outfile);
 
// Create a copy of the file in case the original name contains
// problematic characters like ' or . We can work around that problem
// in python, but the converters might be shell scripts and have more
// troubles with it.
-   string outfile = addExtension(to_base, getExtension(from_file));
script  infile = 
 quoteName(from_file, quote_python)
 \n
@@ -369,10 +365,9 @@ static void build_script(string const  from_file,
 
// If two formats share the same extension we may get identical 
names
if (outfile == infile  conv.result_file.empty()) {
-   TempFile tempfile(tmp);
+   TempFile tempfile(addExtension(gconvertXX, 
conv.To-extension()));
tempfile.setAutoRemove(false);
-   string const new_base = 
tempfile.name().toFilesystemEncoding();
-   outfile = addExtension(new_base, conv.To-extension());
+   outfile = tempfile.name().toFilesystemEncoding();
}
 
// Store these names in the python script


[LyX/master] Mark some singletons with FIXME THREAD

2014-07-05 Thread Georg Baum
commit b88f6ea3aa1c39849a1d295d106ba7bb491e013b
Author: Georg Baum b...@lyx.org
Date:   Sat Jul 5 15:20:54 2014 +0200

Mark some singletons with FIXME THREAD

diff --git a/src/ConverterCache.cpp b/src/ConverterCache.cpp
index 1451f6e..820eb06 100644
--- a/src/ConverterCache.cpp
+++ b/src/ConverterCache.cpp
@@ -223,6 +223,7 @@ ConverterCache::~ConverterCache()
 }
 
 
+// FIXME THREAD
 ConverterCache  ConverterCache::get()
 {
// Now return the cache
diff --git a/src/graphics/GraphicsCache.cpp b/src/graphics/GraphicsCache.cpp
index d508563..b816926 100644
--- a/src/graphics/GraphicsCache.cpp
+++ b/src/graphics/GraphicsCache.cpp
@@ -44,6 +44,7 @@ public:
 };
 
 
+// FIXME THREAD
 Cache  Cache::get()
 {
// Now return the cache
diff --git a/src/graphics/GraphicsLoader.cpp b/src/graphics/GraphicsLoader.cpp
index 4ec5c9a..ade29f1 100644
--- a/src/graphics/GraphicsLoader.cpp
+++ b/src/graphics/GraphicsLoader.cpp
@@ -71,13 +71,13 @@ private:
 };
 
 
-//static int s_numimages_ = 5;
-//static int s_millisecs_ = 500;
 
-// FIXME THREAD
-static int s_numimages_ = 10;
-static int s_millisecs_ = 500;
+//static int const s_numimages_ = 5;
+static int const s_numimages_ = 10;
+static int const s_millisecs_ = 500;
+
 
+// FIXME THREAD
 LoaderQueue  LoaderQueue::get()
 {
static LoaderQueue singleton;


[LyX/master] Fix typo spotted by cppcheck

2014-07-05 Thread Jean-Marc
commit 8715bab65cc87272dd0d701e31b37363d43d6e95
Author: Jean-Marc lasgout...@lyx.org
Date:   Sat Jul 5 18:01:19 2014 +0200

Fix typo spotted by cppcheck

diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp
index 8508e4e..ea1ba59 100644
--- a/src/support/lstrings.cpp
+++ b/src/support/lstrings.cpp
@@ -1458,7 +1458,7 @@ docstring bformat(docstring const  fmt, char const * 
arg1, docstring arg2)
LATTEST(contains(fmt, from_ascii(%1$s)));
LATTEST(contains(fmt, from_ascii(%2$s)));
docstring str = subst(fmt, from_ascii(%1$s), from_ascii(arg1));
-   str = subst(fmt, from_ascii(%2$s), arg2);
+   str = subst(str, from_ascii(%2$s), arg2);
return subst(str, from_ascii(%%), from_ascii(%));
 }
 


[LyX/master] Fix possible bug spotted by cppcheck

2014-07-05 Thread Jean-Marc
commit 1cdbb94ff53ba2e73d60aecd53c7b9b44b042701
Author: Jean-Marc lasgout...@lyx.org
Date:   Sat Jul 5 19:12:09 2014 +0200

Fix possible bug spotted by cppcheck

I am not sure what this locking is really about, but the new code seems to 
be the right thing to do.

diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp
index f39112c..a6d92d9 100644
--- a/src/mathed/MathMacro.cpp
+++ b/src/mathed/MathMacro.cpp
@@ -332,7 +332,7 @@ void MathMacro::updateRepresentation(Cursor * cur, 
MacroContext const  mc,
if (isUpdating_)
return;
 
-   UpdateLocker(*this);
+   UpdateLocker locker(*this);
 
// known macro?
if (macro_ == 0)


[LyX/master] Fix a bunch of small performance issues spotted by cppcheck

2014-07-05 Thread Jean-Marc
commit 93a43742a5f1db8a632233c15e2b8d61b4835f3a
Author: Jean-Marc lasgout...@lyx.org
Date:   Sat Jul 5 19:13:10 2014 +0200

Fix a bunch of small performance issues spotted by cppcheck

Most of these are about passing const strings parameters as references.

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 0a362c3..6c8194c 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -653,7 +653,7 @@ BufferParams const  Buffer::masterParams() const
// Copy child authors to the params. We need those pointers.
AuthorList const  child_authors = params().authors();
AuthorList::Authors::const_iterator it = child_authors.begin();
-   for (; it != child_authors.end(); it++)
+   for (; it != child_authors.end(); ++it)
mparams.authors().record(*it);
return mparams;
 }
@@ -3507,7 +3507,7 @@ void Buffer::changeRefsIfUnique(docstring const  from, 
docstring const  to)
 }
 
 
-void Buffer::getSourceCode(odocstream  os, string const format,
+void Buffer::getSourceCode(odocstream  os, string const  format,
   pit_type par_begin, pit_type par_end,
   OutputWhat output, bool master) const
 {
diff --git a/src/Buffer.h b/src/Buffer.h
index fe0294b..29992f9 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -594,7 +594,7 @@ public:
 
/// get source code (latex/docbook) for some paragraphs, or all 
paragraphs
/// including preamble
-   void getSourceCode(odocstream  os, std::string const format,
+   void getSourceCode(odocstream  os, std::string const  format,
   pit_type par_begin, pit_type par_end, OutputWhat 
output,
   bool master) const;
 
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 792f148..8ae249e 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -2280,7 +2280,7 @@ vectorstring BufferParams::backends() const
 }
 
 
-OutputParams::FLAVOR BufferParams::getOutputFlavor(string const format) const
+OutputParams::FLAVOR BufferParams::getOutputFlavor(string const  format) const
 {
string const dformat = (format.empty() || format == default) ?
getDefaultOutputFormat() : format;
@@ -2362,7 +2362,7 @@ Font const BufferParams::getFont() const
 }
 
 
-InsetQuotes::QuoteLanguage BufferParams::getQuoteStyle(string const qs) const
+InsetQuotes::QuoteLanguage BufferParams::getQuoteStyle(string const  qs) const
 {
return quoteslangtranslator().find(qs);
 }
diff --git a/src/BufferParams.h b/src/BufferParams.h
index 3706399..2d7c749 100644
--- a/src/BufferParams.h
+++ b/src/BufferParams.h
@@ -180,7 +180,7 @@ public:
std::string getDefaultOutputFormat() const;
/// return the output flavor of \p format or the default
OutputParams::FLAVOR getOutputFlavor(
- std::string const format = std::string()) const;
+ std::string const  format = std::string()) const;
///
bool isExportable(std::string const  format) const;
///
@@ -207,7 +207,7 @@ public:
Font const getFont() const;
 
/// translate quote style string to enum value
-   InsetQuotes::QuoteLanguage getQuoteStyle(std::string const qs) const;
+   InsetQuotes::QuoteLanguage getQuoteStyle(std::string const  qs) const;
 
/* these are for the PaperLayout */
/// the papersize
diff --git a/src/Encoding.cpp b/src/Encoding.cpp
index a6f6a60..dcf65d7 100644
--- a/src/Encoding.cpp
+++ b/src/Encoding.cpp
@@ -257,9 +257,9 @@ const char * EncodingException::what() const throw()
 
 
 CharInfo::CharInfo(
-   docstring const textcommand, docstring const mathcommand,
-   std::string const textpreamble, std::string const mathpreamble,
-   std::string const tipashortcut, unsigned int flags)
+   docstring const  textcommand, docstring const  mathcommand,
+   std::string const  textpreamble, std::string const  mathpreamble,
+   std::string const  tipashortcut, unsigned int flags)
: textcommand_(textcommand), mathcommand_(mathcommand),
  textpreamble_(textpreamble), mathpreamble_(mathpreamble),
  tipashortcut_(tipashortcut), flags_(flags)
@@ -380,7 +380,7 @@ pairdocstring, bool Encoding::latexChar(char_type c) const
 }
 
 
-pairdocstring, docstring Encoding::latexString(docstring const input, bool 
dryrun) const
+pairdocstring, docstring Encoding::latexString(docstring const  input, bool 
dryrun) const
 {
docstring result;
docstring uncodable;
diff --git a/src/Encoding.h b/src/Encoding.h
index ed9c27e..7351197 100644
--- a/src/Encoding.h
+++ b/src/Encoding.h
@@ -59,9 +59,9 @@ class CharInfo {
 public:
CharInfo() : flags_(0) {}
CharInfo(
-   docstring const textcommand, docstring const mathcommand,
-   std::string const textpreamble, std::string const mathpreamble,
-   std::string const tipashortcut, unsigned int flags);
+   docstring 

[LyX/master] Make WordList noncopyable

2014-07-05 Thread Georg Baum
commit 7baaeb3fd2d12928f79e32821b6c01784b99b2a6
Author: Georg Baum 
Date:   Fri Jul 4 21:15:21 2014 +0200

Make WordList noncopyable

To avoid unwanted double deletion of d.

diff --git a/src/WordList.h b/src/WordList.h
index f57f20b..d21f9c8 100644
--- a/src/WordList.h
+++ b/src/WordList.h
@@ -17,6 +17,9 @@
 namespace lyx {
 
 class WordList {
+   // noncopyable because of pimpl
+   WordList(WordList const &);
+   WordList & operator=(WordList const &);
 public:
///
WordList();


[LyX/master] Don't guess whether autosave succeeded

2014-07-05 Thread Georg Baum
commit 50467f3f554129b6ff532f4433da27e9b76aff55
Author: Georg Baum 
Date:   Fri Jul 4 21:06:49 2014 +0200

Don't guess whether autosave succeeded

writeFile() tells whether it could save the file, so use the return value
instead of guessing.

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 10e7a27..4331309 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -3738,9 +3738,9 @@ int AutoSaveBuffer::generateChild()
tempfile.setAutoRemove(false);
FileName const tmp_ret = tempfile.name();
if (!tmp_ret.empty()) {
-   buffer_.writeFile(tmp_ret);
-   // assume successful write of tmp_ret
-   if (!tmp_ret.moveTo(fname_))
+   if (!buffer_.writeFile(tmp_ret))
+   failed = true;
+   else if (!tmp_ret.moveTo(fname_))
failed = true;
} else
failed = true;


[LyX/master] Fix bug #9162: Missing \use_indices

2014-07-05 Thread Georg Baum
commit 22dcdd6d8ff39206bcb627ea6ce4de8c6c07417f
Author: Georg Baum 
Date:   Fri Jul 4 19:55:44 2014 +0200

Fix bug #9162: Missing \use_indices

The lyx2lyx conversion for format 352 was incomplete: It should have been
added the \use_indices setting, but it relied on the fact that the default 
in
LyX for missing \use_indices is the same as the old format without that
setting used. However, the default might change in the future, and later
lyx2lyx conversions rely on that setting as well.

diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py
index 5ee8d5f..eb0b079 100644
--- a/lib/lyx2lyx/LyX.py
+++ b/lib/lyx2lyx/LyX.py
@@ -720,6 +720,7 @@ class File(LyX_base):
 self.read()
 
 
+# FIXME: header settings are completely outdated, don't use like this
 #class NewFile(LyX_base):
 #" This class is to create new LyX files."
 #def set_header(self, **params):
@@ -748,6 +749,7 @@ class File(LyX_base):
 #"\\use_amsmath 1",
 #"\\cite_engine basic",
 #"\\use_bibtopic false",
+#"\\use_indices false",
 #"\\paperorientation portrait",
 #"\\secnumdepth 3",
 #"\\tocdepth 3",
diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py
index 2756418..7914cc4 100644
--- a/lib/lyx2lyx/lyx_2_0.py
+++ b/lib/lyx2lyx/lyx_2_0.py
@@ -317,11 +317,33 @@ def revert_backgroundcolor(document):
 '\\pagecolor{page_backgroundcolor}'])
 
 
-def revert_splitindex(document):
-" Reverts splitindex-aware documents "
+def add_use_indices(document):
+" Add \\use_indices if it is missing "
 i = find_token(document.header, '\\use_indices', 0)
+if i != -1:
+return i
+i = find_token(document.header, '\\use_bibtopic', 0)
+if i == -1:
+i = find_token(document.header, '\\cite_engine', 0)
+if i == -1:
+i = find_token(document.header, '\\use_mathdots', 0)
+if i == -1:
+i = find_token(document.header, '\\use_mhchem', 0)
+if i == -1:
+i = find_token(document.header, '\\use_esint', 0)
+if i == -1:
+i = find_token(document.header, '\\use_amsmath', 0)
 if i == -1:
 document.warning("Malformed LyX document: Missing \\use_indices.")
+return -1
+document.header.insert(i + 1, '\\use_indices 0')
+return i + 1
+
+
+def revert_splitindex(document):
+" Reverts splitindex-aware documents "
+i = add_use_indices(document)
+if i == -1:
 return
 useindices = str2bool(get_value(document.header, "\\use_indices", i))
 del document.header[i]
@@ -398,6 +420,7 @@ def revert_splitindex(document):
 
 def convert_splitindex(document):
 " Converts index and printindex insets to splitindex-aware format "
+add_use_indices(document)
 i = 0
 while True:
 i = find_token(document.body, "\\begin_inset Index", i)
@@ -422,9 +445,8 @@ def convert_splitindex(document):
 
 def revert_subindex(document):
 " Reverts \\printsubindex CommandInset types "
-i = find_token(document.header, '\\use_indices', 0)
+i = add_use_indices(document)
 if i == -1:
-document.warning("Malformed LyX document: Missing \\use_indices.")
 return
 useindices = str2bool(get_value(document.header, "\\use_indices", i))
 i = 0
@@ -448,9 +470,8 @@ def revert_subindex(document):
 
 def revert_printindexall(document):
 " Reverts \\print[sub]index* CommandInset types "
-i = find_token(document.header, '\\use_indices', 0)
+i = add_use_indices(document)
 if i == -1:
-document.warning("Malformed LyX document: Missing \\use_indices.")
 return
 useindices = str2bool(get_value(document.header, "\\use_indices", i))
 i = 0
diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py
index ae95841..f9b1e32 100644
--- a/lib/lyx2lyx/lyx_2_1.py
+++ b/lib/lyx2lyx/lyx_2_1.py
@@ -409,9 +409,15 @@ def revert_japanese_encodings(document):
 
 def convert_justification(document):
 " Add the \\justification buffer param"
-i = find_token(document.header, "\\use_indices" , 0)
+i = find_token(document.header, "\\suppress_date" , 0)
 if i == -1:
-document.warning("Malformed LyX document: Missing \\use_indices.")
+i = find_token(document.header, "\\paperorientation" , 0)
+if i == -1:
+i = find_token(document.header, "\\use_indices" , 0)
+if i == -1:
+i = find_token(document.header, "\\use_bibtopic" , 0)
+if i == -1:
+document.warning("Malformed LyX document: Missing \\suppress_date.")
 return
 document.header.insert(i + 1, "\\justification true")
 


[LyX/master] Make theWordList() thread safe.

2014-07-05 Thread Georg Baum
commit cf89851374163be2e8a390dd917d7ef435978979
Author: Georg Baum 
Date:   Fri Jul 4 22:19:43 2014 +0200

Make theWordList() thread safe.

Without this, you get crashes in a few second when you set the autosave
interval to one second and edit quickly (typing new words etc). The reason
is that the cloned buffer wants to insert words into the word list and
remove them again, but it lives in a different thread.

diff --git a/src/WordList.cpp b/src/WordList.cpp
index 3a095af..16f3b92 100644
--- a/src/WordList.cpp
+++ b/src/WordList.cpp
@@ -18,6 +18,8 @@
 #include "support/lassert.h"
 #include "support/weighted_btree.h"
 
+#include 
+
 #include 
 
 using namespace std;
@@ -26,26 +28,37 @@ namespace lyx {
 
 ///
 typedef map GlobalWordList;
-GlobalWordList theGlobalWordList;
+// Each thread uses its own word list, but only the one of the GUI thread is
+// used to do real work. The others are only neded to prevent simultanous
+// write access e.g. from a cloned buffer and a true document buffer.
+QThreadStorage theGlobalWordList;
 
 
 WordList * theWordList(string const & lang)
 {
-   GlobalWordList::iterator it = theGlobalWordList.find(lang);
-   if (it != theGlobalWordList.end())
+   if (!theGlobalWordList.hasLocalData())
+   theGlobalWordList.setLocalData(new GlobalWordList);
+   GlobalWordList * globalWordList = theGlobalWordList.localData();
+   GlobalWordList::iterator it = globalWordList->find(lang);
+   if (it != globalWordList->end())
return it->second;
-   else
-   theGlobalWordList[lang] = new WordList;
-   return theGlobalWordList[lang];
+   else {
+   WordList * wl = new WordList;
+   (*globalWordList)[lang] = wl;
+   return wl;
+   }
 }
 
 
 void WordList::cleanupWordLists()
 {
-   GlobalWordList::const_iterator it = theGlobalWordList.begin();
-   for (; it != theGlobalWordList.end(); ++it)
+   if (!theGlobalWordList.hasLocalData())
+   return;
+   GlobalWordList * globalWordList = theGlobalWordList.localData();
+   GlobalWordList::const_iterator it = globalWordList->begin();
+   for (; it != globalWordList->end(); ++it)
delete it->second;
-   theGlobalWordList.clear();
+   globalWordList->clear();
 }
 
 


[LyX/master] Make preview filename generation threadsafe

2014-07-05 Thread Georg Baum
commit 79e79ed5480883ac1fd77c11a24e1185690f4354
Author: Georg Baum 
Date:   Sat Jul 5 11:19:34 2014 +0200

Make preview filename generation threadsafe

Threadsafety is ensured by the atomic file name generation in TempFile.

diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp
index 1c17226..a6c2c68 100644
--- a/src/graphics/PreviewLoader.cpp
+++ b/src/graphics/PreviewLoader.cpp
@@ -38,6 +38,7 @@
 #include "support/lstrings.h"
 
 #include "support/bind.h"
+#include "support/TempFile.h"
 
 #include 
 #include 
@@ -59,12 +60,11 @@ typedef list PendingSnippets;
 typedef vector BitmapFile;
 
 
-string const unique_filename(string const & bufferpath)
+FileName const unique_tex_filename(FileName const & bufferpath)
 {
-   // FIXME THREAD
-   static int theCounter = 0;
-   string const filename = lyx::convert(theCounter++) + 
"lyxpreview";
-   return addName(bufferpath, filename);
+   TempFile tempfile(bufferpath, "lyxpreviewXX.tex");
+   tempfile.setAutoRemove(false);
+   return tempfile.name();
 }
 
 
@@ -531,9 +531,10 @@ void PreviewLoader::Impl::startLoading(bool wait)
LYXERR(Debug::GRAPHICS, "PreviewLoader::startLoading()");
 
// As used by the LaTeX file and by the resulting image files
-   string const directory = buffer_.temppath();
+   FileName const directory(buffer_.temppath());
 
-   string const filename_base = unique_filename(directory);
+   FileName const latexfile = unique_tex_filename(directory);
+   string const filename_base = removeExtension(latexfile.absFileName());
 
// Create an InProgress instance to place in the map of all
// such processes if it starts correctly.
@@ -543,8 +544,6 @@ void PreviewLoader::Impl::startLoading(bool wait)
pending_.clear();
 
// Output the LaTeX file.
-   FileName const latexfile(filename_base + ".tex");
-
// we use the encoding of the buffer
Encoding const & enc = buffer_.params().encoding();
ofdocstream of;


[LyX/master] Fix Tabular::CellData::operator=()

2014-07-05 Thread Georg Baum
commit 0092b523c7d3c1735b6854bcbdb4e65ec782f092
Author: Georg Baum 
Date:   Sat Jul 5 11:44:13 2014 +0200

Fix Tabular::CellData::operator=()

Don't create an intermediate copy (found by Jean-Marc).
I doubt that this has anything to do with the mystery crash, but it works, 
and
following the standard patterns is better anyway.

diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index 1a84c8e..433fe19 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -602,9 +602,29 @@ Tabular::CellData::CellData(CellData const & cs)
 {
 }
 
-Tabular::CellData & Tabular::CellData::operator=(CellData cs)
-{
-   swap(cs);
+Tabular::CellData & Tabular::CellData::operator=(CellData const & cs)
+{
+   if ( == this)
+   return *this;
+   cellno = cs.cellno;
+   width = cs.width;
+   multicolumn = cs.multicolumn;
+   multirow = cs.multirow;
+   mroffset = cs.mroffset;
+   alignment = cs.alignment;
+   valignment = cs.valignment;
+   decimal_hoffset = cs.decimal_hoffset;
+   decimal_width = cs.decimal_width;
+   voffset = cs.voffset;
+   top_line = cs.top_line;
+   bottom_line = cs.bottom_line;
+   left_line = cs.left_line;
+   right_line = cs.right_line;
+   usebox = cs.usebox;
+   rotate = cs.rotate;
+   align_special = cs.align_special;
+   p_width = cs.p_width;
+   inset.reset(static_cast(cs.inset->clone()));
return *this;
 }
 
diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h
index be1a67f..8941a83 100644
--- a/src/insets/InsetTabular.h
+++ b/src/insets/InsetTabular.h
@@ -610,7 +610,7 @@ public:
///
CellData(CellData const &);
///
-   CellData & operator=(CellData);
+   CellData & operator=(CellData const &);
///
void swap(CellData & rhs);
///


[LyX/master] Make Formats::isZippedFile() threadsafe

2014-07-05 Thread Georg Baum
commit 4a2250a5d1dd551f43f75e54942ecbf0d5702080
Author: Georg Baum 
Date:   Sat Jul 5 11:55:35 2014 +0200

Make Formats::isZippedFile() threadsafe

In this case I use a mutex, so the zip status of files is shared between
threads. This is possible because a deadlock can't happen, and it should 
give
better performance.

diff --git a/src/Format.cpp b/src/Format.cpp
index 063b683..82712af 100644
--- a/src/Format.cpp
+++ b/src/Format.cpp
@@ -22,6 +22,7 @@
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
+#include "support/mutex.h"
 #include "support/os.h"
 #include "support/PathChanger.h"
 #include "support/Systemcall.h"
@@ -503,14 +504,15 @@ struct ZippedInfo {
 };
 
 
-// FIXME THREAD
 /// Mapping absolute pathnames of files to their ZippedInfo metadata.
 static std::map zipped_;
+static Mutex zipped_mutex;
 
 
 bool Formats::isZippedFile(support::FileName const & filename) const {
string const & fname = filename.absFileName();
time_t timestamp = filename.lastModified();
+   Mutex::Locker lock(_mutex);
map::iterator it = zipped_.find(fname);
if (it != zipped_.end() && it->second.timestamp == timestamp)
return it->second.zipped;


[LyX/master] Make include and bibitem insets threadsafe

2014-07-05 Thread Georg Baum
commit 50929b5b8a294079de7b81617a119a51dcb3142c
Author: Georg Baum 
Date:   Sat Jul 5 12:09:49 2014 +0200

Make include and bibitem insets threadsafe

Using a mutex to ensure that the generated filenames and ids are still 
unique.

diff --git a/src/insets/InsetBibitem.cpp b/src/insets/InsetBibitem.cpp
index 4f263e9..d0a28e7 100644
--- a/src/insets/InsetBibitem.cpp
+++ b/src/insets/InsetBibitem.cpp
@@ -41,6 +41,7 @@
 #include "support/docstream.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
+#include "support/mutex.h"
 
 using namespace std;
 using namespace lyx::support;
@@ -48,8 +49,8 @@ using namespace lyx::support;
 namespace lyx {
 
 
-// FIXME THREAD
 int InsetBibitem::key_counter = 0;
+static Mutex counter_mutex;
 docstring const key_prefix = from_ascii("key-");
 
 
@@ -57,8 +58,10 @@ InsetBibitem::InsetBibitem(Buffer * buf, InsetCommandParams 
const & p)
: InsetCommand(buf, p)
 {
buffer().invalidateBibinfoCache();
-   if (getParam("key").empty())
+   if (getParam("key").empty()) {
+   Mutex::Locker lock(_mutex);
setParam("key", key_prefix + convert(++key_counter));
+   }
 }
 
 
@@ -196,6 +199,7 @@ void InsetBibitem::read(Lexer & lex)
 
if (prefixIs(getParam("key"), key_prefix)) {
int const key = 
convert(getParam("key").substr(key_prefix.length()));
+   Mutex::Locker lock(_mutex);
key_counter = max(key_counter, key);
}
 }
diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp
index ff4a329..7494650 100644
--- a/src/insets/InsetInclude.cpp
+++ b/src/insets/InsetInclude.cpp
@@ -60,6 +60,7 @@
 #include "support/lassert.h"
 #include "support/lstrings.h" // contains
 #include "support/lyxalgo.h"
+#include "support/mutex.h"
 
 #include "support/bind.h"
 
@@ -75,8 +76,9 @@ namespace {
 
 docstring const uniqueID()
 {
-   // FIXME THREAD
static unsigned int seed = 1000;
+   static Mutex mutex;
+   Mutex::Locker lock();
return "file" + convert(++seed);
 }
 


[LyX/master] Make DocFileName::mangledFileName() threadsafe

2014-07-05 Thread Georg Baum
commit 0de4bc224af34b6f519afb7ab38f190e634b4c7c
Author: Georg Baum 
Date:   Sat Jul 5 12:22:08 2014 +0200

Make DocFileName::mangledFileName() threadsafe

diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp
index 95880a0..05492f6 100644
--- a/src/support/FileName.cpp
+++ b/src/support/FileName.cpp
@@ -17,6 +17,7 @@
 #include "support/filetools.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
+#include "support/mutex.h"
 #include "support/qstring_helpers.h"
 #include "support/os.h"
 #include "support/Package.h"
@@ -910,13 +911,15 @@ string DocFileName::outputFileName(string const & path) 
const
 
 string DocFileName::mangledFileName(string const & dir) const
 {
-   // FIXME THREAD
// Concurrent access to these variables is possible.
 
// We need to make sure that every DocFileName instance for a given
// filename returns the same mangled name.
typedef map MangledMap;
static MangledMap mangledNames;
+   static Mutex mangledMutex;
+   // this locks both access to mangledNames and counter below 
+   Mutex::Locker lock();
MangledMap::const_iterator const it = mangledNames.find(absFileName());
if (it != mangledNames.end())
return (*it).second;
@@ -942,7 +945,6 @@ string DocFileName::mangledFileName(string const & dir) 
const
// Add the extension back on
mname = support::changeExtension(mname, getExtension(name));
 
-   // FIXME THREAD
// Prepend a counter to the filename. This is necessary to make
// the mangled name unique.
static int counter = 0;


[LyX/master] Make createBufferTmpDir() threadsafe

2014-07-05 Thread Georg Baum
commit 4bfca60359825cf51b09f0a6b35a91e2858df374
Author: Georg Baum 
Date:   Sat Jul 5 12:31:12 2014 +0200

Make createBufferTmpDir() threadsafe

This must not use thread local storage, since the generated directories are
all in the same parent directory which is unique per running LyX instance.

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 4331309..0a362c3 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -97,6 +97,7 @@
 #include "support/gzstream.h"
 #include "support/lstrings.h"
 #include "support/lyxalgo.h"
+#include "support/mutex.h"
 #include "support/os.h"
 #include "support/Package.h"
 #include "support/PathChanger.h"
@@ -353,13 +354,20 @@ private:
 /// Creates the per buffer temporary directory
 static FileName createBufferTmpDir()
 {
-   // FIXME THREAD
-   static int count;
+   // FIXME This would be the ideal application for a TempDir class (like
+   //   TempFile but for directories) 
+   string counter;
+   {
+   static int count;
+   static Mutex mutex;
+   Mutex::Locker locker();
+   counter = convert(count++);
+   }
// We are in our own directory.  Why bother to mangle name?
// In fact I wrote this code to circumvent a problematic behaviour
// (bug?) of EMX mkstemp().
FileName tmpfl(package().temp_dir().absFileName() + "/lyx_tmpbuf" +
-   convert(count++));
+   counter);
 
if (!tmpfl.createDirectory(0777)) {
throw ExceptionMessage(WarningException, _("Disk Error: "), 
bformat(


[LyX/master] Make BufferParams::auto_packages() threadsafe

2014-07-05 Thread Georg Baum
commit e7c41b5f56e48670ed6415edac1811167a1e177b
Author: Georg Baum 
Date:   Sat Jul 5 12:39:59 2014 +0200

Make BufferParams::auto_packages() threadsafe

diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 49c55aa..792f148 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -52,6 +52,7 @@
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/Messages.h"
+#include "support/mutex.h"
 #include "support/Translator.h"
 #include "support/lstrings.h"
 
@@ -446,10 +447,16 @@ void BufferParams::use_package(std::string const & p, 
BufferParams::Package u)
 
 map const & BufferParams::auto_packages()
 {
-   // FIXME THREAD
-   // It is extremely unlikely that there could be a problem here, but...
static map packages;
if (packages.empty()) {
+   // We could have a race condition here that two threads
+   // discover an empty map at the same time and want to fill
+   // it, but that is no problem, since the same contents is
+   // filled in twice then. Having the locker inside the
+   // packages.empty() condition has the advantage that we
+   // don't need the mutex overhead for simple reading.
+   static Mutex mutex;
+   Mutex::Locker locker();
// adding a package here implies a file format change!
packages["amsmath"] =
N_("The LaTeX package amsmath is only used if AMS 
formula types or symbols from the AMS math toolbars are inserted into 
formulas");


[LyX/master] Make BufferList::fileNames() threadsafe

2014-07-05 Thread Georg Baum
commit 922d48da27b4371a089fabc5bc1b6c660ad0f598
Author: Georg Baum 
Date:   Sat Jul 5 12:51:40 2014 +0200

Make BufferList::fileNames() threadsafe

Using a static variable here was premature optimization: fileNames() is only
called from GuiRef (directly or indirectly), and since this is a dialog the
copying of a FileNameList is not noticeable at all.

diff --git a/src/BufferList.cpp b/src/BufferList.cpp
index de5a7ab..c253282 100644
--- a/src/BufferList.cpp
+++ b/src/BufferList.cpp
@@ -154,11 +154,9 @@ void BufferList::closeAll()
 }
 
 
-FileNameList const & BufferList::fileNames() const
+FileNameList BufferList::fileNames() const
 {
-   // FIXME THREAD
-   static FileNameList nvec;
-   nvec.clear();
+   FileNameList nvec;
BufferStorage::const_iterator it = bstore.begin();
BufferStorage::const_iterator end = bstore.end();
for (; it != end; ++it) {
@@ -348,7 +346,7 @@ void BufferList::recordCurrentAuthor(Author const & author)
 
 int BufferList::bufferNum(FileName const & fname) const
 {
-   FileNameList const & buffers = fileNames();
+   FileNameList const buffers(fileNames());
FileNameList::const_iterator cit =
find(buffers.begin(), buffers.end(), fname);
if (cit == buffers.end())
diff --git a/src/BufferList.h b/src/BufferList.h
index 95df26a..4f9cb95 100644
--- a/src/BufferList.h
+++ b/src/BufferList.h
@@ -66,7 +66,7 @@ public:
void closeAll();
 
/// returns a vector with all the buffers filenames
-   support::FileNameList const & fileNames() const;
+   support::FileNameList fileNames() const;
 
/// return true if no buffers loaded
bool empty() const;
diff --git a/src/frontends/qt4/GuiRef.cpp b/src/frontends/qt4/GuiRef.cpp
index 141c67b..c0e6842 100644
--- a/src/frontends/qt4/GuiRef.cpp
+++ b/src/frontends/qt4/GuiRef.cpp
@@ -251,7 +251,7 @@ void GuiRef::updateContents()
 
// insert buffer list
bufferCO->clear();
-   FileNameList const & buffers = theBufferList().fileNames();
+   FileNameList const buffers(theBufferList().fileNames());
for (FileNameList::const_iterator it = buffers.begin();
 it != buffers.end(); ++it) {
bufferCO->addItem(toqstr(makeDisplayPath(it->absFileName(;
@@ -455,7 +455,8 @@ void GuiRef::updateRefs()
refs_.clear();
int const the_buffer = bufferCO->currentIndex();
if (the_buffer != -1) {
-   FileName const & name = theBufferList().fileNames()[the_buffer];
+   FileNameList const names(theBufferList().fileNames());
+   FileName const & name = names[the_buffer];
Buffer const * buf = theBufferList().getBuffer(name);
buf->getLabelList(refs_);
}


[LyX/master] Make newUnnamedFile() threadsafe

2014-07-05 Thread Georg Baum
commit 5c431b9335e7e698f866f516665a2c604e7be396
Author: Georg Baum 
Date:   Sat Jul 5 12:58:22 2014 +0200

Make newUnnamedFile() threadsafe

diff --git a/src/buffer_funcs.cpp b/src/buffer_funcs.cpp
index 3f64b90..03ecc90 100644
--- a/src/buffer_funcs.cpp
+++ b/src/buffer_funcs.cpp
@@ -47,6 +47,7 @@
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
+#include "support/mutex.h"
 #include "support/textutils.h"
 
 using namespace std;
@@ -172,9 +173,10 @@ Buffer * newFile(string const & filename, string const & 
templatename,
 Buffer * newUnnamedFile(FileName const & path, string const & prefix,
string const & templatename)
 {
-   // FIXME THREAD
static map file_number;
+   static Mutex mutex;
 
+   Mutex::Locker locker();
FileName filename;
 
do {


[LyX/master] Support for Swiss German (old spelling)

2014-07-05 Thread Juergen Spitzmueller
commit 0c3b88e3cb817cd030163c534db91ec94f886953
Author: Juergen Spitzmueller 
Date:   Sat Jul 5 13:38:55 2014 +0200

Support for Swiss German (old spelling)

diff --git a/lib/languages b/lib/languages
index 92387a9..e4c0dd5 100644
--- a/lib/languages
+++ b/lib/languages
@@ -491,17 +491,18 @@ Language german-ch
LangCode de_CH
 End
 
-# This is now supported, but requires a file format change
-# Language german-ch-old
-#  GuiName  "German (Switzerland, old spelling)"
-#  BabelNameswissgerman
-#  PolyglossiaName  german
-#  PolyglossiaOpts  "spelling=old,babelshorthands=true"
-## PolyglossiaOpts  "variant=swiss,spelling=old,babelshorthands=true"
-#  QuoteStyle   danish
-#  Encoding iso8859-15
-#  LangCode de_CH
-# End
+# In Babel, this is supported since release 2.7 of babel-german (Dec 2013)
+# Polyglossia does not yet support Swiss German. We use german for now.
+Language german-ch-old
+   GuiName  "German (Switzerland, old spelling)"
+   BabelNameswissgerman
+   PolyglossiaName  german
+   PolyglossiaOpts  "spelling=old,babelshorthands=true"
+#  PolyglossiaOpts  "variant=swiss,spelling=old,babelshorthands=true"
+   QuoteStyle   danish
+   Encoding iso8859-15
+   LangCode de_CH
+End
 
 Language greek
GuiName   "Greek"
diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py
index eb0b079..6364524 100644
--- a/lib/lyx2lyx/LyX.py
+++ b/lib/lyx2lyx/LyX.py
@@ -85,7 +85,7 @@ format_relation = [("0_06",[200], minor_versions("0.6" , 
4)),
("1_6", range(277,346), minor_versions("1.6" , 10)),
("2_0", range(346,414), minor_versions("2.0", 8)),
("2_1", range(414,475), minor_versions("2.1", 0)),
-   ("2_2", range(475,477), minor_versions("2.2", 0))
+   ("2_2", range(475,478), minor_versions("2.2", 0))
   ]
 
 
diff --git a/lib/lyx2lyx/lyx_2_2.py b/lib/lyx2lyx/lyx_2_2.py
index c263c83..f15b0c6 100644
--- a/lib/lyx2lyx/lyx_2_2.py
+++ b/lib/lyx2lyx/lyx_2_2.py
@@ -275,6 +275,23 @@ def revert_smash(document):
 j = k
 
 
+def revert_swissgerman(document):
+" Set language german-ch-old to german "
+i = 0
+if document.language == "german-ch-old":
+document.language = "german"
+i = find_token(document.header, "\\language", 0)
+if i != -1:
+document.header[i] = "\\language german"
+j = 0
+while True:
+j = find_token(document.body, "\\lang german-ch-old", j)
+if j == -1:
+return
+document.body[j] = document.body[j].replace("\\lang german-ch-old", 
"\\lang german")
+j = j + 1
+
+
 ##
 # Conversion hub
 #
@@ -286,9 +303,11 @@ convert = [
# did not load amsmath automatically for these commands, and do not
# want to hardcode amsmath off.
[476, []],
+   [477, []],
   ]
 
 revert =  [
+   [476, [revert_swissgerman]],
[475, [revert_smash]],
[474, [revert_separator]]
   ]
diff --git a/src/version.h b/src/version.h
index 22713f6..f7eb1e1 100644
--- a/src/version.h
+++ b/src/version.h
@@ -30,8 +30,8 @@ extern char const * const lyx_version_info;
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 476 // gb: \smash[t], \smash[b] and \notag
-#define LYX_FORMAT_TEX2LYX 476
+#define LYX_FORMAT_LYX 477 // spitz: support for swissgerman
+#define LYX_FORMAT_TEX2LYX 477
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER


[LyX/master] Make LaTeX export threadsafe.

2014-07-05 Thread Georg Baum
commit 5a8b8ba8e11360a716465b9c6c7c0dc48f37f552
Author: Georg Baum 
Date:   Sat Jul 5 14:23:43 2014 +0200

Make LaTeX export threadsafe.

This is one of the more important threadsafety issues because of export in
thread and simultanous view source. The solution is ugly, but a better one
(see FIXME) would require major rework. These static variables should not
have been used in the first place IMHO.

diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index 735b898..ed46c05 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -35,6 +35,8 @@
 #include "support/lstrings.h"
 #include "support/textutils.h"
 
+#include 
+
 #include 
 #include 
 #include 
@@ -53,13 +55,28 @@ enum OpenEncoding {
CJK
 };
 
-// FIXME THREAD
-// There could easily be a conflict here, with the export process
-// setting this one way, and a View>Source process (possbily for
-// another Buffer) resetting it.
-static int open_encoding_ = none;
-static int cjk_inherited_ = 0;
-Language const * prev_env_language_ = 0;
+
+struct OutputState
+{
+   OutputState() : open_encoding_(none), cjk_inherited_(0),
+   prev_env_language_(0)
+   {
+   }
+   int open_encoding_;
+   int cjk_inherited_;
+   Language const * prev_env_language_;
+};
+
+
+OutputState * getOutputState()
+{
+   // FIXME An instance of OutputState should be kept around for each 
export
+   //   instead of using local thread storage
+   static QThreadStorage outputstate;
+   if (!outputstate.hasLocalData())
+   outputstate.setLocalData(new OutputState);
+   return outputstate.localData();
+}
 
 
 string const getPolyglossiaEnvName(Language const * lang)
@@ -101,7 +118,8 @@ static TeXEnvironmentData prepareEnvironment(Buffer const & 
buf,
ParagraphList::const_iterator const priorpit =
pit == paragraphs.begin() ? pit : boost::prior(pit);
 
-   bool const use_prev_env_language = prev_env_language_ != 0
+   OutputState * state = getOutputState();
+   bool const use_prev_env_language = state->prev_env_language_ != 0
&& priorpit->layout().isEnvironment()
&& (priorpit->getDepth() > pit->getDepth()
|| (priorpit->getDepth() == pit->getDepth()
@@ -112,7 +130,7 @@ static TeXEnvironmentData prepareEnvironment(Buffer const & 
buf,
Language const * const doc_language = bparams.language;
Language const * const prev_par_language =
(pit != paragraphs.begin())
-   ? (use_prev_env_language ? prev_env_language_
+   ? (use_prev_env_language ? state->prev_env_language_
 : priorpit->getParLanguage(bparams))
: doc_language;
 
@@ -191,11 +209,11 @@ static TeXEnvironmentData prepareEnvironment(Buffer const 
& buf,
// in multilingual environments, the CJK tags have to be nested properly
data.cjk_nested = false;
if (data.par_language->encoding()->package() == Encoding::CJK &&
-   open_encoding_ != CJK && pit->isMultiLingual(bparams)) {
+   state->open_encoding_ != CJK && pit->isMultiLingual(bparams)) {
if (prev_par_language->encoding()->package() == Encoding::CJK)
os << "\\begin{CJK}{" << 
from_ascii(data.par_language->encoding()->latexName())
   << "}{" << from_ascii(bparams.fonts_cjk) << "}%\n";
-   open_encoding_ = CJK;
+   state->open_encoding_ = CJK;
data.cjk_nested = true;
}
return data;
@@ -205,17 +223,18 @@ static TeXEnvironmentData prepareEnvironment(Buffer const 
& buf,
 static void finishEnvironment(otexstream & os, OutputParams const & runparams,
  TeXEnvironmentData const & data)
 {
-   if (open_encoding_ == CJK && data.cjk_nested) {
+   OutputState * state = getOutputState();
+   if (state->open_encoding_ == CJK && data.cjk_nested) {
// We need to close the encoding even if it does not change
// to do correct environment nesting
os << "\\end{CJK}\n";
-   open_encoding_ = none;
+   state->open_encoding_ = none;
}
 
if (data.style->isEnvironment()) {
os << breakln
   << "\\end{" << from_ascii(data.style->latexname()) << "}\n";
-   prev_env_language_ = data.par_language;
+   state->prev_env_language_ = data.par_language;
if (runparams.encoding != data.prev_encoding) {
runparams.encoding = data.prev_encoding;
if (!runparams.isFullUnicode())
@@ -225,7 +244,7 @@ static void finishEnvironment(otexstream & os, OutputParams 
const & runparams,
 
if (data.leftindent_open) {
os << breakln << 

[LyX/master] Fix LaTeXFeatures::useLayout() recursion test

2014-07-05 Thread Georg Baum
commit 5093893b59938ab3cb59612a90580d4b7956cfec
Author: Georg Baum 
Date:   Sat Jul 5 14:37:55 2014 +0200

Fix LaTeXFeatures::useLayout() recursion test

It was broken in two ways: It was not threadsafe, and it did never detect
any recursion, since the counter was decremented for each non-recursive call
and never incremented again.

diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index cb35fdf..506af18 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -427,9 +427,13 @@ void LaTeXFeatures::require(set const & names)
 
 void LaTeXFeatures::useLayout(docstring const & layoutname)
 {
+   useLayout(layoutname, 0);
+}
+
+
+void LaTeXFeatures::useLayout(docstring const & layoutname, int level)
+{
// Some code to avoid loops in dependency definition
-   // FIXME THREAD
-   static int level = 0;
const int maxlevel = 30;
if (level > maxlevel) {
lyxerr << "LaTeXFeatures::useLayout: maximum level of "
@@ -449,9 +453,7 @@ void LaTeXFeatures::useLayout(docstring const & layoutname)
require(layout.requires());
 
if (!layout.depends_on().empty()) {
-   ++level;
-   useLayout(layout.depends_on());
-   --level;
+   useLayout(layout.depends_on(), level + 1);
}
usedLayouts_.push_back(layoutname);
} else {
@@ -459,8 +461,6 @@ void LaTeXFeatures::useLayout(docstring const & layoutname)
   << to_utf8(layoutname) << "' does not exist in this 
class"
   << endl;
}
-
-   --level;
 }
 
 
diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h
index 71004be..be00847 100644
--- a/src/LaTeXFeatures.h
+++ b/src/LaTeXFeatures.h
@@ -158,6 +158,8 @@ public:
 
 private:
///
+   void useLayout(docstring const &, int);
+   ///
std::list usedLayouts_;
///
std::list usedInsetLayouts_;


[LyX/master] Fix uncodable author warning

2014-07-05 Thread Georg Baum
commit 2a677592a5fbbc369dc4199b1c4b3a0c84fb068a
Author: Georg Baum 
Date:   Sat Jul 5 14:49:51 2014 +0200

Fix uncodable author warning

The old code was not threadsafe, and the restriction to one message box per
author name did not work if more than two authors were uncodable.

diff --git a/src/Changes.cpp b/src/Changes.cpp
index 39f2a8e..29471f2 100644
--- a/src/Changes.cpp
+++ b/src/Changes.cpp
@@ -27,6 +27,7 @@
 #include "support/gettext.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
+#include "support/mutex.h"
 
 #include "frontends/alert.h"
 
@@ -348,9 +349,7 @@ docstring getLaTeXMarkup(docstring const & macro, docstring 
const & author,
if (macro.empty())
return docstring();
 
-   // FIXME THREAD
-   static docstring warned_author = docstring();
-   docstring uncodable_author = warned_author;
+   docstring uncodable_author;
odocstringstream ods;
 
ods << macro;
@@ -367,8 +366,12 @@ docstring getLaTeXMarkup(docstring const & macro, 
docstring const & author,
ods << author_latexed.first << "}{" << chgTime << "}{";
 
// warn user (once) if we found uncodable glyphs.
-   if (uncodable_author != warned_author) {
-   frontend::Alert::warning(_("Uncodable character in author 
name"),
+   if (!uncodable_author.empty()) {
+   static std::set warned_authors;
+   static Mutex warned_mutex;
+   Mutex::Locker locker(_mutex);
+   if (warned_authors.find(uncodable_author) == 
warned_authors.end()) {
+   frontend::Alert::warning(_("Uncodable character in 
author name"),
support::bformat(_("The author name '%1$s',\n"
  "used for change tracking, contains the 
following glyphs that\n"
  "cannot be represented in the current 
encoding: %2$s.\n"
@@ -376,7 +379,8 @@ docstring getLaTeXMarkup(docstring const & macro, docstring 
const & author,
  "Choose an appropriate document encoding 
(such as utf8)\n"
  "or change the spelling of the author name."),
uncodable_author, author_latexed.second));
-   warned_author = uncodable_author;
+   warned_authors.insert(uncodable_author);
+   }
}
 
return ods.str();


[LyX/master] Make GraphicsConverter threadsafe

2014-07-05 Thread Georg Baum
commit 5a01424bf0dbb939cbff1c72ecd99359803a4675
Author: Georg Baum 
Date:   Sat Jul 5 15:11:24 2014 +0200

Make GraphicsConverter threadsafe

build_script() was already threadsafe, since it used a TempFile, and the
counter was basically not needed, but the new solution makes this obvious
and has the additional advantage that TempFile constructs the real output
file, not a dummy without extension which is not needed.

diff --git a/src/graphics/GraphicsConverter.cpp 
b/src/graphics/GraphicsConverter.cpp
index e833a35..83d895e 100644
--- a/src/graphics/GraphicsConverter.cpp
+++ b/src/graphics/GraphicsConverter.cpp
@@ -143,10 +143,9 @@ Converter::Impl::Impl(FileName const & from_file, string 
const & to_file_base,
<< "\n--\n");
 
// Output the script to file.
-   // FIXME THREAD
-   static int counter = 0;
-   script_file_ = FileName(onlyPath(to_file_base) + "lyxconvert" +
-   convert(counter++) + ".py");
+   TempFile tempfile(to_file_.onlyPath(), "lyxconvertXX.py");
+   tempfile.setAutoRemove(false);
+   script_file_ = tempfile.name();
 
ofstream fs(script_file_.toFilesystemEncoding().c_str());
if (!fs.good()) {
@@ -289,19 +288,16 @@ static void build_script(string const & from_file,
theConverters().getPath(from_format, to_format);
 
// Create a temporary base file-name for all intermediate steps.
-   // Remember to remove the temp file because we only want the name...
-   // FIXME THREAD
-   static int counter = 0;
-   string const tmp = "gconvert" + convert(counter++);
-   TempFile tempfile(tmp);
+   string const from_ext = getExtension(from_file);
+   TempFile tempfile(addExtension("gconvertXX", from_ext));
tempfile.setAutoRemove(false);
-   string const to_base = tempfile.name().toFilesystemEncoding();
+   string outfile = tempfile.name().toFilesystemEncoding();
+   string const to_base = from_ext.empty() ? outfile : 
removeExtension(outfile);
 
// Create a copy of the file in case the original name contains
// problematic characters like ' or ". We can work around that problem
// in python, but the converters might be shell scripts and have more
// troubles with it.
-   string outfile = addExtension(to_base, getExtension(from_file));
script << "infile = "
<< quoteName(from_file, quote_python)
<< "\n"
@@ -369,10 +365,9 @@ static void build_script(string const & from_file,
 
// If two formats share the same extension we may get identical 
names
if (outfile == infile && conv.result_file.empty()) {
-   TempFile tempfile(tmp);
+   TempFile tempfile(addExtension("gconvertXX", 
conv.To->extension()));
tempfile.setAutoRemove(false);
-   string const new_base = 
tempfile.name().toFilesystemEncoding();
-   outfile = addExtension(new_base, conv.To->extension());
+   outfile = tempfile.name().toFilesystemEncoding();
}
 
// Store these names in the python script


[LyX/master] Mark some singletons with FIXME THREAD

2014-07-05 Thread Georg Baum
commit b88f6ea3aa1c39849a1d295d106ba7bb491e013b
Author: Georg Baum 
Date:   Sat Jul 5 15:20:54 2014 +0200

Mark some singletons with FIXME THREAD

diff --git a/src/ConverterCache.cpp b/src/ConverterCache.cpp
index 1451f6e..820eb06 100644
--- a/src/ConverterCache.cpp
+++ b/src/ConverterCache.cpp
@@ -223,6 +223,7 @@ ConverterCache::~ConverterCache()
 }
 
 
+// FIXME THREAD
 ConverterCache & ConverterCache::get()
 {
// Now return the cache
diff --git a/src/graphics/GraphicsCache.cpp b/src/graphics/GraphicsCache.cpp
index d508563..b816926 100644
--- a/src/graphics/GraphicsCache.cpp
+++ b/src/graphics/GraphicsCache.cpp
@@ -44,6 +44,7 @@ public:
 };
 
 
+// FIXME THREAD
 Cache & Cache::get()
 {
// Now return the cache
diff --git a/src/graphics/GraphicsLoader.cpp b/src/graphics/GraphicsLoader.cpp
index 4ec5c9a..ade29f1 100644
--- a/src/graphics/GraphicsLoader.cpp
+++ b/src/graphics/GraphicsLoader.cpp
@@ -71,13 +71,13 @@ private:
 };
 
 
-//static int s_numimages_ = 5;
-//static int s_millisecs_ = 500;
 
-// FIXME THREAD
-static int s_numimages_ = 10;
-static int s_millisecs_ = 500;
+//static int const s_numimages_ = 5;
+static int const s_numimages_ = 10;
+static int const s_millisecs_ = 500;
+
 
+// FIXME THREAD
 LoaderQueue & LoaderQueue::get()
 {
static LoaderQueue singleton;


[LyX/master] Fix typo spotted by cppcheck

2014-07-05 Thread Jean-Marc
commit 8715bab65cc87272dd0d701e31b37363d43d6e95
Author: Jean-Marc 
Date:   Sat Jul 5 18:01:19 2014 +0200

Fix typo spotted by cppcheck

diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp
index 8508e4e..ea1ba59 100644
--- a/src/support/lstrings.cpp
+++ b/src/support/lstrings.cpp
@@ -1458,7 +1458,7 @@ docstring bformat(docstring const & fmt, char const * 
arg1, docstring arg2)
LATTEST(contains(fmt, from_ascii("%1$s")));
LATTEST(contains(fmt, from_ascii("%2$s")));
docstring str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
-   str = subst(fmt, from_ascii("%2$s"), arg2);
+   str = subst(str, from_ascii("%2$s"), arg2);
return subst(str, from_ascii("%%"), from_ascii("%"));
 }
 


[LyX/master] Fix possible bug spotted by cppcheck

2014-07-05 Thread Jean-Marc
commit 1cdbb94ff53ba2e73d60aecd53c7b9b44b042701
Author: Jean-Marc 
Date:   Sat Jul 5 19:12:09 2014 +0200

Fix possible bug spotted by cppcheck

I am not sure what this locking is really about, but the new code seems to 
be the right thing to do.

diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp
index f39112c..a6d92d9 100644
--- a/src/mathed/MathMacro.cpp
+++ b/src/mathed/MathMacro.cpp
@@ -332,7 +332,7 @@ void MathMacro::updateRepresentation(Cursor * cur, 
MacroContext const & mc,
if (isUpdating_)
return;
 
-   UpdateLocker(*this);
+   UpdateLocker locker(*this);
 
// known macro?
if (macro_ == 0)


[LyX/master] Fix a bunch of small performance issues spotted by cppcheck

2014-07-05 Thread Jean-Marc
commit 93a43742a5f1db8a632233c15e2b8d61b4835f3a
Author: Jean-Marc 
Date:   Sat Jul 5 19:13:10 2014 +0200

Fix a bunch of small performance issues spotted by cppcheck

Most of these are about passing const strings parameters as references.

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 0a362c3..6c8194c 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -653,7 +653,7 @@ BufferParams const & Buffer::masterParams() const
// Copy child authors to the params. We need those pointers.
AuthorList const & child_authors = params().authors();
AuthorList::Authors::const_iterator it = child_authors.begin();
-   for (; it != child_authors.end(); it++)
+   for (; it != child_authors.end(); ++it)
mparams.authors().record(*it);
return mparams;
 }
@@ -3507,7 +3507,7 @@ void Buffer::changeRefsIfUnique(docstring const & from, 
docstring const & to)
 }
 
 
-void Buffer::getSourceCode(odocstream & os, string const format,
+void Buffer::getSourceCode(odocstream & os, string const & format,
   pit_type par_begin, pit_type par_end,
   OutputWhat output, bool master) const
 {
diff --git a/src/Buffer.h b/src/Buffer.h
index fe0294b..29992f9 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -594,7 +594,7 @@ public:
 
/// get source code (latex/docbook) for some paragraphs, or all 
paragraphs
/// including preamble
-   void getSourceCode(odocstream & os, std::string const format,
+   void getSourceCode(odocstream & os, std::string const & format,
   pit_type par_begin, pit_type par_end, OutputWhat 
output,
   bool master) const;
 
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 792f148..8ae249e 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -2280,7 +2280,7 @@ vector BufferParams::backends() const
 }
 
 
-OutputParams::FLAVOR BufferParams::getOutputFlavor(string const format) const
+OutputParams::FLAVOR BufferParams::getOutputFlavor(string const & format) const
 {
string const dformat = (format.empty() || format == "default") ?
getDefaultOutputFormat() : format;
@@ -2362,7 +2362,7 @@ Font const BufferParams::getFont() const
 }
 
 
-InsetQuotes::QuoteLanguage BufferParams::getQuoteStyle(string const qs) const
+InsetQuotes::QuoteLanguage BufferParams::getQuoteStyle(string const & qs) const
 {
return quoteslangtranslator().find(qs);
 }
diff --git a/src/BufferParams.h b/src/BufferParams.h
index 3706399..2d7c749 100644
--- a/src/BufferParams.h
+++ b/src/BufferParams.h
@@ -180,7 +180,7 @@ public:
std::string getDefaultOutputFormat() const;
/// return the output flavor of \p format or the default
OutputParams::FLAVOR getOutputFlavor(
- std::string const format = std::string()) const;
+ std::string const & format = std::string()) const;
///
bool isExportable(std::string const & format) const;
///
@@ -207,7 +207,7 @@ public:
Font const getFont() const;
 
/// translate quote style string to enum value
-   InsetQuotes::QuoteLanguage getQuoteStyle(std::string const qs) const;
+   InsetQuotes::QuoteLanguage getQuoteStyle(std::string const & qs) const;
 
/* these are for the PaperLayout */
/// the papersize
diff --git a/src/Encoding.cpp b/src/Encoding.cpp
index a6f6a60..dcf65d7 100644
--- a/src/Encoding.cpp
+++ b/src/Encoding.cpp
@@ -257,9 +257,9 @@ const char * EncodingException::what() const throw()
 
 
 CharInfo::CharInfo(
-   docstring const textcommand, docstring const mathcommand,
-   std::string const textpreamble, std::string const mathpreamble,
-   std::string const tipashortcut, unsigned int flags)
+   docstring const & textcommand, docstring const & mathcommand,
+   std::string const & textpreamble, std::string const & mathpreamble,
+   std::string const & tipashortcut, unsigned int flags)
: textcommand_(textcommand), mathcommand_(mathcommand),
  textpreamble_(textpreamble), mathpreamble_(mathpreamble),
  tipashortcut_(tipashortcut), flags_(flags)
@@ -380,7 +380,7 @@ pair Encoding::latexChar(char_type c) const
 }
 
 
-pair Encoding::latexString(docstring const input, bool 
dryrun) const
+pair Encoding::latexString(docstring const & input, bool 
dryrun) const
 {
docstring result;
docstring uncodable;
diff --git a/src/Encoding.h b/src/Encoding.h
index ed9c27e..7351197 100644
--- a/src/Encoding.h
+++ b/src/Encoding.h
@@ -59,9 +59,9 @@ class CharInfo {
 public:
CharInfo() : flags_(0) {}
CharInfo(
-   docstring const textcommand, docstring const mathcommand,
-   std::string const textpreamble, std::string const mathpreamble,
-   std::string const tipashortcut, unsigned int flags);
+