Andre Poenitz schrieb:
On Sat, Feb 23, 2008 at 12:06:18AM +0100, Bernhard Roider wrote:
hello,

yesterday i played around with layout files and created the following counter definition (ok, i didn't read the docs carefully enough)

Counter
        Name                 MajorVersion
        LabelString          "\theMajorVersion.0"
End

Using this counter causes lyx to crash because of the recursion in the label string. The attached patch catches the recursion and prints a warning message to the console.

ok to commit?

bernhard

Index: src/Counters.cpp
===================================================================
--- src/Counters.cpp    (revision 23138)
+++ src/Counters.cpp    (working copy)
@@ -338,24 +338,51 @@
 }
-docstring Counters::theCounter(docstring const & counter)
+docstring Counters::theCounter(docstring const & counter,
+                                                          std::set<docstring> 
* callers)
 {
        if (!hasCounter(counter))
                return from_ascii("??");
- Counter const & c = counterList[counter];
-       docstring ls = appendix() ? c.labelStringAppendix() : c.labelString();
+       bool owner = false;
+       if (!callers) {
+               callers = new std::set<docstring>;
+               owner = true;
+       }

Hm... what about

docstring Counters::theCounter(docstring const & counter)
{
         std::set<docstrin> callers;
         return theCounter(counter, callers);
}

docstring Counters::theCounter(docstring const & counter,
        std::set<docstring> & callers)
{
        [...]
}

etc instead of the owner/new/delete logic?

Andre'


you are right, allocation on the stack is really better here...

bernhard


Index: src/paragraph.C
===================================================================
--- src/paragraph.C     (revision 17140)
+++ src/paragraph.C     (working copy)
@@ -601,8 +601,17 @@
 }
 
 
-char Paragraph::getAlign() const
+void Paragraph::setAlign(LyXAlignment align)
 {
+       if (align == LYX_ALIGN_LAYOUT || align == layout()->align)
+               params().align(LYX_ALIGN_LAYOUT);
+       else if (align & layout()->alignpossible)
+               params().align(align);
+}
+
+
+LyXAlignment Paragraph::getAlign() const
+{
        if (params().align() == LYX_ALIGN_LAYOUT)
                return layout()->align;
        else
Index: src/paragraph.h
===================================================================
--- src/paragraph.h     (revision 17140)
+++ src/paragraph.h     (working copy)
@@ -21,6 +21,7 @@
 #include "InsetList.h"
 #include "lyxlayout_ptr_fwd.h"
 #include "RowList_fwd.h"
+#include "layout.h"
 
 #include "insets/insetbase.h" // only for InsetBase::Code
 
@@ -237,7 +238,10 @@
        docstring expandLabel(LyXLayout_ptr const &, BufferParams const &,
                bool process_appendix = true) const;
        /// Actual paragraph alignment used
-       char getAlign() const;
+       LyXAlignment getAlign() const;
+       /// Set the paragraph alignment if it is allowed by the layout
+       void setAlign(LyXAlignment align);
+
        /// The nesting depth of a paragraph
        depth_type getDepth() const;
        /// The maximal possible depth of a paragraph after this one
Index: src/text2.C
===================================================================
--- src/text2.C (revision 17140)
+++ src/text2.C (working copy)
@@ -604,18 +604,7 @@
                Paragraph & par = pars_[pit];
                ParagraphParameters & params = par.params();
                params.spacing(spacing);
-
-               // does the layout allow the new alignment?
-               LyXLayout_ptr const & layout = par.layout();
-
-               if (align == LYX_ALIGN_LAYOUT)
-                       align = layout->align;
-               if (align & layout->alignpossible) {
-                       if (align == layout->align)
-                               params.align(LYX_ALIGN_LAYOUT);
-                       else
-                               params.align(align);
-               }
+               par.setAlign(align);
                par.setLabelWidthString(labelwidthstring);
                params.noindent(noindent);
        }
Index: src/text3.C
===================================================================
--- src/text3.C (revision 17140)
+++ src/text3.C (working copy)
@@ -1229,10 +1229,11 @@
                // paragraph at the bottom so that the user can choose where to 
put
                // the graphics (or table).
                if (!content) {
+                       pars[0].setAlign(LYX_ALIGN_CENTER);
                        pars.push_back(Paragraph());
                        pars.back().setInsetOwner(pars[0].inInset());
                        pars.back().layout(tclass.defaultLayout());
-                       
+                       pars.back().setAlign(LYX_ALIGN_CENTER);
                }
 
                // reposition the cursor to the caption

Reply via email to