8000 gh-107211: No longer export internal functions (2) by vstinner · Pull Request #107214 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-107211: No longer export internal functions (2)
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()
  • Loading branch information
vstinner committed Jul 25, 2023
commit 85d3727011edffad9bb1acc5fcff9571e50c6880
12 changes: 6 additions & 6 deletions Include/internal/pycore_long.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,30 @@ static inline PyObject* _PyLong_FromUnsignedChar(unsigned char i)
return Py_NewRef((PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS+i]);
}

PyObject *_PyLong_Add(PyLongObject *left, PyLongObject *right);
PyObject *_PyLong_Multiply(PyLongObject *left, PyLongObject *right);
PyObject *_PyLong_Subtract(PyLongObject *left, PyLongObject *right);
extern PyObject *_PyLong_Add(PyLongObject *left, PyLongObject *right);
extern PyObject *_PyLong_Multiply(PyLongObject *left, PyLongObject *right);
extern PyObject *_PyLong_Subtract(PyLongObject *left, PyLongObject *right);

/* Used by Python/mystrtoul.c, _PyBytes_FromHex(),
_PyBytes_DecodeEscape(), etc. */
PyAPI_DATA(unsigned char) _PyLong_DigitValue[256];

/* Format the object based on the format_spec, as defined in PEP 3101
(Advanced String Formatting). */
PyAPI_FUNC(int) _PyLong_FormatAdvancedWriter(
extern int _PyLong_FormatAdvancedWriter(
_PyUnicodeWriter *writer,
PyObject *obj,
PyObject *format_spec,
Py_ssize_t start,
Py_ssize_t end);

PyAPI_FUNC(int) _PyLong_FormatWriter(
extern int _PyLong_FormatWriter(
_PyUnicodeWriter *writer,
PyObject *obj,
int base,
int alternate);

PyAPI_FUNC(char*) _PyLong_FormatBytesWriter(
extern char* _PyLong_FormatBytesWriter(
_PyBytesWriter *writer,
char *str,
PyObject *obj,
Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

PyAPI_DATA(PyTypeObject) _PyNamespace_Type;
extern PyTypeObject _PyNamespace_Type;

PyAPI_FUNC(PyObject *) _PyNamespace_New(PyObject *kwds);
PyAPI_FUNC(PyObject*) _PyNamespace_New(PyObject *kwds);

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ _Py_DECREF_NO_DEALLOC(PyObject *op)
#endif


PyAPI_FUNC(int) _PyType_CheckConsistency(PyTypeObject *type);
PyAPI_FUNC(int) _PyDict_CheckConsistency(PyObject *mp, int check_content);
extern int _PyType_CheckConsistency(PyTypeObject *type);
extern int _PyDict_CheckConsistency(PyObject *mp, int check_content);

/* Update the Python traceback of an object. This function must be called
when a memory block is reused from a free list.
Expand Down
2 changes: 2 additions & 0 deletions Include/internal/pycore_pyarena.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* An arena-like memory interface for the compiler.
*
* Export symbols for test_peg_generator.
*/

#ifndef Py_INTERNAL_PYARENA_H
Expand Down
72 changes: 36 additions & 36 deletions Include/internal/pycore_pyerrors.h
F438
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,47 @@ extern "C" {

/* Error handling definitions */

PyAPI_FUNC(_PyErr_StackItem*) _PyErr_GetTopmostException(PyThreadState *tstate);
PyAPI_FUNC(PyObject*) _PyErr_GetHandledException(PyThreadState *);
PyAPI_FUNC(void) _PyErr_SetHandledException(PyThreadState *, PyObject *);
PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **);

/* Like PyErr_Format(), but saves current exception as __context__ and
__cause__.
*/
PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause(
extern _PyErr_StackItem* _PyErr_GetTopmostException(PyThreadState *tstate);
extern PyObject* _PyErr_GetHandledException(PyThreadState *);
extern void _PyErr_SetHandledException(PyThreadState *, PyObject *);
extern void _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **);

// Like PyErr_Format(), but saves current exception as __context__ and
// __cause__.
// Export for '_sqlite3' shared extension.
PyAPI_FUNC(PyObject*) _PyErr_FormatFromCause(
PyObject *exception,
const char *format, /* ASCII-encoded string */
...
);

PyAPI_FUNC(int) _PyException_AddNote(
extern int _PyException_AddNote(
PyObject *exc,
PyObject *note);

PyAPI_FUNC(int) _PyErr_CheckSignals(void);
extern int _PyErr_CheckSignals(void);

/* Support for adding program text to SyntaxErrors */

PyAPI_FUNC(PyObject *) _PyErr_ProgramDecodedTextObject(
// Export for test_peg_generator
PyAPI_FUNC(PyObject*) _PyErr_ProgramDecodedTextObject(
PyObject *filename,
int lineno,
const char* encoding);

PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create(
extern PyObject* _PyUnicodeTranslateError_Create(
PyObject *object,
Py_ssize_t start,
Py_ssize_t end,
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 *format,
...);

extern PyObject *_PyErr_SetImportErrorWithNameFrom(
extern PyObject* _PyErr_SetImportErrorWithNameFrom(
PyObject *,
PyObject *,
PyObject *,
Expand Down Expand Up @@ -79,80 +80,79 @@ static inline void _PyErr_ClearExcState(_PyErr_StackItem *exc_state)
Py_CLEAR(exc_state->exc_value);
}

PyAPI_FUNC(PyObject*) _PyErr_StackItemToExcInfoTuple(
extern PyObject* _PyErr_StackItemToExcInfoTuple(
_PyErr_StackItem *err_info);

PyAPI_FUNC(void) _PyErr_Fetch(
extern void _PyErr_Fetch(
PyThreadState *tstate,
PyObject **type,
PyObject **value,
PyObject **traceback);

extern PyObject *
_PyErr_GetRaisedException(PyThreadState *tstate);
extern PyObject* _PyErr_GetRaisedException(PyThreadState *tstate);

PyAPI_FUNC(int) _PyErr_ExceptionMatches(
extern int _PyErr_ExceptionMatches(
PyThreadState *tstate,
PyObject *exc);

void
_PyErr_SetRaisedException(PyThreadState *tstate, PyObject *exc);
extern void _PyErr_SetRaisedException(PyThreadState *tstate, PyObject *exc);

PyAPI_FUNC(void) _PyErr_Restore(
extern void _PyErr_Restore(
PyThreadState *tstate,
PyObject *type,
PyObject *value,
PyObject *traceback);

PyAPI_FUNC(void) _PyErr_SetObject(
extern void _PyErr_SetObject(
PyThreadState *tstate,
PyObject *type,
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,
PyObject *exception,
const char *string);

PyAPI_FUNC(PyObject *) _PyErr_Format(
extern PyObject* _PyErr_Format(
PyThreadState *tstate,
PyObject *exception,
const char *format,
...);

PyAPI_FUNC(void) _PyErr_NormalizeException(
extern void _PyErr_NormalizeException(
PyThreadState *tstate,
PyObject **exc,
PyObject **val,
PyObject **tb);

PyAPI_FUNC(PyObject *) _PyErr_FormatFromCauseTstate(
extern PyObject* _PyErr_FormatFromCauseTstate(
PyThreadState *tstate,
PyObject *exception,
const char *format,
...);

PyAPI_FUNC(PyObject *) _PyExc_CreateExceptionGroup(
extern PyObject* _PyExc_CreateExceptionGroup(
const char *msg,
PyObject *excs);

PyAPI_FUNC(PyObject *) _PyExc_PrepReraiseStar(
extern PyObject* _PyExc_PrepReraiseStar(
PyObject *orig,
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);
// Export for '_testinternalcapi' shared extension
PyAPI_FUNC(Py_ssize_t) _Py_UTF8_Edit_Cost(PyObject *str_a, PyObject *str_b,
Py_ssize_t max_cost);

Expand Down
6 changes: 3 additions & 3 deletions Include/internal/pycore_pymem.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct _pymem_allocators {
/* Set the memory allocator of the specified domain to the default.
Save the old allocator into *old_alloc if it's non-NULL.
Return on success, or return -1 if the domain is unknown. */
PyAPI_FUNC(int) _PyMem_SetDefaultAllocator(
extern int _PyMem_SetDefaultAllocator(
PyMemAllocatorDomain domain,
PyMemAllocatorEx *old_alloc);

Expand Down Expand Up @@ -94,14 +94,14 @@ static inline int _PyMem_IsPtrFreed(const void *ptr)
#endif
}

PyAPI_FUNC(int) _PyMem_GetAllocatorName(
extern int _PyMem_GetAllocatorName(
const char *name,
PyMemAllocatorName *allocator);

/* Configure the Python memory allocators.
Pass PYMEM_ALLOCATOR_DEFAULT to use default allocators.
PYMEM_ALLOCATOR_NOT_SET does nothing. */
PyAPI_FUNC(int) _PyMem_SetupAllocators(PyMemAllocatorName allocator);
extern int _PyMem_SetupAllocators(PyMemAllocatorName allocator);


#ifdef __cplusplus
Expand Down
16 changes: 9 additions & 7 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,16 @@ static inline PyInterpreterState* _PyInterpreterState_GET(void) {

// PyThreadState functions

PyAPI_FUNC(PyThreadState *) _PyThreadState_New(PyInterpreterState *interp);
PyAPI_FUNC(void) _PyThreadState_Bind(PyThreadState *tstate);
PyAPI_FUNC(void) _PyThreadState_DeleteExcept(PyThreadState *tstate);
extern PyThreadState * _PyThreadState_New(PyInterpreterState *interp);
extern void _PyThreadState_Bind(PyThreadState *tstate);
extern void _PyThreadState_DeleteExcept(PyThreadState *tstate);

extern void _PyThreadState_InitDetached(PyThreadState *, PyInterpreterState *);
extern void _PyThreadState_ClearDetached(PyThreadState *);
extern void _PyThreadState_BindDetached(PyThreadState *);
extern void _PyThreadState_UnbindDetached(PyThreadState *);

// Export for '_testinternalcapi' shared extension
PyAPI_FUNC(PyObject*) _PyThreadState_GetDict(PyThreadState *tstate);

/* The implementation of sys._current_frames() Returns a dict mapping
Expand All @@ -145,25 +146,25 @@ extern PyObject* _PyThread_CurrentExceptions(void);

/* Other */

PyAPI_FUNC(PyThreadState *) _PyThreadState_Swap(
extern PyThreadState * _PyThreadState_Swap(
_PyRuntimeState *runtime,
PyThreadState *newts);

PyAPI_FUNC(PyStatus) _PyInterpreterState_Enable(_PyRuntimeState *runtime);
extern PyStatus _PyInterpreterState_Enable(_PyRuntimeState *runtime);

#ifdef HAVE_FORK
extern PyStatus _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime);
extern void _PySignal_AfterFork(void);
#endif


// Export for the stable ABI
PyAPI_FUNC(int) _PyState_AddModule(
PyThreadState *tstate,
PyObject* module,
PyModuleDef* def);


PyAPI_FUNC(int) _PyOS_InterruptOccurred(PyThreadState *tstate);
extern int _PyOS_InterruptOccurred(PyThreadState *tstate);

#define HEAD_LOCK(runtime) \
PyThread_acquire_lock((runtime)->interpreters.mutex, WAIT_LOCK)
Expand All @@ -172,6 +173,7 @@ PyAPI_FUNC(int) _PyOS_InterruptOccurred(PyThreadState *tstate);

// Get the configuration of the current interpreter.
// The caller must hold the GIL.
// Export for test_peg_generator.
PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void);


Expand Down
8 changes: 4 additions & 4 deletions Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,18 @@ typedef struct pyruntimestate {

PyAPI_DATA(_PyRuntimeState) _PyRuntime;

PyAPI_FUNC(PyStatus) _PyRuntimeState_Init(_PyRuntimeState *runtime);
PyAPI_FUNC(void) _PyRuntimeState_Fini(_PyRuntimeState *runtime);
extern PyStatus _PyRuntimeState_Init(_PyRuntimeState *runtime);
extern void _PyRuntimeState_Fini(_PyRuntimeState *runtime);

#ifdef HAVE_FORK
extern PyStatus _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime);
#endif

/* Initialize _PyRuntimeState.
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*
Expand Down
4 changes: 3 additions & 1 deletion Include/internal/pycore_setobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

// _pickle shared extension uses _PySet_NextEntry() and _PySet_Update()
// Export for 'pickle' shared extension
PyAPI_FUNC(int) _PySet_NextEntry(
PyObject *set,
Py_ssize_t *pos,
PyObject **key,
Py_hash_t *hash);

// Export for 'pickle' shared extension
PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);

// Export _PySet_Dummy for the gdb plugin's benefit
Expand Down
3 changes: 2 additions & 1 deletion Include/internal/pycore_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ extern "C" {
#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);

#ifdef _SIG_MAXSIG
Expand Down
0