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).
This commit is contained in:
Victor Stinner 2023-08-21 19:15:52 +02:00 committed by GitHub
parent db55383829
commit 21c0844742
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 65 additions and 4 deletions

View 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;

View 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

View 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.

View 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);

View 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 */

View 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

View 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

View 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

View 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"

View 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

View 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>

View 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>

View File

@ -5,6 +5,10 @@
*/
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
#include "Python.h"

View 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"

View 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"

View 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()