]> git.lyx.org Git - features.git/commitdiff
Fix LaTeXFeatures::useLayout() recursion test
authorGeorg Baum <baum@lyx.org>
Mon, 7 Jul 2014 20:16:13 +0000 (22:16 +0200)
committerGeorg Baum <baum@lyx.org>
Mon, 7 Jul 2014 20:16:13 +0000 (22:16 +0200)
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.

src/LaTeXFeatures.cpp
src/LaTeXFeatures.h

index c68729f5aaf47768595126991941f1b3b511b176..65f342cdef16d5dcedd4d28ca799d0ed28c62cbf 100644 (file)
@@ -426,9 +426,14 @@ void LaTeXFeatures::require(set<string> 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
-       static int level = 0;
        const int maxlevel = 30;
        if (level > maxlevel) {
                lyxerr << "LaTeXFeatures::useLayout: maximum level of "
@@ -448,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 {
@@ -458,8 +461,6 @@ void LaTeXFeatures::useLayout(docstring const & layoutname)
                       << to_utf8(layoutname) << "' does not exist in this class"
                       << endl;
        }
-
-       --level;
 }
 
 
index 71004be4cadc73c130b057f65e79a30ef0692209..be00847f7e80f60b2c5b6755281a588b20d7dea0 100644 (file)
@@ -157,6 +157,8 @@ public:
        docstring const & htmlTitle() const { return htmltitle_; }
 
 private:
+       ///
+       void useLayout(docstring const &, int);
        ///
        std::list<docstring> usedLayouts_;
        ///