mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	bpo-35081: Internal headers require Py_BUILD_CORE (GH-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.
This commit is contained in:
		
							parent
							
								
									0a18e0510a
								
							
						
					
					
						commit
						130893debf
					
				
					 16 changed files with 48 additions and 13 deletions
				
			
		|  | @ -9,6 +9,10 @@ extern "C" { | ||||||
|  *** Its definition may be changed or removed at any moment. |  *** 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 |  * A two-level accumulator of unicode objects that avoids both the overhead | ||||||
|  * of keeping a huge number of small separate objects, and the quadratic |  * of keeping a huge number of small separate objects, and the quadratic | ||||||
|  |  | ||||||
|  | @ -4,8 +4,8 @@ | ||||||
| extern "C" { | extern "C" { | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifndef Py_BUILD_CORE | #if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN) | ||||||
| #  error "Py_BUILD_CORE must be defined to include this header" | #  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define" | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #include "dynamic_annotations.h" | #include "dynamic_annotations.h" | ||||||
|  |  | ||||||
|  | @ -4,6 +4,10 @@ | ||||||
| extern "C" { | extern "C" { | ||||||
| #endif | #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 "pycore_atomic.h" | ||||||
| #include "pythread.h" | #include "pythread.h" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,6 +1,10 @@ | ||||||
| #ifndef Py_INTERNAL_CONDVAR_H | #ifndef Py_INTERNAL_CONDVAR_H | ||||||
| #define 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 | #ifndef _POSIX_THREADS | ||||||
| /* This means pthreads are not implemented in libc headers, hence the macro
 | /* 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 |    not present in unistd.h. But they still can be implemented as an external | ||||||
|  |  | ||||||
|  | @ -1,10 +1,12 @@ | ||||||
| #ifndef Py_INTERNAL_CONTEXT_H | #ifndef Py_INTERNAL_CONTEXT_H | ||||||
| #define 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" | #include "pycore_hamt.h" | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| struct _pycontextobject { | struct _pycontextobject { | ||||||
|     PyObject_HEAD |     PyObject_HEAD | ||||||
|     PyContext *ctx_prev; |     PyContext *ctx_prev; | ||||||
|  | @ -37,5 +39,4 @@ struct _pycontexttokenobject { | ||||||
| int _PyContext_Init(void); | int _PyContext_Init(void); | ||||||
| void _PyContext_Fini(void); | void _PyContext_Fini(void); | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| #endif /* !Py_INTERNAL_CONTEXT_H */ | #endif /* !Py_INTERNAL_CONTEXT_H */ | ||||||
|  |  | ||||||
|  | @ -1,6 +1,10 @@ | ||||||
| #ifndef Py_INTERNAL_PYGETOPT_H | #ifndef Py_INTERNAL_PYGETOPT_H | ||||||
| #define 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_opterr; | ||||||
| extern int _PyOS_optind; | extern int _PyOS_optind; | ||||||
| extern wchar_t *_PyOS_optarg; | extern wchar_t *_PyOS_optarg; | ||||||
|  |  | ||||||
|  | @ -4,6 +4,10 @@ | ||||||
| extern "C" { | extern "C" { | ||||||
| #endif | #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_condvar.h" | ||||||
| #include "pycore_atomic.h" | #include "pycore_atomic.h" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,6 +1,9 @@ | ||||||
| #ifndef Py_INTERNAL_HAMT_H | #ifndef Py_INTERNAL_HAMT_H | ||||||
| #define 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 | #define _Py_HAMT_MAX_TREE_DEPTH 7 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,6 +1,10 @@ | ||||||
| #ifndef Py_INTERNAL_HASH_H | #ifndef Py_INTERNAL_HASH_H | ||||||
| #define 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); | uint64_t _Py_KeyedHash(uint64_t, const char *, Py_ssize_t); | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | @ -4,8 +4,8 @@ | ||||||
| extern "C" { | extern "C" { | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifndef Py_BUILD_CORE | #if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN) | ||||||
| #  error "Py_BUILD_CORE must be defined to include this header" | #  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define" | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| PyAPI_FUNC(int) _Py_UnixMain(int argc, char **argv); | PyAPI_FUNC(int) _Py_UnixMain(int argc, char **argv); | ||||||
|  |  | ||||||
|  | @ -4,8 +4,8 @@ | ||||||
| extern "C" { | extern "C" { | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifndef Py_BUILD_CORE | #if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN) | ||||||
| #  error "Py_BUILD_CORE must be defined to include this header" | #  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN defined" | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #include "objimpl.h" | #include "objimpl.h" | ||||||
|  |  | ||||||
|  | @ -4,8 +4,8 @@ | ||||||
| extern "C" { | extern "C" { | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifndef Py_BUILD_CORE | #if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN) | ||||||
| #  error "Py_BUILD_CORE must be defined to include this header" | #  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define" | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| PyAPI_FUNC(void) _Py_wstrlist_clear( | PyAPI_FUNC(void) _Py_wstrlist_clear( | ||||||
|  |  | ||||||
|  | @ -4,8 +4,8 @@ | ||||||
| extern "C" { | extern "C" { | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifndef Py_BUILD_CORE | #if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN) | ||||||
| #  error "Py_BUILD_CORE must be defined to include this header" | #  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define" | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #include "pystate.h" | #include "pystate.h" | ||||||
|  |  | ||||||
|  | @ -4,6 +4,10 @@ | ||||||
| extern "C" { | extern "C" { | ||||||
| #endif | #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" | #include "object.h" | ||||||
| 
 | 
 | ||||||
| struct _warnings_runtime_state { | struct _warnings_runtime_state { | ||||||
|  |  | ||||||
|  | @ -180,6 +180,7 @@ _symtable symtablemodule.c | ||||||
| #_bisect _bisectmodule.c	# Bisection algorithms | #_bisect _bisectmodule.c	# Bisection algorithms | ||||||
| #_heapq _heapqmodule.c	# Heap queue algorithm | #_heapq _heapqmodule.c	# Heap queue algorithm | ||||||
| #_asyncio _asynciomodule.c  # Fast asyncio Future | #_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 | #unicodedata unicodedata.c    # static Unicode character database | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										4
									
								
								setup.py
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								setup.py
									
										
									
									
									
								
							|  | @ -678,7 +678,9 @@ def detect_modules(self): | ||||||
|         # atexit |         # atexit | ||||||
|         exts.append( Extension("atexit", ["atexitmodule.c"]) ) |         exts.append( Extension("atexit", ["atexitmodule.c"]) ) | ||||||
|         # _json speedups |         # _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 |         # Python C API test module | ||||||
|         exts.append( Extension('_testcapi', ['_testcapimodule.c'], |         exts.append( Extension('_testcapi', ['_testcapimodule.c'], | ||||||
|                                depends=['testcapi_long.h']) ) |                                depends=['testcapi_long.h']) ) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Victor Stinner
						Victor Stinner