@@ -16,6 +16,8 @@ module _tracemalloc
16
16
[clinic start generated code]*/
17
17
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=708a98302fc46e5f]*/
18
18
19
+ #define tracemalloc_config _PyRuntime.tracemalloc.config
20
+
19
21
_Py_DECLARE_STR (anon_unknown , "<unknown>" );
20
22
21
23
/* Trace memory blocks allocated by PyMem_RawMalloc() */
@@ -407,7 +409,7 @@ traceback_get_frames(traceback_t *traceback)
407
409
if (pyframe == NULL ) {
408
410
break ;
409
411
}
410
- if (traceback -> nframe < _Py_tracemalloc_config .max_nframe ) {
412
+ if (traceback -> nframe < tracemalloc_config .max_nframe ) {
411
413
tracemalloc_get_frame (pyframe , & traceback -> frames [traceback -> nframe ]);
412
414
assert (traceback -> frames [traceback -> nframe ].filename != NULL );
413
415
traceback -> nframe ++ ;
@@ -505,7 +507,7 @@ tracemalloc_get_traces_table(unsigned int domain)
505
507
static void
506
508
tracemalloc_remove_trace (unsigned int domain , uintptr_t ptr )
507
509
{
508
- assert (_Py_tracemalloc_config .tracing );
510
+ assert (tracemalloc_config .tracing );
509
511
510
512
_Py_hashtable_t * traces = tracemalloc_get_traces_table (domain );
511
513
if (!traces ) {
@@ -529,7 +531,7 @@ static int
529
531
tracemalloc_add_trace (unsigned int domain , uintptr_t ptr ,
530
532
size_t size )
531
533
{
532
- assert (_Py_tracemalloc_config .tracing );
534
+ assert (tracemalloc_config .tracing );
533
535
534
536
traceback_t * traceback = traceback_new ();
535
537
if (traceback == NULL ) {
@@ -863,13 +865,13 @@ tracemalloc_clear_traces(void)
863
865
static int
864
866
tracemalloc_init (void )
865
867
{
866
- if (_Py_tracemalloc_config .initialized == TRACEMALLOC_FINALIZED ) {
868
+ if (tracemalloc_config .initialized == TRACEMALLOC_FINALIZED ) {
867
869
PyErr_SetString (PyExc_RuntimeError ,
868
870
"the tracemalloc module has been unloaded" );
869
871
return -1 ;
870
872
}
871
873
872
- if (_Py_tracemalloc_config .initialized == TRACEMALLOC_INITIALIZED )
874
+ if (tracemalloc_config .initialized == TRACEMALLOC_INITIALIZED )
873
875
return 0 ;
874
876
875
877
PyMem_GetAllocator (PYMEM_DOMAIN_RAW , & allocators .raw );
@@ -919,17 +921,17 @@ tracemalloc_init(void)
919
921
tracemalloc_empty_traceback .frames [0 ].lineno = 0 ;
920
922
tracemalloc_empty_traceback .hash = traceback_hash (& tracemalloc_empty_traceback );
921
923
922
- _Py_tracemalloc_config .initialized = TRACEMALLOC_INITIALIZED ;
924
+ tracemalloc_config .initialized = TRACEMALLOC_INITIALIZED ;
923
925
return 0 ;
924
926
}
925
927
926
928
927
929
static void
928
930
tracemalloc_deinit (void )
929
931
{
930
- if (_Py_tracemalloc_config .initialized != TRACEMALLOC_INITIALIZED )
932
+ if (tracemalloc_config .initialized != TRACEMALLOC_INITIALIZED )
931
933
return ;
932
- _Py_tracemalloc_config .initialized = TRACEMALLOC_FINALIZED ;
934
+ tracemalloc_config .initialized = TRACEMALLOC_FINALIZED ;
933
935
934
936
tracemalloc_stop ();
935
937
@@ -969,12 +971,12 @@ tracemalloc_start(int max_nframe)
969
971
return -1 ;
970
972
}
971
973
972
- if (_Py_tracemalloc_config .tracing ) {
974
+ if (tracemalloc_config .tracing ) {
973
975
/* hook already installed: do nothing */
974
976
return 0 ;
975
977
}
976
978
977
- _Py_tracemalloc_config .max_nframe = max_nframe ;
979
+ tracemalloc_config .max_nframe = max_nframe ;
978
980
979
981
/* allocate a buffer to store a new traceback */
980
982
size = TRACEBACK_SIZE (max_nframe );
@@ -1010,7 +1012,7 @@ tracemalloc_start(int max_nframe)
1010
1012
PyMem_SetAllocator (PYMEM_DOMAIN_OBJ , & alloc );
1011
1013
1012
1014
/* everything is ready: start tracing Python memory allocations */
1013
- _Py_tracemalloc_config .tracing = 1 ;
1015
+ tracemalloc_config .tracing = 1 ;
1014
1016
1015
1017
return 0 ;
1016
1018
}
@@ -1019,11 +1021,11 @@ tracemalloc_start(int max_nframe)
1019
1021
static void
1020
1022
tracemalloc_stop (void )
1021
1023
{
1022
- if (!_Py_tracemalloc_config .tracing )
1024
+ if (!tracemalloc_config .tracing )
1023
1025
return ;
1024
1026
1025
1027
/* stop tracing Python memory allocations */
1026
- _Py_tracemalloc_config .tracing = 0 ;
1028
+ tracemalloc_config .tracing = 0 ;
1027
1029
1028
1030
/* unregister the hook on memory allocators */
1029
1031
#ifdef TRACE_RAW_MALLOC
@@ -1051,7 +1053,7 @@ static PyObject *
1051
1053
_tracemalloc_is_tracing_impl (PyObject * module )
1052
1054
/*[clinic end generated code: output=2d763b42601cd3ef input=af104b0a00192f63]*/
1053
1055
{
1054
- return PyBool_FromLong (_Py_tracemalloc_config .tracing );
1056
+ return PyBool_FromLong (tracemalloc_config .tracing );
1055
1057
}
1056
1058
1057
1059
@@ -1065,7 +1067,7 @@ static PyObject *
1065
1067
_tracemalloc_clear_traces_impl (PyObject * module )
1066
1068
/*[clinic end generated code: output=a86080ee41b84197 input=0dab5b6c785183a5]*/
1067
1069
{
1068
- if (!_Py_tracemalloc_config .tracing )
1070
+ if (!tracemalloc_config .tracing )
1069
1071
Py_RETURN_NONE ;
1070
1072
1071
1073
set_reentrant (1 );
@@ -1345,7 +1347,7 @@ _tracemalloc__get_traces_impl(PyObject *module)
1345
1347
if (get_traces .list == NULL )
1346
1348
goto error ;
1347
1349
1348
- if (!_Py_tracemalloc_config .tracing )
1350
+ if (!tracemalloc_config .tracing )
1349
1351
return get_traces .list ;
1350
1352
1351
1353
/* the traceback hash table is used temporarily to intern traceback tuple
@@ -1418,7 +1420,7 @@ static traceback_t*
1418
1420
tracemalloc_get_traceback (unsigned int domain , uintptr_t ptr )
1419
1421
{
1420
1422
1421
- if (!_Py_tracemalloc_config .tracing )
1423
+ if (!tracemalloc_config .tracing )
1422
1424
return NULL ;
1423
1425
1424
1426
trace_t * trace ;
@@ -1498,7 +1500,7 @@ _PyMem_DumpTraceback(int fd, const void *ptr)
1498
1500
traceback_t * traceback ;
1499
1501
int i ;
1500
1502
1501
- if (!_Py_tracemalloc_config .tracing ) {
1503
+ if (!tracemalloc_config .tracing ) {
1502
1504
PUTS (fd , "Enable tracemalloc to get the memory block "
1503
1505
"allocation traceback\n\n" );
1504
1506
return ;
@@ -1572,7 +1574,7 @@ static PyObject *
1572
1574
_tracemalloc_get_traceback_limit_impl (PyObject * module )
1573
1575
/*[clinic end generated code: output=d556d9306ba95567 input=da3cd977fc68ae3b]*/
1574
1576
{
1575
- return PyLong_FromLong (_Py_tracemalloc_config .max_nframe );
1577
+ return PyLong_FromLong (tracemalloc_config .max_nframe );
1576
1578
}
1577
1579
1578
1580
@@ -1630,7 +1632,7 @@ _tracemalloc_get_traced_memory_impl(PyObject *module)
1630
1632
{
1631
1633
Py_ssize_t size , peak_size ;
1632
1634
1633
- if (!_Py_tracemalloc_config .tracing )
1635
+ if (!tracemalloc_config .tracing )
1634
1636
return Py_BuildValue ("ii" , 0 , 0 );
1635
1637
1636
1638
TABLES_LOCK ();
@@ -1654,7 +1656,7 @@ static PyObject *
1654
1656
_tracemalloc_reset_peak_impl (PyObject * module )
1655
1657
/*[clinic end generated code: output=140c2870f691dbb2 input=18afd0635066e9ce]*/
1656
1658
{
1657
- if (!_Py_tracemalloc_config .tracing ) {
1659
+ if (!tracemalloc_config .tracing ) {
1658
1660
Py_RETURN_NONE ;
1659
1661
}
1660
1662
@@ -1735,7 +1737,7 @@ PyTraceMalloc_Track(unsigned int domain, uintptr_t ptr,
1735
1737
int res ;
1736
1738
PyGILState_STATE gil_state ;
1737
1739
1738
- if (!_Py_tracemalloc_config .tracing ) {
1740
+ if (!tracemalloc_config .tracing ) {
1739
1741
/* tracemalloc is not tracing: do nothing */
1740
1742
return -2 ;
1741
1743
}
@@ -1754,7 +1756,7 @@ PyTraceMalloc_Track(unsigned int domain, uintptr_t ptr,
1754
1756
int
1755
1757
PyTraceMalloc_Untrack (unsigned int domain , uintptr_t ptr )
1756
1758
{
1757
- if (!_Py_tracemalloc_config .tracing ) {
1759
+ if (!tracemalloc_config .tracing ) {
1758
1760
/* tracemalloc is not tracing: do nothing */
1759
1761
return -2 ;
1760
1762
}
@@ -1777,7 +1779,7 @@ _PyTraceMalloc_NewReference(PyObject *op)
1777
1779
{
1778
1780
assert (PyGILState_Check ());
1779
1781
1780
- if (!_Py_tracemalloc_config .tracing ) {
1782
+ if (!tracemalloc_config .tracing ) {
1781
1783
/* tracemalloc is not tracing: do nothing */
1782
1784
return -1 ;
1783
1785
}
0 commit comments