Skip to content

Commit 3e3c4e5

Browse files
committed
Fix _remote_debugging header include order and macOS compatibility
The _GNU_SOURCE macro must be defined before any system headers are included to enable GNU extensions like process_vm_readv. Moving it before the extern "C" block ensures it takes effect. The internal Python headers are also changed from angle brackets to quotes since they're local to the project. On macOS, the TARGET_OS_OSX macro may not be defined by older SDKs, so we now include TargetConditionals.h explicitly and provide a fallback definition when needed.
1 parent f564654 commit 3e3c4e5

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

Modules/_remote_debugging/_remote_debugging.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,24 @@
88
#ifndef Py_REMOTE_DEBUGGING_H
99
#define Py_REMOTE_DEBUGGING_H
1010

11+
/* _GNU_SOURCE must be defined before any system headers */
12+
#define _GNU_SOURCE
13+
1114
#ifdef __cplusplus
1215
extern "C" {
1316
#endif
1417

15-
#define _GNU_SOURCE
16-
1718
#ifndef Py_BUILD_CORE_BUILTIN
1819
# define Py_BUILD_CORE_MODULE 1
1920
#endif
2021

2122
#include "Python.h"
22-
#include <internal/pycore_debug_offsets.h> // _Py_DebugOffsets
23-
#include <internal/pycore_frame.h> // FRAME_SUSPENDED_YIELD_FROM
24-
#include <internal/pycore_interpframe.h> // FRAME_OWNED_BY_INTERPRETER
25-
#include <internal/pycore_llist.h> // struct llist_node
26-
#include <internal/pycore_long.h> // _PyLong_GetZero
27-
#include <internal/pycore_stackref.h> // Py_TAG_BITS
23+
#include "internal/pycore_debug_offsets.h" // _Py_DebugOffsets
24+
#include "internal/pycore_frame.h" // FRAME_SUSPENDED_YIELD_FROM
25+
#include "internal/pycore_interpframe.h" // FRAME_OWNED_BY_INTERPRETER
26+
#include "internal/pycore_llist.h" // struct llist_node
27+
#include "internal/pycore_long.h" // _PyLong_GetZero
28+
#include "internal/pycore_stackref.h" // Py_TAG_BITS
2829
#include "../../Python/remote_debug.h"
2930

3031
#include <assert.h>
@@ -40,10 +41,17 @@ extern "C" {
4041
# define HAVE_PROCESS_VM_READV 0
4142
#endif
4243

43-
#if defined(__APPLE__) && TARGET_OS_OSX
44-
#include <libproc.h>
45-
#include <sys/types.h>
46-
#define MAX_NATIVE_THREADS 4096
44+
#if defined(__APPLE__)
45+
#include <TargetConditionals.h>
46+
# if !defined(TARGET_OS_OSX)
47+
/* Older macOS SDKs do not define TARGET_OS_OSX */
48+
# define TARGET_OS_OSX 1
49+
# endif
50+
# if TARGET_OS_OSX
51+
# include <libproc.h>
52+
# include <sys/types.h>
53+
# define MAX_NATIVE_THREADS 4096
54+
# endif
4755
#endif
4856

4957
#ifdef MS_WINDOWS

0 commit comments

Comments
 (0)