freepooma-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with domain iterators


From: Richard Guenther
Subject: Problems with domain iterators
Date: Wed, 2 Jun 2004 12:10:52 +0200 (CEST)

All domain iterators contain

  inline const Value_t &operator*() const

which return references to possibly temporary objects.  This is nasty and
not what iterators are supposed to do.  We get miscompiled code dependend
on compiler versions and stack layout.  Ugh.  It's easy to avoid the above
(just return a copy), but what to do with

  // Member selection operator. Allows calling const Loc
  // member functions. Not too useful, but it is part of
  // the required input iterator interface.

  inline const Value_t *operator->() const

not the comment - what is "the required input iterator interface"?  Where
is it defined?  If it is the STL input iterator definition, I cannot find
any sign of required operator->() there.  Referencing the definition, an
input iterator _may_ be mutable, and looking into the Trivial Iterator
definition, it also _may_ be dereferencable, but must not be.

So I guess we should drop operator->() from the domain iterators and
return copies for operator*() const.

Other ideas?

Below is a proposed patch.  Compiled and tested Domain and Layout with
one regression, Layout/sparsetilelayout_test fails with

### POOMA Assertion Failure ###
### Bad location requested in SparseTileLayout
### File /home/rguenth/src/pooma-bk/r2/src/Layout/SparseTileLayout.cpp;
Line 547.

So I guess I opened a can of worms!?

Richard.

Index: DomainBlockIterator.h
===================================================================
RCS file: /home/pooma/Repository/r2/src/Domain/DomainBlockIterator.h,v
retrieving revision 1.10
diff -u -u -r1.10 DomainBlockIterator.h
--- DomainBlockIterator.h       10 Oct 2003 19:26:43 -0000      1.10
+++ DomainBlockIterator.h       2 Jun 2004 10:10:39 -0000
@@ -133,7 +133,7 @@

   // Dereference operator. Returns const ref to internal block.

-  inline const Block_t &operator*() const
+  inline Block_t operator*() const
     {
       PAssert(!done());
       return block_m;
@@ -146,7 +146,7 @@
   inline const Block_t *operator->() const
     {
       PAssert(!done());
-      return block_m;
+      return &block_m;
     }

   // Return the upper-left corner of the current block; this is just a
Index: DomainIterator.h
===================================================================
RCS file: /home/pooma/Repository/r2/src/Domain/DomainIterator.h,v
retrieving revision 1.11
diff -u -u -r1.11 DomainIterator.h
--- DomainIterator.h    10 Oct 2003 19:26:43 -0000      1.11
+++ DomainIterator.h    2 Jun 2004 10:10:39 -0000
@@ -127,7 +127,7 @@

   // Dereference operator. Returns const ref to internal Loc.

-  inline const Value_t &operator*() const
+  inline Value_t operator*() const
     {
       PAssert(!done());
       return loc_m;
Index: IndirectionListIterator.h
===================================================================
RCS file: /home/pooma/Repository/r2/src/Domain/IndirectionListIterator.h,v
retrieving revision 1.6
diff -u -u -r1.6 IndirectionListIterator.h
--- IndirectionListIterator.h   12 Oct 2003 11:14:38 -0000      1.6
+++ IndirectionListIterator.h   2 Jun 2004 10:10:39 -0000
@@ -110,7 +110,7 @@

   // Dereference operator. Returns const ref to T.

-  inline const Value_t & operator*() const { PAssert(!done()); return val_m; }
+  inline Value_t operator*() const { PAssert(!done()); return val_m; }

   // Member selection operator.

Index: IntervalIterator.h
===================================================================
RCS file: /home/pooma/Repository/r2/src/Domain/IntervalIterator.h,v
retrieving revision 1.7
diff -u -u -r1.7 IntervalIterator.h
--- IntervalIterator.h  12 Oct 2003 11:14:38 -0000      1.7
+++ IntervalIterator.h  2 Jun 2004 10:10:39 -0000
@@ -107,7 +107,7 @@

   // Dereference operator. Returns const ref to internal Loc.

-  inline const Value_t &operator*() const { PAssert(!done()); return val_m; }
+  inline Value_t operator*() const { PAssert(!done()); return val_m; }

   // Member selection operator. Not really useful (ints have no
   // members to invoke), but part of the required interface.
Index: RangeIterator.h
===================================================================
RCS file: /home/pooma/Repository/r2/src/Domain/RangeIterator.h,v
retrieving revision 1.7
diff -u -u -r1.7 RangeIterator.h
--- RangeIterator.h     12 Oct 2003 11:14:38 -0000      1.7
+++ RangeIterator.h     2 Jun 2004 10:10:39 -0000
@@ -109,7 +109,7 @@

   // Dereference operator. Returns const ref to internal Loc.

-  inline const Value_t &operator*() const { PAssert(!done()); return val_m; }
+  inline Value_t operator*() const { PAssert(!done()); return val_m; }

   // Member selection operator. Not really useful (ints have no
   // members to invoke), but part of the required interface.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]