Skip to content

Commit ed4aa83

Browse files
committed
require a long long data type (closes python#27961)
1 parent b3b0767 commit ed4aa83

32 files changed

+156
-442
lines changed

Doc/c-api/unicode.rst

-5
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,6 @@ APIs:
524524
An unrecognized format character causes all the rest of the format string to be
525525
copied as-is to the result string, and any extra arguments discarded.
526526
527-
.. note::
528-
529-
The `"%lld"` and `"%llu"` format specifiers are only available
530-
when :const:`HAVE_LONG_LONG` is defined.
531-
532527
.. note::
533528
The width formatter unit is number of characters rather than bytes.
534529
The precision formatter unit is number of bytes for ``"%s"`` and

Include/longobject.h

-2
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,12 @@ PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);
8585
PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);
8686
PyAPI_FUNC(void *) PyLong_AsVoidPtr(PyObject *);
8787

88-
#ifdef HAVE_LONG_LONG
8988
PyAPI_FUNC(PyObject *) PyLong_FromLongLong(PY_LONG_LONG);
9089
PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG);
9190
PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLong(PyObject *);
9291
PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLong(PyObject *);
9392
PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *);
9493
PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLongAndOverflow(PyObject *, int *);
95-
#endif /* HAVE_LONG_LONG */
9694

9795
PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int);
9896
#ifndef Py_LIMITED_API

Include/pyport.h

+8-17
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ HAVE_UINTPTR_T
3535
Meaning: The C9X type uintptr_t is supported by the compiler
3636
Used in: Py_uintptr_t
3737
38-
HAVE_LONG_LONG
39-
Meaning: The compiler supports the C type "long long"
40-
Used in: PY_LONG_LONG
41-
4238
**************************************************************************/
4339

4440
/* typedefs for some C9X-defined synonyms for integral types.
@@ -53,7 +49,6 @@ Used in: PY_LONG_LONG
5349
* integral synonyms. Only define the ones we actually need.
5450
*/
5551

56-
#ifdef HAVE_LONG_LONG
5752
#ifndef PY_LONG_LONG
5853
#define PY_LONG_LONG long long
5954
#if defined(LLONG_MAX)
@@ -78,7 +73,6 @@ Used in: PY_LONG_LONG
7873
#define PY_ULLONG_MAX (PY_LLONG_MAX * Py_ULL(2) + 1)
7974
#endif /* LLONG_MAX */
8075
#endif
81-
#endif /* HAVE_LONG_LONG */
8276

8377
/* a build with 30-bit digits for Python integers needs an exact-width
8478
* 32-bit unsigned integer type to store those digits. (We could just use
@@ -161,7 +155,7 @@ typedef int Py_intptr_t;
161155
typedef unsigned long Py_uintptr_t;
162156
typedef long Py_intptr_t;
163157

164-
#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
158+
#elif SIZEOF_VOID_P <= SIZEOF_LONG_LONG
165159
typedef unsigned PY_LONG_LONG Py_uintptr_t;
166160
typedef PY_LONG_LONG Py_intptr_t;
167161

@@ -248,19 +242,16 @@ typedef int Py_ssize_clean_t;
248242
#endif
249243

250244
/* PY_FORMAT_LONG_LONG is analogous to PY_FORMAT_SIZE_T above, but for
251-
* the long long type instead of the size_t type. It's only available
252-
* when HAVE_LONG_LONG is defined. The "high level" Python format
245+
* the long long type instead of the size_t type. The "high level" Python format
253246
* functions listed above will interpret "lld" or "llu" correctly on
254247
* all platforms.
255248
*/
256-
#ifdef HAVE_LONG_LONG
257-
# ifndef PY_FORMAT_LONG_LONG
258-
# ifdef MS_WINDOWS
259-
# define PY_FORMAT_LONG_LONG "I64"
260-
# else
261-
# error "This platform's pyconfig.h needs to define PY_FORMAT_LONG_LONG"
262-
# endif
263-
# endif
249+
#ifndef PY_FORMAT_LONG_LONG
250+
# ifdef MS_WINDOWS
251+
# define PY_FORMAT_LONG_LONG "I64"
252+
# else
253+
# error "This platform's pyconfig.h needs to define PY_FORMAT_LONG_LONG"
254+
# endif
264255
#endif
265256

266257
/* Py_LOCAL can be used instead of static to get the fastest possible calling

Include/pythread.h

-5
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,8 @@ PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int);
3737
module exposes a higher-level API, with timeouts expressed in seconds
3838
and floating-point numbers allowed.
3939
*/
40-
#if defined(HAVE_LONG_LONG)
4140
#define PY_TIMEOUT_T PY_LONG_LONG
4241
#define PY_TIMEOUT_MAX PY_LLONG_MAX
43-
#else
44-
#define PY_TIMEOUT_T long
45-
#define PY_TIMEOUT_MAX LONG_MAX
46-
#endif
4742

4843
/* In the NT API, the timeout is a DWORD and is expressed in milliseconds */
4944
#if defined (NT_THREADS)

Include/structmember.h

-2
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ typedef struct PyMemberDef {
4949
#define T_OBJECT_EX 16 /* Like T_OBJECT, but raises AttributeError
5050
when the value is NULL, instead of
5151
converting to None. */
52-
#ifdef HAVE_LONG_LONG
5352
#define T_LONGLONG 17
5453
#define T_ULONGLONG 18
55-
#endif /* HAVE_LONG_LONG */
5654

5755
#define T_PYSSIZET 19 /* Py_ssize_t */
5856
#define T_NONE 20 /* Value is always None */

Lib/test/test_struct.py

+3-18
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,10 @@
1616
def iter_integer_formats(byteorders=byteorders):
1717
for code in integer_codes:
1818
for byteorder in byteorders:
19-
if (byteorder in ('', '@') and code in ('q', 'Q') and
20-
not HAVE_LONG_LONG):
21-
continue
2219
if (byteorder not in ('', '@') and code in ('n', 'N')):
2320
continue
2421
yield code, byteorder
2522

26-
# Native 'q' packing isn't available on systems that don't have the C
27-
# long long type.
28-
try:
29-
struct.pack('q', 5)
30-
except struct.error:
31-
HAVE_LONG_LONG = False
32-
else:
33-
HAVE_LONG_LONG = True
34-
3523
def string_reverse(s):
3624
return s[::-1]
3725

@@ -159,9 +147,7 @@ def test_calcsize(self):
159147
self.assertEqual(size, expected_size[code])
160148

161149
# native integer sizes
162-
native_pairs = 'bB', 'hH', 'iI', 'lL', 'nN'
163-
if HAVE_LONG_LONG:
164-
native_pairs += 'qQ',
150+
native_pairs = 'bB', 'hH', 'iI', 'lL', 'nN', 'qQ'
165151
for format_pair in native_pairs:
166152
for byteorder in '', '@':
167153
signed_size = struct.calcsize(byteorder + format_pair[0])
@@ -174,9 +160,8 @@ def test_calcsize(self):
174160
self.assertLessEqual(4, struct.calcsize('l'))
175161
self.assertLessEqual(struct.calcsize('h'), struct.calcsize('i'))
176162
self.assertLessEqual(struct.calcsize('i'), struct.calcsize('l'))
177-
if HAVE_LONG_LONG:
178-
self.assertLessEqual(8, struct.calcsize('q'))
179-
self.assertLessEqual(struct.calcsize('l'), struct.calcsize('q'))
163+
self.assertLessEqual(8, struct.calcsize('q'))
164+
self.assertLessEqual(struct.calcsize('l'), struct.calcsize('q'))
180165
self.assertGreaterEqual(struct.calcsize('n'), struct.calcsize('i'))
181166
self.assertGreaterEqual(struct.calcsize('n'), struct.calcsize('P'))
182167

Misc/NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.6.0 beta 1
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #27961?: Require platforms to support ``long long``. Python hasn't
14+
compiled without ``long long`` for years, so this is basically a formality.
15+
1316
- Issue #27355: Removed support for Windows CE. It was never finished,
1417
and Windows CE is no longer a relevant platform for Python.
1518

Modules/_ctypes/_ctypes_test.c

-3
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ EXPORT(int) _testfunc_callback_with_pointer(int (*func)(int *))
233233
return (*func)(table);
234234
}
235235

236-
#ifdef HAVE_LONG_LONG
237236
EXPORT(PY_LONG_LONG) _testfunc_q_bhilfdq(signed char b, short h, int i, long l, float f,
238237
double d, PY_LONG_LONG q)
239238
{
@@ -267,8 +266,6 @@ EXPORT(PY_LONG_LONG) _testfunc_callback_q_qf(PY_LONG_LONG value,
267266
return sum;
268267
}
269268

270-
#endif
271-
272269
typedef struct {
273270
char *name;
274271
char *value;

Modules/_ctypes/callproc.c

-4
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ PyCArg_repr(PyCArgObject *self)
474474
self->tag, self->value.l);
475475
break;
476476

477-
#ifdef HAVE_LONG_LONG
478477
case 'q':
479478
case 'Q':
480479
sprintf(buffer,
@@ -485,7 +484,6 @@ PyCArg_repr(PyCArgObject *self)
485484
#endif
486485
self->tag, self->value.q);
487486
break;
488-
#endif
489487
case 'd':
490488
sprintf(buffer, "<cparam '%c' (%f)>",
491489
self->tag, self->value.d);
@@ -593,9 +591,7 @@ union result {
593591
short h;
594592
int i;
595593
long l;
596-
#ifdef HAVE_LONG_LONG
597594
PY_LONG_LONG q;
598-
#endif
599595
long double D;
600596
double d;
601597
float f;

Modules/_ctypes/cfield.c

+1-13
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,6 @@ get_ulong(PyObject *v, unsigned long *p)
379379
return 0;
380380
}
381381

382-
#ifdef HAVE_LONG_LONG
383-
384382
/* Same, but handling native long long. */
385383

386384
static int
@@ -417,8 +415,6 @@ get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p)
417415
return 0;
418416
}
419417

420-
#endif
421-
422418
/*****************************************************************
423419
* Integer fields, with bitfield support
424420
*/
@@ -888,7 +884,6 @@ L_get_sw(void *ptr, Py_ssize_t size)
888884
return PyLong_FromUnsignedLong(val);
889885
}
890886

891-
#ifdef HAVE_LONG_LONG
892887
static PyObject *
893888
q_set(void *ptr, PyObject *value, Py_ssize_t size)
894889
{
@@ -982,7 +977,6 @@ Q_get_sw(void *ptr, Py_ssize_t size)
982977
GET_BITFIELD(val, size);
983978
return PyLong_FromUnsignedLongLong(val);
984979
}
985-
#endif
986980

987981
/*****************************************************************
988982
* non-integer accessor methods, not supporting bit fields
@@ -1490,9 +1484,7 @@ P_set(void *ptr, PyObject *value, Py_ssize_t size)
14901484
#if SIZEOF_VOID_P <= SIZEOF_LONG
14911485
v = (void *)PyLong_AsUnsignedLongMask(value);
14921486
#else
1493-
#ifndef HAVE_LONG_LONG
1494-
# error "PyLong_AsVoidPtr: sizeof(void*) > sizeof(long), but no long long"
1495-
#elif SIZEOF_LONG_LONG < SIZEOF_VOID_P
1487+
#if SIZEOF_LONG_LONG < SIZEOF_VOID_P
14961488
# error "PyLong_AsVoidPtr: sizeof(PY_LONG_LONG) < sizeof(void*)"
14971489
#endif
14981490
v = (void *)PyLong_AsUnsignedLongLongMask(value);
@@ -1538,13 +1530,11 @@ static struct fielddesc formattable[] = {
15381530
#else
15391531
# error
15401532
#endif
1541-
#ifdef HAVE_LONG_LONG
15421533
#if SIZEOF_LONG_LONG == 8
15431534
{ 'q', q_set, q_get, &ffi_type_sint64, q_set_sw, q_get_sw},
15441535
{ 'Q', Q_set, Q_get, &ffi_type_uint64, Q_set_sw, Q_get_sw},
15451536
#else
15461537
# error
1547-
#endif
15481538
#endif
15491539
{ 'P', P_set, P_get, &ffi_type_pointer},
15501540
{ 'z', z_set, z_get, &ffi_type_pointer},
@@ -1635,10 +1625,8 @@ typedef struct { char c; wchar_t *x; } s_wchar_p;
16351625
#endif
16361626
*/
16371627

1638-
#ifdef HAVE_LONG_LONG
16391628
typedef struct { char c; PY_LONG_LONG x; } s_long_long;
16401629
#define LONG_LONG_ALIGN (sizeof(s_long_long) - sizeof(PY_LONG_LONG))
1641-
#endif
16421630

16431631
/* from ffi.h:
16441632
typedef struct _ffi_type

Modules/_ctypes/ctypes.h

-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ union value {
3131
long l;
3232
float f;
3333
double d;
34-
#ifdef HAVE_LONG_LONG
3534
PY_LONG_LONG ll;
36-
#endif
3735
long double D;
3836
};
3937

@@ -303,9 +301,7 @@ struct tagPyCArgObject {
303301
short h;
304302
int i;
305303
long l;
306-
#ifdef HAVE_LONG_LONG
307304
PY_LONG_LONG q;
308-
#endif
309305
long double D;
310306
double d;
311307
float f;

Modules/_io/_iomodule.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ typedef off_t Py_off_t;
104104
# define PY_OFF_T_MIN PY_SSIZE_T_MIN
105105
# define PY_OFF_T_COMPAT Py_ssize_t
106106
# define PY_PRIdOFF "zd"
107-
#elif (HAVE_LONG_LONG && SIZEOF_OFF_T == SIZEOF_LONG_LONG)
107+
#elif (SIZEOF_OFF_T == SIZEOF_LONG_LONG)
108108
# define PyLong_AsOff_t PyLong_AsLongLong
109109
# define PyLong_FromOff_t PyLong_FromLongLong
110110
# define PY_OFF_T_MAX PY_LLONG_MAX

Modules/_lsprof.c

-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
#include "frameobject.h"
33
#include "rotatingtree.h"
44

5-
#if !defined(HAVE_LONG_LONG)
6-
#error "This module requires long longs!"
7-
#endif
8-
95
/*** Selection of a high-precision timer ***/
106

117
#ifdef MS_WINDOWS

Modules/_multiprocessing/multiprocessing.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#if SIZEOF_VOID_P == SIZEOF_LONG
6161
# define F_POINTER "k"
6262
# define T_POINTER T_ULONG
63-
#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P == SIZEOF_LONG_LONG)
63+
#elif SIZEOF_VOID_P == SIZEOF_LONG_LONG
6464
# define F_POINTER "K"
6565
# define T_POINTER T_ULONGLONG
6666
#else

Modules/_sqlite/util.c

-19
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ int _pysqlite_seterror(sqlite3* db, sqlite3_stmt* st)
113113
PyObject *
114114
_pysqlite_long_from_int64(sqlite_int64 value)
115115
{
116-
#ifdef HAVE_LONG_LONG
117116
# if SIZEOF_LONG_LONG < 8
118117
if (value > PY_LLONG_MAX || value < PY_LLONG_MIN) {
119118
return _PyLong_FromByteArray(&value, sizeof(value),
@@ -124,38 +123,20 @@ _pysqlite_long_from_int64(sqlite_int64 value)
124123
if (value > LONG_MAX || value < LONG_MIN)
125124
return PyLong_FromLongLong(value);
126125
# endif
127-
#else
128-
# if SIZEOF_LONG < 8
129-
if (value > LONG_MAX || value < LONG_MIN) {
130-
return _PyLong_FromByteArray(&value, sizeof(value),
131-
IS_LITTLE_ENDIAN, 1 /* signed */);
132-
}
133-
# endif
134-
#endif
135126
return PyLong_FromLong(Py_SAFE_DOWNCAST(value, sqlite_int64, long));
136127
}
137128

138129
sqlite_int64
139130
_pysqlite_long_as_int64(PyObject * py_val)
140131
{
141132
int overflow;
142-
#ifdef HAVE_LONG_LONG
143133
PY_LONG_LONG value = PyLong_AsLongLongAndOverflow(py_val, &overflow);
144-
#else
145-
long value = PyLong_AsLongAndOverflow(py_val, &overflow);
146-
#endif
147134
if (value == -1 && PyErr_Occurred())
148135
return -1;
149136
if (!overflow) {
150-
#ifdef HAVE_LONG_LONG
151137
# if SIZEOF_LONG_LONG > 8
152138
if (-0x8000000000000000LL <= value && value <= 0x7FFFFFFFFFFFFFFFLL)
153139
# endif
154-
#else
155-
# if SIZEOF_LONG > 8
156-
if (-0x8000000000000000L <= value && value <= 0x7FFFFFFFFFFFFFFFL)
157-
# endif
158-
#endif
159140
return value;
160141
}
161142
else if (sizeof(value) < sizeof(sqlite_int64)) {

0 commit comments

Comments
 (0)