X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Fpickle.hpp;h=84b643a93ab7301c2e4fdbaa5520fa7bb8e176d9;hb=bd6b0c166872c38289375b7acb807ee790e87096;hp=736025b2a1cd8b3ee6583e8bfac336b30edad876;hpb=b16a4a88f021ec70cae2fc6278c2bd25224681a8;p=apitrace diff --git a/common/pickle.hpp b/common/pickle.hpp index 736025b..84b643a 100644 --- a/common/pickle.hpp +++ b/common/pickle.hpp @@ -36,6 +36,7 @@ #include #include +#include class PickleWriter @@ -268,6 +269,16 @@ public: os.put(u.c[0]); } + inline void writeByteArray(const void *buf, size_t length) { + os.put(GLOBAL); + os << "__builtin__\nbytearray\n"; + os.put(BINPUT); + os.put(1); + writeString(static_cast(buf), length); + os.put(TUPLE1); + os.put(REDUCE); + } + protected: inline void putInt16(uint16_t i) { os.put( i & 0xff); @@ -290,12 +301,20 @@ protected: return; } - unsigned c = 1; // Same as l >> (8 * sizeof l), but without the warnings - T sign = l < 0 ? ~0 : 0; - while ((l >> (8 * c)) != sign) { - ++c; + T sign; + if (std::numeric_limits::is_signed) { + sign = l < 0 ? ~0 : 0; + } else { + sign = 0; } + + T sl = l; + unsigned c = 0; + do { + ++c; + } while (sl >>= 8 != sign); + // Add an extra byte if sign bit doesn't match if (((l >> (8 * c - 1)) & 1) != ((l >> (8 * sizeof l - 1)) & 1)) { ++c;