@@ -569,28 +569,19 @@ _PyInterpreterState_Enable(_PyRuntimeState *runtime)
569569    return  _PyStatus_OK ();
570570}
571571
572- #ifdef  _Py_HAS_UNDEFINED_BEHAVIOR_SANITIZER 
573- #define  RAW_ALIGN_PTR_OFFSET  sizeof(void *)
574- #endif 
575- 
576572static  PyInterpreterState  * 
577573alloc_interpreter (void )
578574{
579- #ifdef  _Py_HAS_UNDEFINED_BEHAVIOR_SANITIZER 
580-     size_t  statesize  =  sizeof (PyInterpreterState );
581575    size_t  alignment  =  _Alignof(PyInterpreterState );
582-     size_t  allocsize  =  statesize  +  alignment  -  1   +   RAW_ALIGN_PTR_OFFSET ;
576+     size_t  allocsize  =  sizeof ( PyInterpreterState )  +  alignment  -  1 ;
583577    void  * mem  =  PyMem_RawCalloc (1 , allocsize );
584578    if  (mem  ==  NULL ) {
585579        return  NULL ;
586580    }
587-     char  * interp  =  _Py_ALIGN_UP ((char  * )mem  +  RAW_ALIGN_PTR_OFFSET , alignment );
588-     * (void  * * )(interp  -  RAW_ALIGN_PTR_OFFSET ) =  mem ;
581+     PyInterpreterState  * interp  =  _Py_ALIGN_UP (mem , alignment );
589582    assert (_Py_IS_ALIGNED (interp , alignment ));
590-     return  (PyInterpreterState  * )interp ;
591- #else 
592-     return  PyMem_RawCalloc (1 , sizeof (PyInterpreterState ));
593- #endif 
583+     interp -> _malloced  =  (uintptr_t )mem ;
584+     return  interp ;
594585}
595586
596587static  void 
@@ -604,21 +595,11 @@ free_interpreter(PyInterpreterState *interp)
604595            PyMem_RawFree (interp -> obmalloc );
605596            interp -> obmalloc  =  NULL ;
606597        }
607- #ifdef  _Py_HAS_UNDEFINED_BEHAVIOR_SANITIZER 
608598        assert (_Py_IS_ALIGNED (interp , _Alignof(PyInterpreterState )));
609-         char  * mem_location  =  (char  * )interp  -  RAW_ALIGN_PTR_OFFSET ;
610-         void  * mem  =  * ((void  * * )mem_location );
611-         PyMem_RawFree (mem );
612- #else 
613-         PyMem_RawFree (interp );
614- #endif 
599+         PyMem_RawFree ((void  * )interp -> _malloced );
615600    }
616601}
617602
618- #ifdef  _Py_HAS_UNDEFINED_BEHAVIOR_SANITIZER 
619- #undef  RAW_ALIGN_PTR_OFFSET
620- #endif 
621- 
622603#ifndef  NDEBUG 
623604static  inline  int  check_interpreter_whence (long );
624605#endif 
0 commit comments