Fix 32-bit Python encoding integer issue
Summary: Python on 32-bit platforms 2.4+ wants to keep hexconstants positive, therefore converting 0x800000000 to a (long) type to keep that. This causes issues when performing comparison with a signed negative integer.
Reviewed By: dreiss
Test Plan: Python on 32 bit 2.4+ system making Thrift calls
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665287 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/py/src/protocol/TBinaryProtocol.py b/lib/py/src/protocol/TBinaryProtocol.py
index 9755ada..d163a6e 100644
--- a/lib/py/src/protocol/TBinaryProtocol.py
+++ b/lib/py/src/protocol/TBinaryProtocol.py
@@ -13,8 +13,17 @@
"""Binary implementation of the Thrift protocol driver."""
- VERSION_MASK = 0xffff0000
- VERSION_1 = 0x80010000
+ # NastyHaxx. Python 2.4+ on 32-bit machines forces hex constants to be
+ # positive, converting this into a long. If we hardcode the int value
+ # instead it'll stay in 32 bit-land.
+
+ # VERSION_MASK = 0xffff0000
+ VERSION_MASK = -65536
+
+ # VERSION_1 = 0x80010000
+ VERSION_1 = -2147418112
+
+ TYPE_MASK = 0x000000ff
def __init__(self, trans, strictRead=False, strictWrite=True):
TProtocolBase.__init__(self, trans)
@@ -108,7 +117,7 @@
version = sz & TBinaryProtocol.VERSION_MASK
if version != TBinaryProtocol.VERSION_1:
raise TProtocolException(TProtocolException.BAD_VERSION, 'Bad version in readMessageBegin: %d' % (sz))
- type = version & 0x000000ff
+ type = sz & TBinaryProtocol.TYPE_MASK
name = self.readString()
seqid = self.readI32()
else: