]> granicus.if.org Git - python/commitdiff
bpo-35081: Internal headers require Py_BUILD_CORE (GH-10363)
authorVictor Stinner <vstinner@redhat.com>
Fri, 9 Nov 2018 12:03:37 +0000 (13:03 +0100)
committerGitHub <noreply@github.com>
Fri, 9 Nov 2018 12:03:37 +0000 (13:03 +0100)
* 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.

16 files changed:
Include/internal/pycore_accu.h
Include/internal/pycore_atomic.h
Include/internal/pycore_ceval.h
Include/internal/pycore_condvar.h
Include/internal/pycore_context.h
Include/internal/pycore_getopt.h
Include/internal/pycore_gil.h
Include/internal/pycore_hamt.h
Include/internal/pycore_hash.h
Include/internal/pycore_lifecycle.h
Include/internal/pycore_mem.h
Include/internal/pycore_pathconfig.h
Include/internal/pycore_state.h
Include/internal/pycore_warnings.h
Modules/Setup
setup.py

index ab1aad28034644a84b8f965a3d056ebfb9b5b82a..4350db58a26905dc96fe2f98eb3d8737b6948a78 100644 (file)
@@ -9,6 +9,10 @@ extern "C" {
  *** Its definition may be changed or removed at any moment.
  ***/
 
+#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+#  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#endif
+
 /*
  * A two-level accumulator of unicode objects that avoids both the overhead
  * of keeping a huge number of small separate objects, and the quadratic
index 5f349cc3e9e99c531d615c3179ac895d4346c93a..f430a5c26ff882cb2e1d76b199afe9433d8753f4 100644 (file)
@@ -4,8 +4,8 @@
 extern "C" {
 #endif
 
-#ifndef Py_BUILD_CORE
-#  error "Py_BUILD_CORE must be defined to include this header"
+#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+#  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
 #endif
 
 #include "dynamic_annotations.h"
index ddeeb5c4256f50641387e4f4cbe2f0fa5b3cf8eb..c8c63b1c7fdafe7969a140650a1390ab2be5ce7f 100644 (file)
@@ -4,6 +4,10 @@
 extern "C" {
 #endif
 
+#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+#  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#endif
+
 #include "pycore_atomic.h"
 #include "pythread.h"
 
index f9330890d3e64580775713caf29f82101e9a8e54..a12b6994ad55cc4a13ac3967214e5b0c972e9492 100644 (file)
@@ -1,6 +1,10 @@
 #ifndef Py_INTERNAL_CONDVAR_H
 #define Py_INTERNAL_CONDVAR_H
 
+#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+#  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#endif
+
 #ifndef _POSIX_THREADS
 /* This means pthreads are not implemented in libc headers, hence the macro
    not present in unistd.h. But they still can be implemented as an external
index 57a410c06f687a162625aaffc2f7f11631f847c1..70701cdd11dc612e43a055e55efed115b0b140c2 100644 (file)
@@ -1,10 +1,12 @@
 #ifndef Py_INTERNAL_CONTEXT_H
 #define Py_INTERNAL_CONTEXT_H
 
+#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+#  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#endif
 
 #include "pycore_hamt.h"
 
-
 struct _pycontextobject {
     PyObject_HEAD
     PyContext *ctx_prev;
@@ -37,5 +39,4 @@ struct _pycontexttokenobject {
 int _PyContext_Init(void);
 void _PyContext_Fini(void);
 
-
 #endif /* !Py_INTERNAL_CONTEXT_H */
index 8ef2ada72fee2477ddd46e5a3d29917dae270125..e6f4654a666b6b51bf0fd6d455b704b122add949 100644 (file)
@@ -1,6 +1,10 @@
 #ifndef Py_INTERNAL_PYGETOPT_H
 #define Py_INTERNAL_PYGETOPT_H
 
+#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+#  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#endif
+
 extern int _PyOS_opterr;
 extern int _PyOS_optind;
 extern wchar_t *_PyOS_optarg;
index 5059850d76f85a55096a6c677ec7526db30a60bd..014e75fd182f189c0743f626e194acc84feae1cb 100644 (file)
@@ -4,6 +4,10 @@
 extern "C" {
 #endif
 
+#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+#  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#endif
+
 #include "pycore_condvar.h"
 #include "pycore_atomic.h"
 
index 29ad28b1d8706e77706bd0e1d1f59d4bc666fd4c..8b2ce1fc96c346ece9a06b570c92e87583060f04 100644 (file)
@@ -1,6 +1,9 @@
 #ifndef Py_INTERNAL_HAMT_H
 #define Py_INTERNAL_HAMT_H
 
+#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+#  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#endif
 
 #define _Py_HAMT_MAX_TREE_DEPTH 7
 
index e14b80a7f27fd36a48b7b1cabebfc66f60506e7c..babbc95b879e35d5dc0b0b1a6d0289efbadc0974 100644 (file)
@@ -1,6 +1,10 @@
 #ifndef Py_INTERNAL_HASH_H
 #define Py_INTERNAL_HASH_H
 
+#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+#  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#endif
+
 uint64_t _Py_KeyedHash(uint64_t, const char *, Py_ssize_t);
 
 #endif
index cf36440eabcf44b79e58ca4d7d3eb8632f70023a..e10431690cbda6142b3b71f230b6b59a70f6ef64 100644 (file)
@@ -4,8 +4,8 @@
 extern "C" {
 #endif
 
-#ifndef Py_BUILD_CORE
-#  error "Py_BUILD_CORE must be defined to include this header"
+#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+#  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
 #endif
 
 PyAPI_FUNC(int) _Py_UnixMain(int argc, char **argv);
index 4a41b77734ac41aee1c303640c1bfa7a6f487973..247426afe722e42ab56dc28c055a4c07f8ed8316 100644 (file)
@@ -4,8 +4,8 @@
 extern "C" {
 #endif
 
-#ifndef Py_BUILD_CORE
-#  error "Py_BUILD_CORE must be defined to include this header"
+#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+#  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN defined"
 #endif
 
 #include "objimpl.h"
index 00d7bbf23ea411a14cada8336704d32fb62e343f..267e690976da87d290d75fab34f3f5c633f1aa5f 100644 (file)
@@ -4,8 +4,8 @@
 extern "C" {
 #endif
 
-#ifndef Py_BUILD_CORE
-#  error "Py_BUILD_CORE must be defined to include this header"
+#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+#  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
 #endif
 
 PyAPI_FUNC(void) _Py_wstrlist_clear(
index 6285ecf5f5dc4241869bf0137b23d95efdf707ac..01f214045c5026247f235a9960c7d8942976719f 100644 (file)
@@ -4,8 +4,8 @@
 extern "C" {
 #endif
 
-#ifndef Py_BUILD_CORE
-#  error "Py_BUILD_CORE must be defined to include this header"
+#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+#  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
 #endif
 
 #include "pystate.h"
index 2878a28a2ee837bb0d1ce67fb97baf1fa6f72d78..91bf90232f5c795671f492a49b27a38fd9046f1c 100644 (file)
@@ -4,6 +4,10 @@
 extern "C" {
 #endif
 
+#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+#  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
+#endif
+
 #include "object.h"
 
 struct _warnings_runtime_state {
index e2b5f86f38e0fd1e598fc66b95e5c543c3cee118..e7b939d55182348426ddd8fc9d458ac5d5ca0f59 100644 (file)
@@ -180,6 +180,7 @@ _symtable symtablemodule.c
 #_bisect _bisectmodule.c       # Bisection algorithms
 #_heapq _heapqmodule.c # Heap queue algorithm
 #_asyncio _asynciomodule.c  # Fast asyncio Future
+#_json -I$(srcdir)/Include/internal -DPy_BUILD_CORE_BUILTIN _json.c    # _json speedups
 
 #unicodedata unicodedata.c    # static Unicode character database
 
index 37c5dd58a6d2d7de67da1c26467ab057a7332497..b87d05d2143f38317e97e7a823d78096d448bc32 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -678,7 +678,9 @@ class PyBuildExt(build_ext):
         # atexit
         exts.append( Extension("atexit", ["atexitmodule.c"]) )
         # _json speedups
-        exts.append( Extension("_json", ["_json.c"]) )
+        exts.append( Extension("_json", ["_json.c"],
+                               # pycore_accu.h requires Py_BUILD_CORE_BUILTIN
+                               extra_compile_args=['-DPy_BUILD_CORE_BUILTIN']) )
         # Python C API test module
         exts.append( Extension('_testcapi', ['_testcapimodule.c'],
                                depends=['testcapi_long.h']) )