Skip to content

Commit e9bbe8b

Browse files
committed
Issue #15480: Remove the deprecated and unused TYPE_INT64 code from marshal.
Initial patch by Daniel Riti.
1 parent e2cef88 commit e9bbe8b

File tree

4 files changed

+8
-73
lines changed

4 files changed

+8
-73
lines changed

Lib/test/test_marshal.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,12 @@ def helper(self, sample, *extra):
2323

2424
class IntTestCase(unittest.TestCase, HelperMixin):
2525
def test_ints(self):
26-
# Test the full range of Python ints.
27-
n = sys.maxsize
26+
# Test a range of Python ints larger than the machine word size.
27+
n = sys.maxsize ** 2
2828
while n:
2929
for expected in (-n, n):
3030
self.helper(expected)
31-
n = n >> 1
32-
33-
def test_int64(self):
34-
# Simulate int marshaling on a 64-bit box. This is most interesting if
35-
# we're running the test on a 32-bit box, of course.
36-
37-
def to_little_endian_string(value, nbytes):
38-
b = bytearray()
39-
for i in range(nbytes):
40-
b.append(value & 0xff)
41-
value >>= 8
42-
return b
43-
44-
maxint64 = (1 << 63) - 1
45-
minint64 = -maxint64-1
46-
47-
for base in maxint64, minint64, -maxint64, -(minint64 >> 1):
48-
while base:
49-
s = b'I' + to_little_endian_string(base, 8)
50-
got = marshal.loads(s)
51-
self.assertEqual(base, got)
52-
if base == -1: # a fixed-point for shifting right 1
53-
base = 0
54-
else:
55-
base >>= 1
31+
n = n >> 1
5632

5733
def test_bool(self):
5834
for b in (True, False):

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,7 @@ Nicholas Riley
10241024
Jean-Claude Rimbault
10251025
Vlad Riscutia
10261026
Wes Rishel
1027+
Daniel Riti
10271028
Juan M. Bello Rivas
10281029
Davide Rizzo
10291030
Anthony Roach

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Core and Builtins
4444
Library
4545
-------
4646

47+
- Issue #15480: Remove the deprecated and unused TYPE_INT64 code from marshal.
48+
Initial patch by Daniel Riti.
49+
4750
- Issue #2118: SMTPException is now a subclass of IOError.
4851

4952
- Issue #17016: Get rid of possible pointer wraparounds and integer overflows

Python/marshal.c

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333
#define TYPE_STOPITER 'S'
3434
#define TYPE_ELLIPSIS '.'
3535
#define TYPE_INT 'i'
36-
/* TYPE_INT64 is deprecated. It is not
37-
generated anymore, and support for reading it
38-
will be removed in Python 3.4. */
39-
#define TYPE_INT64 'I'
4036
#define TYPE_FLOAT 'f'
4137
#define TYPE_BINARY_FLOAT 'g'
4238
#define TYPE_COMPLEX 'x'
@@ -638,42 +634,6 @@ r_long(RFILE *p)
638634
return x;
639635
}
640636

641-
/* r_long64 deals with the TYPE_INT64 code. On a machine with
642-
sizeof(long) > 4, it returns a Python int object, else a Python long
643-
object. Note that w_long64 writes out TYPE_INT if 32 bits is enough,
644-
so there's no inefficiency here in returning a PyLong on 32-bit boxes
645-
for everything written via TYPE_INT64 (i.e., if an int is written via
646-
TYPE_INT64, it *needs* more than 32 bits).
647-
*/
648-
static PyObject *
649-
r_long64(RFILE *p)
650-
{
651-
PyObject *result = NULL;
652-
long lo4 = r_long(p);
653-
long hi4 = r_long(p);
654-
655-
if (!PyErr_Occurred()) {
656-
#if SIZEOF_LONG > 4
657-
long x = (hi4 << 32) | (lo4 & 0xFFFFFFFFL);
658-
result = PyLong_FromLong(x);
659-
#else
660-
unsigned char buf[8];
661-
int one = 1;
662-
int is_little_endian = (int)*(char*)&one;
663-
if (is_little_endian) {
664-
memcpy(buf, &lo4, 4);
665-
memcpy(buf+4, &hi4, 4);
666-
}
667-
else {
668-
memcpy(buf, &hi4, 4);
669-
memcpy(buf+4, &lo4, 4);
670-
}
671-
result = _PyLong_FromByteArray(buf, 8, is_little_endian, 1);
672-
#endif
673-
}
674-
return result;
675-
}
676-
677637
static PyObject *
678638
r_PyLong(RFILE *p)
679639
{
@@ -871,11 +831,6 @@ r_object(RFILE *p)
871831
R_REF(retval);
872832
break;
873833

874-
case TYPE_INT64:
875-
retval = r_long64(p);
876-
R_REF(retval);
877-
break;
878-
879834
case TYPE_LONG:
880835
retval = r_PyLong(p);
881836
R_REF(retval);
@@ -1201,7 +1156,7 @@ r_object(RFILE *p)
12011156
PyObject *name = NULL;
12021157
int firstlineno;
12031158
PyObject *lnotab = NULL;
1204-
1159+
12051160
idx = r_ref_reserve(flag, p);
12061161
if (idx < 0) {
12071162
retval = NULL;

0 commit comments

Comments
 (0)