Results 1 to 5 of 5

Thread: Ice::OutputStream::writeTypeId bug

  1. #1
    Sheff is offline Registered User
    Name: Stanislav Vorobiov
    Organization: FocusMedia
    Project: Object System
    Join Date
    Nov 2008
    Posts
    13

    Ice::OutputStream::writeTypeId bug

    It seems that code like:

    Code:
    Ice::OutputStreamPtr out = Ice::createOutputStream(some_communicator);
    
    out->writeTypeId("::My::SomeObject");
    causes segmentation fault, so does this one:

    Code:
    Ice::OutputStreamPtr out = Ice::createOutputStream(some_communicator);
    
    out->startEncapsulation();
    out->writeTypeId("::My::SomeObject");
    out->endEncapsulation();
    In first case the problem is in IceInternal::BasicStream::writeTypeId:

    Code:
    TypeIdWriteMap::const_iterator k = _currentWriteEncaps->typeIdMap->find(id);
    _currentWriteEncaps is NULL, as I understand in should be lazy intialized and
    startEncapsulation does the job, but not completly, in IceInternal::BasicStream::startWriteEncaps:

    Code:
            if(!oldEncaps) // First allocated encaps?
            {
                _currentWriteEncaps = &_preAllocatedWriteEncaps;
            }
    but _preAllocatedWriteEncaps is just an instance of IceInternal::WriteEncaps where typeIdMap member is NULL that's why that segmentation fault happens.
    The only place where typeIdMap and other members of _currentWriteEncaps get initialized is IceInternal::BasicStream::write(const ObjectPtr&), but
    I don't want to send objects this way, I need to do it manually, any workaround for this ?

  2. #2
    benoit's Avatar
    benoit is offline ZeroC Staff
    Name: Benoit Foucher
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Rennes, France
    Posts
    2,196
    Hi,

    This method is only supposed to be used when marshalling an object and the code doesn't expect it to be called for another purpose. That being said, an exception would be nicer than a crash We'll fix this!

    Why do you want to use writeTypeId here? Can't you just encode the type as a string?

    Cheers,
    Benoit.

  3. #3
    Sheff is offline Registered User
    Name: Stanislav Vorobiov
    Organization: FocusMedia
    Project: Object System
    Join Date
    Nov 2008
    Posts
    13
    The problem is: I need to pass a class to some method using dynamic Ice and all I know about that class is it's type id, it's members and their types, so I want to be able to write like this:
    Code:
    outStream->writeTypeId("::My::SomeObject")
    outStream->startSlice();
    outStream->writeInt(100);
    outStream->writeByte(10);
    outStream->endSlice();
    i.e pass an object of type:
    Code:
    namespace My
    {
    class SomeObject
    {
    int a;
    byte b;
    }
    }
    I really need to do this using dynamic Ice, I'm able to pass simple types via ice_invoke and I should be able to pass classes using ice_invoke as well I guess...

  4. #4
    benoit's Avatar
    benoit is offline ZeroC Staff
    Name: Benoit Foucher
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Rennes, France
    Posts
    2,196
    You can't write the object directly to the stream. Usually, to marshall an object the easiest is to use the generated code helper functions (the "My::ice_writeSomeObject" method in your example).

    If your program doesn't have access to the generated code, you can implement an Ice::ObjectWritter wrapper and call writeObject with this wrapper. The Ice::ObjectWriter write method will be called when its time to marshal the object (this occurs when you call writePendingObjects on the streaming interface). E.g.:

    Code:
    // C++
    
    class SomeObjectWriter : public Ice::ObjectWriter
    {
        virtual void write(const OutputStreamPtr& outStream) const
        {
            outStream->writeTypeId("::My::SomeObject")
            outStream->startSlice();
            outStream->writeInt(100);
            outStream->writeByte(10);
            outStream->endSlice();
        }
    };
    
    
    outStream->writeObject(new SomeObjectWriter); // Insert the object into the stream.
    
    ...
    outStream->writePendingObjects();
    ...
    See here in the Ice manual for more information.

    Cheers,
    Benoit.

  5. #5
    Sheff is offline Registered User
    Name: Stanislav Vorobiov
    Organization: FocusMedia
    Project: Object System
    Join Date
    Nov 2008
    Posts
    13
    Great, just what I need, thanks a lot !!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 03-13-2012, 03:58 AM
  2. Bug in ThreadPool in Ice 3.2.1
    By dhogan in forum Bug Reports
    Replies: 1
    Last Post: 02-10-2009, 04:46 PM
  3. Replies: 0
    Last Post: 10-28-2008, 03:51 PM
  4. one bug in Ice 3.1.1 manual
    By rc_hz in forum Comments
    Replies: 1
    Last Post: 11-12-2006, 03:31 PM
  5. A bug in Ice manual 2.0.0
    By Mjollnir in forum Bug Reports
    Replies: 7
    Last Post: 02-09-2005, 09:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •