From 561c5bfd50664bd5eb172a1de58a930ef2eb746a Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Fri, 11 Oct 2013 20:38:05 +0200 Subject: [PATCH] Fix missing updates for lazy MacroData Not all accessors did update the data previously. Therefore it could happen that document export from the command line would output \newcommand, and from GUI it would output \renewcommand for the same macro, simply because in the GUI case the data was updated as a side effect of the GUI thread reading some other member. I also removed the mutable flag for requires_, since this member is always set on construction and does not need any lazy update. --- src/mathed/MacroTable.cpp | 23 +++++++++++------------ src/mathed/MacroTable.h | 34 +++++++++++++++------------------- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/mathed/MacroTable.cpp b/src/mathed/MacroTable.cpp index fbcd7e69e5..6daa2a8aed 100644 --- a/src/mathed/MacroTable.cpp +++ b/src/mathed/MacroTable.cpp @@ -45,16 +45,15 @@ MacroData::MacroData(Buffer * buf) redefinition_(false), type_(MacroTypeNewcommand) {} - - + MacroData::MacroData(Buffer * buf, DocIterator const & pos) : buffer_(buf), pos_(pos), queried_(false), numargs_(0), optionals_(0), lockCount_(0), redefinition_(false), type_(MacroTypeNewcommand) { } - - + + MacroData::MacroData(Buffer * buf, MathMacroTemplate const & macro) : buffer_(buf), queried_(false), numargs_(0), optionals_(0), lockCount_(0), redefinition_(false), type_(MacroTypeNewcommand) @@ -100,7 +99,7 @@ size_t MacroData::optionals() const } -vector const & MacroData::defaults() const +vector const & MacroData::defaults() const { updateData(); return defaults_; @@ -126,7 +125,7 @@ void MacroData::queryData(MathMacroTemplate const & macro) const redefinition_ = macro.redefinition(); type_ = macro.type(); optionals_ = macro.numOptionals(); - + macro.getDefaults(defaults_); } @@ -137,21 +136,21 @@ void MacroData::updateData() const return; LBUFERR(buffer_); - + // Try to fix position DocIterator. Should not do anything in theory. pos_.fixIfBroken(); - + // find macro template Inset * inset = pos_.nextInset(); if (inset == 0 || inset->lyxCode() != MATHMACRO_CODE) { lyxerr << "BUG: No macro template found by MacroData" << endl; return; } - + // query the data from the macro template - queryData(static_cast(*inset)); + queryData(static_cast(*inset)); } - + int MacroData::write(odocstream & os, bool overwriteRedefinition) const { @@ -163,7 +162,7 @@ int MacroData::write(odocstream & os, bool overwriteRedefinition) const lyxerr << "BUG: No macro template found by MacroData" << endl; return 0; } - + // output template MathMacroTemplate const & tmpl = static_cast(*inset); diff --git a/src/mathed/MacroTable.h b/src/mathed/MacroTable.h index 3a1fed4fa6..6f8201f29e 100644 --- a/src/mathed/MacroTable.h +++ b/src/mathed/MacroTable.h @@ -33,7 +33,7 @@ enum MacroType { MacroTypeNewcommandx, MacroTypeDef }; - + /// class MacroData { public: @@ -58,27 +58,23 @@ public: /// std::vector const & defaults() const; /// - std::string const & requires() const { updateData(); return requires_; } + std::string const & requires() const { return requires_; } /// - std::string & requires() { updateData(); return requires_; } - + std::string & requires() { return requires_; } + /// lock while being drawn to avoid recursions int lock() const { return ++lockCount_; } /// is it being drawn? bool locked() const { return lockCount_ != 0; } /// void unlock() const; - - /// - bool redefinition() const { return redefinition_; } - /// - void setRedefinition(bool redefined) { redefinition_ = redefined; } /// - MacroType type() const { return type_; } + bool redefinition() const { updateData(); return redefinition_; } + /// - MacroType & type() { return type_; } - + MacroType type() const { updateData(); return type_; } + /// output as TeX macro, only works for lazy MacroData!!! int write(odocstream & os, bool overwriteRedefinition) const; @@ -86,7 +82,7 @@ public: bool operator==(MacroData const & x) const { updateData(); x.updateData(); - return definition_ == x.definition_ + return definition_ == x.definition_ && numargs_ == x.numargs_ && display_ == x.display_ && requires_ == x.requires_ @@ -105,10 +101,10 @@ private: Buffer const * buffer_; /// The position of the definition in the buffer. /// There is no guarantee it stays valid if the buffer - /// changes. But it (normally) exists only until the + /// changes. But it (normally) exists only until the /// next Buffer::updateMacros call where new MacroData /// objects are created for each macro definition. - /// In the worst case, it is invalidated and the MacroData + /// In the worst case, it is invalidated and the MacroData /// returns its defaults values and the user sees unfolded /// macros. mutable DocIterator pos_; @@ -121,7 +117,7 @@ private: /// mutable docstring display_; /// - mutable std::string requires_; + std::string requires_; /// mutable size_t optionals_; /// @@ -140,7 +136,7 @@ class MacroNameSet : public std::set {}; /// class MacroSet : public std::set {}; - + /// A lookup table of macro definitions. /** * This contains a table of "global" macros that are always accessible, @@ -179,10 +175,10 @@ class MacroContext { public: /// construct context for the insets at pos MacroContext(Buffer const * buf, DocIterator const & pos); - + /// Lookup macro MacroData const * get(docstring const & name) const; - + private: /// Buffer const * buf_; -- 2.39.2