Skip to content

Commit b780882

Browse files
authored
gh-107211: No longer export internal functions (5) (#108423)
No longer export _PyCompile_AstOptimize() internal C API function. Change comment style to "// comment" and add comment explaining why other functions have to be exported.
1 parent f1ae706 commit b780882

10 files changed

+73
-39
lines changed

Include/internal/pycore_bytesobject.h

+23-18
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,37 @@ PyAPI_FUNC(PyObject*) _PyBytes_DecodeEscape(const char *, Py_ssize_t,
2828
extern PyObject* _PyBytes_Join(PyObject *sep, PyObject *x);
2929

3030

31-
/* Substring Search.
32-
33-
Returns the index of the first occurrence of
34-
a substring ("needle") in a larger text ("haystack").
35-
If the needle is not found, return -1.
36-
If the needle is found, add offset to the index.
37-
*/
38-
31+
// Substring Search.
32+
//
33+
// Returns the index of the first occurrence of
34+
// a substring ("needle") in a larger text ("haystack").
35+
// If the needle is not found, return -1.
36+
// If the needle is found, add offset to the index.
37+
//
38+
// Export for 'mmap' shared extension.
3939
PyAPI_FUNC(Py_ssize_t)
4040
_PyBytes_Find(const char *haystack, Py_ssize_t len_haystack,
4141
const char *needle, Py_ssize_t len_needle,
4242
Py_ssize_t offset);
4343

44-
/* Same as above, but search right-to-left */
44+
// Same as above, but search right-to-left.
45+
// Export for 'mmap' shared extension.
4546
PyAPI_FUNC(Py_ssize_t)
4647
_PyBytes_ReverseFind(const char *haystack, Py_ssize_t len_haystack,
4748
const char *needle, Py_ssize_t len_needle,
4849
Py_ssize_t offset);
4950

5051

51-
/** Helper function to implement the repeat and inplace repeat methods on a buffer
52-
*
53-
* len_dest is assumed to be an integer multiple of len_src.
54-
* If src equals dest, then assume the operation is inplace.
55-
*
56-
* This method repeately doubles the number of bytes copied to reduce
57-
* the number of invocations of memcpy.
58-
*/
52+
// Helper function to implement the repeat and inplace repeat methods on a
53+
// buffer.
54+
//
55+
// len_dest is assumed to be an integer multiple of len_src.
56+
// If src equals dest, then assume the operation is inplace.
57+
//
58+
// This method repeately doubles the number of bytes copied to reduce
59+
// the number of invocations of memcpy.
60+
//
61+
// Export for 'array' shared extension.
5962
PyAPI_FUNC(void)
6063
_PyBytes_Repeat(char* dest, Py_ssize_t len_dest,
6164
const char* src, Py_ssize_t len_src);
@@ -91,7 +94,9 @@ typedef struct {
9194
/* Initialize a bytes writer
9295
9396
By default, the overallocation is disabled. Set the overallocate attribute
94-
to control the allocation of the buffer. */
97+
to control the allocation of the buffer.
98+
99+
Export _PyBytesWriter API for '_pickle' shared extension. */
95100
PyAPI_FUNC(void) _PyBytesWriter_Init(_PyBytesWriter *writer);
96101

97102
/* Get the buffer content and reset the writer.

Include/internal/pycore_call.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ extern "C" {
2222
#define _PY_FASTCALL_SMALL_STACK 5
2323

2424

25-
// Export for 'math' shared extension, function used
26-
// via inlined _PyObject_VectorcallTstate() function.
25+
// Export for 'math' shared extension, used via _PyObject_VectorcallTstate()
26+
// static inline function.
2727
PyAPI_FUNC(PyObject*) _Py_CheckFunctionResult(
2828
PyThreadState *tstate,
2929
PyObject *callable,
@@ -120,8 +120,8 @@ _PyObject_CallMethodIdOneArg(PyObject *self, _Py_Identifier *name, PyObject *arg
120120
// Call callable using tp_call. Arguments are like PyObject_Vectorcall(),
121121
// except that nargs is plainly the number of arguments without flags.
122122
//
123-
// Export for 'math' shared extension, function used
124-
// via inlined _PyObject_VectorcallTstate() function.
123+
// Export for 'math' shared extension, used via _PyObject_VectorcallTstate()
124+
// static inline function.
125125
PyAPI_FUNC(PyObject*) _PyObject_MakeTpCall(
126126
PyThreadState *tstate,
127127
PyObject *callable,

Include/internal/pycore_ceval.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ extern void _Py_FinishPendingCalls(PyThreadState *tstate);
2323
extern void _PyEval_InitState(PyInterpreterState *, PyThread_type_lock);
2424
extern void _PyEval_FiniState(struct _ceval_state *ceval);
2525
extern void _PyEval_SignalReceived(PyInterpreterState *interp);
26+
2627
// Export for '_testinternalcapi' shared extension
2728
PyAPI_FUNC(int) _PyEval_AddPendingCall(
2829
PyInterpreterState *interp,
2930
int (*func)(void *),
3031
void *arg,
3132
int mainthreadonly);
33+
3234
extern void _PyEval_SignalAsyncExc(PyInterpreterState *interp);
3335
#ifdef HAVE_FORK
3436
extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);
@@ -122,7 +124,8 @@ static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
122124
}
123125
#endif
124126

125-
// Export for _Py_EnterRecursiveCall()
127+
// Export for '_json' shared extension, used via _Py_EnterRecursiveCall()
128+
// static inline function.
126129
PyAPI_FUNC(int) _Py_CheckRecursiveCall(
127130
PyThreadState *tstate,
128131
const char *where);

Include/internal/pycore_compile.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ PyAPI_FUNC(PyCodeObject*) _PyAST_Compile(
2020
struct _arena *arena);
2121

2222
/* AST optimizations */
23-
PyAPI_FUNC(int) _PyCompile_AstOptimize(
23+
extern int _PyCompile_AstOptimize(
2424
struct _mod *mod,
2525
PyObject *filename,
2626
PyCompilerFlags *flags,
@@ -107,18 +107,21 @@ int _PyCompile_ConstCacheMergeOne(PyObject *const_cache, PyObject **obj);
107107
// Export for '_testinternalcapi' shared extension
108108
PyAPI_FUNC(PyObject*) _PyCompile_CleanDoc(PyObject *doc);
109109

110+
// Export for '_testinternalcapi' shared extension
110111
PyAPI_FUNC(PyObject*) _PyCompile_CodeGen(
111112
PyObject *ast,
112113
PyObject *filename,
113114
PyCompilerFlags *flags,
114115
int optimize,
115116
int compile_mode);
116117

118+
// Export for '_testinternalcapi' shared extension
117119
PyAPI_FUNC(PyObject*) _PyCompile_OptimizeCfg(
118120
PyObject *instructions,
119121
PyObject *consts,
120122
int nlocals);
121123

124+
// Export for '_testinternalcapi' shared extension
122125
PyAPI_FUNC(PyCodeObject*)
123126
_PyCompile_Assemble(_PyCompile_CodeUnitMetadata *umd, PyObject *filename,
124127
PyObject *instructions);

Include/internal/pycore_complexobject.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ extern "C" {
1010

1111
#include "pycore_unicodeobject.h" // _PyUnicodeWriter
1212

13-
/* Operations on complex numbers from complexmodule.c */
14-
13+
// Operations on complex numbers.
14+
// Export functions for 'cmath' shared extension.
1515
PyAPI_FUNC(Py_complex) _Py_c_sum(Py_complex, Py_complex);
1616
PyAPI_FUNC(Py_complex) _Py_c_diff(Py_complex, Py_complex);
1717
PyAPI_FUNC(Py_complex) _Py_c_neg(Py_complex);

Include/internal/pycore_fileutils.h

+18-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ typedef enum {
3535
_Py_ERROR_OTHER
3636
} _Py_error_handler;
3737

38+
// Export for '_testinternalcapi' shared extension
3839
PyAPI_FUNC(_Py_error_handler) _Py_GetErrorHandler(const char *errors);
3940

41+
// Export for '_testinternalcapi' shared extension
4042
PyAPI_FUNC(int) _Py_DecodeLocaleEx(
4143
const char *arg,
4244
wchar_t **wstr,
@@ -45,6 +47,7 @@ PyAPI_FUNC(int) _Py_DecodeLocaleEx(
4547
int current_locale,
4648
_Py_error_handler errors);
4749

50+
// Export for '_testinternalcapi' shared extension
4851
PyAPI_FUNC(int) _Py_EncodeLocaleEx(
4952
const wchar_t *text,
5053
char **str,
@@ -98,23 +101,27 @@ struct _Py_stat_struct {
98101
# define _Py_stat_struct stat
99102
#endif
100103

104+
// Export for 'mmap' shared extension
101105
PyAPI_FUNC(int) _Py_fstat(
102106
int fd,
103107
struct _Py_stat_struct *status);
104108

109+
// Export for 'mmap' shared extension
105110
PyAPI_FUNC(int) _Py_fstat_noraise(
106111
int fd,
107112
struct _Py_stat_struct *status);
108113

114+
// Export for '_tkinter' shared extension
109115
PyAPI_FUNC(int) _Py_stat(
110116
PyObject *path,
111117
struct stat *status);
112118

113-
// Export for 'select' shared extension (Solaris newDevPollObject() uses it)
119+
// Export for 'select' shared extension (Solaris newDevPollObject())
114120
PyAPI_FUNC(int) _Py_open(
115121
const char *pathname,
116122
int flags);
117123

124+
// Export for '_posixsubprocess' shared extension
118125
PyAPI_FUNC(int) _Py_open_noraise(
119126
const char *pathname,
120127
int flags);
@@ -128,12 +135,13 @@ extern Py_ssize_t _Py_read(
128135
void *buf,
129136
size_t count);
130137

131-
// Export for 'select' shared extension (Solaris devpoll_flush() uses it)
138+
// Export for 'select' shared extension (Solaris devpoll_flush())
132139
PyAPI_FUNC(Py_ssize_t) _Py_write(
133140
int fd,
134141
const void *buf,
135142
size_t count);
136143

144+
// Export for '_posixsubprocess' shared extension
137145
PyAPI_FUNC(Py_ssize_t) _Py_write_noraise(
138146
int fd,
139147
const void *buf,
@@ -165,12 +173,15 @@ extern wchar_t* _Py_wgetcwd(
165173

166174
extern int _Py_get_inheritable(int fd);
167175

176+
// Export for '_socket' shared extension
168177
PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable,
169178
int *atomic_flag_works);
170179

180+
// Export for '_posixsubprocess' shared extension
171181
PyAPI_FUNC(int) _Py_set_inheritable_async_safe(int fd, int inheritable,
172182
int *atomic_flag_works);
173183

184+
// Export for '_socket' shared extension
174185
PyAPI_FUNC(int) _Py_dup(int fd);
175186

176187
extern int _Py_get_blocking(int fd);
@@ -180,6 +191,7 @@ extern int _Py_set_blocking(int fd, int blocking);
180191
#ifdef MS_WINDOWS
181192
extern void* _Py_get_osfhandle_noraise(int fd);
182193

194+
// Export for '_testconsole' shared extension
183195
PyAPI_FUNC(void*) _Py_get_osfhandle(int fd);
184196

185197
extern int _Py_open_osfhandle_noraise(void *handle, int flags);
@@ -234,6 +246,7 @@ extern int _Py_GetLocaleconvNumeric(
234246
PyObject **decimal_point,
235247
PyObject **thousands_sep);
236248

249+
// Export for '_posixsubprocess' (on macOS)
237250
PyAPI_FUNC(void) _Py_closerange(int first, int last);
238251

239252
extern wchar_t* _Py_GetLocaleEncoding(void);
@@ -262,7 +275,10 @@ extern int _Py_add_relfile(wchar_t *dirname,
262275
const wchar_t *relfile,
263276
size_t bufsize);
264277
extern size_t _Py_find_basename(const wchar_t *filename);
278+
279+
// Export for '_testinternalcapi' shared extension
265280
PyAPI_FUNC(wchar_t*) _Py_normpath(wchar_t *path, Py_ssize_t size);
281+
266282
extern wchar_t *_Py_normpath_and_size(wchar_t *path, Py_ssize_t size, Py_ssize_t *length);
267283

268284
// The Windows Games API family does not provide these functions

Include/internal/pycore_genobject.h

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extern void _PyGen_Finalize(PyObject *self);
1313

1414
// Export for '_asyncio' shared extension
1515
PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);
16+
1617
// Export for '_asyncio' shared extension
1718
PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
1819

Include/internal/pycore_hashtable.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ struct _Py_hashtable_t {
7070
_Py_hashtable_allocator_t alloc;
7171
};
7272

73+
// Export _Py_hashtable functions for '_testinternalcapi' shared extension
74+
PyAPI_FUNC(_Py_hashtable_t *) _Py_hashtable_new(
75+
_Py_hashtable_hash_func hash_func,
76+
_Py_hashtable_compare_func compare_func);
77+
7378
/* Hash a pointer (void*) */
7479
PyAPI_FUNC(Py_uhash_t) _Py_hashtable_hash_ptr(const void *key);
7580

@@ -78,10 +83,6 @@ PyAPI_FUNC(int) _Py_hashtable_compare_direct(
7883
const void *key1,
7984
const void *key2);
8085

81-
PyAPI_FUNC(_Py_hashtable_t *) _Py_hashtable_new(
82-
_Py_hashtable_hash_func hash_func,
83-
_Py_hashtable_compare_func compare_func);
84-
8586
PyAPI_FUNC(_Py_hashtable_t *) _Py_hashtable_new_full(
8687
_Py_hashtable_hash_func hash_func,
8788
_Py_hashtable_compare_func compare_func,

Include/internal/pycore_import.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ extern "C" {
1414

1515
extern int _PyImport_IsInitialized(PyInterpreterState *);
1616

17+
// Export for 'pyexpat' shared extension
1718
PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module);
19+
1820
extern int _PyImport_SetModuleString(const char *name, PyObject* module);
1921

2022
extern void _PyImport_AcquireLock(PyInterpreterState *interp);
@@ -28,7 +30,10 @@ extern int _PyImport_FixupBuiltin(
2830
extern int _PyImport_FixupExtensionObject(PyObject*, PyObject *,
2931
PyObject *, PyObject *);
3032

33+
// Export for many shared extensions, like '_json'
3134
PyAPI_FUNC(PyObject*) _PyImport_GetModuleAttr(PyObject *, PyObject *);
35+
36+
// Export for many shared extensions, like '_datetime'
3237
PyAPI_FUNC(PyObject*) _PyImport_GetModuleAttrString(const char *, const char *);
3338

3439

@@ -187,11 +192,9 @@ struct _module_alias {
187192
const char *orig; /* ASCII encoded string */
188193
};
189194

190-
// Export for test_ctypes
195+
// Export these 3 symbols for test_ctypes
191196
PyAPI_DATA(const struct _frozen*) _PyImport_FrozenBootstrap;
192-
// Export for test_ctypes
193197
PyAPI_DATA(const struct _frozen*) _PyImport_FrozenStdlib;
194-
// Export for test_ctypes
195198
PyAPI_DATA(const struct _frozen*) _PyImport_FrozenTest;
196199

197200
extern const struct _module_alias * _PyImport_FrozenAliases;

Include/internal/pycore_initconfig.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ extern PyStatus _PyPreCmdline_Read(_PyPreCmdline *cmdline,
124124

125125
// Export for '_testembed' program
126126
PyAPI_FUNC(void) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig);
127+
127128
extern void _PyPreConfig_InitFromConfig(
128129
PyPreConfig *preconfig,
129130
const PyConfig *config);
@@ -149,6 +150,7 @@ typedef enum {
149150

150151
// Export for '_testembed' program
151152
PyAPI_FUNC(void) _PyConfig_InitCompatConfig(PyConfig *config);
153+
152154
extern PyStatus _PyConfig_Copy(
153155
PyConfig *config,
154156
const PyConfig *config2);
@@ -163,16 +165,16 @@ extern PyStatus _PyConfig_SetPyArgv(
163165
PyConfig *config,
164166
const _PyArgv *args);
165167

166-
PyAPI_FUNC(PyObject*) _PyConfig_AsDict(const PyConfig *config);
167-
PyAPI_FUNC(int) _PyConfig_FromDict(PyConfig *config, PyObject *dict);
168168

169169
extern void _Py_DumpPathConfig(PyThreadState *tstate);
170170

171-
PyAPI_FUNC(PyObject*) _Py_Get_Getpath_CodeObject(void);
172-
173171

174172
/* --- Function used for testing ---------------------------------- */
175173

174+
// Export these functions for '_testinternalcapi' shared extension
175+
PyAPI_FUNC(PyObject*) _PyConfig_AsDict(const PyConfig *config);
176+
PyAPI_FUNC(int) _PyConfig_FromDict(PyConfig *config, PyObject *dict);
177+
PyAPI_FUNC(PyObject*) _Py_Get_Getpath_CodeObject(void);
176178
PyAPI_FUNC(PyObject*) _Py_GetConfigsAsDict(void);
177179

178180
#ifdef __cplusplus

0 commit comments

Comments
 (0)