replace Python aliases for standard integer types with the standard integer types (#17884)
This commit is contained in:
parent
88bd3edb3e
commit
9b3d77052f
|
@ -42,10 +42,10 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if PYLONG_BITS_IN_DIGIT == 30
|
#if PYLONG_BITS_IN_DIGIT == 30
|
||||||
typedef PY_UINT32_T digit;
|
typedef uint32_t digit;
|
||||||
typedef PY_INT32_T sdigit; /* signed variant of digit */
|
typedef int32_t sdigit; /* signed variant of digit */
|
||||||
typedef PY_UINT64_T twodigits;
|
typedef uint64_t twodigits;
|
||||||
typedef PY_INT64_T stwodigits; /* signed variant of twodigits */
|
typedef int64_t stwodigits; /* signed variant of twodigits */
|
||||||
#define PyLong_SHIFT 30
|
#define PyLong_SHIFT 30
|
||||||
#define _PyLong_DECIMAL_SHIFT 9 /* max(e such that 10**e fits in a digit) */
|
#define _PyLong_DECIMAL_SHIFT 9 /* max(e such that 10**e fits in a digit) */
|
||||||
#define _PyLong_DECIMAL_BASE ((digit)1000000000) /* 10 ** DECIMAL_SHIFT */
|
#define _PyLong_DECIMAL_BASE ((digit)1000000000) /* 10 ** DECIMAL_SHIFT */
|
||||||
|
|
|
@ -36,14 +36,14 @@ PyAPI_FUNC(Py_hash_t) _Py_HashBytes(const void*, Py_ssize_t);
|
||||||
* memory layout on 64 bit systems
|
* memory layout on 64 bit systems
|
||||||
* cccccccc cccccccc cccccccc uc -- unsigned char[24]
|
* cccccccc cccccccc cccccccc uc -- unsigned char[24]
|
||||||
* pppppppp ssssssss ........ fnv -- two Py_hash_t
|
* pppppppp ssssssss ........ fnv -- two Py_hash_t
|
||||||
* k0k0k0k0 k1k1k1k1 ........ siphash -- two PY_UINT64_T
|
* k0k0k0k0 k1k1k1k1 ........ siphash -- two uint64_t
|
||||||
* ........ ........ ssssssss djbx33a -- 16 bytes padding + one Py_hash_t
|
* ........ ........ ssssssss djbx33a -- 16 bytes padding + one Py_hash_t
|
||||||
* ........ ........ eeeeeeee pyexpat XML hash salt
|
* ........ ........ eeeeeeee pyexpat XML hash salt
|
||||||
*
|
*
|
||||||
* memory layout on 32 bit systems
|
* memory layout on 32 bit systems
|
||||||
* cccccccc cccccccc cccccccc uc
|
* cccccccc cccccccc cccccccc uc
|
||||||
* ppppssss ........ ........ fnv -- two Py_hash_t
|
* ppppssss ........ ........ fnv -- two Py_hash_t
|
||||||
* k0k0k0k0 k1k1k1k1 ........ siphash -- two PY_UINT64_T (*)
|
* k0k0k0k0 k1k1k1k1 ........ siphash -- two uint64_t (*)
|
||||||
* ........ ........ ssss.... djbx33a -- 16 bytes padding + one Py_hash_t
|
* ........ ........ ssss.... djbx33a -- 16 bytes padding + one Py_hash_t
|
||||||
* ........ ........ eeee.... pyexpat XML hash salt
|
* ........ ........ eeee.... pyexpat XML hash salt
|
||||||
*
|
*
|
||||||
|
@ -59,13 +59,11 @@ typedef union {
|
||||||
Py_hash_t prefix;
|
Py_hash_t prefix;
|
||||||
Py_hash_t suffix;
|
Py_hash_t suffix;
|
||||||
} fnv;
|
} fnv;
|
||||||
#ifdef PY_UINT64_T
|
|
||||||
/* two uint64 for SipHash24 */
|
/* two uint64 for SipHash24 */
|
||||||
struct {
|
struct {
|
||||||
PY_UINT64_T k0;
|
uint64_t k0;
|
||||||
PY_UINT64_T k1;
|
uint64_t k1;
|
||||||
} siphash;
|
} siphash;
|
||||||
#endif
|
|
||||||
/* a different (!) Py_hash_t for small string optimization */
|
/* a different (!) Py_hash_t for small string optimization */
|
||||||
struct {
|
struct {
|
||||||
unsigned char padding[16];
|
unsigned char padding[16];
|
||||||
|
@ -121,8 +119,7 @@ PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void);
|
||||||
* configure script.
|
* configure script.
|
||||||
*
|
*
|
||||||
* - FNV is available on all platforms and architectures.
|
* - FNV is available on all platforms and architectures.
|
||||||
* - SIPHASH24 only works on plaforms that provide PY_UINT64_T and doesn't
|
* - SIPHASH24 only works on plaforms that don't require aligned memory for integers.
|
||||||
* require aligned memory for integers.
|
|
||||||
* - With EXTERNAL embedders can provide an alternative implementation with::
|
* - With EXTERNAL embedders can provide an alternative implementation with::
|
||||||
*
|
*
|
||||||
* PyHash_FuncDef PyHash_Func = {...};
|
* PyHash_FuncDef PyHash_Func = {...};
|
||||||
|
@ -134,8 +131,7 @@ PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void);
|
||||||
#define Py_HASH_FNV 2
|
#define Py_HASH_FNV 2
|
||||||
|
|
||||||
#ifndef Py_HASH_ALGORITHM
|
#ifndef Py_HASH_ALGORITHM
|
||||||
# if (defined(PY_UINT64_T) && defined(PY_UINT32_T) \
|
# ifndef HAVE_ALIGNED_REQUIRED
|
||||||
&& !defined(HAVE_ALIGNED_REQUIRED))
|
|
||||||
# define Py_HASH_ALGORITHM Py_HASH_SIPHASH24
|
# define Py_HASH_ALGORITHM Py_HASH_SIPHASH24
|
||||||
# else
|
# else
|
||||||
# define Py_HASH_ALGORITHM Py_HASH_FNV
|
# define Py_HASH_ALGORITHM Py_HASH_FNV
|
||||||
|
|
|
@ -13,16 +13,12 @@ functions and constants
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PY_INT64_T
|
|
||||||
/* _PyTime_t: Python timestamp with subsecond precision. It can be used to
|
/* _PyTime_t: Python timestamp with subsecond precision. It can be used to
|
||||||
store a duration, and so indirectly a date (related to another date, like
|
store a duration, and so indirectly a date (related to another date, like
|
||||||
UNIX epoch). */
|
UNIX epoch). */
|
||||||
typedef PY_INT64_T _PyTime_t;
|
typedef int64_t _PyTime_t;
|
||||||
#define _PyTime_MIN PY_LLONG_MIN
|
#define _PyTime_MIN PY_LLONG_MIN
|
||||||
#define _PyTime_MAX PY_LLONG_MAX
|
#define _PyTime_MAX PY_LLONG_MAX
|
||||||
#else
|
|
||||||
# error "_PyTime_t need signed 64-bit integer type"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
/* Round towards minus infinity (-inf).
|
/* Round towards minus infinity (-inf).
|
||||||
|
|
|
@ -69,10 +69,6 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include <time.h> /* for seeding to current time */
|
#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. */
|
/* Period parameters -- These are all magic. Don't change. */
|
||||||
#define N 624
|
#define N 624
|
||||||
#define M 397
|
#define M 397
|
||||||
|
@ -83,7 +79,7 @@
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
int index;
|
int index;
|
||||||
PY_UINT32_T state[N];
|
uint32_t state[N];
|
||||||
} RandomObject;
|
} RandomObject;
|
||||||
|
|
||||||
static PyTypeObject Random_Type;
|
static PyTypeObject Random_Type;
|
||||||
|
@ -95,13 +91,13 @@ static PyTypeObject Random_Type;
|
||||||
|
|
||||||
|
|
||||||
/* generates a random number on [0,0xffffffff]-interval */
|
/* generates a random number on [0,0xffffffff]-interval */
|
||||||
static PY_UINT32_T
|
static uint32_t
|
||||||
genrand_int32(RandomObject *self)
|
genrand_int32(RandomObject *self)
|
||||||
{
|
{
|
||||||
PY_UINT32_T y;
|
uint32_t y;
|
||||||
static const PY_UINT32_T mag01[2] = {0x0U, MATRIX_A};
|
static const uint32_t mag01[2] = {0x0U, MATRIX_A};
|
||||||
/* mag01[x] = x * MATRIX_A for x=0,1 */
|
/* mag01[x] = x * MATRIX_A for x=0,1 */
|
||||||
PY_UINT32_T *mt;
|
uint32_t *mt;
|
||||||
|
|
||||||
mt = self->state;
|
mt = self->state;
|
||||||
if (self->index >= N) { /* generate N words at one time */
|
if (self->index >= N) { /* generate N words at one time */
|
||||||
|
@ -141,16 +137,16 @@ genrand_int32(RandomObject *self)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
random_random(RandomObject *self)
|
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));
|
return PyFloat_FromDouble((a*67108864.0+b)*(1.0/9007199254740992.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initializes mt[N] with a seed */
|
/* initializes mt[N] with a seed */
|
||||||
static void
|
static void
|
||||||
init_genrand(RandomObject *self, PY_UINT32_T s)
|
init_genrand(RandomObject *self, uint32_t s)
|
||||||
{
|
{
|
||||||
int mti;
|
int mti;
|
||||||
PY_UINT32_T *mt;
|
uint32_t *mt;
|
||||||
|
|
||||||
mt = self->state;
|
mt = self->state;
|
||||||
mt[0]= s;
|
mt[0]= s;
|
||||||
|
@ -170,10 +166,10 @@ init_genrand(RandomObject *self, PY_UINT32_T s)
|
||||||
/* init_key is the array for initializing keys */
|
/* init_key is the array for initializing keys */
|
||||||
/* key_length is its length */
|
/* key_length is its length */
|
||||||
static PyObject *
|
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 */
|
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;
|
mt = self->state;
|
||||||
init_genrand(self, 19650218U);
|
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);
|
k = (N>key_length ? N : key_length);
|
||||||
for (; k; k--) {
|
for (; k; k--) {
|
||||||
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525U))
|
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++;
|
i++; j++;
|
||||||
if (i>=N) { mt[0] = mt[N-1]; i=1; }
|
if (i>=N) { mt[0] = mt[N-1]; i=1; }
|
||||||
if (j>=key_length) j=0;
|
if (j>=key_length) j=0;
|
||||||
}
|
}
|
||||||
for (k=N-1; k; k--) {
|
for (k=N-1; k; k--) {
|
||||||
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941U))
|
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941U))
|
||||||
- (PY_UINT32_T)i; /* non linear */
|
- (uint32_t)i; /* non linear */
|
||||||
i++;
|
i++;
|
||||||
if (i>=N) { mt[0] = mt[N-1]; i=1; }
|
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 *result = NULL; /* guilty until proved innocent */
|
||||||
PyObject *n = NULL;
|
PyObject *n = NULL;
|
||||||
PY_UINT32_T *key = NULL;
|
uint32_t *key = NULL;
|
||||||
size_t bits, keyused;
|
size_t bits, keyused;
|
||||||
int res;
|
int res;
|
||||||
PyObject *arg = NULL;
|
PyObject *arg = NULL;
|
||||||
|
@ -220,7 +216,7 @@ random_seed(RandomObject *self, PyObject *args)
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
time(&now);
|
time(&now);
|
||||||
init_genrand(self, (PY_UINT32_T)now);
|
init_genrand(self, (uint32_t)now);
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
@ -248,7 +244,7 @@ random_seed(RandomObject *self, PyObject *args)
|
||||||
keyused = bits == 0 ? 1 : (bits - 1) / 32 + 1;
|
keyused = bits == 0 ? 1 : (bits - 1) / 32 + 1;
|
||||||
|
|
||||||
/* Convert seed to byte sequence. */
|
/* 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) {
|
if (key == NULL) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
goto Done;
|
goto Done;
|
||||||
|
@ -267,7 +263,7 @@ random_seed(RandomObject *self, PyObject *args)
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
/* Reverse an array. */
|
/* Reverse an array. */
|
||||||
for (i = 0, j = keyused - 1; i < j; i++, j--) {
|
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[i] = key[j];
|
||||||
key[j] = tmp;
|
key[j] = tmp;
|
||||||
}
|
}
|
||||||
|
@ -329,7 +325,7 @@ random_setstate(RandomObject *self, PyObject *state)
|
||||||
element = PyLong_AsUnsignedLong(PyTuple_GET_ITEM(state, i));
|
element = PyLong_AsUnsignedLong(PyTuple_GET_ITEM(state, i));
|
||||||
if (element == (unsigned long)-1 && PyErr_Occurred())
|
if (element == (unsigned long)-1 && PyErr_Occurred())
|
||||||
return NULL;
|
return NULL;
|
||||||
self->state[i] = (PY_UINT32_T)element;
|
self->state[i] = (uint32_t)element;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = PyLong_AsLong(PyTuple_GET_ITEM(state, i));
|
index = PyLong_AsLong(PyTuple_GET_ITEM(state, i));
|
||||||
|
@ -349,8 +345,8 @@ static PyObject *
|
||||||
random_getrandbits(RandomObject *self, PyObject *args)
|
random_getrandbits(RandomObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
int k, i, words;
|
int k, i, words;
|
||||||
PY_UINT32_T r;
|
uint32_t r;
|
||||||
PY_UINT32_T *wordarray;
|
uint32_t *wordarray;
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "i:getrandbits", &k))
|
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));
|
return PyLong_FromUnsignedLong(genrand_int32(self) >> (32 - k));
|
||||||
|
|
||||||
words = (k - 1) / 32 + 1;
|
words = (k - 1) / 32 + 1;
|
||||||
wordarray = (PY_UINT32_T *)PyMem_Malloc(words * 4);
|
wordarray = (uint32_t *)PyMem_Malloc(words * 4);
|
||||||
if (wordarray == NULL) {
|
if (wordarray == NULL) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -98,14 +98,14 @@ test_sizeof_c_types(PyObject *self)
|
||||||
CHECK_SIGNNESS(Py_UCS1, 0);
|
CHECK_SIGNNESS(Py_UCS1, 0);
|
||||||
CHECK_SIGNNESS(Py_UCS2, 0);
|
CHECK_SIGNNESS(Py_UCS2, 0);
|
||||||
CHECK_SIGNNESS(Py_UCS4, 0);
|
CHECK_SIGNNESS(Py_UCS4, 0);
|
||||||
CHECK_SIZEOF(PY_INT32_T, 4);
|
CHECK_SIZEOF(int32_t, 4);
|
||||||
CHECK_SIGNNESS(PY_INT32_T, 1);
|
CHECK_SIGNNESS(int32_t, 1);
|
||||||
CHECK_SIZEOF(PY_UINT32_T, 4);
|
CHECK_SIZEOF(uint32_t, 4);
|
||||||
CHECK_SIGNNESS(PY_UINT32_T, 0);
|
CHECK_SIGNNESS(uint32_t, 0);
|
||||||
CHECK_SIZEOF(PY_INT64_T, 8);
|
CHECK_SIZEOF(int64_t, 8);
|
||||||
CHECK_SIGNNESS(PY_INT64_T, 1);
|
CHECK_SIGNNESS(int64_t, 1);
|
||||||
CHECK_SIZEOF(PY_UINT64_T, 8);
|
CHECK_SIZEOF(uint64_t, 8);
|
||||||
CHECK_SIGNNESS(PY_UINT64_T, 0);
|
CHECK_SIGNNESS(uint64_t, 0);
|
||||||
|
|
||||||
/* pointer/size types */
|
/* pointer/size types */
|
||||||
CHECK_SIZEOF(size_t, sizeof(void *));
|
CHECK_SIZEOF(size_t, sizeof(void *));
|
||||||
|
|
|
@ -297,7 +297,7 @@ static const int stepsizeTable[89] = {
|
||||||
|
|
||||||
#define GETINT8(cp, i) GETINTX(signed char, (cp), (i))
|
#define GETINT8(cp, i) GETINTX(signed char, (cp), (i))
|
||||||
#define GETINT16(cp, i) GETINTX(short, (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
|
#if WORDS_BIGENDIAN
|
||||||
#define GETINT24(cp, i) ( \
|
#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 SETINT8(cp, i, val) SETINTX(signed char, (cp), (i), (val))
|
||||||
#define SETINT16(cp, i, val) SETINTX(short, (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
|
#if WORDS_BIGENDIAN
|
||||||
#define SETINT24(cp, i, val) do { \
|
#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;
|
val = ((unsigned int)GETINT24(fragment->buf, i)) & 0xffffffu;
|
||||||
else {
|
else {
|
||||||
assert(width == 4);
|
assert(width == 4);
|
||||||
val = GETINTX(PY_UINT32_T, fragment->buf, i);
|
val = GETINTX(uint32_t, fragment->buf, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
val += (unsigned int)bias;
|
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);
|
SETINT24(ncp, i, (int)val);
|
||||||
else {
|
else {
|
||||||
assert(width == 4);
|
assert(width == 4);
|
||||||
SETINTX(PY_UINT32_T, ncp, i, val);
|
SETINTX(uint32_t, ncp, i, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
|
|
|
@ -5330,7 +5330,7 @@ _PyUnicode_EncodeUTF32(PyObject *str,
|
||||||
const void *data;
|
const void *data;
|
||||||
Py_ssize_t len;
|
Py_ssize_t len;
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
PY_UINT32_T *out;
|
uint32_t *out;
|
||||||
#if PY_LITTLE_ENDIAN
|
#if PY_LITTLE_ENDIAN
|
||||||
int native_ordering = byteorder <= 0;
|
int native_ordering = byteorder <= 0;
|
||||||
#else
|
#else
|
||||||
|
@ -5361,7 +5361,7 @@ _PyUnicode_EncodeUTF32(PyObject *str,
|
||||||
|
|
||||||
/* output buffer is 4-bytes aligned */
|
/* output buffer is 4-bytes aligned */
|
||||||
assert(_Py_IS_ALIGNED(PyBytes_AS_STRING(v), 4));
|
assert(_Py_IS_ALIGNED(PyBytes_AS_STRING(v), 4));
|
||||||
out = (PY_UINT32_T *)PyBytes_AS_STRING(v);
|
out = (uint32_t *)PyBytes_AS_STRING(v);
|
||||||
if (byteorder == 0)
|
if (byteorder == 0)
|
||||||
*out++ = 0xFEFF;
|
*out++ = 0xFEFF;
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
|
@ -5427,7 +5427,7 @@ _PyUnicode_EncodeUTF32(PyObject *str,
|
||||||
|
|
||||||
/* four bytes are reserved for each surrogate */
|
/* four bytes are reserved for each surrogate */
|
||||||
if (moreunits > 1) {
|
if (moreunits > 1) {
|
||||||
Py_ssize_t outpos = out - (PY_UINT32_T*) PyBytes_AS_STRING(v);
|
Py_ssize_t outpos = out - (uint32_t*) PyBytes_AS_STRING(v);
|
||||||
Py_ssize_t morebytes = 4 * (moreunits - 1);
|
Py_ssize_t morebytes = 4 * (moreunits - 1);
|
||||||
if (PyBytes_GET_SIZE(v) > PY_SSIZE_T_MAX - morebytes) {
|
if (PyBytes_GET_SIZE(v) > PY_SSIZE_T_MAX - morebytes) {
|
||||||
/* integer overflow */
|
/* integer overflow */
|
||||||
|
@ -5436,7 +5436,7 @@ _PyUnicode_EncodeUTF32(PyObject *str,
|
||||||
}
|
}
|
||||||
if (_PyBytes_Resize(&v, PyBytes_GET_SIZE(v) + morebytes) < 0)
|
if (_PyBytes_Resize(&v, PyBytes_GET_SIZE(v) + morebytes) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
out = (PY_UINT32_T*) PyBytes_AS_STRING(v) + outpos;
|
out = (uint32_t*) PyBytes_AS_STRING(v) + outpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PyBytes_Check(rep)) {
|
if (PyBytes_Check(rep)) {
|
||||||
|
|
|
@ -318,40 +318,37 @@ static PyHash_FuncDef PyHash_Func = {fnv, "fnv", 8 * SIZEOF_PY_HASH_T,
|
||||||
|
|
||||||
Modified for Python by Christian Heimes:
|
Modified for Python by Christian Heimes:
|
||||||
- C89 / MSVC compatibility
|
- C89 / MSVC compatibility
|
||||||
- PY_UINT64_T, PY_UINT32_T and PY_UINT8_T
|
|
||||||
- _rotl64() on Windows
|
- _rotl64() on Windows
|
||||||
- letoh64() fallback
|
- letoh64() fallback
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef unsigned char PY_UINT8_T;
|
|
||||||
|
|
||||||
/* byte swap little endian to host endian
|
/* byte swap little endian to host endian
|
||||||
* Endian conversion not only ensures that the hash function returns the same
|
* Endian conversion not only ensures that the hash function returns the same
|
||||||
* value on all platforms. It is also required to for a good dispersion of
|
* value on all platforms. It is also required to for a good dispersion of
|
||||||
* the hash values' least significant bits.
|
* the hash values' least significant bits.
|
||||||
*/
|
*/
|
||||||
#if PY_LITTLE_ENDIAN
|
#if PY_LITTLE_ENDIAN
|
||||||
# define _le64toh(x) ((PY_UINT64_T)(x))
|
# define _le64toh(x) ((uint64_t)(x))
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
# define _le64toh(x) OSSwapLittleToHostInt64(x)
|
# define _le64toh(x) OSSwapLittleToHostInt64(x)
|
||||||
#elif defined(HAVE_LETOH64)
|
#elif defined(HAVE_LETOH64)
|
||||||
# define _le64toh(x) le64toh(x)
|
# define _le64toh(x) le64toh(x)
|
||||||
#else
|
#else
|
||||||
# define _le64toh(x) (((PY_UINT64_T)(x) << 56) | \
|
# define _le64toh(x) (((uint64_t)(x) << 56) | \
|
||||||
(((PY_UINT64_T)(x) << 40) & 0xff000000000000ULL) | \
|
(((uint64_t)(x) << 40) & 0xff000000000000ULL) | \
|
||||||
(((PY_UINT64_T)(x) << 24) & 0xff0000000000ULL) | \
|
(((uint64_t)(x) << 24) & 0xff0000000000ULL) | \
|
||||||
(((PY_UINT64_T)(x) << 8) & 0xff00000000ULL) | \
|
(((uint64_t)(x) << 8) & 0xff00000000ULL) | \
|
||||||
(((PY_UINT64_T)(x) >> 8) & 0xff000000ULL) | \
|
(((uint64_t)(x) >> 8) & 0xff000000ULL) | \
|
||||||
(((PY_UINT64_T)(x) >> 24) & 0xff0000ULL) | \
|
(((uint64_t)(x) >> 24) & 0xff0000ULL) | \
|
||||||
(((PY_UINT64_T)(x) >> 40) & 0xff00ULL) | \
|
(((uint64_t)(x) >> 40) & 0xff00ULL) | \
|
||||||
((PY_UINT64_T)(x) >> 56))
|
((uint64_t)(x) >> 56))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# define ROTATE(x, b) _rotl64(x, b)
|
# define ROTATE(x, b) _rotl64(x, b)
|
||||||
#else
|
#else
|
||||||
# define ROTATE(x, b) (PY_UINT64_T)( ((x) << (b)) | ( (x) >> (64 - (b))) )
|
# define ROTATE(x, b) (uint64_t)( ((x) << (b)) | ( (x) >> (64 - (b))) )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define HALF_ROUND(a,b,c,d,s,t) \
|
#define HALF_ROUND(a,b,c,d,s,t) \
|
||||||
|
@ -369,22 +366,22 @@ typedef unsigned char PY_UINT8_T;
|
||||||
|
|
||||||
static Py_hash_t
|
static Py_hash_t
|
||||||
siphash24(const void *src, Py_ssize_t src_sz) {
|
siphash24(const void *src, Py_ssize_t src_sz) {
|
||||||
PY_UINT64_T k0 = _le64toh(_Py_HashSecret.siphash.k0);
|
uint64_t k0 = _le64toh(_Py_HashSecret.siphash.k0);
|
||||||
PY_UINT64_T k1 = _le64toh(_Py_HashSecret.siphash.k1);
|
uint64_t k1 = _le64toh(_Py_HashSecret.siphash.k1);
|
||||||
PY_UINT64_T b = (PY_UINT64_T)src_sz << 56;
|
uint64_t b = (uint64_t)src_sz << 56;
|
||||||
const PY_UINT64_T *in = (PY_UINT64_T*)src;
|
const uint64_t *in = (uint64_t*)src;
|
||||||
|
|
||||||
PY_UINT64_T v0 = k0 ^ 0x736f6d6570736575ULL;
|
uint64_t v0 = k0 ^ 0x736f6d6570736575ULL;
|
||||||
PY_UINT64_T v1 = k1 ^ 0x646f72616e646f6dULL;
|
uint64_t v1 = k1 ^ 0x646f72616e646f6dULL;
|
||||||
PY_UINT64_T v2 = k0 ^ 0x6c7967656e657261ULL;
|
uint64_t v2 = k0 ^ 0x6c7967656e657261ULL;
|
||||||
PY_UINT64_T v3 = k1 ^ 0x7465646279746573ULL;
|
uint64_t v3 = k1 ^ 0x7465646279746573ULL;
|
||||||
|
|
||||||
PY_UINT64_T t;
|
uint64_t t;
|
||||||
PY_UINT8_T *pt;
|
uint8_t *pt;
|
||||||
PY_UINT8_T *m;
|
uint8_t *m;
|
||||||
|
|
||||||
while (src_sz >= 8) {
|
while (src_sz >= 8) {
|
||||||
PY_UINT64_T mi = _le64toh(*in);
|
uint64_t mi = _le64toh(*in);
|
||||||
in += 1;
|
in += 1;
|
||||||
src_sz -= 8;
|
src_sz -= 8;
|
||||||
v3 ^= mi;
|
v3 ^= mi;
|
||||||
|
@ -393,13 +390,13 @@ siphash24(const void *src, Py_ssize_t src_sz) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t = 0;
|
t = 0;
|
||||||
pt = (PY_UINT8_T *)&t;
|
pt = (uint8_t *)&t;
|
||||||
m = (PY_UINT8_T *)in;
|
m = (uint8_t *)in;
|
||||||
switch (src_sz) {
|
switch (src_sz) {
|
||||||
case 7: pt[6] = m[6];
|
case 7: pt[6] = m[6];
|
||||||
case 6: pt[5] = m[5];
|
case 6: pt[5] = m[5];
|
||||||
case 5: pt[4] = m[4];
|
case 5: pt[4] = m[4];
|
||||||
case 4: Py_MEMCPY(pt, m, sizeof(PY_UINT32_T)); break;
|
case 4: Py_MEMCPY(pt, m, sizeof(uint32_t)); break;
|
||||||
case 3: pt[2] = m[2];
|
case 3: pt[2] = m[2];
|
||||||
case 2: pt[1] = m[1];
|
case 2: pt[1] = m[1];
|
||||||
case 1: pt[0] = m[0];
|
case 1: pt[0] = m[0];
|
||||||
|
|
Loading…
Reference in New Issue