File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -691,6 +691,8 @@ PyAPI_DATA(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */
691691/* Macro for returning Py_NotImplemented from a function */
692692#define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
693693
694+ extern Py_ssize_t _PyHASH_NONE ;
695+
694696/* Rich comparison opcodes */
695697#define Py_LT 0
696698#define Py_LE 1
Original file line number Diff line number Diff line change @@ -1638,6 +1638,16 @@ none_bool(PyObject *v)
16381638 return 0 ;
16391639}
16401640
1641+ Py_ssize_t _PyHASH_NONE ;
1642+
1643+ static Py_hash_t none_hash (PyObject * v )
1644+ {
1645+ #ifdef Py_DEBUG
1646+ assert (_Py_HashSecret_Initialized );
1647+ #endif
1648+ return _PyHASH_NONE ;
1649+ }
1650+
16411651static PyNumberMethods none_as_number = {
16421652 0 , /* nb_add */
16431653 0 , /* nb_subtract */
@@ -1689,7 +1699,7 @@ PyTypeObject _PyNone_Type = {
16891699 & none_as_number , /*tp_as_number*/
16901700 0 , /*tp_as_sequence*/
16911701 0 , /*tp_as_mapping*/
1692- 0 , /* tp_hash */
1702+ ( hashfunc ) none_hash , /* tp_hash */
16931703 0 , /*tp_call */
16941704 0 , /*tp_str */
16951705 0 , /*tp_getattro */
Original file line number Diff line number Diff line change @@ -543,6 +543,11 @@ _PyOS_URandomNonblock(void *buffer, Py_ssize_t size)
543543 return pyurandom (buffer , size , 0 , 1 );
544544}
545545
546+ void
547+ _Py_InitNoneHash () {
548+ const unsigned char data [] = {0xFC , 0xA8 , 0x64 , 0x20 };
549+ _PyHASH_NONE = _Py_HashBytes (data , sizeof (data ));
550+ }
546551
547552PyStatus
548553_Py_HashRandomization_Init (const PyConfig * config )
@@ -576,14 +581,15 @@ _Py_HashRandomization_Init(const PyConfig *config)
576581 pyurandom() is non-blocking mode (blocking=0): see the PEP 524. */
577582 res = pyurandom (secret , secret_size , 0 , 0 );
578583 if (res < 0 ) {
584+ _Py_HashSecret_Initialized = 0 ;
579585 return _PyStatus_ERR ("failed to get random numbers "
580586 "to initialize Python" );
581587 }
582588 }
589+ _Py_InitNoneHash ();
583590 return _PyStatus_OK ();
584591}
585592
586-
587593void
588594_Py_HashRandomization_Fini (void )
589595{
You can’t perform that action at this time.
0 commit comments