Skip to content

Commit 21c0844

Browse files
authored
gh-108220: Internal header files require Py_BUILD_CORE to be defined (#108221)
* pycore_intrinsics.h does nothing if included twice (add #ifndef and #define). * Update Tools/cases_generator/generate_cases.py to generate the Py_BUILD_CORE test. * _bz2, _lzma, _opcode and zlib extensions now define the Py_BUILD_CORE_MODULE macro to use internal headers (pycore_code.h, pycore_intrinsics.h and pycore_blocks_output_buffer.h).
1 parent db55383 commit 21c0844

16 files changed

+65
-4
lines changed

Include/internal/pycore_blocks_output_buffer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ extern "C" {
4040

4141
#include "Python.h"
4242

43+
#ifndef Py_BUILD_CORE
44+
# error "this header requires Py_BUILD_CORE define"
45+
#endif
46+
4347
typedef struct {
4448
// List of bytes objects
4549
PyObject *list;
@@ -314,4 +318,4 @@ _BlocksOutputBuffer_OnError(_BlocksOutputBuffer *buffer)
314318
#ifdef __cplusplus
315319
}
316320
#endif
317-
#endif /* Py_INTERNAL_BLOCKS_OUTPUT_BUFFER_H */
321+
#endif /* Py_INTERNAL_BLOCKS_OUTPUT_BUFFER_H */

Include/internal/pycore_code.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
extern "C" {
55
#endif
66

7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
10+
711
#define CODE_MAX_WATCHERS 8
812

913
/* PEP 659

Include/internal/pycore_codecs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
extern "C" {
55
#endif
66

7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
10+
711
extern PyObject* _PyCodec_Lookup(const char *encoding);
812

913
/* Text codec specific encoding and decoding API.

Include/internal/pycore_emscripten_signal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
#if defined(__EMSCRIPTEN__)
55

6+
#ifndef Py_BUILD_CORE
7+
# error "this header requires Py_BUILD_CORE define"
8+
#endif
9+
610
void
711
_Py_CheckEmscriptenSignals(void);
812

Include/internal/pycore_fileutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern "C" {
55
#endif
66

77
#ifndef Py_BUILD_CORE
8-
# error "Py_BUILD_CORE must be defined to include this header"
8+
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

1111
#include <locale.h> /* struct lconv */

Include/internal/pycore_fileutils_windows.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern "C" {
55
#endif
66

77
#ifndef Py_BUILD_CORE
8-
# error "Py_BUILD_CORE must be defined to include this header"
8+
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

1111
#ifdef MS_WINDOWS

Include/internal/pycore_frame.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
extern "C" {
55
#endif
66

7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
10+
711
#include <stdbool.h>
812
#include <stddef.h> // offsetof()
913
#include "pycore_code.h" // STATS

Include/internal/pycore_import.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
extern "C" {
66
#endif
77

8+
#ifndef Py_BUILD_CORE
9+
# error "this header requires Py_BUILD_CORE define"
10+
#endif
11+
812
#include "pycore_hashtable.h" // _Py_hashtable_t
913
#include "pycore_time.h" // _PyTime_t
1014

Include/internal/pycore_instruments.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
21
#ifndef Py_INTERNAL_INSTRUMENT_H
32
#define Py_INTERNAL_INSTRUMENT_H
43

4+
#ifndef Py_BUILD_CORE
5+
# error "this header requires Py_BUILD_CORE define"
6+
#endif
57

68
#include "pycore_bitutils.h" // _Py_popcount32
79
#include "pycore_frame.h"

Include/internal/pycore_intrinsics.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#ifndef Py_INTERNAL_INTRINSIC_H
2+
#define Py_INTERNAL_INTRINSIC_H
3+
4+
#ifndef Py_BUILD_CORE
5+
# error "this header requires Py_BUILD_CORE define"
6+
#endif
17

28
/* Unary Functions: */
39
#define INTRINSIC_1_INVALID 0
@@ -40,3 +46,5 @@ typedef struct {
4046

4147
extern const intrinsic_func1_info _PyIntrinsics_UnaryFunctions[];
4248
extern const intrinsic_func2_info _PyIntrinsics_BinaryFunctions[];
49+
50+
#endif // !Py_INTERNAL_INTRINSIC_H

0 commit comments

Comments
 (0)