Ticket #3108: osx-libcpp-serialization-fixes.patch

File osx-libcpp-serialization-fixes.patch, 6.8 KB (added by historic_bruno, 9 years ago)

Updated for latest SVN

  • source/lib/file/common/trace.cpp

     
    1 /* Copyright (c) 2010 Wildfire Games
     1/* Copyright (c) 2015 Wildfire Games
    22 *
    33 * Permission is hereby granted, free of charge, to any person obtaining
    44 * a copy of this software and associated documentation files (the
     
    8080    stream >> m_size;
    8181
    8282    ENSURE(stream.get() == '\n');
    83     ENSURE(stream.good());
     83    // NOTE: Don't use good() here - it fails due to a bug in older libc++ versions
     84    ENSURE(!stream.bad() && !stream.fail());
    8485    ENSURE(stream.get() == WEOF);
    8586}
    8687
  • source/simulation2/serialization/BinarySerializer.h

     
    3535{
    3636    NONCOPYABLE(CSerializerStreamBuf);
    3737    T& m_SerializerImpl;
     38    char m_Buffer[16];
    3839public:
    3940    CSerializerStreamBuf(T& impl) :
    4041        m_SerializerImpl(impl)
    4142    {
     43        setp(m_Buffer, m_Buffer + ARRAY_SIZE(m_Buffer) - 1);
    4244    }
    4345
     46protected:
     47    // Override overflow and sync, because older versions of libc++ streams
     48    // write strings as individual characters, then xsputn is never called
     49    int overflow(int ch)
     50    {
     51        if (ch == traits_type::eof())
     52            return traits_type::not_eof(ch);
     53       
     54        ENSURE(pptr() <= epptr());
     55        *pptr() = ch;
     56        pbump(1);
     57        sync();
     58        return ch;
     59    }
     60
     61    int sync()
     62    {
     63        std::ptrdiff_t n = pptr() - pbase();
     64        if (n != 0)
     65        {
     66            pbump(-n);
     67            m_SerializerImpl.Put("stream", reinterpret_cast<const u8*> (pbase()), n);
     68        }
     69        return 0;
     70    }
     71
    4472    std::streamsize xsputn(const char* s, std::streamsize n)
    4573    {
    4674        m_SerializerImpl.Put("stream", reinterpret_cast<const u8*> (s), n);
  • source/simulation2/serialization/StdDeserializer.cpp

     
    8484    if (!m_Stream.good())
    8585    {
    8686        // hit eof before len, or other errors
    87         // Note: older libc++ versions incorrectly set eofbit on the last char; test gcount as a workaround
     87        // NOTE: older libc++ versions incorrectly set eofbit on the last char; test gcount as a workaround
    8888        // see https://llvm.org/bugs/show_bug.cgi?id=9335
    8989        if (m_Stream.bad() || m_Stream.fail() || (m_Stream.eof() && m_Stream.gcount() != (std::streamsize)len))
    9090            throw PSERROR_Deserialize_ReadFailed();
  • source/simulation2/serialization/StdSerializer.cpp

     
    1 /* Copyright (C) 2011 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2222CStdSerializerImpl::CStdSerializerImpl(std::ostream& stream) :
    2323    m_Stream(stream)
    2424{
     25    m_Stream << std::unitbuf;
    2526}
    2627
    2728CStdSerializer::CStdSerializer(ScriptInterface& scriptInterface, std::ostream& stream) :
  • source/simulation2/system/ComponentManagerSerialization.cpp

     
    9797
    9898bool CComponentManager::ComputeStateHash(std::string& outHash, bool quick)
    9999{
     100    TIMER(L"ComputeStateHash");
    100101    // Hash serialization: this includes the minimal data necessary to detect
    101102    // differences in the state, and ignores things like counts and names
    102103
  • source/simulation2/tests/test_Serializer.h

     
    167167        deserialize.NumberI32("z", n, 0, 65535);
    168168        TS_ASSERT_EQUALS(n, 12345);
    169169
    170         TS_ASSERT(stream.good());
     170        // NOTE: Don't use good() here - it fails due to a bug in older libc++ versions
     171        TS_ASSERT(!stream.bad() && !stream.fail());
    171172        TS_ASSERT_EQUALS(stream.peek(), EOF);
    172173    }
    173174
     
    233234        deserialize.RawBytes("raw bytes", cbuf, 6);
    234235        TS_ASSERT_SAME_DATA(cbuf, (const u8*)"\0\1\2\3\x0f\x10\x42", 7);
    235236
    236         TS_ASSERT(stream.good());
     237        // NOTE: Don't use good() here - it fails due to a bug in older libc++ versions
     238        TS_ASSERT(!stream.bad() && !stream.fail());
    237239        TS_ASSERT_EQUALS(stream.peek(), EOF);
    238240    }
    239241
     
    248250
    249251        TS_ASSERT_EQUALS(serialize.GetHashLength(), (size_t)16);
    250252        TS_ASSERT_SAME_DATA(serialize.ComputeHash(), "\xa0\x3a\xe5\x3e\x9b\xd7\xfb\x11\x88\x35\xc6\xfb\xb9\x94\xa9\x72", 16);
    251         // echo -en "\x85\xff\xff\xff\xd2\x04\x00\x00\x39\x30\x00\x00" | openssl md5 | perl -pe 's/(..)/\\x$1/g'
     253        // echo -en "\x85\xff\xff\xff\xd2\x04\x00\x00\x39\x30\x00\x00" | openssl md5 -binary | xxd -p | perl -pe 's/(..)/\\x$1/g'
    252254    }
    253255
     256    void test_Hash_stream()
     257    {
     258        ScriptInterface script("Test", "Test", g_ScriptRuntime);
     259        CHashSerializer hashSerialize(script);
     260
     261        hashSerialize.NumberI32_Unbounded("x", -123);
     262        hashSerialize.NumberU32_Unbounded("y", 1234);
     263        hashSerialize.NumberI32("z", 12345, 0, 65535);
     264
     265        ISerializer& serialize = hashSerialize;
     266        CStdSerializer streamSerialize(script, serialize.GetStream());
     267
     268        streamSerialize.NumberI32_Unbounded("x2", -456);
     269        streamSerialize.NumberU32_Unbounded("y2", 5678);
     270        streamSerialize.NumberI32("z2", 45678, 0, 65535);
     271
     272        TS_ASSERT_EQUALS(hashSerialize.GetHashLength(), (size_t)16);
     273        TS_ASSERT_SAME_DATA(hashSerialize.ComputeHash(), "\x5c\xff\x33\xd1\x72\xdd\x6d\x77\xa8\xd4\xa1\xf6\x84\xcc\xaa\x10", 16);
     274        // echo -en "\x85\xff\xff\xff\xd2\x04\x00\x00\x39\x30\x00\x00\x38\xfe\xff\xff\x2e\x16\x00\x00\x6e\xb2\x00\x00" | openssl md5 -binary | xxd -p | perl -pe 's/(..)/\\x$1/g'
     275    }
     276
    254277    void test_bounds()
    255278    {
    256279        ScriptInterface script("Test", "Test", g_ScriptRuntime);
     
    295318
    296319        JS::RootedValue newobj(cx);
    297320        deserialize.ScriptVal("script", &newobj);
    298         TSM_ASSERT(msg, stream.good());
     321        // NOTE: Don't use good() here - it fails due to a bug in older libc++ versions
     322        TSM_ASSERT(msg, !stream.bad() && !stream.fail());
    299323        TSM_ASSERT_EQUALS(msg, stream.peek(), EOF);
    300324
    301325        std::string source;
     
    769793
    770794            JS::RootedValue newobj(cx);
    771795            deserialize.ScriptVal("script", &newobj);
    772             TS_ASSERT(stream.good());
     796            // NOTE: Don't use good() here - it fails due to a bug in older libc++ versions
     797            TS_ASSERT(!stream.bad() && !stream.fail());
    773798            TS_ASSERT_EQUALS(stream.peek(), EOF);
    774799
    775800            if (i == 0)