diff options
author | Benjamin Peterson <benjamin@python.org> | 2016-09-06 20:24:00 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2016-09-06 20:24:00 (GMT) |
commit | 9b3d77052f58858ebe1f6ff0dd8dc1caf933cd62 (patch) | |
tree | 8a2fc78befc25702a9bf1f474644ef2ed2367138 /Modules | |
parent | 88bd3edb3e533ca426d633b97fad91d82aeb2b34 (diff) | |
download | cpython-9b3d77052f58858ebe1f6ff0dd8dc1caf933cd62.zip cpython-9b3d77052f58858ebe1f6ff0dd8dc1caf933cd62.tar.gz cpython-9b3d77052f58858ebe1f6ff0dd8dc1caf933cd62.tar.bz2 |
replace Python aliases for standard integer types with the standard integer types (#17884)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_randommodule.c | 44 | ||||
-rw-r--r-- | Modules/_testcapimodule.c | 16 | ||||
-rw-r--r-- | Modules/audioop.c | 8 |
3 files changed, 32 insertions, 36 deletions
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index fd6b230..63a060c 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -69,10 +69,6 @@ #include "Python.h" #include <time.h> /* for seeding to current time */ -#ifndef PY_UINT32_T -# error "Failed to find an exact-width 32-bit integer type" -#endif - /* Period parameters -- These are all magic. Don't change. */ #define N 624 #define M 397 @@ -83,7 +79,7 @@ typedef struct { PyObject_HEAD int index; - PY_UINT32_T state[N]; + uint32_t state[N]; } RandomObject; static PyTypeObject Random_Type; @@ -95,13 +91,13 @@ static PyTypeObject Random_Type; /* generates a random number on [0,0xffffffff]-interval */ -static PY_UINT32_T +static uint32_t genrand_int32(RandomObject *self) { - PY_UINT32_T y; - static const PY_UINT32_T mag01[2] = {0x0U, MATRIX_A}; + uint32_t y; + static const uint32_t mag01[2] = {0x0U, MATRIX_A}; /* mag01[x] = x * MATRIX_A for x=0,1 */ - PY_UINT32_T *mt; + uint32_t *mt; mt = self->state; if (self->index >= N) { /* generate N words at one time */ @@ -141,16 +137,16 @@ genrand_int32(RandomObject *self) static PyObject * random_random(RandomObject *self) { - PY_UINT32_T a=genrand_int32(self)>>5, b=genrand_int32(self)>>6; + uint32_t a=genrand_int32(self)>>5, b=genrand_int32(self)>>6; return PyFloat_FromDouble((a*67108864.0+b)*(1.0/9007199254740992.0)); } /* initializes mt[N] with a seed */ static void -init_genrand(RandomObject *self, PY_UINT32_T s) +init_genrand(RandomObject *self, uint32_t s) { int mti; - PY_UINT32_T *mt; + uint32_t *mt; mt = self->state; mt[0]= s; @@ -170,10 +166,10 @@ init_genrand(RandomObject *self, PY_UINT32_T s) /* init_key is the array for initializing keys */ /* key_length is its length */ static PyObject * -init_by_array(RandomObject *self, PY_UINT32_T init_key[], size_t key_length) +init_by_array(RandomObject *self, uint32_t init_key[], size_t key_length) { size_t i, j, k; /* was signed in the original code. RDH 12/16/2002 */ - PY_UINT32_T *mt; + uint32_t *mt; mt = self->state; init_genrand(self, 19650218U); @@ -181,14 +177,14 @@ init_by_array(RandomObject *self, PY_UINT32_T init_key[], size_t key_length) k = (N>key_length ? N : key_length); for (; k; k--) { mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525U)) - + init_key[j] + (PY_UINT32_T)j; /* non linear */ + + init_key[j] + (uint32_t)j; /* non linear */ i++; j++; if (i>=N) { mt[0] = mt[N-1]; i=1; } if (j>=key_length) j=0; } for (k=N-1; k; k--) { mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941U)) - - (PY_UINT32_T)i; /* non linear */ + - (uint32_t)i; /* non linear */ i++; if (i>=N) { mt[0] = mt[N-1]; i=1; } } @@ -208,7 +204,7 @@ random_seed(RandomObject *self, PyObject *args) { PyObject *result = NULL; /* guilty until proved innocent */ PyObject *n = NULL; - PY_UINT32_T *key = NULL; + uint32_t *key = NULL; size_t bits, keyused; int res; PyObject *arg = NULL; @@ -220,7 +216,7 @@ random_seed(RandomObject *self, PyObject *args) time_t now; time(&now); - init_genrand(self, (PY_UINT32_T)now); + init_genrand(self, (uint32_t)now); Py_INCREF(Py_None); return Py_None; } @@ -248,7 +244,7 @@ random_seed(RandomObject *self, PyObject *args) keyused = bits == 0 ? 1 : (bits - 1) / 32 + 1; /* Convert seed to byte sequence. */ - key = (PY_UINT32_T *)PyMem_Malloc((size_t)4 * keyused); + key = (uint32_t *)PyMem_Malloc((size_t)4 * keyused); if (key == NULL) { PyErr_NoMemory(); goto Done; @@ -267,7 +263,7 @@ random_seed(RandomObject *self, PyObject *args) size_t i, j; /* Reverse an array. */ for (i = 0, j = keyused - 1; i < j; i++, j--) { - PY_UINT32_T tmp = key[i]; + uint32_t tmp = key[i]; key[i] = key[j]; key[j] = tmp; } @@ -329,7 +325,7 @@ random_setstate(RandomObject *self, PyObject *state) element = PyLong_AsUnsignedLong(PyTuple_GET_ITEM(state, i)); if (element == (unsigned long)-1 && PyErr_Occurred()) return NULL; - self->state[i] = (PY_UINT32_T)element; + self->state[i] = (uint32_t)element; } index = PyLong_AsLong(PyTuple_GET_ITEM(state, i)); @@ -349,8 +345,8 @@ static PyObject * random_getrandbits(RandomObject *self, PyObject *args) { int k, i, words; - PY_UINT32_T r; - PY_UINT32_T *wordarray; + uint32_t r; + uint32_t *wordarray; PyObject *result; if (!PyArg_ParseTuple(args, "i:getrandbits", &k)) @@ -366,7 +362,7 @@ random_getrandbits(RandomObject *self, PyObject *args) return PyLong_FromUnsignedLong(genrand_int32(self) >> (32 - k)); words = (k - 1) / 32 + 1; - wordarray = (PY_UINT32_T *)PyMem_Malloc(words * 4); + wordarray = (uint32_t *)PyMem_Malloc(words * 4); if (wordarray == NULL) { PyErr_NoMemory(); return NULL; diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 290797f..8d2cf31 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -98,14 +98,14 @@ test_sizeof_c_types(PyObject *self) CHECK_SIGNNESS(Py_UCS1, 0); CHECK_SIGNNESS(Py_UCS2, 0); CHECK_SIGNNESS(Py_UCS4, 0); - CHECK_SIZEOF(PY_INT32_T, 4); - CHECK_SIGNNESS(PY_INT32_T, 1); - CHECK_SIZEOF(PY_UINT32_T, 4); - CHECK_SIGNNESS(PY_UINT32_T, 0); - CHECK_SIZEOF(PY_INT64_T, 8); - CHECK_SIGNNESS(PY_INT64_T, 1); - CHECK_SIZEOF(PY_UINT64_T, 8); - CHECK_SIGNNESS(PY_UINT64_T, 0); + CHECK_SIZEOF(int32_t, 4); + CHECK_SIGNNESS(int32_t, 1); + CHECK_SIZEOF(uint32_t, 4); + CHECK_SIGNNESS(uint32_t, 0); + CHECK_SIZEOF(int64_t, 8); + CHECK_SIGNNESS(int64_t, 1); + CHECK_SIZEOF(uint64_t, 8); + CHECK_SIGNNESS(uint64_t, 0); /* pointer/size types */ CHECK_SIZEOF(size_t, sizeof(void *)); diff --git a/Modules/audioop.c b/Modules/audioop.c index ed1eca3..c11506c 100644 --- a/Modules/audioop.c +++ b/Modules/audioop.c @@ -297,7 +297,7 @@ static const int stepsizeTable[89] = { #define GETINT8(cp, i) GETINTX(signed char, (cp), (i)) #define GETINT16(cp, i) GETINTX(short, (cp), (i)) -#define GETINT32(cp, i) GETINTX(PY_INT32_T, (cp), (i)) +#define GETINT32(cp, i) GETINTX(int32_t, (cp), (i)) #if WORDS_BIGENDIAN #define GETINT24(cp, i) ( \ @@ -314,7 +314,7 @@ static const int stepsizeTable[89] = { #define SETINT8(cp, i, val) SETINTX(signed char, (cp), (i), (val)) #define SETINT16(cp, i, val) SETINTX(short, (cp), (i), (val)) -#define SETINT32(cp, i, val) SETINTX(PY_INT32_T, (cp), (i), (val)) +#define SETINT32(cp, i, val) SETINTX(int32_t, (cp), (i), (val)) #if WORDS_BIGENDIAN #define SETINT24(cp, i, val) do { \ @@ -1129,7 +1129,7 @@ audioop_bias_impl(PyObject *module, Py_buffer *fragment, int width, int bias) val = ((unsigned int)GETINT24(fragment->buf, i)) & 0xffffffu; else { assert(width == 4); - val = GETINTX(PY_UINT32_T, fragment->buf, i); + val = GETINTX(uint32_t, fragment->buf, i); } val += (unsigned int)bias; @@ -1144,7 +1144,7 @@ audioop_bias_impl(PyObject *module, Py_buffer *fragment, int width, int bias) SETINT24(ncp, i, (int)val); else { assert(width == 4); - SETINTX(PY_UINT32_T, ncp, i, val); + SETINTX(uint32_t, ncp, i, val); } } return rv; |