Skip to content

Commit 130893d

Browse files
authored
bpo-35081: Internal headers require Py_BUILD_CORE (pythonGH-10363)
* All internal header files now require Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN to be defined. * _json.c is now compiled with Py_BUILD_CORE_BUILTIN to access pycore_accu.h header. * Add an example to Modules/Setup to show how to build _json as a built-in module; it requires non trivial compiler options.
1 parent 0a18e05 commit 130893d

16 files changed

+48
-13
lines changed

Include/internal/pycore_accu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ extern "C" {
99
*** Its definition may be changed or removed at any moment.
1010
***/
1111

12+
#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
13+
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
14+
#endif
15+
1216
/*
1317
* A two-level accumulator of unicode objects that avoids both the overhead
1418
* of keeping a huge number of small separate objects, and the quadratic

Include/internal/pycore_atomic.h

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

7-
#ifndef Py_BUILD_CORE
8-
# error "Py_BUILD_CORE must be defined to include this header"
7+
#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
8+
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
99
#endif
1010

1111
#include "dynamic_annotations.h"

Include/internal/pycore_ceval.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+
#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
8+
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
9+
#endif
10+
711
#include "pycore_atomic.h"
812
#include "pythread.h"
913

Include/internal/pycore_condvar.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#ifndef Py_INTERNAL_CONDVAR_H
22
#define Py_INTERNAL_CONDVAR_H
33

4+
#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
5+
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
6+
#endif
7+
48
#ifndef _POSIX_THREADS
59
/* This means pthreads are not implemented in libc headers, hence the macro
610
not present in unistd.h. But they still can be implemented as an external

Include/internal/pycore_context.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#ifndef Py_INTERNAL_CONTEXT_H
22
#define Py_INTERNAL_CONTEXT_H
33

4+
#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
5+
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
6+
#endif
47

58
#include "pycore_hamt.h"
69

7-
810
struct _pycontextobject {
911
PyObject_HEAD
1012
PyContext *ctx_prev;
@@ -37,5 +39,4 @@ struct _pycontexttokenobject {
3739
int _PyContext_Init(void);
3840
void _PyContext_Fini(void);
3941

40-
4142
#endif /* !Py_INTERNAL_CONTEXT_H */

Include/internal/pycore_getopt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#ifndef Py_INTERNAL_PYGETOPT_H
22
#define Py_INTERNAL_PYGETOPT_H
33

4+
#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
5+
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
6+
#endif
7+
48
extern int _PyOS_opterr;
59
extern int _PyOS_optind;
610
extern wchar_t *_PyOS_optarg;

Include/internal/pycore_gil.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+
#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
8+
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
9+
#endif
10+
711
#include "pycore_condvar.h"
812
#include "pycore_atomic.h"
913

Include/internal/pycore_hamt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#ifndef Py_INTERNAL_HAMT_H
22
#define Py_INTERNAL_HAMT_H
33

4+
#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
5+
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
6+
#endif
47

58
#define _Py_HAMT_MAX_TREE_DEPTH 7
69

Include/internal/pycore_hash.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#ifndef Py_INTERNAL_HASH_H
22
#define Py_INTERNAL_HASH_H
33

4+
#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
5+
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
6+
#endif
7+
48
uint64_t _Py_KeyedHash(uint64_t, const char *, Py_ssize_t);
59

610
#endif

Include/internal/pycore_lifecycle.h

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

7-
#ifndef Py_BUILD_CORE
8-
# error "Py_BUILD_CORE must be defined to include this header"
7+
#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
8+
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
99
#endif
1010

1111
PyAPI_FUNC(int) _Py_UnixMain(int argc, char **argv);

0 commit comments

Comments
 (0)