Ticket #3108: osx-libcpp-serialization-fixes.patch
File osx-libcpp-serialization-fixes.patch, 6.8 KB (added by , 9 years ago) |
---|
-
source/lib/file/common/trace.cpp
1 /* Copyright (c) 201 0Wildfire Games1 /* Copyright (c) 2015 Wildfire Games 2 2 * 3 3 * Permission is hereby granted, free of charge, to any person obtaining 4 4 * a copy of this software and associated documentation files (the … … 80 80 stream >> m_size; 81 81 82 82 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()); 84 85 ENSURE(stream.get() == WEOF); 85 86 } 86 87 -
source/simulation2/serialization/BinarySerializer.h
35 35 { 36 36 NONCOPYABLE(CSerializerStreamBuf); 37 37 T& m_SerializerImpl; 38 char m_Buffer[16]; 38 39 public: 39 40 CSerializerStreamBuf(T& impl) : 40 41 m_SerializerImpl(impl) 41 42 { 43 setp(m_Buffer, m_Buffer + ARRAY_SIZE(m_Buffer) - 1); 42 44 } 43 45 46 protected: 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 44 72 std::streamsize xsputn(const char* s, std::streamsize n) 45 73 { 46 74 m_SerializerImpl.Put("stream", reinterpret_cast<const u8*> (s), n); -
source/simulation2/serialization/StdDeserializer.cpp
84 84 if (!m_Stream.good()) 85 85 { 86 86 // hit eof before len, or other errors 87 // N ote: older libc++ versions incorrectly set eofbit on the last char; test gcount as a workaround87 // NOTE: older libc++ versions incorrectly set eofbit on the last char; test gcount as a workaround 88 88 // see https://llvm.org/bugs/show_bug.cgi?id=9335 89 89 if (m_Stream.bad() || m_Stream.fail() || (m_Stream.eof() && m_Stream.gcount() != (std::streamsize)len)) 90 90 throw PSERROR_Deserialize_ReadFailed(); -
source/simulation2/serialization/StdSerializer.cpp
1 /* Copyright (C) 201 1Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 22 22 CStdSerializerImpl::CStdSerializerImpl(std::ostream& stream) : 23 23 m_Stream(stream) 24 24 { 25 m_Stream << std::unitbuf; 25 26 } 26 27 27 28 CStdSerializer::CStdSerializer(ScriptInterface& scriptInterface, std::ostream& stream) : -
source/simulation2/system/ComponentManagerSerialization.cpp
97 97 98 98 bool CComponentManager::ComputeStateHash(std::string& outHash, bool quick) 99 99 { 100 TIMER(L"ComputeStateHash"); 100 101 // Hash serialization: this includes the minimal data necessary to detect 101 102 // differences in the state, and ignores things like counts and names 102 103 -
source/simulation2/tests/test_Serializer.h
167 167 deserialize.NumberI32("z", n, 0, 65535); 168 168 TS_ASSERT_EQUALS(n, 12345); 169 169 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()); 171 172 TS_ASSERT_EQUALS(stream.peek(), EOF); 172 173 } 173 174 … … 233 234 deserialize.RawBytes("raw bytes", cbuf, 6); 234 235 TS_ASSERT_SAME_DATA(cbuf, (const u8*)"\0\1\2\3\x0f\x10\x42", 7); 235 236 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()); 237 239 TS_ASSERT_EQUALS(stream.peek(), EOF); 238 240 } 239 241 … … 248 250 249 251 TS_ASSERT_EQUALS(serialize.GetHashLength(), (size_t)16); 250 252 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' 252 254 } 253 255 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 254 277 void test_bounds() 255 278 { 256 279 ScriptInterface script("Test", "Test", g_ScriptRuntime); … … 295 318 296 319 JS::RootedValue newobj(cx); 297 320 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()); 299 323 TSM_ASSERT_EQUALS(msg, stream.peek(), EOF); 300 324 301 325 std::string source; … … 769 793 770 794 JS::RootedValue newobj(cx); 771 795 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()); 773 798 TS_ASSERT_EQUALS(stream.peek(), EOF); 774 799 775 800 if (i == 0)