Matthias Brantner has proposed merging lp:~zorba-coders/zorba/bug-fixing into 
lp:zorba.

Requested reviews:
  William Candillon (wcandillon)
  Nicolae Brinza (nbrinza)
Related bugs:
  Bug #898064 in Zorba: "Stringstream error"
  https://bugs.launchpad.net/zorba/+bug/898064
  Bug #898208 in Zorba: "building xqdoc on cmake < 2.8"
  https://bugs.launchpad.net/zorba/+bug/898208

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-fixing/+merge/83991

fix for bug #898064
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-fixing/+merge/83991
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/api/serialization/serializer.cpp'
--- src/api/serialization/serializer.cpp	2011-11-11 07:44:01 +0000
+++ src/api/serialization/serializer.cpp	2011-11-30 18:31:30 +0000
@@ -1682,14 +1682,18 @@
   std::streambuf *  pbuf;
   std::streamsize   read_bytes;
   std::istream& is = item->getStream();
-
-  // prepare the stream
+  std::streampos pos;
   std::ios::iostate const old_exceptions = is.exceptions();
-  is.exceptions( std::ios::badbit | std::ios::failbit );
-  std::streampos const pos = is.tellg();
-  if (pos)
-    is.seekg(0, std::ios::beg);
-  is.exceptions(is.exceptions() & ~std::ios::failbit);
+
+  if (item->isSeekable())
+  {
+    // prepare the stream
+    is.exceptions( std::ios::badbit | std::ios::failbit );
+    pos = is.tellg();
+    if (pos)
+      is.seekg(0, std::ios::beg);
+    is.exceptions(is.exceptions() & ~std::ios::failbit);
+  }
 
   // read bytes and do string expansion
   do
@@ -1703,12 +1707,15 @@
 
   // restore stream's state
   is.clear();                   // clear eofbit
-  if (pos)
+  if (item->isSeekable())
   {
-    is.exceptions(is.exceptions() | std::ios::failbit);
-    is.seekg(pos, std::ios::beg);
+    if (pos != 0 && pos != -1)
+    {
+      is.exceptions(is.exceptions() | std::ios::failbit);
+      is.seekg(pos, std::ios::beg);
+    }
+    is.exceptions(old_exceptions);
   }
-  is.exceptions(old_exceptions);
 }
 
 

=== modified file 'src/store/api/item.h'
--- src/store/api/item.h	2011-10-15 10:41:19 +0000
+++ src/store/api/item.h	2011-11-30 18:31:30 +0000
@@ -807,6 +807,14 @@
   virtual bool isStreamable() const;
 
   /**
+   * Checks whether the item's content is streamable
+   * and the underlying stream is seekable
+   *
+   * @return true only if it is.
+   */
+  virtual bool isSeekable() const;
+
+  /**
    * Gets an istream for the item's content.
    *
    * @return the stream.

=== modified file 'src/store/naive/item.cpp'
--- src/store/naive/item.cpp	2011-10-15 10:41:19 +0000
+++ src/store/naive/item.cpp	2011-11-30 18:31:30 +0000
@@ -1291,6 +1291,11 @@
   return false;
 }
 
+bool Item::isSeekable() const
+{
+  return false;
+}
+
 std::istream& Item::getStream()
 {
   throw ZORBA_EXCEPTION(

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to