@@ -33,18 +33,12 @@ static int _PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event,
33
33
#define allocators _PyRuntime.tracemalloc.allocators
34
34
35
35
36
- #if defined(TRACE_RAW_MALLOC )
37
36
/* This lock is needed because tracemalloc_free() is called without
38
37
the GIL held from PyMem_RawFree(). It cannot acquire the lock because it
39
38
would introduce a deadlock in _PyThreadState_DeleteCurrent(). */
40
- # define tables_lock _PyRuntime.tracemalloc.tables_lock
41
- # define TABLES_LOCK () PyThread_acquire_lock(tables_lock, 1)
42
- # define TABLES_UNLOCK () PyThread_release_lock(tables_lock)
43
- #else
44
- /* variables are protected by the GIL */
45
- # define TABLES_LOCK ()
46
- # define TABLES_UNLOCK ()
47
- #endif
39
+ #define tables_lock _PyRuntime.tracemalloc.tables_lock
40
+ #define TABLES_LOCK () PyThread_acquire_lock(tables_lock, 1)
41
+ #define TABLES_UNLOCK () PyThread_release_lock(tables_lock)
48
42
49
43
50
44
#define DEFAULT_DOMAIN 0
@@ -98,9 +92,6 @@ tracemalloc_error(const char *format, ...)
98
92
#endif
99
93
100
94
101
- #if defined(TRACE_RAW_MALLOC )
102
- #define REENTRANT_THREADLOCAL
103
-
104
95
#define tracemalloc_reentrant_key _PyRuntime.tracemalloc.reentrant_key
105
96
106
97
/* Any non-NULL pointer can be used */
@@ -137,25 +128,6 @@ set_reentrant(int reentrant)
137
128
}
138
129
}
139
130
140
- #else
141
-
142
- /* TRACE_RAW_MALLOC not defined: variable protected by the GIL */
143
- static int tracemalloc_reentrant = 0 ;
144
-
145
- static int
146
- get_reentrant (void )
147
- {
148
- return tracemalloc_reentrant ;
149
- }
150
-
151
- static void
152
- set_reentrant (int reentrant )
153
- {
154
- assert (reentrant != tracemalloc_reentrant );
155
- tracemalloc_reentrant = reentrant ;
156
- }
157
- #endif
158
-
159
131
160
132
static Py_uhash_t
161
133
hashtable_hash_pyobject (const void * key )
@@ -709,7 +681,6 @@ tracemalloc_realloc_gil(void *ctx, void *ptr, size_t new_size)
709
681
}
710
682
711
683
712
- #ifdef TRACE_RAW_MALLOC
713
684
static void *
714
685
tracemalloc_raw_malloc (void * ctx , size_t size )
715
686
{
@@ -729,7 +700,6 @@ tracemalloc_raw_realloc(void *ctx, void *ptr, size_t new_size)
729
700
{
730
701
return tracemalloc_realloc (1 , ctx , ptr , new_size );
731
702
}
732
- #endif /* TRACE_RAW_MALLOC */
733
703
734
704
735
705
static void
@@ -767,20 +737,16 @@ _PyTraceMalloc_Init(void)
767
737
768
738
PyMem_GetAllocator (PYMEM_DOMAIN_RAW , & allocators .raw );
769
739
770
- #ifdef REENTRANT_THREADLOCAL
771
740
if (PyThread_tss_create (& tracemalloc_reentrant_key ) != 0 ) {
772
741
return _PyStatus_NO_MEMORY ();
773
742
}
774
- #endif
775
743
776
- #if defined(TRACE_RAW_MALLOC )
777
744
if (tables_lock == NULL ) {
778
745
tables_lock = PyThread_allocate_lock ();
779
746
if (tables_lock == NULL ) {
780
747
return _PyStatus_NO_MEMORY ();
781
748
}
782
749
}
783
- #endif
784
750
785
751
tracemalloc_filenames = hashtable_new (hashtable_hash_pyobject ,
786
752
hashtable_compare_unicode ,
@@ -826,16 +792,12 @@ tracemalloc_deinit(void)
826
792
_Py_hashtable_destroy (tracemalloc_tracebacks );
827
793
_Py_hashtable_destroy (tracemalloc_filenames );
828
794
829
- #if defined(TRACE_RAW_MALLOC )
830
795
if (tables_lock != NULL ) {
831
796
PyThread_free_lock (tables_lock );
832
797
tables_lock = NULL ;
833
798
}
834
- #endif
835
799
836
- #ifdef REENTRANT_THREADLOCAL
837
800
PyThread_tss_delete (& tracemalloc_reentrant_key );
838
- #endif
839
801
}
840
802
841
803
@@ -866,7 +828,6 @@ _PyTraceMalloc_Start(int max_nframe)
866
828
}
867
829
868
830
PyMemAllocatorEx alloc ;
869
- #ifdef TRACE_RAW_MALLOC
870
831
alloc .malloc = tracemalloc_raw_malloc ;
871
832
alloc .calloc = tracemalloc_raw_calloc ;
872
833
alloc .realloc = tracemalloc_raw_realloc ;
@@ -875,7 +836,6 @@ _PyTraceMalloc_Start(int max_nframe)
875
836
alloc .ctx = & allocators .raw ;
876
837
PyMem_GetAllocator (PYMEM_DOMAIN_RAW , & allocators .raw );
877
838
PyMem_SetAllocator (PYMEM_DOMAIN_RAW , & alloc );
878
- #endif
879
839
880
840
alloc .malloc = tracemalloc_malloc_gil ;
881
841
alloc .calloc = tracemalloc_calloc_gil ;
@@ -916,9 +876,7 @@ _PyTraceMalloc_Stop(void)
916
876
tracemalloc_config .tracing = 0 ;
917
877
918
878
/* unregister the hook on memory allocators */
919
- #ifdef TRACE_RAW_MALLOC
920
879
PyMem_SetAllocator (PYMEM_DOMAIN_RAW , & allocators .raw );
921
- #endif
922
880
PyMem_SetAllocator (PYMEM_DOMAIN_MEM , & allocators .mem );
923
881
PyMem_SetAllocator (PYMEM_DOMAIN_OBJ , & allocators .obj );
924
882
0 commit comments