[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Limit looping in Grob::common_refpoint (issue 4079) (issue 134600043 by
From: |
eble |
Subject: |
Limit looping in Grob::common_refpoint (issue 4079) (issue 134600043 by address@hidden) |
Date: |
Sun, 07 Sep 2014 00:49:10 +0000 |
Reviewers: ,
Description:
Limit looping in Grob::common_refpoint (issue 4079)
This does not address the root cause, but it fails in a better way.
For those curious about the root cause, it does not appear to be any
cycle in parentage within the range of the loop counter. That's all I
know.
Please review this at https://codereview.appspot.com/134600043/
Affected files (+59, -1 lines):
A flower/include/strict-counter.hh
M lily/grob.cc
Index: flower/include/strict-counter.hh
diff --git a/flower/include/strict-counter.hh
b/flower/include/strict-counter.hh
new file mode 100644
index
0000000000000000000000000000000000000000..39d27863078f69ce323801c80510bd05fbad7b64
--- /dev/null
+++ b/flower/include/strict-counter.hh
@@ -0,0 +1,57 @@
+/*
+ This file is part of LilyPond, the GNU music typesetter.
+
+ Copyright (C) 1996--2014 Han-Wen Nienhuys <address@hidden>
+
+ LilyPond is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ LilyPond is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef STRICT_COUNTER_HH
+#define STRICT_COUNTER_HH
+
+#include <limits>
+#include <cstdlib>
+
+/**
+ Counter that calls abort() rather than wrapping around.
+*/
+template<class T>
+class Strict_counter
+{
+ int value_;
+
+ Strict_counter(const Strict_counter &); // not needed yet
+ Strict_counter &operator = (const Strict_counter &); // not needed yet
+
+public:
+ Strict_counter() : value_(0) {}
+ operator T () const { return value_; }
+ Strict_counter &operator ++ ()
+ {
+ if (value_ == std::numeric_limits<T>::max())
+ abort();
+ ++ value_;
+ return *this;
+ }
+
+ Strict_counter &operator -- ()
+ {
+ if (value_ == std::numeric_limits<T>::min())
+ abort();
+ -- value_;
+ return *this;
+ }
+};
+
+#endif // STRICT_COUNTER_HH
Index: lily/grob.cc
diff --git a/lily/grob.cc b/lily/grob.cc
index
eeb219e244f0c0835ab20c517e137b0f85ded724..5d296330dc84418699f94055f58452cd0dc79bc3
100644
--- a/lily/grob.cc
+++ b/lily/grob.cc
@@ -35,6 +35,7 @@
#include "program-option.hh"
#include "stencil.hh"
#include "stream-event.hh"
+#include "strict-counter.hh"
#include "system.hh"
#include "unpure-pure-container.hh"
#include "warn.hh"
@@ -548,7 +549,7 @@ Grob::common_refpoint (Grob const *s, Axis a) const
differ, but keeping track of the ends makes the loop more costly.
*/
- int balance = 0;
+ Strict_counter<int> balance;
Grob const *c;
Grob const *d;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Limit looping in Grob::common_refpoint (issue 4079) (issue 134600043 by address@hidden),
eble <=