From 9b36ef3575c13aa360f1b2fac312683270978094 Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Tue, 2 Oct 2007 04:44:48 +0000 Subject: [PATCH] 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 --- lib/py/src/protocol/TBinaryProtocol.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/py/src/protocol/TBinaryProtocol.py b/lib/py/src/protocol/TBinaryProtocol.py index 9755ada7..d163a6e6 100644 --- a/lib/py/src/protocol/TBinaryProtocol.py +++ b/lib/py/src/protocol/TBinaryProtocol.py @@ -13,8 +13,17 @@ class TBinaryProtocol(TProtocolBase): """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 @@ class TBinaryProtocol(TProtocolBase): 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: -- 2.17.1