10000 gh-107211: No longer export internal functions (6) (#108424) · python/cpython@ea871c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit ea871c9

Browse files
authored
gh-107211: No longer export internal functions (6) (#108424)
No longer export these 5 internal C API functions: * _PyArena_AddPyObject() * _PyArena_Free() * _PyArena_Malloc() * _PyArena_New() * _Py_FatalRefcountErrorFunc() Change comment style to "// comment" and add comment explaining why other functions have to be exported.
1 parent 3f7e93b commit ea871c9

8 files changed

+45
-43
lines changed

Include/internal/pycore_interp.h

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -243,40 +243,40 @@ extern void _PyInterpreterState_IDDecref(PyInterpreterState *);
243243

244244
extern const PyConfig* _PyInterpreterState_GetConfig(PyInterpreterState *interp);
245245

246-
/* Get a copy of the current interpreter configuration.
247-
248-
Return 0 on success. Raise an exception and return -1 on error.
249-
250-
The caller must initialize 'config', using PyConfig_InitPythonConfig()
251-
for example.
252-
253-
Python must be preinitialized to call this method.
254-
The caller must hold the GIL.
255-
256-
Once done with the configuration, PyConfig_Clear() must be called to clear
257-
it.
258-
259-
Export for '_testinternalcapi' shared extension. */
246+
// Get a copy of the current interpreter configuration.
247+
//
248+
// Return 0 on success. Raise an exception and return -1 on error.
249+
//
250+
// The caller must initialize 'config', using PyConfig_InitPythonConfig()
251+
// for example.
252+
//
253+
// Python must be preinitialized to call this method.
254+
// The caller must hold the GIL.
255+
//
256+
// Once done with the configuration, PyConfig_Clear() must be called to clear
257+
// it.
258+
//
259+
// Export for '_testinternalcapi' shared extension.
260260
PyAPI_FUNC(int) _PyInterpreterState_GetConfigCopy(
261261
struct PyConfig *config);
262262

263-
/* Set the configuration of the current interpreter.
264-
265-
This function should be called during or just after the Python
266-
initialization.
267-
268-
Update the sys module with the new configuration. If the sys module was
269-
modified directly after the Python initialization, these changes are lost.
270-
271-
Some configuration like faulthandler or warnoptions can be updated in the
272-
configuration, but don't reconfigure Python (don't enable/disable
273-
faulthandler and don't reconfigure warnings filters).
274-
275-
Return 0 on success. Raise an exception and return -1 on error.
276-
277-
The configuration should come from _PyInterpreterState_GetConfigCopy().
278-
279-
Export for '_testinternalcapi' shared extension. */
263+
// Set the configuration of the current interpreter.
264+
//
265+
// This function should be called during or just after the Python
266+
// initialization.
267+
//
268+
// Update the sys module with the new configuration. If the sys module was
269+
// modified directly after the Python initialization, these changes are lost.
270+
//
271+
// Some configuration like faulthandler or warnoptions can be updated in the
272+
// configuration, but don't reconfigure Python (don't enable/disable
273+
// faulthandler and don't reconfigure warnings filters).
274+
//
275+
// Return 0 on success. Raise an exception and return -1 on error.
276+
//
277+
// The configuration should come from _PyInterpreterState_GetConfigCopy().
278+
//
279+
// Export for '_testinternalcapi' shared extension.
280280
PyAPI_FUNC(int) _PyInterpreterState_SetConfig(
281281
const struct PyConfig *config);
282282

Include/internal/pycore_long.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ extern PyObject *_PyLong_Add(PyLongObject *left, PyLongObject *right);
8383
extern PyObject *_PyLong_Multiply(PyLongObject *left, PyLongObject *right);
8484
extern PyObject *_PyLong_Subtract(PyLongObject *left, PyLongObject *right);
8585

86-
// Used by _PyBytes_FromHex(), _PyBytes_DecodeEscape(), Python/mystrtoul.c.
8786
// Export for 'binascii' shared extension.
8887
PyAPI_DATA(unsigned char) _PyLong_DigitValue[256];
8988

Include/internal/pycore_object.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
5454
.ob_size = size \
5555
},
5656

57-
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalRefcountErrorFunc(
57+
extern void _Py_NO_RETURN _Py_FatalRefcountErrorFunc(
5858
const char *func,
5959
const char *message);
6060

@@ -469,13 +469,11 @@ extern PyObject* _PyCFunctionWithKeywords_TrampolineCall(
469469
(meth)((self), (args), (kw))
470470
#endif // __EMSCRIPTEN__ && PY_CALL_TRAMPOLINE
471471

472-
// Export for '_pickle' shared extension
472+
// Export these 2 symbols for '_pickle' shared extension
473473
PyAPI_DATA(PyTypeObject) _PyNone_Type;
474-
// Export for '_pickle' shared extension
475474
PyAPI_DATA(PyTypeObject) _PyNotImplemented_Type;
476475

477476
// Maps Py_LT to Py_GT, ..., Py_GE to Py_LE.
478-
// Defined in Objects/object.c.
479477
// Export for the stable ABI.
480478
PyAPI_DATA(int) _Py_SwappedOp[];
481479

Include/internal/pycore_obmalloc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ extern void _PyInterpreterState_FinalizeAllocatedBlocks(PyInterpreterState *);
687687

688688

689689
#ifdef WITH_PYMALLOC
690-
// Export the symbol for the 3rd party guppy3 project
690+
// Export the symbol for the 3rd party 'guppy3' project
691691
PyAPI_FUNC(int) _PyObject_DebugMallocStats(FILE *out);
692692
#endif
693693

Include/internal/pycore_pathconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extern "C" {
1010

1111
// Export for '_testinternalcapi' shared extension
1212
PyAPI_FUNC(void) _PyPathConfig_ClearGlobal(void);
13+
1314
extern PyStatus _PyPathConfig_ReadGlobal(PyConfig *config);
1415
extern PyStatus _PyPathConfig_UpdateGlobal(const PyConfig *config);
1516
extern const wchar_t * _PyPathConfig_GetGlobalModuleSearchPath(void);

Include/internal/pycore_pyarena.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ typedef struct _arena PyArena;
3737
XXX block_new(DEFAULT_BLOCK_SIZE) returns NULL, that's passed on but
3838
XXX an exception is not set in that case).
3939
*/
40-
PyAPI_FUNC(PyArena*) _PyArena_New(void);
41-
PyAPI_FUNC(void) _PyArena_Free(PyArena *);
40+
extern PyArena* _PyArena_New(void);
41+
extern void _PyArena_Free(PyArena *);
4242

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

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

6363
#ifdef __cplusplus
6464
}

Include/internal/pycore_pyerrors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ extern int _PyErr_CheckSignalsTstate(PyThreadState *tstate);
152152
extern void _Py_DumpExtensionModules(int fd, PyInterpreterState *interp);
153153
extern PyObject* _Py_CalculateSuggestions(PyObject *dir, PyObject *name);
154154
extern PyObject* _Py_Offer_Suggestions(PyObject* exception);
155+
155156
// Export for '_testinternalcapi' shared extension
156157
PyAPI_FUNC(Py_ssize_t) _Py_UTF8_Edit_Cost(PyObject *str_a, PyObject *str_b,
157158
Py_ssize_t max_cost);

Include/internal/pycore_pyhash.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77

88
/* Helpers for hash functions */
99
extern Py_hash_t _Py_HashDouble(PyObject *, double);
10-
// _decimal shared extensions uses _Py_HashPointer()
10+
11+
// Export for '_decimal' shared extension
1112
PyAPI_FUNC(Py_hash_t) _Py_HashPointer(const void*);
13+
1214
// Similar to _Py_HashPointer(), but don't replace -1 with -2
1315
extern Py_hash_t _Py_HashPointerRaw(const void*);
14-
// _datetime shared extension uses _Py_HashBytes()
16+
17+
// Export for '_datetime' shared extension
1518
PyAPI_FUNC(Py_hash_t) _Py_HashBytes(const void*, Py_ssize_t);
1619

1720
/* Prime multiplier used in string and various other hashes. */

0 commit comments

Comments
 (0)
0