Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e249dca

Browse files
committed
merge 3.2
2 parents 4fe85ab + 69e9727 commit e249dca

5 files changed

Lines changed: 15 additions & 4 deletions

File tree

Include/object.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ typedef struct {
523523
} _Py_HashSecret_t;
524524
PyAPI_DATA(_Py_HashSecret_t) _Py_HashSecret;
525525

526+
#ifdef Py_DEBUG
527+
PyAPI_DATA(int) _Py_HashSecret_Initialized;
528+
#endif
529+
526530
/* Helper for passing objects to printf and the like */
527531
#define PyObject_REPR(obj) _PyUnicode_AsString(PyObject_Repr(obj))
528532

Modules/_datetimemodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,6 +2784,7 @@ generic_hash(unsigned char *data, int len)
27842784
register unsigned char *p;
27852785
register Py_hash_t x;
27862786

2787+
assert(_Py_HashSecret_Initialized);
27872788
p = (unsigned char *) data;
27882789
x = _Py_HashSecret.prefix;
27892790
x ^= *p << 7;

Objects/bytesobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ bytes_hash(PyBytesObject *a)
875875
register unsigned char *p;
876876
register Py_hash_t x;
877877

878+
assert(_Py_HashSecret_Initialized);
878879
if (a->ob_shash != -1)
879880
return a->ob_shash;
880881
len = Py_SIZE(a);

Objects/unicodeobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7673,6 +7673,7 @@ unicode_hash(PyUnicodeObject *self)
76737673
Py_UNICODE *p;
76747674
Py_hash_t x;
76757675

7676+
assert(_Py_HashSecret_Initialized);
76767677
if (self->hash != -1)
76777678
return self->hash;
76787679
len = Py_SIZE(self);

Python/random.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
#include <fcntl.h>
66
#endif
77

8-
static int random_initialized = 0;
8+
#ifdef Py_DEBUG
9+
int _Py_HashSecret_Initialized = 0;
10+
#else
11+
static int _Py_HashSecret_Initialized = 0;
12+
#endif
913

1014
#ifdef MS_WINDOWS
1115
typedef BOOL (WINAPI *CRYPTACQUIRECONTEXTA)(HCRYPTPROV *phProv,\
@@ -246,11 +250,11 @@ _PyRandom_Init(void)
246250
{
247251
char *env;
248252
void *secret = &_Py_HashSecret;
249-
Py_ssize_t secret_size = sizeof(_Py_HashSecret);
253+
Py_ssize_t secret_size = sizeof(_Py_HashSecret_t);
250254

251-
if (random_initialized)
255+
if (_Py_HashSecret_Initialized)
252256
return;
253-
random_initialized = 1;
257+
_Py_HashSecret_Initialized = 1;
254258

255259
/*
256260
By default, hash randomization is disabled, and only

0 commit comments

Comments
 (0)