gh-107211: No longer export internal functions (2) (#107214)

No longer export these 43 internal C API functions:

* _PyDict_CheckConsistency()
* _PyErr_ChainStackItem()
* _PyErr_CheckSignals()
* _PyErr_CheckSignalsTstate()
* _PyErr_Clear()
* _PyErr_ExceptionMatches()
* _PyErr_Fetch()
* _PyErr_Format()
* _PyErr_FormatFromCauseTstate()
* _PyErr_GetExcInfo()
* _PyErr_GetHandledException()
* _PyErr_GetTopmostException()
* _PyErr_NoMemory()
* _PyErr_NormalizeException()
* _PyErr_Restore()
* _PyErr_SetHandledException()
* _PyErr_SetNone()
* _PyErr_SetObject()
* _PyErr_SetString()
* _PyErr_StackItemToExcInfoTuple()
* _PyExc_CreateExceptionGroup()
* _PyExc_PrepReraiseStar()
* _PyException_AddNote()
* _PyInterpreterState_Enable()
* _PyLong_FormatAdvancedWriter()
* _PyLong_FormatBytesWriter()
* _PyLong_FormatWriter()
* _PyMem_GetAllocatorName()
* _PyMem_SetDefaultAllocator()
* _PyMem_SetupAllocators()
* _PyOS_InterruptOccurred()
* _PyRuntimeState_Fini()
* _PyRuntimeState_Init()
* _PyRuntime_Finalize()
* _PyRuntime_Initialize()
* _PyThreadState_Bind()
* _PyThreadState_DeleteExcept()
* _PyThreadState_New()
* _PyThreadState_Swap()
* _PyType_CheckConsistency()
* _PyUnicodeTranslateError_Create()
* _Py_DumpExtensionModules()
* _Py_FatalErrorFormat()
This commit is contained in:
Victor Stinner 2023-07-25 03:49:28 +02:00 committed by GitHub
parent 11306a91bd
commit 5a61692c6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 68 additions and 61 deletions

View file

@ -79,9 +79,9 @@ static inline PyObject* _PyLong_FromUnsignedChar(unsigned char i)
return Py_NewRef((PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS+i]); return Py_NewRef((PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS+i]);
} }
PyObject *_PyLong_Add(PyLongObject *left, PyLongObject *right); extern PyObject *_PyLong_Add(PyLongObject *left, PyLongObject *right);
PyObject *_PyLong_Multiply(PyLongObject *left, PyLongObject *right); extern PyObject *_PyLong_Multiply(PyLongObject *left, PyLongObject *right);
PyObject *_PyLong_Subtract(PyLongObject *left, PyLongObject *right); extern PyObject *_PyLong_Subtract(PyLongObject *left, PyLongObject *right);
/* Used by Python/mystrtoul.c, _PyBytes_FromHex(), /* Used by Python/mystrtoul.c, _PyBytes_FromHex(),
_PyBytes_DecodeEscape(), etc. */ _PyBytes_DecodeEscape(), etc. */
@ -89,20 +89,20 @@ PyAPI_DATA(unsigned char) _PyLong_DigitValue[256];
/* Format the object based on the format_spec, as defined in PEP 3101 /* Format the object based on the format_spec, as defined in PEP 3101
(Advanced String Formatting). */ (Advanced String Formatting). */
PyAPI_FUNC(int) _PyLong_FormatAdvancedWriter( extern int _PyLong_FormatAdvancedWriter(
_PyUnicodeWriter *writer, _PyUnicodeWriter *writer,
PyObject *obj, PyObject *obj,
PyObject *format_spec, PyObject *format_spec,
Py_ssize_t start, Py_ssize_t start,
Py_ssize_t end); Py_ssize_t end);
PyAPI_FUNC(int) _PyLong_FormatWriter( extern int _PyLong_FormatWriter(
_PyUnicodeWriter *writer, _PyUnicodeWriter *writer,
PyObject *obj, PyObject *obj,
int base, int base,
int alternate); int alternate);
PyAPI_FUNC(char*) _PyLong_FormatBytesWriter( extern char* _PyLong_FormatBytesWriter(
_PyBytesWriter *writer, _PyBytesWriter *writer,
char *str, char *str,
PyObject *obj, PyObject *obj,

View file

@ -10,7 +10,7 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define" # error "this header requires Py_BUILD_CORE define"
#endif #endif
PyAPI_DATA(PyTypeObject) _PyNamespace_Type; extern PyTypeObject _PyNamespace_Type;
PyAPI_FUNC(PyObject*) _PyNamespace_New(PyObject *kwds); PyAPI_FUNC(PyObject*) _PyNamespace_New(PyObject *kwds);

View file

@ -156,8 +156,8 @@ _Py_DECREF_NO_DEALLOC(PyObject *op)
#endif #endif
PyAPI_FUNC(int) _PyType_CheckConsistency(PyTypeObject *type); extern int _PyType_CheckConsistency(PyTypeObject *type);
PyAPI_FUNC(int) _PyDict_CheckConsistency(PyObject *mp, int check_content); extern int _PyDict_CheckConsistency(PyObject *mp, int check_content);
/* Update the Python traceback of an object. This function must be called /* Update the Python traceback of an object. This function must be called
when a memory block is reused from a free list. when a memory block is reused from a free list.

View file

@ -1,4 +1,6 @@
/* An arena-like memory interface for the compiler. /* An arena-like memory interface for the compiler.
*
* Export symbols for test_peg_generator.
*/ */
#ifndef Py_INTERNAL_PYARENA_H #ifndef Py_INTERNAL_PYARENA_H

View file

@ -11,41 +11,42 @@ extern "C" {
/* Error handling definitions */ /* Error handling definitions */
PyAPI_FUNC(_PyErr_StackItem*) _PyErr_GetTopmostException(PyThreadState *tstate); extern _PyErr_StackItem* _PyErr_GetTopmostException(PyThreadState *tstate);
PyAPI_FUNC(PyObject*) _PyErr_GetHandledException(PyThreadState *); extern PyObject* _PyErr_GetHandledException(PyThreadState *);
PyAPI_FUNC(void) _PyErr_SetHandledException(PyThreadState *, PyObject *); extern void _PyErr_SetHandledException(PyThreadState *, PyObject *);
PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **); extern void _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **);
/* Like PyErr_Format(), but saves current exception as __context__ and // Like PyErr_Format(), but saves current exception as __context__ and
__cause__. // __cause__.
*/ // Export for '_sqlite3' shared extension.
PyAPI_FUNC(PyObject*) _PyErr_FormatFromCause( PyAPI_FUNC(PyObject*) _PyErr_FormatFromCause(
PyObject *exception, PyObject *exception,
const char *format, /* ASCII-encoded string */ const char *format, /* ASCII-encoded string */
... ...
); );
PyAPI_FUNC(int) _PyException_AddNote( extern int _PyException_AddNote(
PyObject *exc, PyObject *exc,
PyObject *note); PyObject *note);
PyAPI_FUNC(int) _PyErr_CheckSignals(void); extern int _PyErr_CheckSignals(void);
/* Support for adding program text to SyntaxErrors */ /* Support for adding program text to SyntaxErrors */
// Export for test_peg_generator
PyAPI_FUNC(PyObject*) _PyErr_ProgramDecodedTextObject( PyAPI_FUNC(PyObject*) _PyErr_ProgramDecodedTextObject(
PyObject *filename, PyObject *filename,
int lineno, int lineno,
const char* encoding); const char* encoding);
PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create( extern PyObject* _PyUnicodeTranslateError_Create(
PyObject *object, PyObject *object,
Py_ssize_t start, Py_ssize_t start,
Py_ssize_t end, Py_ssize_t end,
const char *reason /* UTF-8 encoded string */ const char *reason /* UTF-8 encoded string */
); );
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFormat( extern void _Py_NO_RETURN _Py_FatalErrorFormat(
const char *func, const char *func,
const char *format, const char *format,
...); ...);
@ -79,80 +80,79 @@ static inline void _PyErr_ClearExcState(_PyErr_StackItem *exc_state)
Py_CLEAR(exc_state->exc_value); Py_CLEAR(exc_state->exc_value);
} }
PyAPI_FUNC(PyObject*) _PyErr_StackItemToExcInfoTuple( extern PyObject* _PyErr_StackItemToExcInfoTuple(
_PyErr_StackItem *err_info); _PyErr_StackItem *err_info);
PyAPI_FUNC(void) _PyErr_Fetch( extern void _PyErr_Fetch(
PyThreadState *tstate, PyThreadState *tstate,
PyObject **type, PyObject **type,
PyObject **value, PyObject **value,
PyObject **traceback); PyObject **traceback);
extern PyObject * extern PyObject* _PyErr_GetRaisedException(PyThreadState *tstate);
_PyErr_GetRaisedException(PyThreadState *tstate);
PyAPI_FUNC(int) _PyErr_ExceptionMatches( extern int _PyErr_ExceptionMatches(
PyThreadState *tstate, PyThreadState *tstate,
PyObject *exc); PyObject *exc);
void extern void _PyErr_SetRaisedException(PyThreadState *tstate, PyObject *exc);
_PyErr_SetRaisedException(PyThreadState *tstate, PyObject *exc);
PyAPI_FUNC(void) _PyErr_Restore( extern void _PyErr_Restore(
PyThreadState *tstate, PyThreadState *tstate,
PyObject *type, PyObject *type,
PyObject *value, PyObject *value,
PyObject *traceback); PyObject *traceback);
PyAPI_FUNC(void) _PyErr_SetObject( extern void _PyErr_SetObject(
PyThreadState *tstate, PyThreadState *tstate,
PyObject *type, PyObject *type,
PyObject *value); PyObject *value);
PyAPI_FUNC(void) _PyErr_ChainStackItem(void); extern void _PyErr_ChainStackItem(void);
PyAPI_FUNC(void) _PyErr_Clear(PyThreadState *tstate); extern void _PyErr_Clear(PyThreadState *tstate);
PyAPI_FUNC(void) _PyErr_SetNone(PyThreadState *tstate, PyObject *exception); extern void _PyErr_SetNone(PyThreadState *tstate, PyObject *exception);
PyAPI_FUNC(PyObject *) _PyErr_NoMemory(PyThreadState *tstate); extern PyObject* _PyErr_NoMemory(PyThreadState *tstate);
PyAPI_FUNC(void) _PyErr_SetString( extern void _PyErr_SetString(
PyThreadState *tstate, PyThreadState *tstate,
PyObject *exception, PyObject *exception,
const char *string); const char *string);
PyAPI_FUNC(PyObject *) _PyErr_Format( extern PyObject* _PyErr_Format(
PyThreadState *tstate, PyThreadState *tstate,
PyObject *exception, PyObject *exception,
const char *format, const char *format,
...); ...);
PyAPI_FUNC(void) _PyErr_NormalizeException( extern void _PyErr_NormalizeException(
PyThreadState *tstate, PyThreadState *tstate,
PyObject **exc, PyObject **exc,
PyObject **val, PyObject **val,
PyObject **tb); PyObject **tb);
PyAPI_FUNC(PyObject *) _PyErr_FormatFromCauseTstate( extern PyObject* _PyErr_FormatFromCauseTstate(
PyThreadState *tstate, PyThreadState *tstate,
PyObject *exception, PyObject *exception,
const char *format, const char *format,
...); ...);
PyAPI_FUNC(PyObject *) _PyExc_CreateExceptionGroup( extern PyObject* _PyExc_CreateExceptionGroup(
const char *msg, const char *msg,
PyObject *excs); PyObject *excs);
PyAPI_FUNC(PyObject *) _PyExc_PrepReraiseStar( extern PyObject* _PyExc_PrepReraiseStar(
PyObject *orig, PyObject *orig,
PyObject *excs); PyObject *excs);
PyAPI_FUNC(int) _PyErr_CheckSignalsTstate(PyThreadState *tstate); extern int _PyErr_CheckSignalsTstate(PyThreadState *tstate);
PyAPI_FUNC(void) _Py_DumpExtensionModules(int fd, PyInterpreterState *interp); extern void _Py_DumpExtensionModules(int fd, PyInterpreterState *interp);
extern PyObject* _Py_Offer_Suggestions(PyObject* exception); extern PyObject* _Py_Offer_Suggestions(PyObject* exception);
// Export for '_testinternalcapi' shared extension
PyAPI_FUNC(Py_ssize_t) _Py_UTF8_Edit_Cost(PyObject *str_a, PyObject *str_b, PyAPI_FUNC(Py_ssize_t) _Py_UTF8_Edit_Cost(PyObject *str_a, PyObject *str_b,
Py_ssize_t max_cost); Py_ssize_t max_cost);

View file

@ -48,7 +48,7 @@ struct _pymem_allocators {
/* Set the memory allocator of the specified domain to the default. /* Set the memory allocator of the specified domain to the default.
Save the old allocator into *old_alloc if it's non-NULL. Save the old allocator into *old_alloc if it's non-NULL.
Return on success, or return -1 if the domain is unknown. */ Return on success, or return -1 if the domain is unknown. */
PyAPI_FUNC(int) _PyMem_SetDefaultAllocator( extern int _PyMem_SetDefaultAllocator(
PyMemAllocatorDomain domain, PyMemAllocatorDomain domain,
PyMemAllocatorEx *old_alloc); PyMemAllocatorEx *old_alloc);
@ -94,14 +94,14 @@ static inline int _PyMem_IsPtrFreed(const void *ptr)
#endif #endif
} }
PyAPI_FUNC(int) _PyMem_GetAllocatorName( extern int _PyMem_GetAllocatorName(
const char *name, const char *name,
PyMemAllocatorName *allocator); PyMemAllocatorName *allocator);
/* Configure the Python memory allocators. /* Configure the Python memory allocators.
Pass PYMEM_ALLOCATOR_DEFAULT to use default allocators. Pass PYMEM_ALLOCATOR_DEFAULT to use default allocators.
PYMEM_ALLOCATOR_NOT_SET does nothing. */ PYMEM_ALLOCATOR_NOT_SET does nothing. */
PyAPI_FUNC(int) _PyMem_SetupAllocators(PyMemAllocatorName allocator); extern int _PyMem_SetupAllocators(PyMemAllocatorName allocator);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -121,15 +121,16 @@ static inline PyInterpreterState* _PyInterpreterState_GET(void) {
// PyThreadState functions // PyThreadState functions
PyAPI_FUNC(PyThreadState *) _PyThreadState_New(PyInterpreterState *interp); extern PyThreadState * _PyThreadState_New(PyInterpreterState *interp);
PyAPI_FUNC(void) _PyThreadState_Bind(PyThreadState *tstate); extern void _PyThreadState_Bind(PyThreadState *tstate);
PyAPI_FUNC(void) _PyThreadState_DeleteExcept(PyThreadState *tstate); extern void _PyThreadState_DeleteExcept(PyThreadState *tstate);
extern void _PyThreadState_InitDetached(PyThreadState *, PyInterpreterState *); extern void _PyThreadState_InitDetached(PyThreadState *, PyInterpreterState *);
extern void _PyThreadState_ClearDetached(PyThreadState *); extern void _PyThreadState_ClearDetached(PyThreadState *);
extern void _PyThreadState_BindDetached(PyThreadState *); extern void _PyThreadState_BindDetached(PyThreadState *);
extern void _PyThreadState_UnbindDetached(PyThreadState *); extern void _PyThreadState_UnbindDetached(PyThreadState *);
// Export for '_testinternalcapi' shared extension
PyAPI_FUNC(PyObject*) _PyThreadState_GetDict(PyThreadState *tstate); PyAPI_FUNC(PyObject*) _PyThreadState_GetDict(PyThreadState *tstate);
/* The implementation of sys._current_frames() Returns a dict mapping /* The implementation of sys._current_frames() Returns a dict mapping
@ -145,25 +146,25 @@ extern PyObject* _PyThread_CurrentExceptions(void);
/* Other */ /* Other */
PyAPI_FUNC(PyThreadState *) _PyThreadState_Swap( extern PyThreadState * _PyThreadState_Swap(
_PyRuntimeState *runtime, _PyRuntimeState *runtime,
PyThreadState *newts); PyThreadState *newts);
PyAPI_FUNC(PyStatus) _PyInterpreterState_Enable(_PyRuntimeState *runtime); extern PyStatus _PyInterpreterState_Enable(_PyRuntimeState *runtime);
#ifdef HAVE_FORK #ifdef HAVE_FORK
extern PyStatus _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime); extern PyStatus _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime);
extern void _PySignal_AfterFork(void); extern void _PySignal_AfterFork(void);
#endif #endif
// Export for the stable ABI
PyAPI_FUNC(int) _PyState_AddModule( PyAPI_FUNC(int) _PyState_AddModule(
PyThreadState *tstate, PyThreadState *tstate,
PyObject* module, PyObject* module,
PyModuleDef* def); PyModuleDef* def);
PyAPI_FUNC(int) _PyOS_InterruptOccurred(PyThreadState *tstate); extern int _PyOS_InterruptOccurred(PyThreadState *tstate);
#define HEAD_LOCK(runtime) \ #define HEAD_LOCK(runtime) \
PyThread_acquire_lock((runtime)->interpreters.mutex, WAIT_LOCK) PyThread_acquire_lock((runtime)->interpreters.mutex, WAIT_LOCK)
@ -172,6 +173,7 @@ PyAPI_FUNC(int) _PyOS_InterruptOccurred(PyThreadState *tstate);
// Get the configuration of the current interpreter. // Get the configuration of the current interpreter.
// The caller must hold the GIL. // The caller must hold the GIL.
// Export for test_peg_generator.
PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void); PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void);

View file

@ -274,8 +274,8 @@ typedef struct pyruntimestate {
PyAPI_DATA(_PyRuntimeState) _PyRuntime; PyAPI_DATA(_PyRuntimeState) _PyRuntime;
PyAPI_FUNC(PyStatus) _PyRuntimeState_Init(_PyRuntimeState *runtime); extern PyStatus _PyRuntimeState_Init(_PyRuntimeState *runtime);
PyAPI_FUNC(void) _PyRuntimeState_Fini(_PyRuntimeState *runtime); extern void _PyRuntimeState_Fini(_PyRuntimeState *runtime);
#ifdef HAVE_FORK #ifdef HAVE_FORK
extern PyStatus _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime); extern PyStatus _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime);
@ -283,9 +283,9 @@ extern PyStatus _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime);
/* Initialize _PyRuntimeState. /* Initialize _PyRuntimeState.
Return NULL on success, or return an error message on failure. */ Return NULL on success, or return an error message on failure. */
PyAPI_FUNC(PyStatus) _PyRuntime_Initialize(void); extern PyStatus _PyRuntime_Initialize(void);
PyAPI_FUNC(void) _PyRuntime_Finalize(void); extern void _PyRuntime_Finalize(void);
static inline PyThreadState* static inline PyThreadState*

View file

@ -8,12 +8,14 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define" # error "this header requires Py_BUILD_CORE define"
#endif #endif
// _pickle shared extension uses _PySet_NextEntry() and _PySet_Update() // Export for 'pickle' shared extension
PyAPI_FUNC(int) _PySet_NextEntry( PyAPI_FUNC(int) _PySet_NextEntry(
PyObject *set, PyObject *set,
Py_ssize_t *pos, Py_ssize_t *pos,
PyObject **key, PyObject **key,
Py_hash_t *hash); Py_hash_t *hash);
// Export for 'pickle' shared extension
PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable); PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);
// Export _PySet_Dummy for the gdb plugin's benefit // Export _PySet_Dummy for the gdb plugin's benefit

View file

@ -14,7 +14,8 @@ extern "C" {
#include <signal.h> // NSIG #include <signal.h> // NSIG
/* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL. */ // Restore signals that the interpreter has called SIG_IGN on to SIG_DFL.
// Export for '_posixsubprocess' shared extension.
PyAPI_FUNC(void) _Py_RestoreSignals(void); PyAPI_FUNC(void) _Py_RestoreSignals(void);
#ifdef _SIG_MAXSIG #ifdef _SIG_MAXSIG