aboutsummaryrefslogtreecommitdiffhomepage
path: root/python/google/protobuf/internal
diff options
context:
space:
mode:
authorGravatar Dan O'Reilly <oreilldf@gmail.com>2015-08-14 15:26:33 -0400
committerGravatar Dan O'Reilly <oreilldf@gmail.com>2015-08-14 15:26:33 -0400
commitfe7d9379df3ce7c951bc0652a451413cff02382a (patch)
tree9f07e17b2dd4f77c67b126c28123e9945ee9f7f9 /python/google/protobuf/internal
parent6654e77f1d9d67b92eef5e0066c71ee3c6263817 (diff)
Fixing some long/int bugs
Signed-off-by: Dan O'Reilly <oreilldf@gmail.com>
Diffstat (limited to 'python/google/protobuf/internal')
-rwxr-xr-xpython/google/protobuf/internal/decoder.py7
-rwxr-xr-xpython/google/protobuf/internal/reflection_test.py10
-rwxr-xr-xpython/google/protobuf/internal/type_checkers.py11
3 files changed, 17 insertions, 11 deletions
diff --git a/python/google/protobuf/internal/decoder.py b/python/google/protobuf/internal/decoder.py
index 130386f2..4fd7a864 100755
--- a/python/google/protobuf/internal/decoder.py
+++ b/python/google/protobuf/internal/decoder.py
@@ -86,6 +86,9 @@ import struct
import six
+if six.PY3:
+ long = int
+
from google.protobuf.internal import encoder
from google.protobuf.internal import wire_format
from google.protobuf import message
@@ -157,8 +160,8 @@ def _SignedVarintDecoder(mask, result_type):
# alternate implementations where the distinction is more significant
# (e.g. the C++ implementation) simpler.
-_DecodeVarint = _VarintDecoder((1 << 64) - 1, int)
-_DecodeSignedVarint = _SignedVarintDecoder((1 << 64) - 1, int)
+_DecodeVarint = _VarintDecoder((1 << 64) - 1, long)
+_DecodeSignedVarint = _SignedVarintDecoder((1 << 64) - 1, long)
# Use these versions for values which must be limited to 32 bits.
_DecodeVarint32 = _VarintDecoder((1 << 32) - 1, int)
diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py
index d1c18c1f..9fe3abee 100755
--- a/python/google/protobuf/internal/reflection_test.py
+++ b/python/google/protobuf/internal/reflection_test.py
@@ -630,17 +630,17 @@ class ReflectionTest(unittest.TestCase):
TestGetAndDeserialize('optional_int32', 1, int)
TestGetAndDeserialize('optional_int32', 1 << 30, int)
TestGetAndDeserialize('optional_uint32', 1 << 30, int)
+ try:
+ integer_64 = long
+ except NameError: # Python3
+ integer_64 = int
if struct.calcsize('L') == 4:
# Python only has signed ints, so 32-bit python can't fit an uint32
# in an int.
- TestGetAndDeserialize('optional_uint32', 1 << 31, int)
+ TestGetAndDeserialize('optional_uint32', 1 << 31, long)
else:
# 64-bit python can fit uint32 inside an int
TestGetAndDeserialize('optional_uint32', 1 << 31, int)
- try:
- integer_64 = long
- except NameError: # Python3
- integer_64 = int
TestGetAndDeserialize('optional_int64', 1 << 30, integer_64)
TestGetAndDeserialize('optional_int64', 1 << 60, integer_64)
TestGetAndDeserialize('optional_uint64', 1 << 30, integer_64)
diff --git a/python/google/protobuf/internal/type_checkers.py b/python/google/protobuf/internal/type_checkers.py
index 363018ed..8fa3d8c8 100755
--- a/python/google/protobuf/internal/type_checkers.py
+++ b/python/google/protobuf/internal/type_checkers.py
@@ -49,6 +49,9 @@ __author__ = 'robinson@google.com (Will Robinson)'
import six
+if six.PY3:
+ long = int
+
from google.protobuf.internal import decoder
from google.protobuf.internal import encoder
from google.protobuf.internal import wire_format
@@ -195,13 +198,13 @@ class Uint32ValueChecker(IntValueChecker):
class Int64ValueChecker(IntValueChecker):
_MIN = -(1 << 63)
_MAX = (1 << 63) - 1
- _TYPE = int
+ _TYPE = long
class Uint64ValueChecker(IntValueChecker):
_MIN = 0
_MAX = (1 << 64) - 1
- _TYPE = int
+ _TYPE = long
# Type-checkers for all scalar CPPTYPEs.
@@ -211,9 +214,9 @@ _VALUE_CHECKERS = {
_FieldDescriptor.CPPTYPE_UINT32: Uint32ValueChecker(),
_FieldDescriptor.CPPTYPE_UINT64: Uint64ValueChecker(),
_FieldDescriptor.CPPTYPE_DOUBLE: TypeChecker(
- float, int, int),
+ float, int, long),
_FieldDescriptor.CPPTYPE_FLOAT: TypeChecker(
- float, int, int),
+ float, int, long),
_FieldDescriptor.CPPTYPE_BOOL: TypeChecker(bool, int),
_FieldDescriptor.CPPTYPE_STRING: TypeChecker(bytes),
}