@@ -16,6 +16,8 @@ module _tracemalloc
1616[clinic start generated code]*/
1717/*[clinic end generated code: output=da39a3ee5e6b4b0d input=708a98302fc46e5f]*/
1818
19+ #define tracemalloc_config _PyRuntime.tracemalloc.config
20+
1921_Py_DECLARE_STR (anon_unknown , "<unknown>" );
2022
2123/* Trace memory blocks allocated by PyMem_RawMalloc() */
@@ -407,7 +409,7 @@ traceback_get_frames(traceback_t *traceback)
407409 if (pyframe == NULL ) {
408410 break ;
409411 }
410- if (traceback -> nframe < _Py_tracemalloc_config .max_nframe ) {
412+ if (traceback -> nframe < tracemalloc_config .max_nframe ) {
411413 tracemalloc_get_frame (pyframe , & traceback -> frames [traceback -> nframe ]);
412414 assert (traceback -> frames [traceback -> nframe ].filename != NULL );
413415 traceback -> nframe ++ ;
@@ -505,7 +507,7 @@ tracemalloc_get_traces_table(unsigned int domain)
505507static void
506508tracemalloc_remove_trace (unsigned int domain , uintptr_t ptr )
507509{
508- assert (_Py_tracemalloc_config .tracing );
510+ assert (tracemalloc_config .tracing );
509511
510512 _Py_hashtable_t * traces = tracemalloc_get_traces_table (domain );
511513 if (!traces ) {
@@ -529,7 +531,7 @@ static int
529531tracemalloc_add_trace (unsigned int domain , uintptr_t ptr ,
530532 size_t size )
531533{
532- assert (_Py_tracemalloc_config .tracing );
534+ assert (tracemalloc_config .tracing );
533535
534536 traceback_t * traceback = traceback_new ();
535537 if (traceback == NULL ) {
@@ -863,13 +865,13 @@ tracemalloc_clear_traces(void)
863865static int
864866tracemalloc_init (void )
865867{
866- if (_Py_tracemalloc_config .initialized == TRACEMALLOC_FINALIZED ) {
868+ if (tracemalloc_config .initialized == TRACEMALLOC_FINALIZED ) {
867869 PyErr_SetString (PyExc_RuntimeError ,
868870 "the tracemalloc module has been unloaded" );
869871 return -1 ;
870872 }
871873
872- if (_Py_tracemalloc_config .initialized == TRACEMALLOC_INITIALIZED )
874+ if (tracemalloc_config .initialized == TRACEMALLOC_INITIALIZED )
873875 return 0 ;
874876
875877 PyMem_GetAllocator (PYMEM_DOMAIN_RAW , & allocators .raw );
@@ -919,17 +921,17 @@ tracemalloc_init(void)
919921 tracemalloc_empty_traceback .frames [0 ].lineno = 0 ;
920922 tracemalloc_empty_traceback .hash = traceback_hash (& tracemalloc_empty_traceback );
921923
922- _Py_tracemalloc_config .initialized = TRACEMALLOC_INITIALIZED ;
924+ tracemalloc_config .initialized = TRACEMALLOC_INITIALIZED ;
923925 return 0 ;
924926}
925927
926928
927929static void
928930tracemalloc_deinit (void )
929931{
930- if (_Py_tracemalloc_config .initialized != TRACEMALLOC_INITIALIZED )
932+ if (tracemalloc_config .initialized != TRACEMALLOC_INITIALIZED )
931933 return ;
932- _Py_tracemalloc_config .initialized = TRACEMALLOC_FINALIZED ;
934+ tracemalloc_config .initialized = TRACEMALLOC_FINALIZED ;
933935
934936 tracemalloc_stop ();
935937
@@ -969,12 +971,12 @@ tracemalloc_start(int max_nframe)
969971 return -1 ;
970972 }
971973
972- if (_Py_tracemalloc_config .tracing ) {
974+ if (tracemalloc_config .tracing ) {
973975 /* hook already installed: do nothing */
974976 return 0 ;
975977 }
976978
977- _Py_tracemalloc_config .max_nframe = max_nframe ;
979+ tracemalloc_config .max_nframe = max_nframe ;
978980
979981 /* allocate a buffer to store a new traceback */
980982 size = TRACEBACK_SIZE (max_nframe );
@@ -1010,7 +1012,7 @@ tracemalloc_start(int max_nframe)
10101012 PyMem_SetAllocator (PYMEM_DOMAIN_OBJ , & alloc );
10111013
10121014 /* everything is ready: start tracing Python memory allocations */
1013- _Py_tracemalloc_config .tracing = 1 ;
1015+ tracemalloc_config .tracing = 1 ;
10141016
10151017 return 0 ;
10161018}
@@ -1019,11 +1021,11 @@ tracemalloc_start(int max_nframe)
10191021static void
10201022tracemalloc_stop (void )
10211023{
1022- if (!_Py_tracemalloc_config .tracing )
1024+ if (!tracemalloc_config .tracing )
10231025 return ;
10241026
10251027 /* stop tracing Python memory allocations */
1026- _Py_tracemalloc_config .tracing = 0 ;
1028+ tracemalloc_config .tracing = 0 ;
10271029
10281030 /* unregister the hook on memory allocators */
10291031#ifdef TRACE_RAW_MALLOC
@@ -1051,7 +1053,7 @@ static PyObject *
10511053_tracemalloc_is_tracing_impl (PyObject * module )
10521054/*[clinic end generated code: output=2d763b42601cd3ef input=af104b0a00192f63]*/
10531055{
1054- return PyBool_FromLong (_Py_tracemalloc_config .tracing );
1056+ return PyBool_FromLong (tracemalloc_config .tracing );
10551057}
10561058
10571059
@@ -1065,7 +1067,7 @@ static PyObject *
10651067_tracemalloc_clear_traces_impl (PyObject * module )
10661068/*[clinic end generated code: output=a86080ee41b84197 input=0dab5b6c785183a5]*/
10671069{
1068- if (!_Py_tracemalloc_config .tracing )
1070+ if (!tracemalloc_config .tracing )
10691071 Py_RETURN_NONE ;
10701072
10711073 set_reentrant (1 );
@@ -1345,7 +1347,7 @@ _tracemalloc__get_traces_impl(PyObject *module)
13451347 if (get_traces .list == NULL )
13461348 goto error ;
13471349
1348- if (!_Py_tracemalloc_config .tracing )
1350+ if (!tracemalloc_config .tracing )
13491351 return get_traces .list ;
13501352
13511353 /* the traceback hash table is used temporarily to intern traceback tuple
@@ -1418,7 +1420,7 @@ static traceback_t*
14181420tracemalloc_get_traceback (unsigned int domain , uintptr_t ptr )
14191421{
14201422
1421- if (!_Py_tracemalloc_config .tracing )
1423+ if (!tracemalloc_config .tracing )
14221424 return NULL ;
14231425
14241426 trace_t * trace ;
@@ -1498,7 +1500,7 @@ _PyMem_DumpTraceback(int fd, const void *ptr)
14981500 traceback_t * traceback ;
14991501 int i ;
15001502
1501- if (!_Py_tracemalloc_config .tracing ) {
1503+ if (!tracemalloc_config .tracing ) {
15021504 PUTS (fd , "Enable tracemalloc to get the memory block "
15031505 "allocation traceback\n\n" );
15041506 return ;
@@ -1572,7 +1574,7 @@ static PyObject *
15721574_tracemalloc_get_traceback_limit_impl (PyObject * module )
15731575/*[clinic end generated code: output=d556d9306ba95567 input=da3cd977fc68ae3b]*/
15741576{
1575- return PyLong_FromLong (_Py_tracemalloc_config .max_nframe );
1577+ return PyLong_FromLong (tracemalloc_config .max_nframe );
15761578}
15771579
15781580
@@ -1630,7 +1632,7 @@ _tracemalloc_get_traced_memory_impl(PyObject *module)
16301632{
16311633 Py_ssize_t size , peak_size ;
16321634
1633- if (!_Py_tracemalloc_config .tracing )
1635+ if (!tracemalloc_config .tracing )
16341636 return Py_BuildValue ("ii" , 0 , 0 );
16351637
16361638 TABLES_LOCK ();
@@ -1654,7 +1656,7 @@ static PyObject *
16541656_tracemalloc_reset_peak_impl (PyObject * module )
16551657/*[clinic end generated code: output=140c2870f691dbb2 input=18afd0635066e9ce]*/
16561658{
1657- if (!_Py_tracemalloc_config .tracing ) {
1659+ if (!tracemalloc_config .tracing ) {
16581660 Py_RETURN_NONE ;
16591661 }
16601662
@@ -1735,7 +1737,7 @@ PyTraceMalloc_Track(unsigned int domain, uintptr_t ptr,
17351737 int res ;
17361738 PyGILState_STATE gil_state ;
17371739
1738- if (!_Py_tracemalloc_config .tracing ) {
1740+ if (!tracemalloc_config .tracing ) {
17391741 /* tracemalloc is not tracing: do nothing */
17401742 return -2 ;
17411743 }
@@ -1754,7 +1756,7 @@ PyTraceMalloc_Track(unsigned int domain, uintptr_t ptr,
17541756int
17551757PyTraceMalloc_Untrack (unsigned int domain , uintptr_t ptr )
17561758{
1757- if (!_Py_tracemalloc_config .tracing ) {
1759+ if (!tracemalloc_config .tracing ) {
17581760 /* tracemalloc is not tracing: do nothing */
17591761 return -2 ;
17601762 }
@@ -1777,7 +1779,7 @@ _PyTraceMalloc_NewReference(PyObject *op)
17771779{
17781780 assert (PyGILState_Check ());
17791781
1780- if (!_Py_tracemalloc_config .tracing ) {
1782+ if (!tracemalloc_config .tracing ) {
17811783 /* tracemalloc is not tracing: do nothing */
17821784 return -1 ;
17831785 }
0 commit comments