[hydra-commits] beagles: branch ice/slice-preserving-translators r604 - in /ice/branches/slic...

SVN commits to the Hydra project hydra-commits at lists.digium.com
Wed Apr 28 09:03:22 CDT 2010


Author: beagles
Date: Wed Apr 28 09:03:21 2010
New Revision: 604

URL: https://origsvn.digium.com/svn-view/hydra?view=rev&rev=604
Log:
First kick at resolving broken encapsulation for collections of unsliceable objects

Modified:
    ice/branches/slice-preserving-translators/cpp/include/Ice/BasicStream.h
    ice/branches/slice-preserving-translators/cpp/src/Ice/BasicStream.cpp
    ice/branches/slice-preserving-translators/cpp/src/slice2cpp/Gen.cpp
    ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/exceptions/AllTests.cpp
    ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/exceptions/TestAMD.ice
    ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/exceptions/TestAMDI.cpp
    ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/objects/AllTests.cpp
    ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/objects/TestI.cpp

Modified: ice/branches/slice-preserving-translators/cpp/include/Ice/BasicStream.h
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-preserving-translators/cpp/include/Ice/BasicStream.h?view=diff&rev=604&r1=603&r2=604
==============================================================================
--- ice/branches/slice-preserving-translators/cpp/include/Ice/BasicStream.h (original)
+++ ice/branches/slice-preserving-translators/cpp/include/Ice/BasicStream.h Wed Apr 28 09:03:21 2010
@@ -34,6 +34,12 @@
 
 namespace IceInternal
 {
+
+struct SkippedSlice
+{
+    std::string typeId;
+    std::vector< ::Ice::Byte > slice;
+};
 
 class ICE_API BasicStream : public Buffer
 {
@@ -177,6 +183,7 @@
         _currentReadEncaps->encodingMajor = eMajor;
         _currentReadEncaps->encodingMinor = eMinor;
     }
+
     void endReadEncaps()
     {
         assert(_currentReadEncaps);
@@ -209,6 +216,7 @@
             delete oldEncaps;
         }
     }
+
     void skipEmptyEncaps()
     {
         Ice::Int sz;
@@ -224,6 +232,7 @@
         }
         i += 2;
     }
+
     void endReadEncapsChecked(); // Used by public stream API.
 
     Ice::Int getReadEncapsSize();
@@ -235,6 +244,8 @@
     void startReadSlice();
     void endReadSlice();
     void skipSlice();
+
+    void skipSlice(const std::string& typeName);
 
     void writeSize(Ice::Int v) // Inlined for performance reasons.
     {
@@ -301,7 +312,7 @@
     void writeBlob(const std::vector<Ice::Byte>&);
     void readBlob(std::vector<Ice::Byte>&, Ice::Int);
 
-    void readSkippedSlicesBlob(std::vector<Ice::Byte>&);
+    void getSkippedSlices(std::vector<SkippedSlice>&);
 
     void writeBlob(const Ice::Byte* v, Container::size_type sz)
     {
@@ -651,7 +662,8 @@
     Container::size_type _writeSlice;
 
     Container::iterator _currentObjectStart;
-    Container::iterator _currentSliceStart;
+
+    std::vector<SkippedSlice> _skippedSlices;
 
     void writeInstance(const Ice::ObjectPtr&, Ice::Int);
     void patchPointers(Ice::Int, IndexToPtrMap::const_iterator, PatchMap::iterator);

Modified: ice/branches/slice-preserving-translators/cpp/src/Ice/BasicStream.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-preserving-translators/cpp/src/Ice/BasicStream.cpp?view=diff&rev=604&r1=603&r2=604
==============================================================================
--- ice/branches/slice-preserving-translators/cpp/src/Ice/BasicStream.cpp (original)
+++ ice/branches/slice-preserving-translators/cpp/src/Ice/BasicStream.cpp Wed Apr 28 09:03:21 2010
@@ -324,6 +324,19 @@
 }
 
 void
+IceInternal::BasicStream::skipSlice(const string& typeId)
+{
+    SkippedSlice newSlice;
+    newSlice.typeId = typeId;
+    skipSlice();
+    if(_currentObjectStart < i)
+    {
+	vector<Byte>(_currentObjectStart, i).swap(newSlice.slice);
+    }
+    _skippedSlices.push_back(newSlice);
+}
+
+void
 IceInternal::BasicStream::readAndCheckSeqSize(int minSize, Ice::Int& sz)
 {
     readSize(sz);
@@ -439,11 +452,11 @@
 }
 
 void
-IceInternal::BasicStream::readSkippedSlicesBlob(vector<Byte>& v)
-{
-    if(_currentObjectStart < _currentSliceStart)
-    {
-        vector<Byte>(_currentObjectStart, _currentSliceStart).swap(v);
+IceInternal::BasicStream::getSkippedSlices(vector<SkippedSlice>& v)
+{
+    if(!_skippedSlices.empty())
+    {
+        _skippedSlices.swap(v);
     }
     else
     {
@@ -1769,7 +1782,6 @@
         _currentReadEncaps->unmarshaledMap = new IndexToPtrMap;
         _currentReadEncaps->typeIdMap = new TypeIdReadMap;
     }
-
     ObjectPtr v;
 
     Int index;
@@ -1812,9 +1824,13 @@
         throw MarshalException(__FILE__, __LINE__, "Invalid class instance index");
     }
 
-    _currentObjectStart = _currentSliceStart = i;
     string mostDerivedId;
     readTypeId(mostDerivedId);
+    _skippedSlices.clear();
+    //
+    // These things *must* come after the readTypeId.. we want the data only parts, not the encoded type info.
+    //
+    _currentObjectStart = i;
     string id = mostDerivedId;
     while(true)
     {
@@ -1879,9 +1895,9 @@
                 {
                     traceSlicing("class", id, _slicingCat, _instance->initializationData().logger);
                 }
-                skipSlice(); // Slice off this derived part -- we don't understand it.
-                _currentSliceStart = i;
+                skipSlice(id); // Slice off this derived part -- we don't understand it.
                 readTypeId(id); // Read next id for next iteration.
+		_currentObjectStart = i;
                 continue;
             }
             else
@@ -1936,9 +1952,11 @@
     bool usesClasses;
     read(usesClasses);
 
-    _currentObjectStart = _currentSliceStart = i;
+    _skippedSlices.clear();
+
     string id;
     read(id, false);
+    _currentObjectStart = i;
     const string origId = id;
 
     for(;;)
@@ -1984,12 +2002,12 @@
                 traceSlicing("exception", id, _slicingCat, _instance->initializationData().logger);
             }
 
-            skipSlice(); // Slice off what we don't understand.
-            _currentSliceStart = i;
+            skipSlice(id); // Slice off what we don't understand.
 
             try
             {
                 read(id, false); // Read type id for next slice.
+		_currentObjectStart = i;
             }
             catch(UnmarshalOutOfBoundsException& ex)
             {

Modified: ice/branches/slice-preserving-translators/cpp/src/slice2cpp/Gen.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-preserving-translators/cpp/src/slice2cpp/Gen.cpp?view=diff&rev=604&r1=603&r2=604
==============================================================================
--- ice/branches/slice-preserving-translators/cpp/src/slice2cpp/Gen.cpp (original)
+++ ice/branches/slice-preserving-translators/cpp/src/slice2cpp/Gen.cpp Wed Apr 28 09:03:21 2010
@@ -839,14 +839,18 @@
 		H.zeroIndent();
 		H << nl << "protected:";
 		H.restoreIndent();
-		H << nl << "std::vector< ::Ice::Byte > __preserved;";
+		H << nl << "std::vector< ::IceInternal::SkippedSlice > __preserved;";
 	}
 	
         C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(::IceInternal::BasicStream* __os) const";
         C << sb;
 	if(preserving) 
 	{
-	    C << nl << "__os->writeBlob(__preserved);";
+	    C << nl << "for(std::vector< ::IceInternal::SkippedSlice >::const_iterator i = __preserved.begin(); i != __preserved.end(); ++i)";
+	    C << sb;
+	    C << nl << "__os->write(i->typeId, false);";
+	    C << nl << "__os->writeBlob(i->slice);";
+	    C << eb;
 	    C << nl << "__writeImpl(__os);";
 	    C << eb;
 	    C << sp << nl << "void" << nl << scoped.substr(2) << "::__writeImpl(::IceInternal::BasicStream* __os) const";
@@ -879,7 +883,7 @@
 	{
 	    C << nl << "if(__preserved.empty())";
 	    C << sb;
-	    C << nl << "__is->readSkippedSlicesBlob(__preserved);";
+	    C << nl << "__is->getSkippedSlices(__preserved);";
 	    C << eb;
 	}
         C << nl << "if(__rid)";
@@ -4263,7 +4267,11 @@
 
 	if(preserving)
 	{
-	    C << nl << "__os->writeBlob(__preserved);";
+		C << nl << "for(std::vector< ::IceInternal::SkippedSlice >::const_iterator i = __preserved.begin(); i != __preserved.end(); ++i)";
+	    C << sb;
+	    C << nl << "__os->writeTypeId(i->typeId);";
+	    C << nl << "__os->writeBlob(i->slice);";
+	    C << eb;
 	    C << nl << "__writeImpl(__os);";
 	    C << eb;
 
@@ -4298,7 +4306,7 @@
 	{
 	    C << nl << "if(__preserved.empty())";
 	    C << sb;
-	    C << nl << "__is->readSkippedSlicesBlob(__preserved);";
+	    C << nl << "__is->getSkippedSlices(__preserved);";
 	    C << eb;
 	}
 
@@ -4515,7 +4523,7 @@
 	{
 	    H << sp << "protected:";
 	}
-	H << sp << nl << "::std::vector< ::Ice::Byte > __preserved;";
+	H << sp << nl << "::std::vector< ::IceInternal::SkippedSlice > __preserved;";
     }
 
     H << eb << ';';

Modified: ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/exceptions/AllTests.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/exceptions/AllTests.cpp?view=diff&rev=604&r1=603&r2=604
==============================================================================
--- ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/exceptions/AllTests.cpp (original)
+++ ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/exceptions/AllTests.cpp Wed Apr 28 09:03:21 2010
@@ -840,6 +840,11 @@
 	    test(b.b == "Base");
             test(b.ice_name() =="Test::ClientUnsliceableDerived");	// *NOT* sliced by server
         }
+	catch(const Ice::Exception& ex)
+	{
+	    std::cerr << ex << std::endl;
+	    test(false);
+	}
 	catch(...)
 	{
             test(false);

Modified: ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/exceptions/TestAMD.ice
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/exceptions/TestAMD.ice?view=diff&rev=604&r1=603&r2=604
==============================================================================
--- ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/exceptions/TestAMD.ice (original)
+++ ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/exceptions/TestAMD.ice Wed Apr 28 09:03:21 2010
@@ -33,6 +33,7 @@
     string kmd;
 };
 
+["preserve"]
 exception BaseUnsliceable extends Base
 {
 };

Modified: ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/exceptions/TestAMDI.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/exceptions/TestAMDI.cpp?view=diff&rev=604&r1=603&r2=604
==============================================================================
--- ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/exceptions/TestAMDI.cpp (original)
+++ ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/exceptions/TestAMDI.cpp Wed Apr 28 09:03:21 2010
@@ -13,46 +13,8 @@
 using namespace std;
 using namespace Test;
 
-template <typename T>
-class PreserverFactory : public IceInternal::UserExceptionFactory
-{
-public:
-    void createAndThrow() {
-        throw Preserver();
-    }
-private:
-    class Preserver : virtual public T
-    {
-    public:
-        vector< ::Ice::Byte > __skippedSlices;
-        void __write(IceInternal::BasicStream* stream) const
-        {
-            stream->writeBlob(__skippedSlices);
-            T::__write(stream);
-        }
-        void __read(IceInternal::BasicStream* stream, bool rid)
-        {
-            stream->readSkippedSlicesBlob(__skippedSlices);
-            T::__read(stream, rid);
-        }
-        void ice_throw() const
-        {
-            throw *this;
-        }
-        ~Preserver() throw() {}
-    };
-};
-
 TestI::TestI(const Ice::CommunicatorPtr& communicator)
 {
-    // the factoryTable interface is... interesting. if you add an exception factory
-    // with the same name as one already in the table, it just increments the reference
-    // count  on the existing factory, without even comparing the factory object
-    // handles to see if it is in fact the same factory being added. so for now we
-    // need to explicitly remove the factory that the slice2cpp translator generated
-    // before adding our own
-    IceInternal::factoryTable->removeExceptionFactory("::Test::BaseUnsliceable");
-    IceInternal::factoryTable->addExceptionFactory("::Test::BaseUnsliceable", new PreserverFactory<BaseUnsliceable>);
 }
 
 void

Modified: ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/objects/AllTests.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/objects/AllTests.cpp?view=diff&rev=604&r1=603&r2=604
==============================================================================
--- ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/objects/AllTests.cpp (original)
+++ ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/objects/AllTests.cpp Wed Apr 28 09:03:21 2010
@@ -273,9 +273,10 @@
     }
 
     void
-    response_echoSeq(const BSeq& r)
+    response_echoSeq(const BSeq& r, const BSeq& out)
     {
         rseq = r;
+	outseq = out;
         called();
     }
 
@@ -374,6 +375,7 @@
     }
 
     BSeq rseq;
+    BSeq outseq;
     BPtr rb;
     SS3 rss3;
     BDict rbdict;
@@ -1291,7 +1293,6 @@
         cb->check();
     }
     cout << "ok" << endl;
-
     cout << "sequence of slice-preserved objects... " << flush;
     {
         BSeq seq;
@@ -1345,6 +1346,64 @@
     }
     cout << "ok" << endl;
 
+    cout << "sequence of slice-preserved objects (AMI)... " << flush;
+    {
+        BSeq seq;
+        D5Ptr current = new D5;
+        current->sd5 = "0";
+        seq.push_back(current);
+        
+        current = new D5;
+        current->sd5 = "1";
+        seq.push_back(current);
+        current = new D5;
+        current->sd5 = "2";
+        seq.push_back(current);
+        current = new D5;
+        current->sd5 = "3";
+        seq.push_back(current);
+
+        try
+        {
+
+            CallbackPtr cb = new Callback;
+            test->begin_echoSeq(seq, 
+                newCallback_TestIntf_echoSeq(cb, &Callback::response_echoSeq, &Callback::exception));
+            cb->check();
+	    BSeq ret = cb->rseq;
+            BSeq out = cb->outseq;
+
+            test(out.size() == seq.size());
+            test(ret.size() == seq.size());
+
+            test(out.back()->ice_id() == "::Test::D5");
+            test(ret.back()->ice_id() == "::Test::D5");
+            BSeq::const_iterator outi = out.begin();
+            BSeq::const_iterator reti = ret.begin();
+            for(BSeq::const_iterator i = seq.begin(); i != seq.end(); ++i)
+            {
+                test(outi != out.end());
+                test(reti != ret.end());
+
+                D5Ptr reference = D5Ptr::dynamicCast(*i);
+                D5Ptr outValue = D5Ptr::dynamicCast(*outi);
+                D5Ptr retValue = D5Ptr::dynamicCast(*reti);
+            
+                test(reference->sd5 == outValue->sd5);
+                ++outi;
+            
+                test(reference->sd5 == retValue->sd5);
+                ++reti;
+            }
+        }
+        catch(const Ice::Exception& ex)
+        {
+            throw;
+        }
+
+    }
+    cout << "ok" << endl;
+
     cout << "param ptr slicing, instance marshaled in unknown derived as base... " << flush;
     {
         try

Modified: ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/objects/TestI.cpp
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/objects/TestI.cpp?view=diff&rev=604&r1=603&r2=604
==============================================================================
--- ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/objects/TestI.cpp (original)
+++ ice/branches/slice-preserving-translators/cpp/test/Ice/slicing/objects/TestI.cpp Wed Apr 28 09:03:21 2010
@@ -233,8 +233,8 @@
 BSeq
 TestI::echoSeq(const BSeq& s1, BSeq& s2, const ::Ice::Current&)
 {
-    BSeq result(s1);
-    s2 = result;
+    s2 = s1;
+    BSeq result = s1;
     return result;
 }
 





More information about the asterisk-scf-commits mailing list