@@ -221,7 +221,9 @@ static void __attribute__((constructor)) constructor() {
221221#endif
222222 // Initialize Rust static state before we start doing any calls via malloc(),
223223 // to ensure we don't get unpleasant reentrancy issues.
224+ increment_reentrancy ();
224225 pymemprofile_reset ("/tmp" );
226+ decrement_reentrancy ();
225227
226228 // Drop LD_PRELOAD so that Linux subprocesses don't have this preloaded.
227229 unsetenv ("LD_PRELOAD" );
@@ -350,7 +352,9 @@ __attribute__((visibility("default"))) void register_fil_tracer() {
350352 // C threads inherit their callstack from the creating Python thread. That's
351353 // fine. However, if a tracer is being registered, that means this is not a
352354 // pure C thread, it's a new Python thread with its own callstack.
355+ increment_reentrancy ();
353356 pymemprofile_clear_current_callstack ();
357+ decrement_reentrancy ();
354358 // We use 123 as a marker object for tests.
355359 PyEval_SetProfile (fil_tracer , PyLong_FromLong (123 ));
356360}
@@ -590,7 +594,9 @@ SYMBOL_PREFIX(pthread_create)(pthread_t *thread, const pthread_attr_t *attr,
590594 }
591595 struct NewThreadArgs * wrapper_args =
592596 REAL_IMPL (malloc )(sizeof (struct NewThreadArgs ));
597+ increment_reentrancy ();
593598 wrapper_args -> callstack = pymemprofile_get_current_callstack ();
599+ decrement_reentrancy ();
594600 wrapper_args -> start_routine = start_routine ;
595601 wrapper_args -> arg = arg ;
596602 int result = underlying_real_pthread_create (
0 commit comments