X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Fpickle.hpp;h=41667e653783be3bf934ceba9a11afaaba373615;hb=67ec200baea241d55bea33c43fd5194d90d9e401;hp=736025b2a1cd8b3ee6583e8bfac336b30edad876;hpb=b16a4a88f021ec70cae2fc6278c2bd25224681a8;p=apitrace diff --git a/common/pickle.hpp b/common/pickle.hpp index 736025b..41667e6 100644 --- a/common/pickle.hpp +++ b/common/pickle.hpp @@ -268,6 +268,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 +300,15 @@ 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) { + + 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;