22#include  "pycore_fileutils.h"      // _Py_write_noraise() 
33#include  "pycore_gc.h"             // PyGC_Head 
44#include  "pycore_hashtable.h"      // _Py_hashtable_t 
5+ #include  "pycore_initconfig.h"     // _PyStatus_NO_MEMORY() 
56#include  "pycore_object.h"         // _PyType_PreHeaderSize() 
67#include  "pycore_pymem.h"          // _Py_tracemalloc_config 
78#include  "pycore_runtime.h"        // _Py_ID() 
@@ -815,37 +816,24 @@ tracemalloc_clear_traces_unlocked(void)
815816}
816817
817818
818- int 
819+ PyStatus 
819820_PyTraceMalloc_Init (void )
820821{
821-     if  (tracemalloc_config .initialized  ==  TRACEMALLOC_FINALIZED ) {
822-         PyErr_SetString (PyExc_RuntimeError ,
823-                         "the tracemalloc module has been unloaded" );
824-         return  -1 ;
825-     }
826- 
827-     if  (tracemalloc_config .initialized  ==  TRACEMALLOC_INITIALIZED )
828-         return  0 ;
822+     assert (tracemalloc_config .initialized  ==  TRACEMALLOC_NOT_INITIALIZED );
829823
830824    PyMem_GetAllocator (PYMEM_DOMAIN_RAW , & allocators .raw );
831825
832826#ifdef  REENTRANT_THREADLOCAL 
833827    if  (PyThread_tss_create (& tracemalloc_reentrant_key ) !=  0 ) {
834- #ifdef  MS_WINDOWS 
835-         PyErr_SetFromWindowsErr (0 );
836- #else 
837-         PyErr_SetFromErrno (PyExc_OSError );
838- #endif 
839-         return  -1 ;
828+         return  _PyStatus_NO_MEMORY ();
840829    }
841830#endif 
842831
843832#if  defined(TRACE_RAW_MALLOC )
844833    if  (tables_lock  ==  NULL ) {
845834        tables_lock  =  PyThread_allocate_lock ();
846835        if  (tables_lock  ==  NULL ) {
847-             PyErr_SetString (PyExc_RuntimeError , "cannot allocate lock" );
848-             return  -1 ;
836+             return  _PyStatus_NO_MEMORY ();
849837        }
850838    }
851839#endif 
@@ -862,9 +850,9 @@ _PyTraceMalloc_Init(void)
862850    tracemalloc_domains  =  tracemalloc_create_domains_table ();
863851
864852    if  (tracemalloc_filenames  ==  NULL  ||  tracemalloc_tracebacks  ==  NULL 
865-        ||  tracemalloc_traces  ==  NULL  ||  tracemalloc_domains  ==  NULL ) { 
866-          PyErr_NoMemory (); 
867-         return  -1 ;
853+        ||  tracemalloc_traces  ==  NULL  ||  tracemalloc_domains  ==  NULL )
854+     { 
855+         return  _PyStatus_NO_MEMORY () ;
868856    }
869857
870858    tracemalloc_empty_traceback .nframe  =  1 ;
@@ -875,7 +863,7 @@ _PyTraceMalloc_Init(void)
875863    tracemalloc_empty_traceback .hash  =  traceback_hash (& tracemalloc_empty_traceback );
876864
877865    tracemalloc_config .initialized  =  TRACEMALLOC_INITIALIZED ;
878-     return  0 ;
866+     return  _PyStatus_OK () ;
879867}
880868
881869
@@ -920,10 +908,6 @@ _PyTraceMalloc_Start(int max_nframe)
920908        return  -1 ;
921909    }
922910
923-     if  (_PyTraceMalloc_Init () <  0 ) {
924-         return  -1 ;
925-     }
926- 
927911    if  (PyRefTracer_SetTracer (_PyTraceMalloc_TraceRef , NULL ) <  0 ) {
928912        return  -1 ;
929913    }
0 commit comments