Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/spprof/_ext/platform/darwin_mach.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@
#include "../code_registry.h"

/* Internal API for Python frame capture */
#ifdef SPPROF_USE_INTERNAL_API
#include "../internal/pycore_tstate.h"
#endif

/* Architecture-specific includes */
#if defined(__x86_64__)
Expand Down Expand Up @@ -913,7 +911,6 @@ static void sample_all_threads(ThreadSnapshot* snapshot, MachSamplerState* state
uintptr_t instr_ptrs[SPPROF_MAX_STACK_DEPTH];
int python_depth = 0;

#ifdef SPPROF_USE_INTERNAL_API
/* Capture Python frames from the suspended thread's state.
* This is safe because the target thread is suspended. */
python_depth = _spprof_capture_frames_with_instr_from_tstate(
Expand Down Expand Up @@ -945,7 +942,6 @@ static void sample_all_threads(ThreadSnapshot* snapshot, MachSamplerState* state
uint64_t gc_epoch = code_registry_get_gc_epoch();
code_registry_add_refs_batch(python_frames, python_depth, gc_epoch);
}
#endif

/* ================================================================
* Resume thread IMMEDIATELY after capture and INCREF
Expand Down
39 changes: 10 additions & 29 deletions src/spprof/_ext/signal_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@
* This file is still compiled on Darwin for compatibility but the signal
* handler is not used. */

#ifdef SPPROF_USE_INTERNAL_API
#include "internal/pycore_frame.h"
#include "internal/pycore_tstate.h"
#endif

/*
* FREE-THREADING SAFETY CHECK
Expand All @@ -92,12 +90,10 @@
* Darwin uses Mach-based sampling (darwin_mach.c) which is safe.
* This file is still compiled but the handler is effectively disabled.
*/
#ifdef SPPROF_USE_INTERNAL_API
#if !SPPROF_FREE_THREADING_SAFE
/* Signal handler will return immediately without capturing frames */
#define SPPROF_SIGNAL_HANDLER_DISABLED 1
#endif
#endif

/*
* =============================================================================
Expand Down Expand Up @@ -209,17 +205,12 @@ static inline uint64_t get_thread_id_unsafe(void) {
*/
static inline int
capture_python_stack_unsafe(uintptr_t* frames, int max_depth) {
#ifdef SPPROF_USE_INTERNAL_API
#if SPPROF_FREE_THREADED && defined(__linux__)
/* Free-threaded Linux: Use speculative capture with validation */
return _spprof_capture_frames_speculative(frames, max_depth);
#else
/* GIL-enabled or Darwin (uses Mach sampler): Use direct capture */
return _spprof_capture_frames_unsafe(frames, max_depth);
#endif
#if SPPROF_FREE_THREADED && defined(__linux__)
/* Free-threaded Linux: Use speculative capture with validation */
return _spprof_capture_frames_speculative(frames, max_depth);
#else
/* Fallback: use framewalker (may not be fully signal-safe) */
return framewalker_capture_raw(frames, max_depth);
/* GIL-enabled or Darwin (uses Mach sampler): Use direct capture */
return _spprof_capture_frames_unsafe(frames, max_depth);
#endif
}

Expand All @@ -232,22 +223,12 @@ capture_python_stack_unsafe(uintptr_t* frames, int max_depth) {
*/
static inline int
capture_python_stack_with_instr_unsafe(uintptr_t* frames, uintptr_t* instr_ptrs, int max_depth) {
#ifdef SPPROF_USE_INTERNAL_API
#if SPPROF_FREE_THREADED && defined(__linux__)
/* Free-threaded Linux: Use speculative capture with validation */
return _spprof_capture_frames_with_instr_speculative(frames, instr_ptrs, max_depth);
#else
/* GIL-enabled or Darwin (uses Mach sampler): Use direct capture */
return _spprof_capture_frames_with_instr_unsafe(frames, instr_ptrs, max_depth);
#endif
#if SPPROF_FREE_THREADED && defined(__linux__)
/* Free-threaded Linux: Use speculative capture with validation */
return _spprof_capture_frames_with_instr_speculative(frames, instr_ptrs, max_depth);
#else
/* Fallback: capture frames only, no instruction pointers */
int depth = framewalker_capture_raw(frames, max_depth);
/* Zero out instruction pointers - resolver will use first line */
for (int i = 0; i < depth; i++) {
instr_ptrs[i] = 0;
}
return depth;
/* GIL-enabled or Darwin (uses Mach sampler): Use direct capture */
return _spprof_capture_frames_with_instr_unsafe(frames, instr_ptrs, max_depth);
#endif
}

Expand Down
Loading