From d9e234b6da75e83aa52e1f2e35386068348096d8 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Mon, 7 Jul 2014 22:16:13 +0200 Subject: [PATCH] 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. --- src/LaTeXFeatures.cpp | 13 +++++++------ src/LaTeXFeatures.h | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index c68729f5aa..65f342cdef 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -426,9 +426,14 @@ 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 - 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; } diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h index 71004be4ca..be00847f7e 100644 --- a/src/LaTeXFeatures.h +++ b/src/LaTeXFeatures.h @@ -157,6 +157,8 @@ public: docstring const & htmlTitle() const { return htmltitle_; } private: + /// + void useLayout(docstring const &, int); /// std::list usedLayouts_; /// -- 2.39.5