changeset 39456:8d858fbf2759

cbor: teach the encoder to handle python `long` type for Windows The tests for 2**32 and -7000000000 were blowing up, complaining about not knowing how to encode type 'long'. sys.maxint tops out at 2**31-1 on Windows, but I guess is 2^63-1 on Linux? I *think* we're OK on the decode side, as there is an assertion that the decoded value is equal to the original primitive value. I opted for the pycompat alias instead of swallowing the NameError because the vendored cbor package uses an alias, and I see at least pywatchman and templatefilters open codes their own aliases.
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 04 Sep 2018 22:29:38 -0400
parents ab452995eaff
children a913d2892e17
files mercurial/pycompat.py mercurial/utils/cborutil.py
diffstat 2 files changed, 6 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/pycompat.py	Tue Sep 04 20:48:22 2018 -0400
+++ b/mercurial/pycompat.py	Tue Sep 04 22:29:38 2018 -0400
@@ -120,6 +120,8 @@
     rawinput = input
     getargspec = inspect.getfullargspec
 
+    long = int
+
     # TODO: .buffer might not exist if std streams were replaced; we'll need
     # a silly wrapper to make a bytes stream backed by a unicode one.
     stdin = sys.stdin.buffer
@@ -384,6 +386,7 @@
     ospardir = os.pardir
     ossep = os.sep
     osaltsep = os.altsep
+    long = long
     stdin = sys.stdin
     stdout = sys.stdout
     stderr = sys.stderr
--- a/mercurial/utils/cborutil.py	Tue Sep 04 20:48:22 2018 -0400
+++ b/mercurial/utils/cborutil.py	Tue Sep 04 22:29:38 2018 -0400
@@ -10,6 +10,8 @@
 import struct
 import sys
 
+from .. import pycompat
+
 # Very short very of RFC 7049...
 #
 # Each item begins with a byte. The 3 high bits of that byte denote the
@@ -190,6 +192,7 @@
 STREAM_ENCODERS = {
     bytes: streamencodebytestring,
     int: streamencodeint,
+    pycompat.long: streamencodeint,
     list: streamencodearray,
     tuple: streamencodearray,
     dict: streamencodemap,