]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-108220: Internal header files require Py_BUILD_CORE to be defined (#108221)
authorVictor Stinner <vstinner@python.org>
Mon, 21 Aug 2023 17:15:52 +0000 (19:15 +0200)
committerGitHub <noreply@github.com>
Mon, 21 Aug 2023 17:15:52 +0000 (19:15 +0200)
* 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).

16 files changed:
Include/internal/pycore_blocks_output_buffer.h
Include/internal/pycore_code.h
Include/internal/pycore_codecs.h
Include/internal/pycore_emscripten_signal.h
Include/internal/pycore_fileutils.h
Include/internal/pycore_fileutils_windows.h
Include/internal/pycore_frame.h
Include/internal/pycore_import.h
Include/internal/pycore_instruments.h
Include/internal/pycore_intrinsics.h
Include/internal/pycore_opcode_metadata.h
Modules/_bz2module.c
Modules/_lzmamodule.c
Modules/_opcode.c
Modules/zlibmodule.c
Tools/cases_generator/generate_cases.py

index 28cf6fba4eeba2e68d7cde88b676589befae4c48..573e10359b7bd271c2da4c9674a643b8e738ae41 100644 (file)
@@ -40,6 +40,10 @@ extern "C" {
 
 #include "Python.h"
 
+#ifndef Py_BUILD_CORE
+#  error "this header requires Py_BUILD_CORE define"
+#endif
+
 typedef struct {
     // List of bytes objects
     PyObject *list;
@@ -314,4 +318,4 @@ _BlocksOutputBuffer_OnError(_BlocksOutputBuffer *buffer)
 #ifdef __cplusplus
 }
 #endif
-#endif /* Py_INTERNAL_BLOCKS_OUTPUT_BUFFER_H */
\ No newline at end of file
+#endif /* Py_INTERNAL_BLOCKS_OUTPUT_BUFFER_H */
index 00099376635e9bad39b355cfe5cf5b981097a64d..f5127a81144353bf72788e115e0c3aad622ee504 100644 (file)
@@ -4,6 +4,10 @@
 extern "C" {
 #endif
 
+#ifndef Py_BUILD_CORE
+#  error "this header requires Py_BUILD_CORE define"
+#endif
+
 #define CODE_MAX_WATCHERS 8
 
 /* PEP 659
index a2465192eacd5edc5bbccb402031f8933c8da492..a2a7151d50ade7ce61932681aef806686de2fcfe 100644 (file)
@@ -4,6 +4,10 @@
 extern "C" {
 #endif
 
+#ifndef Py_BUILD_CORE
+#  error "this header requires Py_BUILD_CORE define"
+#endif
+
 extern PyObject* _PyCodec_Lookup(const char *encoding);
 
 /* Text codec specific encoding and decoding API.
index 8b3287d85da4b2e313b7bed953953f1eb0743ecb..d1bcb9a92c77264f17a68a0aa11287c09b0fb6a8 100644 (file)
@@ -3,6 +3,10 @@
 
 #if defined(__EMSCRIPTEN__)
 
+#ifndef Py_BUILD_CORE
+#  error "this header requires Py_BUILD_CORE define"
+#endif
+
 void
 _Py_CheckEmscriptenSignals(void);
 
index 0ed139f79b14295adc8f0efa785674749f4093c4..25b383b9780adcf5be6b7e853fca988c2f52db17 100644 (file)
@@ -5,7 +5,7 @@ extern "C" {
 #endif
 
 #ifndef Py_BUILD_CORE
-#  error "Py_BUILD_CORE must be defined to include this header"
+#  error "this header requires Py_BUILD_CORE define"
 #endif
 
 #include <locale.h>   /* struct lconv */
index e804d385e76708167887db6a80bfae5fb299eeb1..b79aa9fb4653765cb7f171ade2b1570b5c451e9d 100644 (file)
@@ -5,7 +5,7 @@ extern "C" {
 #endif
 
 #ifndef Py_BUILD_CORE
-#  error "Py_BUILD_CORE must be defined to include this header"
+#  error "this header requires Py_BUILD_CORE define"
 #endif
 
 #ifdef MS_WINDOWS
index 0dc2a1814cb1d56aa70554703a824ae147d4a59a..ae77367f6a3c9b83378e7b17a39cd1372353b43c 100644 (file)
@@ -4,6 +4,10 @@
 extern "C" {
 #endif
 
+#ifndef Py_BUILD_CORE
+#  error "this header requires Py_BUILD_CORE define"
+#endif
+
 #include <stdbool.h>
 #include <stddef.h>               // offsetof()
 #include "pycore_code.h"          // STATS
index 077508e6c58f6c59d8944083472b4e7d4c2c6587..34f572bd59296901011cb0afb7d64b3e95905331 100644 (file)
@@ -5,6 +5,10 @@
 extern "C" {
 #endif
 
+#ifndef Py_BUILD_CORE
+#  error "this header requires Py_BUILD_CORE define"
+#endif
+
 #include "pycore_hashtable.h"     // _Py_hashtable_t
 #include "pycore_time.h"          // _PyTime_t
 
index 56de9f8717148449226a04614d07ecc50e9c003f..e15447acec2c0cac928f6ad0e382c7cada7b2591 100644 (file)
@@ -1,7 +1,9 @@
-
 #ifndef Py_INTERNAL_INSTRUMENT_H
 #define Py_INTERNAL_INSTRUMENT_H
 
+#ifndef Py_BUILD_CORE
+#  error "this header requires Py_BUILD_CORE define"
+#endif
 
 #include "pycore_bitutils.h"      // _Py_popcount32
 #include "pycore_frame.h"
index 37d4efc12bb771e9d9d28e5c488623697867f8bb..3a8dd95cff8e5db677d9be16c5dfbcbdd9cfc821 100644 (file)
@@ -1,3 +1,9 @@
+#ifndef Py_INTERNAL_INTRINSIC_H
+#define Py_INTERNAL_INTRINSIC_H
+
+#ifndef Py_BUILD_CORE
+#  error "this header requires Py_BUILD_CORE define"
+#endif
 
 /* Unary Functions: */
 #define INTRINSIC_1_INVALID                      0
@@ -40,3 +46,5 @@ typedef struct {
 
 extern const intrinsic_func1_info _PyIntrinsics_UnaryFunctions[];
 extern const intrinsic_func2_info _PyIntrinsics_BinaryFunctions[];
+
+#endif  // !Py_INTERNAL_INTRINSIC_H
index 396d194ed2734e3ca97e9f76c69b7163a90b494e..fab91e611b6175d3aa6748d5fa98816203f8d4b0 100644 (file)
@@ -3,6 +3,10 @@
 //   Python/bytecodes.c
 // Do not edit!
 
+#ifndef Py_BUILD_CORE
+#  error "this header requires Py_BUILD_CORE define"
+#endif
+
 #include <stdbool.h>
 
 
index 0a84f25ca4cbe7bf773d364a1f0fae3ffc51374f..3d0d4ee5e79c2bb5634d5474b11cc6ec153ca3f3 100644 (file)
@@ -1,5 +1,9 @@
 /* _bz2 - Low-level Python interface to libbzip2. */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 
 #include <bzlib.h>
index c548f8fa3839e0193927197d78c0f93b7372197e..eb90c308d16d19590db0763ae67f43a00efd902a 100644 (file)
@@ -5,6 +5,10 @@
 
 */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 
 
index 4f85e7ee26de2a06a1694ff614d82b758cea49f5..3e13dbb6edc26edcd5f4d30807cc0949d0022ed3 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include "compile.h"
 #include "opcode.h"
index a98a37adadcff0292bf4f9055f19de0d579a14fd..9b76afa0e56f76e6e2f700080902bb6d0664f5a7 100644 (file)
@@ -3,6 +3,10 @@
 
 /* Windows users:  read Python's PCbuild\readme.txt */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 
 #include "zlib.h"
index 7b1880b98a8feb1a003af0855f355f1cb7077dcc..c3b729df44a6a286e5a0586e12fdf12d18f6a0d8 100644 (file)
@@ -9,6 +9,7 @@ import itertools
 import os
 import posixpath
 import sys
+import textwrap
 import typing
 from collections.abc import Iterator
 
@@ -403,6 +404,12 @@ class Generator(Analyzer):
 
             self.write_provenance_header()
 
+            self.out.emit("\n" + textwrap.dedent("""
+                #ifndef Py_BUILD_CORE
+                #  error "this header requires Py_BUILD_CORE define"
+                #endif
+            """).strip())
+
             self.out.emit("\n#include <stdbool.h>")
 
             self.write_pseudo_instrs()