]> git.lyx.org Git - features.git/commitdiff
Fix missing updates for lazy MacroData
authorGeorg Baum <baum@lyx.org>
Fri, 11 Oct 2013 18:38:05 +0000 (20:38 +0200)
committerGeorg Baum <baum@lyx.org>
Fri, 11 Oct 2013 18:38:05 +0000 (20:38 +0200)
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
src/mathed/MacroTable.h

index fbcd7e69e578549d1130d99cf67e133c76f3ab4d..6daa2a8aed2eec42410b4cffc510a010d923ed90 100644 (file)
@@ -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<docstring> const &  MacroData::defaults() const
+vector<docstring> 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<MathMacroTemplate const &>(*inset));      
+       queryData(static_cast<MathMacroTemplate const &>(*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<MathMacroTemplate const &>(*inset);
index 3a1fed4fa682bb89d833f54d4d4dc1cb6b51e215..6f8201f29e70c001b1ad7e93912622f47dee6f20 100644 (file)
@@ -33,7 +33,7 @@ enum MacroType {
        MacroTypeNewcommandx,
        MacroTypeDef
 };
-       
+
 ///
 class MacroData {
 public:
@@ -58,27 +58,23 @@ public:
        ///
        std::vector<docstring> 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<docstring> {};
 ///
 class MacroSet : public std::set<MacroData const *> {};
 
-       
+
 /// 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_;