gh-107211: No longer export internal functions (5) (#108423)

No longer export _PyCompile_AstOptimize() internal C API function.

Change comment style to "// comment" and add comment explaining why
other functions have to be exported.
This commit is contained in:
Victor Stinner 2023-08-24 18:06:53 +02:00 committed by GitHub
parent f1ae706ca5
commit b7808820b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 73 additions and 39 deletions

View File

@ -28,34 +28,37 @@ PyAPI_FUNC(PyObject*) _PyBytes_DecodeEscape(const char *, Py_ssize_t,
extern PyObject* _PyBytes_Join(PyObject *sep, PyObject *x); extern PyObject* _PyBytes_Join(PyObject *sep, PyObject *x);
/* Substring Search. // Substring Search.
//
Returns the index of the first occurrence of // Returns the index of the first occurrence of
a substring ("needle") in a larger text ("haystack"). // a substring ("needle") in a larger text ("haystack").
If the needle is not found, return -1. // If the needle is not found, return -1.
If the needle is found, add offset to the index. // If the needle is found, add offset to the index.
*/ //
// Export for 'mmap' shared extension.
PyAPI_FUNC(Py_ssize_t) PyAPI_FUNC(Py_ssize_t)
_PyBytes_Find(const char *haystack, Py_ssize_t len_haystack, _PyBytes_Find(const char *haystack, Py_ssize_t len_haystack,
const char *needle, Py_ssize_t len_needle, const char *needle, Py_ssize_t len_needle,
Py_ssize_t offset); Py_ssize_t offset);
/* Same as above, but search right-to-left */ // Same as above, but search right-to-left.
// Export for 'mmap' shared extension.
PyAPI_FUNC(Py_ssize_t) PyAPI_FUNC(Py_ssize_t)
_PyBytes_ReverseFind(const char *haystack, Py_ssize_t len_haystack, _PyBytes_ReverseFind(const char *haystack, Py_ssize_t len_haystack,
const char *needle, Py_ssize_t len_needle, const char *needle, Py_ssize_t len_needle,
Py_ssize_t offset); Py_ssize_t offset);
/** Helper function to implement the repeat and inplace repeat methods on a buffer // Helper function to implement the repeat and inplace repeat methods on a
* // buffer.
* len_dest is assumed to be an integer multiple of len_src. //
* If src equals dest, then assume the operation is inplace. // len_dest is assumed to be an integer multiple of len_src.
* // If src equals dest, then assume the operation is inplace.
* This method repeately doubles the number of bytes copied to reduce //
* the number of invocations of memcpy. // This method repeately doubles the number of bytes copied to reduce
*/ // the number of invocations of memcpy.
//
// Export for 'array' shared extension.
PyAPI_FUNC(void) PyAPI_FUNC(void)
_PyBytes_Repeat(char* dest, Py_ssize_t len_dest, _PyBytes_Repeat(char* dest, Py_ssize_t len_dest,
const char* src, Py_ssize_t len_src); const char* src, Py_ssize_t len_src);
@ -91,7 +94,9 @@ typedef struct {
/* Initialize a bytes writer /* Initialize a bytes writer
By default, the overallocation is disabled. Set the overallocate attribute By default, the overallocation is disabled. Set the overallocate attribute
to control the allocation of the buffer. */ to control the allocation of the buffer.
Export _PyBytesWriter API for '_pickle' shared extension. */
PyAPI_FUNC(void) _PyBytesWriter_Init(_PyBytesWriter *writer); PyAPI_FUNC(void) _PyBytesWriter_Init(_PyBytesWriter *writer);
/* Get the buffer content and reset the writer. /* Get the buffer content and reset the writer.

View File

@ -22,8 +22,8 @@ extern "C" {
#define _PY_FASTCALL_SMALL_STACK 5 #define _PY_FASTCALL_SMALL_STACK 5
// Export for 'math' shared extension, function used // Export for 'math' shared extension, used via _PyObject_VectorcallTstate()
// via inlined _PyObject_VectorcallTstate() function. // static inline function.
PyAPI_FUNC(PyObject*) _Py_CheckFunctionResult( PyAPI_FUNC(PyObject*) _Py_CheckFunctionResult(
PyThreadState *tstate, PyThreadState *tstate,
PyObject *callable, PyObject *callable,
@ -120,8 +120,8 @@ _PyObject_CallMethodIdOneArg(PyObject *self, _Py_Identifier *name, PyObject *arg
// Call callable using tp_call. Arguments are like PyObject_Vectorcall(), // Call callable using tp_call. Arguments are like PyObject_Vectorcall(),
// except that nargs is plainly the number of arguments without flags. // except that nargs is plainly the number of arguments without flags.
// //
// Export for 'math' shared extension, function used // Export for 'math' shared extension, used via _PyObject_VectorcallTstate()
// via inlined _PyObject_VectorcallTstate() function. // static inline function.
PyAPI_FUNC(PyObject*) _PyObject_MakeTpCall( PyAPI_FUNC(PyObject*) _PyObject_MakeTpCall(
PyThreadState *tstate, PyThreadState *tstate,
PyObject *callable, PyObject *callable,

View File

@ -23,12 +23,14 @@ extern void _Py_FinishPendingCalls(PyThreadState *tstate);
extern void _PyEval_InitState(PyInterpreterState *, PyThread_type_lock); extern void _PyEval_InitState(PyInterpreterState *, PyThread_type_lock);
extern void _PyEval_FiniState(struct _ceval_state *ceval); extern void _PyEval_FiniState(struct _ceval_state *ceval);
extern void _PyEval_SignalReceived(PyInterpreterState *interp); extern void _PyEval_SignalReceived(PyInterpreterState *interp);
// Export for '_testinternalcapi' shared extension // Export for '_testinternalcapi' shared extension
PyAPI_FUNC(int) _PyEval_AddPendingCall( PyAPI_FUNC(int) _PyEval_AddPendingCall(
PyInterpreterState *interp, PyInterpreterState *interp,
int (*func)(void *), int (*func)(void *),
void *arg, void *arg,
int mainthreadonly); int mainthreadonly);
extern void _PyEval_SignalAsyncExc(PyInterpreterState *interp); extern void _PyEval_SignalAsyncExc(PyInterpreterState *interp);
#ifdef HAVE_FORK #ifdef HAVE_FORK
extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate); extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);
@ -122,7 +124,8 @@ static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
} }
#endif #endif
// Export for _Py_EnterRecursiveCall() // Export for '_json' shared extension, used via _Py_EnterRecursiveCall()
// static inline function.
PyAPI_FUNC(int) _Py_CheckRecursiveCall( PyAPI_FUNC(int) _Py_CheckRecursiveCall(
PyThreadState *tstate, PyThreadState *tstate,
const char *where); const char *where);

View File

@ -20,7 +20,7 @@ PyAPI_FUNC(PyCodeObject*) _PyAST_Compile(
struct _arena *arena); struct _arena *arena);
/* AST optimizations */ /* AST optimizations */
PyAPI_FUNC(int) _PyCompile_AstOptimize( extern int _PyCompile_AstOptimize(
struct _mod *mod, struct _mod *mod,
PyObject *filename, PyObject *filename,
PyCompilerFlags *flags, PyCompilerFlags *flags,
@ -107,6 +107,7 @@ int _PyCompile_ConstCacheMergeOne(PyObject *const_cache, PyObject **obj);
// Export for '_testinternalcapi' shared extension // Export for '_testinternalcapi' shared extension
PyAPI_FUNC(PyObject*) _PyCompile_CleanDoc(PyObject *doc); PyAPI_FUNC(PyObject*) _PyCompile_CleanDoc(PyObject *doc);
// Export for '_testinternalcapi' shared extension
PyAPI_FUNC(PyObject*) _PyCompile_CodeGen( PyAPI_FUNC(PyObject*) _PyCompile_CodeGen(
PyObject *ast, PyObject *ast,
PyObject *filename, PyObject *filename,
@ -114,11 +115,13 @@ PyAPI_FUNC(PyObject*) _PyCompile_CodeGen(
int optimize, int optimize,
int compile_mode); int compile_mode);
// Export for '_testinternalcapi' shared extension
PyAPI_FUNC(PyObject*) _PyCompile_OptimizeCfg( PyAPI_FUNC(PyObject*) _PyCompile_OptimizeCfg(
PyObject *instructions, PyObject *instructions,
PyObject *consts, PyObject *consts,
int nlocals); int nlocals);
// Export for '_testinternalcapi' shared extension
PyAPI_FUNC(PyCodeObject*) PyAPI_FUNC(PyCodeObject*)
_PyCompile_Assemble(_PyCompile_CodeUnitMetadata *umd, PyObject *filename, _PyCompile_Assemble(_PyCompile_CodeUnitMetadata *umd, PyObject *filename,
PyObject *instructions); PyObject *instructions);

View File

@ -10,8 +10,8 @@ extern "C" {
#include "pycore_unicodeobject.h" // _PyUnicodeWriter #include "pycore_unicodeobject.h" // _PyUnicodeWriter
/* Operations on complex numbers from complexmodule.c */ // Operations on complex numbers.
// Export functions for 'cmath' shared extension.
PyAPI_FUNC(Py_complex) _Py_c_sum(Py_complex, Py_complex); PyAPI_FUNC(Py_complex) _Py_c_sum(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) _Py_c_diff(Py_complex, Py_complex); PyAPI_FUNC(Py_complex) _Py_c_diff(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) _Py_c_neg(Py_complex); PyAPI_FUNC(Py_complex) _Py_c_neg(Py_complex);

View File

@ -35,8 +35,10 @@ typedef enum {
_Py_ERROR_OTHER _Py_ERROR_OTHER
} _Py_error_handler; } _Py_error_handler;
// Export for '_testinternalcapi' shared extension
PyAPI_FUNC(_Py_error_handler) _Py_GetErrorHandler(const char *errors); PyAPI_FUNC(_Py_error_handler) _Py_GetErrorHandler(const char *errors);
// Export for '_testinternalcapi' shared extension
PyAPI_FUNC(int) _Py_DecodeLocaleEx( PyAPI_FUNC(int) _Py_DecodeLocaleEx(
const char *arg, const char *arg,
wchar_t **wstr, wchar_t **wstr,
@ -45,6 +47,7 @@ PyAPI_FUNC(int) _Py_DecodeLocaleEx(
int current_locale, int current_locale,
_Py_error_handler errors); _Py_error_handler errors);
// Export for '_testinternalcapi' shared extension
PyAPI_FUNC(int) _Py_EncodeLocaleEx( PyAPI_FUNC(int) _Py_EncodeLocaleEx(
const wchar_t *text, const wchar_t *text,
char **str, char **str,
@ -98,23 +101,27 @@ struct _Py_stat_struct {
# define _Py_stat_struct stat # define _Py_stat_struct stat
#endif #endif
// Export for 'mmap' shared extension
PyAPI_FUNC(int) _Py_fstat( PyAPI_FUNC(int) _Py_fstat(
int fd, int fd,
struct _Py_stat_struct *status); struct _Py_stat_struct *status);
// Export for 'mmap' shared extension
PyAPI_FUNC(int) _Py_fstat_noraise( PyAPI_FUNC(int) _Py_fstat_noraise(
int fd, int fd,
struct _Py_stat_struct *status); struct _Py_stat_struct *status);
// Export for '_tkinter' shared extension
PyAPI_FUNC(int) _Py_stat( PyAPI_FUNC(int) _Py_stat(
PyObject *path, PyObject *path,
struct stat *status); struct stat *status);
// Export for 'select' shared extension (Solaris newDevPollObject() uses it) // Export for 'select' shared extension (Solaris newDevPollObject())
PyAPI_FUNC(int) _Py_open( PyAPI_FUNC(int) _Py_open(
const char *pathname, const char *pathname,
int flags); int flags);
// Export for '_posixsubprocess' shared extension
PyAPI_FUNC(int) _Py_open_noraise( PyAPI_FUNC(int) _Py_open_noraise(
const char *pathname, const char *pathname,
int flags); int flags);
@ -128,12 +135,13 @@ extern Py_ssize_t _Py_read(
void *buf, void *buf,
size_t count); size_t count);
// Export for 'select' shared extension (Solaris devpoll_flush() uses it) // Export for 'select' shared extension (Solaris devpoll_flush())
PyAPI_FUNC(Py_ssize_t) _Py_write( PyAPI_FUNC(Py_ssize_t) _Py_write(
int fd, int fd,
const void *buf, const void *buf,
size_t count); size_t count);
// Export for '_posixsubprocess' shared extension
PyAPI_FUNC(Py_ssize_t) _Py_write_noraise( PyAPI_FUNC(Py_ssize_t) _Py_write_noraise(
int fd, int fd,
const void *buf, const void *buf,
@ -165,12 +173,15 @@ extern wchar_t* _Py_wgetcwd(
extern int _Py_get_inheritable(int fd); extern int _Py_get_inheritable(int fd);
// Export for '_socket' shared extension
PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable, PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable,
int *atomic_flag_works); int *atomic_flag_works);
// Export for '_posixsubprocess' shared extension
PyAPI_FUNC(int) _Py_set_inheritable_async_safe(int fd, int inheritable, PyAPI_FUNC(int) _Py_set_inheritable_async_safe(int fd, int inheritable,
int *atomic_flag_works); int *atomic_flag_works);
// Export for '_socket' shared extension
PyAPI_FUNC(int) _Py_dup(int fd); PyAPI_FUNC(int) _Py_dup(int fd);
extern int _Py_get_blocking(int fd); extern int _Py_get_blocking(int fd);
@ -180,6 +191,7 @@ extern int _Py_set_blocking(int fd, int blocking);
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
extern void* _Py_get_osfhandle_noraise(int fd); extern void* _Py_get_osfhandle_noraise(int fd);
// Export for '_testconsole' shared extension
PyAPI_FUNC(void*) _Py_get_osfhandle(int fd); PyAPI_FUNC(void*) _Py_get_osfhandle(int fd);
extern int _Py_open_osfhandle_noraise(void *handle, int flags); extern int _Py_open_osfhandle_noraise(void *handle, int flags);
@ -234,6 +246,7 @@ extern int _Py_GetLocaleconvNumeric(
PyObject **decimal_point, PyObject **decimal_point,
PyObject **thousands_sep); PyObject **thousands_sep);
// Export for '_posixsubprocess' (on macOS)
PyAPI_FUNC(void) _Py_closerange(int first, int last); PyAPI_FUNC(void) _Py_closerange(int first, int last);
extern wchar_t* _Py_GetLocaleEncoding(void); extern wchar_t* _Py_GetLocaleEncoding(void);
@ -262,7 +275,10 @@ extern int _Py_add_relfile(wchar_t *dirname,
const wchar_t *relfile, const wchar_t *relfile,
size_t bufsize); size_t bufsize);
extern size_t _Py_find_basename(const wchar_t *filename); extern size_t _Py_find_basename(const wchar_t *filename);
// Export for '_testinternalcapi' shared extension
PyAPI_FUNC(wchar_t*) _Py_normpath(wchar_t *path, Py_ssize_t size); PyAPI_FUNC(wchar_t*) _Py_normpath(wchar_t *path, Py_ssize_t size);
extern wchar_t *_Py_normpath_and_size(wchar_t *path, Py_ssize_t size, Py_ssize_t *length); extern wchar_t *_Py_normpath_and_size(wchar_t *path, Py_ssize_t size, Py_ssize_t *length);
// The Windows Games API family does not provide these functions // The Windows Games API family does not provide these functions

View File

@ -13,6 +13,7 @@ extern void _PyGen_Finalize(PyObject *self);
// Export for '_asyncio' shared extension // Export for '_asyncio' shared extension
PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *); PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);
// Export for '_asyncio' shared extension // Export for '_asyncio' shared extension
PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **); PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);

View File

@ -70,6 +70,11 @@ struct _Py_hashtable_t {
_Py_hashtable_allocator_t alloc; _Py_hashtable_allocator_t alloc;
}; };
// Export _Py_hashtable functions for '_testinternalcapi' shared extension
PyAPI_FUNC(_Py_hashtable_t *) _Py_hashtable_new(
_Py_hashtable_hash_func hash_func,
_Py_hashtable_compare_func compare_func);
/* Hash a pointer (void*) */ /* Hash a pointer (void*) */
PyAPI_FUNC(Py_uhash_t) _Py_hashtable_hash_ptr(const void *key); PyAPI_FUNC(Py_uhash_t) _Py_hashtable_hash_ptr(const void *key);
@ -78,10 +83,6 @@ PyAPI_FUNC(int) _Py_hashtable_compare_direct(
const void *key1, const void *key1,
const void *key2); const void *key2);
PyAPI_FUNC(_Py_hashtable_t *) _Py_hashtable_new(
_Py_hashtable_hash_func hash_func,
_Py_hashtable_compare_func compare_func);
PyAPI_FUNC(_Py_hashtable_t *) _Py_hashtable_new_full( PyAPI_FUNC(_Py_hashtable_t *) _Py_hashtable_new_full(
_Py_hashtable_hash_func hash_func, _Py_hashtable_hash_func hash_func,
_Py_hashtable_compare_func compare_func, _Py_hashtable_compare_func compare_func,

View File

@ -14,7 +14,9 @@ extern "C" {
extern int _PyImport_IsInitialized(PyInterpreterState *); extern int _PyImport_IsInitialized(PyInterpreterState *);
// Export for 'pyexpat' shared extension
PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module); PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module);
extern int _PyImport_SetModuleString(const char *name, PyObject* module); extern int _PyImport_SetModuleString(const char *name, PyObject* module);
extern void _PyImport_AcquireLock(PyInterpreterState *interp); extern void _PyImport_AcquireLock(PyInterpreterState *interp);
@ -28,7 +30,10 @@ extern int _PyImport_FixupBuiltin(
extern int _PyImport_FixupExtensionObject(PyObject*, PyObject *, extern int _PyImport_FixupExtensionObject(PyObject*, PyObject *,
PyObject *, PyObject *); PyObject *, PyObject *);
// Export for many shared extensions, like '_json'
PyAPI_FUNC(PyObject*) _PyImport_GetModuleAttr(PyObject *, PyObject *); PyAPI_FUNC(PyObject*) _PyImport_GetModuleAttr(PyObject *, PyObject *);
// Export for many shared extensions, like '_datetime'
PyAPI_FUNC(PyObject*) _PyImport_GetModuleAttrString(const char *, const char *); PyAPI_FUNC(PyObject*) _PyImport_GetModuleAttrString(const char *, const char *);
@ -187,11 +192,9 @@ struct _module_alias {
const char *orig; /* ASCII encoded string */ const char *orig; /* ASCII encoded string */
}; };
// Export for test_ctypes // Export these 3 symbols for test_ctypes
PyAPI_DATA(const struct _frozen*) _PyImport_FrozenBootstrap; PyAPI_DATA(const struct _frozen*) _PyImport_FrozenBootstrap;
// Export for test_ctypes
PyAPI_DATA(const struct _frozen*) _PyImport_FrozenStdlib; PyAPI_DATA(const struct _frozen*) _PyImport_FrozenStdlib;
// Export for test_ctypes
PyAPI_DATA(const struct _frozen*) _PyImport_FrozenTest; PyAPI_DATA(const struct _frozen*) _PyImport_FrozenTest;
extern const struct _module_alias * _PyImport_FrozenAliases; extern const struct _module_alias * _PyImport_FrozenAliases;

View File

@ -124,6 +124,7 @@ extern PyStatus _PyPreCmdline_Read(_PyPreCmdline *cmdline,
// Export for '_testembed' program // Export for '_testembed' program
PyAPI_FUNC(void) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig); PyAPI_FUNC(void) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig);
extern void _PyPreConfig_InitFromConfig( extern void _PyPreConfig_InitFromConfig(
PyPreConfig *preconfig, PyPreConfig *preconfig,
const PyConfig *config); const PyConfig *config);
@ -149,6 +150,7 @@ typedef enum {
// Export for '_testembed' program // Export for '_testembed' program
PyAPI_FUNC(void) _PyConfig_InitCompatConfig(PyConfig *config); PyAPI_FUNC(void) _PyConfig_InitCompatConfig(PyConfig *config);
extern PyStatus _PyConfig_Copy( extern PyStatus _PyConfig_Copy(
PyConfig *config, PyConfig *config,
const PyConfig *config2); const PyConfig *config2);
@ -163,16 +165,16 @@ extern PyStatus _PyConfig_SetPyArgv(
PyConfig *config, PyConfig *config,
const _PyArgv *args); const _PyArgv *args);
PyAPI_FUNC(PyObject*) _PyConfig_AsDict(const PyConfig *config);
PyAPI_FUNC(int) _PyConfig_FromDict(PyConfig *config, PyObject *dict);
extern void _Py_DumpPathConfig(PyThreadState *tstate); extern void _Py_DumpPathConfig(PyThreadState *tstate);
PyAPI_FUNC(PyObject*) _Py_Get_Getpath_CodeObject(void);
/* --- Function used for testing ---------------------------------- */ /* --- Function used for testing ---------------------------------- */
// Export these functions for '_testinternalcapi' shared extension
PyAPI_FUNC(PyObject*) _PyConfig_AsDict(const PyConfig *config);
PyAPI_FUNC(int) _PyConfig_FromDict(PyConfig *config, PyObject *dict);
PyAPI_FUNC(PyObject*) _Py_Get_Getpath_CodeObject(void);
PyAPI_FUNC(PyObject*) _Py_GetConfigsAsDict(void); PyAPI_FUNC(PyObject*) _Py_GetConfigsAsDict(void);
#ifdef __cplusplus #ifdef __cplusplus