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

Skip to content

Commit 601d099

Browse files
committed
gh-107211: No longer export internal functions (2)
No longer export these 50 internal C API functions: * _PyArena_AddPyObject() * _PyArena_Free() * _PyArena_Malloc() * _PyArena_New() * _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_ProgramDecodedTextObject() * _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() * _PyState_AddModule() * _PyThreadState_Bind() * _PyThreadState_DeleteExcept() * _PyThreadState_New() * _PyThreadState_Swap() * _PyType_CheckConsistency() * _PyUnicodeTranslateError_Create() * _Py_DumpExtensionModules() * _Py_FatalErrorFormat() * _Py_GetConfig()
1 parent 4bbf071 commit 601d099

File tree

10 files changed

+70
-67
lines changed

10 files changed

+70
-67
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ typedef struct _arena PyArena;
3535
XXX block_new(DEFAULT_BLOCK_SIZE) returns NULL, that's passed on but
3636
XXX an exception is not set in that case).
3737
*/
38-
PyAPI_FUNC(PyArena*) _PyArena_New(void);
39-
PyAPI_FUNC(void) _PyArena_Free(PyArena *);
38+
extern PyArena* _PyArena_New(void);
39+
extern void _PyArena_Free(PyArena *);
4040

4141
/* Mostly like malloc(), return the address of a block of memory spanning
4242
* `size` bytes, or return NULL (without setting an exception) if enough
@@ -50,13 +50,13 @@ PyAPI_FUNC(void) _PyArena_Free(PyArena *);
5050
* until _PyArena_Free(ar) is called, at which point all pointers obtained
5151
* from the arena `ar` become invalid simultaneously.
5252
*/
53-
PyAPI_FUNC(void*) _PyArena_Malloc(PyArena *, size_t size);
53+
extern void* _PyArena_Malloc(PyArena *, size_t size);
5454

5555
/* This routine isn't a proper arena allocation routine. It takes
5656
* a PyObject* and records it so that it can be DECREFed when the
5757
* arena is freed.
5858
*/
59-
PyAPI_FUNC(int) _PyArena_AddPyObject(PyArena *, PyObject *);
59+
extern int _PyArena_AddPyObject(PyArena *, PyObject *);
6060

6161
#ifdef __cplusplus
6262
}

Include/internal/pycore_pyerrors.h

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,46 @@ 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+
extern PyObject* _PyErr_ProgramDecodedTextObject(
3737
PyObject *filename,
3838
int lineno,
3939
const char* encoding);
4040

41-
PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create(
41+
extern PyObject* _PyUnicodeTranslateError_Create(
4242
PyObject *object,
4343
Py_ssize_t start,
4444
Py_ssize_t end,
4545
const char *reason /* UTF-8 encoded string */
4646
);
4747

48-
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFormat(
48+
extern void _Py_NO_RETURN _Py_FatalErrorFormat(
4949
const char *func,
5050
const char *format,
5151
...);
5252

53-
extern PyObject *_PyErr_SetImportErrorWithNameFrom(
53+
extern PyObject* _PyErr_SetImportErrorWithNameFrom(
5454
PyObject *,
5555
PyObject *,
5656
PyObject *,
@@ -79,80 +79,79 @@ static inline void _PyErr_ClearExcState(_PyErr_StackItem *exc_state)
7979
Py_CLEAR(exc_state->exc_value);
8080
}
8181

82-
PyAPI_FUNC(PyObject*) _PyErr_StackItemToExcInfoTuple(
82+
extern PyObject* _PyErr_StackItemToExcInfoTuple(
8383
_PyErr_StackItem *err_info);
8484

85-
PyAPI_FUNC(void) _PyErr_Fetch(
85+
extern void _PyErr_Fetch(
8686
PyThreadState *tstate,
8787
PyObject **type,
8888
PyObject **value,
8989
PyObject **traceback);
9090

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

94-
PyAPI_FUNC(int) _PyErr_ExceptionMatches(
93+
extern int _PyErr_ExceptionMatches(
9594
PyThreadState *tstate,
9695
PyObject *exc);
9796

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

101-
PyAPI_FUNC(void) _PyErr_Restore(
99+
extern void _PyErr_Restore(
102100
PyThreadState *tstate,
103101
PyObject *type,
104102
PyObject *value,
105103
PyObject *traceback);
106104

107-
PyAPI_FUNC(void) _PyErr_SetObject(
105+
extern void _PyErr_SetObject(
108106
PyThreadState *tstate,
109107
PyObject *type,
110108
PyObject *value);
111109

112-
PyAPI_FUNC(void) _PyErr_ChainStackItem(void);
110+
extern void _PyErr_ChainStackItem(void);
113111

114-
PyAPI_FUNC(void) _PyErr_Clear(PyThreadState *tstate);
112+
extern void _PyErr_Clear(PyThreadState *tstate);
115113

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

118-
PyAPI_FUNC(PyObject *) _PyErr_NoMemory(PyThreadState *tstate);
116+
extern PyObject* _PyErr_NoMemory(PyThreadState *tstate);
119117

120-
PyAPI_FUNC(void) _PyErr_SetString(
118+
extern void _PyErr_SetString(
121119
PyThreadState *tstate,
122120
PyObject *exception,
123121
const char *string);
124122

125-
PyAPI_FUNC(PyObject *) _PyErr_Format(
123+
extern PyObject* _PyErr_Format(
126124
PyThreadState *tstate,
127125
PyObject *exception,
128126
const char *format,
129127
...);
130128

131-
PyAPI_FUNC(void) _PyErr_NormalizeException(
129+
extern void _PyErr_NormalizeException(
132130
PyThreadState *tstate,
133131
PyObject **exc,
134132
PyObject **val,
135133
PyObject **tb);
136134

137-
PyAPI_FUNC(PyObject *) _PyErr_FormatFromCauseTstate(
135+
extern PyObject* _PyErr_FormatFromCauseTstate(
138136
PyThreadState *tstate,
139137
PyObject *exception,
140138
const char *format,
141139
...);
142140

143-
PyAPI_FUNC(PyObject *) _PyExc_CreateExceptionGroup(
141+
extern PyObject* _PyExc_CreateExceptionGroup(
144142
const char *msg,
145143
PyObject *excs);
146144

147-
PyAPI_FUNC(PyObject *) _PyExc_PrepReraiseStar(
145+
extern PyObject* _PyExc_PrepReraiseStar(
148146
PyObject *orig,
149147
PyObject *excs);
150148

151-
PyAPI_FUNC(int) _PyErr_CheckSignalsTstate(PyThreadState *tstate);
149+
extern int _PyErr_CheckSignalsTstate(PyThreadState *tstate);
152150

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

155153
extern PyObject* _Py_Offer_Suggestions(PyObject* exception);
154+
// Export for '_testinternalcapi' shared extension
156155
PyAPI_FUNC(Py_ssize_t) _Py_UTF8_Edit_Cost(PyObject *str_a, PyObject *str_b,
157156
Py_ssize_t max_cost);
158157

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 & 8 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

159160

160-
PyAPI_FUNC(int) _PyState_AddModule(
161+
extern 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,7 +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.
175-
PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void);
176+
extern const PyConfig* _Py_GetConfig(void);
176177

177178

178179
#ifdef __cplusplus

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