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

Skip to content

Commit 5a61692

Browse files
authored
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()
1 parent 11306a9 commit 5a61692

10 files changed

+69
-62
lines changed

Include/internal/pycore_long.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,30 +79,30 @@ static inline PyObject* _PyLong_FromUnsignedChar(unsigned char i)
7979
return Py_NewRef((PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS+i]);
8080
}
8181

82-
PyObject *_PyLong_Add(PyLongObject *left, PyLongObject *right);
83-
PyObject *_PyLong_Multiply(PyLongObject *left, PyLongObject *right);
84-
PyObject *_PyLong_Subtract(PyLongObject *left, PyLongObject *right);
82+
extern PyObject *_PyLong_Add(PyLongObject *left, PyLongObject *right);
83+
extern PyObject *_PyLong_Multiply(PyLongObject *left, PyLongObject *right);
84+
extern PyObject *_PyLong_Subtract(PyLongObject *left, PyLongObject *right);
8585

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

9090
/* Format the object based on the format_spec, as defined in PEP 3101
9191
(Advanced String Formatting). */
92-
PyAPI_FUNC(int) _PyLong_FormatAdvancedWriter(
92+
extern int _PyLong_FormatAdvancedWriter(
9393
_PyUnicodeWriter *writer,
9494
PyObject *obj,
9595
PyObject *format_spec,
9696
Py_ssize_t start,
9797
Py_ssize_t end);
9898

99-
PyAPI_FUNC(int) _PyLong_FormatWriter(
99+
extern int _PyLong_FormatWriter(
100100
_PyUnicodeWriter *writer,
101101
PyObject *obj,
102102
int base,
103103
int alternate);
104104

105-
PyAPI_FUNC(char*) _PyLong_FormatBytesWriter(
105+
extern char* _PyLong_FormatBytesWriter(
106106
_PyBytesWriter *writer,
107107
char *str,
108108
PyObject *obj,

Include/internal/pycore_namespace.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ extern "C" {
1010
# error "this header requires Py_BUILD_CORE define"
1111
#endif
1212

13-
PyAPI_DATA(PyTypeObject) _PyNamespace_Type;
13+
extern PyTypeObject _PyNamespace_Type;
1414

15-
PyAPI_FUNC(PyObject *) _PyNamespace_New(PyObject *kwds);
15+
PyAPI_FUNC(PyObject*) _PyNamespace_New(PyObject *kwds);
1616

1717
#ifdef __cplusplus
1818
}

Include/internal/pycore_object.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ _Py_DECREF_NO_DEALLOC(PyObject *op)
156156
#endif
157157

158158

159-
PyAPI_FUNC(int) _PyType_CheckConsistency(PyTypeObject *type);
160-
PyAPI_FUNC(int) _PyDict_CheckConsistency(PyObject *mp, int check_content);
159+
extern int _PyType_CheckConsistency(PyTypeObject *type);
160+
extern int _PyDict_CheckConsistency(PyObject *mp, int check_content);
161161

162162
/* Update the Python traceback of an object. This function must be called
163163
when a memory block is reused from a free list.

Include/internal/pycore_pyarena.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/* An arena-like memory interface for the compiler.
2+
*
3+
* Export symbols for test_peg_generator.
24
*/
35

46
#ifndef Py_INTERNAL_PYARENA_H

Include/internal/pycore_pyerrors.h

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,47 @@ extern "C" {
1111

1212
/* Error handling definitions */
1313

14-
PyAPI_FUNC(_PyErr_StackItem*) _PyErr_GetTopmostException(PyThreadState *tstate);
15-
PyAPI_FUNC(PyObject*) _PyErr_GetHandledException(PyThreadState *);
16-
PyAPI_FUNC(void) _PyErr_SetHandledException(PyThreadState *, PyObject *);
17-
PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **);
18-
19-
/* Like PyErr_Format(), but saves current exception as __context__ and
20-
__cause__.
21-
*/
22-
PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause(
14+
extern _PyErr_StackItem* _PyErr_GetTopmostException(PyThreadState *tstate);
15+
extern PyObject* _PyErr_GetHandledException(PyThreadState *);
16+
extern void _PyErr_SetHandledException(PyThreadState *, PyObject *);
17+
extern void _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **);
18+
19+
// Like PyErr_Format(), but saves current exception as __context__ and
20+
// __cause__.
21+
// Export for '_sqlite3' shared extension.
22+
PyAPI_FUNC(PyObject*) _PyErr_FormatFromCause(
2323
PyObject *exception,
2424
const char *format, /* ASCII-encoded string */
2525
...
2626
);
2727

28-
PyAPI_FUNC(int) _PyException_AddNote(
28+
extern int _PyException_AddNote(
2929
PyObject *exc,
3030
PyObject *note);
3131

32-
PyAPI_FUNC(int) _PyErr_CheckSignals(void);
32+
extern int _PyErr_CheckSignals(void);
3333

3434
/* Support for adding program text to SyntaxErrors */
3535

36-
PyAPI_FUNC(PyObject *) _PyErr_ProgramDecodedTextObject(
36+
// Export for test_peg_generator
37+
PyAPI_FUNC(PyObject*) _PyErr_ProgramDecodedTextObject(
3738
PyObject *filename,
3839
int lineno,
3940
const char* encoding);
4041

41-
PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create(
42+
extern PyObject* _PyUnicodeTranslateError_Create(
4243
PyObject *object,
4344
Py_ssize_t start,
4445
Py_ssize_t end,
4546
const char *reason /* UTF-8 encoded string */
4647
);
4748

48-
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFormat(
49+
extern void _Py_NO_RETURN _Py_FatalErrorFormat(
4950
const char *func,
5051
const char *format,
5152
...);
5253

53-
extern PyObject *_PyErr_SetImportErrorWithNameFrom(
54+
extern PyObject* _PyErr_SetImportErrorWithNameFrom(
5455
PyObject *,
5556
PyObject *,
5657
PyObject *,
@@ -79,80 +80,79 @@ static inline void _PyErr_ClearExcState(_PyErr_StackItem *exc_state)
7980
Py_CLEAR(exc_state->exc_value);
8081
}
8182

82-
PyAPI_FUNC(PyObject*) _PyErr_StackItemToExcInfoTuple(
83+
extern PyObject* _PyErr_StackItemToExcInfoTuple(
8384
_PyErr_StackItem *err_info);
8485

85-
PyAPI_FUNC(void) _PyErr_Fetch(
86+
extern void _PyErr_Fetch(
8687
PyThreadState *tstate,
8788
PyObject **type,
8889
PyObject **value,
8990
PyObject **traceback);
9091

91-
extern PyObject *
92-
_PyErr_GetRaisedException(PyThreadState *tstate);
92+
extern PyObject* _PyErr_GetRaisedException(PyThreadState *tstate);
9393

94-
PyAPI_FUNC(int) _PyErr_ExceptionMatches(
94+
extern int _PyErr_ExceptionMatches(
9595
PyThreadState *tstate,
9696
PyObject *exc);
9797

98-
void
99-
_PyErr_SetRaisedException(PyThreadState *tstate, PyObject *exc);
98+
extern void _PyErr_SetRaisedException(PyThreadState *tstate, PyObject *exc);
10099

101-
PyAPI_FUNC(void) _PyErr_Restore(
100+
extern void _PyErr_Restore(
102101
PyThreadState *tstate,
103102
PyObject *type,
104103
PyObject *value,
105104
PyObject *traceback);
106105

107-
PyAPI_FUNC(void) _PyErr_SetObject(
106+
extern void _PyErr_SetObject(
108107
PyThreadState *tstate,
109108
PyObject *type,
110109
PyObject *value);
111110

112-
PyAPI_FUNC(void) _PyErr_ChainStackItem(void);
111+
extern void _PyErr_ChainStackItem(void);
113112

114-
PyAPI_FUNC(void) _PyErr_Clear(PyThreadState *tstate);
113+
extern void _PyErr_Clear(PyThreadState *tstate);
115114

116-
PyAPI_FUNC(void) _PyErr_SetNone(PyThreadState *tstate, PyObject *exception);
115+
extern void _PyErr_SetNone(PyThreadState *tstate, PyObject *exception);
117116

118-
PyAPI_FUNC(PyObject *) _PyErr_NoMemory(PyThreadState *tstate);
117+
extern PyObject* _PyErr_NoMemory(PyThreadState *tstate);
119118

120-
PyAPI_FUNC(void) _PyErr_SetString(
119+
extern void _PyErr_SetString(
121120
PyThreadState *tstate,
122121
PyObject *exception,
123122
const char *string);
124123

125-
PyAPI_FUNC(PyObject *) _PyErr_Format(
124+
extern PyObject* _PyErr_Format(
126125
PyThreadState *tstate,
127126
PyObject *exception,
128127
const char *format,
129128
...);
130129

131-
PyAPI_FUNC(void) _PyErr_NormalizeException(
130+
extern void _PyErr_NormalizeException(
132131
PyThreadState *tstate,
133132
PyObject **exc,
134133
PyObject **val,
135134
PyObject **tb);
136135

137-
PyAPI_FUNC(PyObject *) _PyErr_FormatFromCauseTstate(
136+
extern PyObject* _PyErr_FormatFromCauseTstate(
138137
PyThreadState *tstate,
139138
PyObject *exception,
140139
const char *format,
141140
...);
142141

143-
PyAPI_FUNC(PyObject *) _PyExc_CreateExceptionGroup(
142+
extern PyObject* _PyExc_CreateExceptionGroup(
144143
const char *msg,
145144
PyObject *excs);
146145

147-
PyAPI_FUNC(PyObject *) _PyExc_PrepReraiseStar(
146+
extern PyObject* _PyExc_PrepReraiseStar(
148147
PyObject *orig,
149148
PyObject *excs);
150149

151-
PyAPI_FUNC(int) _PyErr_CheckSignalsTstate(PyThreadState *tstate);
150+
extern int _PyErr_CheckSignalsTstate(PyThreadState *tstate);
152151

153-
PyAPI_FUNC(void) _Py_DumpExtensionModules(int fd, PyInterpreterState *interp);
152+
extern void _Py_DumpExtensionModules(int fd, PyInterpreterState *interp);
154153

155154
extern PyObject* _Py_Offer_Suggestions(PyObject* exception);
155+
// Export for '_testinternalcapi' shared extension
156156
PyAPI_FUNC(Py_ssize_t) _Py_UTF8_Edit_Cost(PyObject *str_a, PyObject *str_b,
157157
Py_ssize_t max_cost);
158158

Include/internal/pycore_pymem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct _pymem_allocators {
4848
/* Set the memory allocator of the specified domain to the default.
4949
Save the old allocator into *old_alloc if it's non-NULL.
5050
Return on success, or return -1 if the domain is unknown. */
51-
PyAPI_FUNC(int) _PyMem_SetDefaultAllocator(
51+
extern int _PyMem_SetDefaultAllocator(
5252
PyMemAllocatorDomain domain,
5353
PyMemAllocatorEx *old_alloc);
5454

@@ -94,14 +94,14 @@ static inline int _PyMem_IsPtrFreed(const void *ptr)
9494
#endif
9595
}
9696

97-
PyAPI_FUNC(int) _PyMem_GetAllocatorName(
97+
extern int _PyMem_GetAllocatorName(
9898
const char *name,
9999
PyMemAllocatorName *allocator);
100100

101101
/* Configure the Python memory allocators.
102102
Pass PYMEM_ALLOCATOR_DEFAULT to use default allocators.
103103
PYMEM_ALLOCATOR_NOT_SET does nothing. */
104-
PyAPI_FUNC(int) _PyMem_SetupAllocators(PyMemAllocatorName allocator);
104+
extern int _PyMem_SetupAllocators(PyMemAllocatorName allocator);
105105

106106

107107
#ifdef __cplusplus

Include/internal/pycore_pystate.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,16 @@ static inline PyInterpreterState* _PyInterpreterState_GET(void) {
121121

122122
// PyThreadState functions
123123

124-
PyAPI_FUNC(PyThreadState *) _PyThreadState_New(PyInterpreterState *interp);
125-
PyAPI_FUNC(void) _PyThreadState_Bind(PyThreadState *tstate);
126-
PyAPI_FUNC(void) _PyThreadState_DeleteExcept(PyThreadState *tstate);
124+
extern PyThreadState * _PyThreadState_New(PyInterpreterState *interp);
125+
extern void _PyThreadState_Bind(PyThreadState *tstate);
126+
extern void _PyThreadState_DeleteExcept(PyThreadState *tstate);
127127

128128
extern void _PyThreadState_InitDetached(PyThreadState *, PyInterpreterState *);
129129
extern void _PyThreadState_ClearDetached(PyThreadState *);
130130
extern void _PyThreadState_BindDetached(PyThreadState *);
131131
extern void _PyThreadState_UnbindDetached(PyThreadState *);
132132

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

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

146147
/* Other */
147148

148-
PyAPI_FUNC(PyThreadState *) _PyThreadState_Swap(
149+
extern PyThreadState * _PyThreadState_Swap(
149150
_PyRuntimeState *runtime,
150151
PyThreadState *newts);
151152

152-
PyAPI_FUNC(PyStatus) _PyInterpreterState_Enable(_PyRuntimeState *runtime);
153+
extern PyStatus _PyInterpreterState_Enable(_PyRuntimeState *runtime);
153154

154155
#ifdef HAVE_FORK
155156
extern PyStatus _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime);
156157
extern void _PySignal_AfterFork(void);
157158
#endif
158159

159-
160+
// Export for the stable ABI
160161
PyAPI_FUNC(int) _PyState_AddModule(
161162
PyThreadState *tstate,
162163
PyObject* module,
163164
PyModuleDef* def);
164165

165166

166-
PyAPI_FUNC(int) _PyOS_InterruptOccurred(PyThreadState *tstate);
167+
extern int _PyOS_InterruptOccurred(PyThreadState *tstate);
167168

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

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

177179

Include/internal/pycore_runtime.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,18 +274,18 @@ typedef struct pyruntimestate {
274274

275275
PyAPI_DATA(_PyRuntimeState) _PyRuntime;
276276

277-
PyAPI_FUNC(PyStatus) _PyRuntimeState_Init(_PyRuntimeState *runtime);
278-
PyAPI_FUNC(void) _PyRuntimeState_Fini(_PyRuntimeState *runtime);
277+
extern PyStatus _PyRuntimeState_Init(_PyRuntimeState *runtime);
278+
extern void _PyRuntimeState_Fini(_PyRuntimeState *runtime);
279279

280280
#ifdef HAVE_FORK
281281
extern PyStatus _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime);
282282
#endif
283283

284284
/* Initialize _PyRuntimeState.
285285
Return NULL on success, or return an error message on failure. */
286-
PyAPI_FUNC(PyStatus) _PyRuntime_Initialize(void);
286+
extern PyStatus _PyRuntime_Initialize(void);
287287

288-
PyAPI_FUNC(void) _PyRuntime_Finalize(void);
288+
extern void _PyRuntime_Finalize(void);
289289

290290

291291
static inline PyThreadState*

Include/internal/pycore_setobject.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
// _pickle shared extension uses _PySet_NextEntry() and _PySet_Update()
11+
// Export for 'pickle' shared extension
1212
PyAPI_FUNC(int) _PySet_NextEntry(
1313
PyObject *set,
1414
Py_ssize_t *pos,
1515
PyObject **key,
1616
Py_hash_t *hash);
17+
18+
// Export for 'pickle' shared extension
1719
PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);
1820

1921
// Export _PySet_Dummy for the gdb plugin's benefit

Include/internal/pycore_signal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ extern "C" {
1414
#include <signal.h> // NSIG
1515

1616

17-
/* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL. */
17+
// Restore signals that the interpreter has called SIG_IGN on to SIG_DFL.
18+
// Export for '_posixsubprocess' shared extension.
1819
PyAPI_FUNC(void) _Py_RestoreSignals(void);
1920

2021
#ifdef _SIG_MAXSIG

0 commit comments

Comments
 (0)
0