Skip to content

Commit 9b3d770

Browse files
committed
replace Python aliases for standard integer types with the standard integer types (python#17884)
1 parent 88bd3ed commit 9b3d770

8 files changed

Lines changed: 72 additions & 87 deletions

File tree

Include/longintrepr.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ extern "C" {
4242
*/
4343

4444
#if PYLONG_BITS_IN_DIGIT == 30
45-
typedef PY_UINT32_T digit;
46-
typedef PY_INT32_T sdigit; /* signed variant of digit */
47-
typedef PY_UINT64_T twodigits;
48-
typedef PY_INT64_T stwodigits; /* signed variant of twodigits */
45+
typedef uint32_t digit;
46+
typedef int32_t sdigit; /* signed variant of digit */
47+
typedef uint64_t twodigits;
48+
typedef int64_t stwodigits; /* signed variant of twodigits */
4949
#define PyLong_SHIFT 30
5050
#define _PyLong_DECIMAL_SHIFT 9 /* max(e such that 10**e fits in a digit) */
5151
#define _PyLong_DECIMAL_BASE ((digit)1000000000) /* 10 ** DECIMAL_SHIFT */

Include/pyhash.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ PyAPI_FUNC(Py_hash_t) _Py_HashBytes(const void*, Py_ssize_t);
3636
* memory layout on 64 bit systems
3737
* cccccccc cccccccc cccccccc uc -- unsigned char[24]
3838
* pppppppp ssssssss ........ fnv -- two Py_hash_t
39-
* k0k0k0k0 k1k1k1k1 ........ siphash -- two PY_UINT64_T
39+
* k0k0k0k0 k1k1k1k1 ........ siphash -- two uint64_t
4040
* ........ ........ ssssssss djbx33a -- 16 bytes padding + one Py_hash_t
4141
* ........ ........ eeeeeeee pyexpat XML hash salt
4242
*
4343
* memory layout on 32 bit systems
4444
* cccccccc cccccccc cccccccc uc
4545
* ppppssss ........ ........ fnv -- two Py_hash_t
46-
* k0k0k0k0 k1k1k1k1 ........ siphash -- two PY_UINT64_T (*)
46+
* k0k0k0k0 k1k1k1k1 ........ siphash -- two uint64_t (*)
4747
* ........ ........ ssss.... djbx33a -- 16 bytes padding + one Py_hash_t
4848
* ........ ........ eeee.... pyexpat XML hash salt
4949
*
@@ -59,13 +59,11 @@ typedef union {
5959
Py_hash_t prefix;
6060
Py_hash_t suffix;
6161
} fnv;
62-
#ifdef PY_UINT64_T
6362
/* two uint64 for SipHash24 */
6463
struct {
65-
PY_UINT64_T k0;
66-
PY_UINT64_T k1;
64+
uint64_t k0;
65+
uint64_t k1;
6766
} siphash;
68-
#endif
6967
/* a different (!) Py_hash_t for small string optimization */
7068
struct {
7169
unsigned char padding[16];
@@ -121,8 +119,7 @@ PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void);
121119
* configure script.
122120
*
123121
* - FNV is available on all platforms and architectures.
124-
* - SIPHASH24 only works on plaforms that provide PY_UINT64_T and doesn't
125-
* require aligned memory for integers.
122+
* - SIPHASH24 only works on plaforms that don't require aligned memory for integers.
126123
* - With EXTERNAL embedders can provide an alternative implementation with::
127124
*
128125
* PyHash_FuncDef PyHash_Func = {...};
@@ -134,8 +131,7 @@ PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void);
134131
#define Py_HASH_FNV 2
135132

136133
#ifndef Py_HASH_ALGORITHM
137-
# if (defined(PY_UINT64_T) && defined(PY_UINT32_T) \
138-
&& !defined(HAVE_ALIGNED_REQUIRED))
134+
# ifndef HAVE_ALIGNED_REQUIRED
139135
# define Py_HASH_ALGORITHM Py_HASH_SIPHASH24
140136
# else
141137
# define Py_HASH_ALGORITHM Py_HASH_FNV

Include/pytime.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,12 @@ functions and constants
1313
extern "C" {
1414
#endif
1515

16-
#ifdef PY_INT64_T
1716
/* _PyTime_t: Python timestamp with subsecond precision. It can be used to
1817
store a duration, and so indirectly a date (related to another date, like
1918
UNIX epoch). */
20-
typedef PY_INT64_T _PyTime_t;
19+
typedef int64_t _PyTime_t;
2120
#define _PyTime_MIN PY_LLONG_MIN
2221
#define _PyTime_MAX PY_LLONG_MAX
23-
#else
24-
# error "_PyTime_t need signed 64-bit integer type"
25-
#endif
2622

2723
typedef enum {
2824
/* Round towards minus infinity (-inf).

Modules/_randommodule.c

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@
6969
#include "Python.h"
7070
#include <time.h> /* for seeding to current time */
7171

72-
#ifndef PY_UINT32_T
73-
# error "Failed to find an exact-width 32-bit integer type"
74-
#endif
75-
7672
/* Period parameters -- These are all magic. Don't change. */
7773
#define N 624
7874
#define M 397
@@ -83,7 +79,7 @@
8379
typedef struct {
8480
PyObject_HEAD
8581
int index;
86-
PY_UINT32_T state[N];
82+
uint32_t state[N];
8783
} RandomObject;
8884

8985
static PyTypeObject Random_Type;
@@ -95,13 +91,13 @@ static PyTypeObject Random_Type;
9591

9692

9793
/* generates a random number on [0,0xffffffff]-interval */
98-
static PY_UINT32_T
94+
static uint32_t
9995
genrand_int32(RandomObject *self)
10096
{
101-
PY_UINT32_T y;
102-
static const PY_UINT32_T mag01[2] = {0x0U, MATRIX_A};
97+
uint32_t y;
98+
static const uint32_t mag01[2] = {0x0U, MATRIX_A};
10399
/* mag01[x] = x * MATRIX_A for x=0,1 */
104-
PY_UINT32_T *mt;
100+
uint32_t *mt;
105101

106102
mt = self->state;
107103
if (self->index >= N) { /* generate N words at one time */
@@ -141,16 +137,16 @@ genrand_int32(RandomObject *self)
141137
static PyObject *
142138
random_random(RandomObject *self)
143139
{
144-
PY_UINT32_T a=genrand_int32(self)>>5, b=genrand_int32(self)>>6;
140+
uint32_t a=genrand_int32(self)>>5, b=genrand_int32(self)>>6;
145141
return PyFloat_FromDouble((a*67108864.0+b)*(1.0/9007199254740992.0));
146142
}
147143

148144
/* initializes mt[N] with a seed */
149145
static void
150-
init_genrand(RandomObject *self, PY_UINT32_T s)
146+
init_genrand(RandomObject *self, uint32_t s)
151147
{
152148
int mti;
153-
PY_UINT32_T *mt;
149+
uint32_t *mt;
154150

155151
mt = self->state;
156152
mt[0]= s;
@@ -170,25 +166,25 @@ init_genrand(RandomObject *self, PY_UINT32_T s)
170166
/* init_key is the array for initializing keys */
171167
/* key_length is its length */
172168
static PyObject *
173-
init_by_array(RandomObject *self, PY_UINT32_T init_key[], size_t key_length)
169+
init_by_array(RandomObject *self, uint32_t init_key[], size_t key_length)
174170
{
175171
size_t i, j, k; /* was signed in the original code. RDH 12/16/2002 */
176-
PY_UINT32_T *mt;
172+
uint32_t *mt;
177173

178174
mt = self->state;
179175
init_genrand(self, 19650218U);
180176
i=1; j=0;
181177
k = (N>key_length ? N : key_length);
182178
for (; k; k--) {
183179
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525U))
184-
+ init_key[j] + (PY_UINT32_T)j; /* non linear */
180+
+ init_key[j] + (uint32_t)j; /* non linear */
185181
i++; j++;
186182
if (i>=N) { mt[0] = mt[N-1]; i=1; }
187183
if (j>=key_length) j=0;
188184
}
189185
for (k=N-1; k; k--) {
190186
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941U))
191-
- (PY_UINT32_T)i; /* non linear */
187+
- (uint32_t)i; /* non linear */
192188
i++;
193189
if (i>=N) { mt[0] = mt[N-1]; i=1; }
194190
}
@@ -208,7 +204,7 @@ random_seed(RandomObject *self, PyObject *args)
208204
{
209205
PyObject *result = NULL; /* guilty until proved innocent */
210206
PyObject *n = NULL;
211-
PY_UINT32_T *key = NULL;
207+
uint32_t *key = NULL;
212208
size_t bits, keyused;
213209
int res;
214210
PyObject *arg = NULL;
@@ -220,7 +216,7 @@ random_seed(RandomObject *self, PyObject *args)
220216
time_t now;
221217

222218
time(&now);
223-
init_genrand(self, (PY_UINT32_T)now);
219+
init_genrand(self, (uint32_t)now);
224220
Py_INCREF(Py_None);
225221
return Py_None;
226222
}
@@ -248,7 +244,7 @@ random_seed(RandomObject *self, PyObject *args)
248244
keyused = bits == 0 ? 1 : (bits - 1) / 32 + 1;
249245

250246
/* Convert seed to byte sequence. */
251-
key = (PY_UINT32_T *)PyMem_Malloc((size_t)4 * keyused);
247+
key = (uint32_t *)PyMem_Malloc((size_t)4 * keyused);
252248
if (key == NULL) {
253249
PyErr_NoMemory();
254250
goto Done;
@@ -267,7 +263,7 @@ random_seed(RandomObject *self, PyObject *args)
267263
size_t i, j;
268264
/* Reverse an array. */
269265
for (i = 0, j = keyused - 1; i < j; i++, j--) {
270-
PY_UINT32_T tmp = key[i];
266+
uint32_t tmp = key[i];
271267
key[i] = key[j];
272268
key[j] = tmp;
273269
}
@@ -329,7 +325,7 @@ random_setstate(RandomObject *self, PyObject *state)
329325
element = PyLong_AsUnsignedLong(PyTuple_GET_ITEM(state, i));
330326
if (element == (unsigned long)-1 && PyErr_Occurred())
331327
return NULL;
332-
self->state[i] = (PY_UINT32_T)element;
328+
self->state[i] = (uint32_t)element;
333329
}
334330

335331
index = PyLong_AsLong(PyTuple_GET_ITEM(state, i));
@@ -349,8 +345,8 @@ static PyObject *
349345
random_getrandbits(RandomObject *self, PyObject *args)
350346
{
351347
int k, i, words;
352-
PY_UINT32_T r;
353-
PY_UINT32_T *wordarray;
348+
uint32_t r;
349+
uint32_t *wordarray;
354350
PyObject *result;
355351

356352
if (!PyArg_ParseTuple(args, "i:getrandbits", &k))
@@ -366,7 +362,7 @@ random_getrandbits(RandomObject *self, PyObject *args)
366362
return PyLong_FromUnsignedLong(genrand_int32(self) >> (32 - k));
367363

368364
words = (k - 1) / 32 + 1;
369-
wordarray = (PY_UINT32_T *)PyMem_Malloc(words * 4);
365+
wordarray = (uint32_t *)PyMem_Malloc(words * 4);
370366
if (wordarray == NULL) {
371367
PyErr_NoMemory();
372368
return NULL;

Modules/_testcapimodule.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ test_sizeof_c_types(PyObject *self)
9898
CHECK_SIGNNESS(Py_UCS1, 0);
9999
CHECK_SIGNNESS(Py_UCS2, 0);
100100
CHECK_SIGNNESS(Py_UCS4, 0);
101-
CHECK_SIZEOF(PY_INT32_T, 4);
102-
CHECK_SIGNNESS(PY_INT32_T, 1);
103-
CHECK_SIZEOF(PY_UINT32_T, 4);
104-
CHECK_SIGNNESS(PY_UINT32_T, 0);
105-
CHECK_SIZEOF(PY_INT64_T, 8);
106-
CHECK_SIGNNESS(PY_INT64_T, 1);
107-
CHECK_SIZEOF(PY_UINT64_T, 8);
108-
CHECK_SIGNNESS(PY_UINT64_T, 0);
101+
CHECK_SIZEOF(int32_t, 4);
102+
CHECK_SIGNNESS(int32_t, 1);
103+
CHECK_SIZEOF(uint32_t, 4);
104+
CHECK_SIGNNESS(uint32_t, 0);
105+
CHECK_SIZEOF(int64_t, 8);
106+
CHECK_SIGNNESS(int64_t, 1);
107+
CHECK_SIZEOF(uint64_t, 8);
108+
CHECK_SIGNNESS(uint64_t, 0);
109109

110110
/* pointer/size types */
111111
CHECK_SIZEOF(size_t, sizeof(void *));

Modules/audioop.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static const int stepsizeTable[89] = {
297297

298298
#define GETINT8(cp, i) GETINTX(signed char, (cp), (i))
299299
#define GETINT16(cp, i) GETINTX(short, (cp), (i))
300-
#define GETINT32(cp, i) GETINTX(PY_INT32_T, (cp), (i))
300+
#define GETINT32(cp, i) GETINTX(int32_t, (cp), (i))
301301

302302
#if WORDS_BIGENDIAN
303303
#define GETINT24(cp, i) ( \
@@ -314,7 +314,7 @@ static const int stepsizeTable[89] = {
314314

315315
#define SETINT8(cp, i, val) SETINTX(signed char, (cp), (i), (val))
316316
#define SETINT16(cp, i, val) SETINTX(short, (cp), (i), (val))
317-
#define SETINT32(cp, i, val) SETINTX(PY_INT32_T, (cp), (i), (val))
317+
#define SETINT32(cp, i, val) SETINTX(int32_t, (cp), (i), (val))
318318

319319
#if WORDS_BIGENDIAN
320320
#define SETINT24(cp, i, val) do { \
@@ -1129,7 +1129,7 @@ audioop_bias_impl(PyObject *module, Py_buffer *fragment, int width, int bias)
11291129
val = ((unsigned int)GETINT24(fragment->buf, i)) & 0xffffffu;
11301130
else {
11311131
assert(width == 4);
1132-
val = GETINTX(PY_UINT32_T, fragment->buf, i);
1132+
val = GETINTX(uint32_t, fragment->buf, i);
11331133
}
11341134

11351135
val += (unsigned int)bias;
@@ -1144,7 +1144,7 @@ audioop_bias_impl(PyObject *module, Py_buffer *fragment, int width, int bias)
11441144
SETINT24(ncp, i, (int)val);
11451145
else {
11461146
assert(width == 4);
1147-
SETINTX(PY_UINT32_T, ncp, i, val);
1147+
SETINTX(uint32_t, ncp, i, val);
11481148
}
11491149
}
11501150
return rv;

Objects/unicodeobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5330,7 +5330,7 @@ _PyUnicode_EncodeUTF32(PyObject *str,
53305330
const void *data;
53315331
Py_ssize_t len;
53325332
PyObject *v;
5333-
PY_UINT32_T *out;
5333+
uint32_t *out;
53345334
#if PY_LITTLE_ENDIAN
53355335
int native_ordering = byteorder <= 0;
53365336
#else
@@ -5361,7 +5361,7 @@ _PyUnicode_EncodeUTF32(PyObject *str,
53615361

53625362
/* output buffer is 4-bytes aligned */
53635363
assert(_Py_IS_ALIGNED(PyBytes_AS_STRING(v), 4));
5364-
out = (PY_UINT32_T *)PyBytes_AS_STRING(v);
5364+
out = (uint32_t *)PyBytes_AS_STRING(v);
53655365
if (byteorder == 0)
53665366
*out++ = 0xFEFF;
53675367
if (len == 0)
@@ -5427,7 +5427,7 @@ _PyUnicode_EncodeUTF32(PyObject *str,
54275427

54285428
/* four bytes are reserved for each surrogate */
54295429
if (moreunits > 1) {
5430-
Py_ssize_t outpos = out - (PY_UINT32_T*) PyBytes_AS_STRING(v);
5430+
Py_ssize_t outpos = out - (uint32_t*) PyBytes_AS_STRING(v);
54315431
Py_ssize_t morebytes = 4 * (moreunits - 1);
54325432
if (PyBytes_GET_SIZE(v) > PY_SSIZE_T_MAX - morebytes) {
54335433
/* integer overflow */
@@ -5436,7 +5436,7 @@ _PyUnicode_EncodeUTF32(PyObject *str,
54365436
}
54375437
if (_PyBytes_Resize(&v, PyBytes_GET_SIZE(v) + morebytes) < 0)
54385438
goto error;
5439-
out = (PY_UINT32_T*) PyBytes_AS_STRING(v) + outpos;
5439+
out = (uint32_t*) PyBytes_AS_STRING(v) + outpos;
54405440
}
54415441

54425442
if (PyBytes_Check(rep)) {

0 commit comments

Comments
 (0)