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

Skip to content

Commit 11306a9

Browse files
authored
gh-107211: No longer export internal functions (1) (#107213)
No longer export these 49 internal C API functions: * _PyArgv_AsWstrList() * _PyCode_New() * _PyCode_Validate() * _PyFloat_DebugMallocStats() * _PyFloat_FormatAdvancedWriter() * _PyImport_CheckSubinterpIncompatibleExtensionAllowed() * _PyImport_ClearExtension() * _PyImport_GetModuleId() * _PyImport_SetModuleString() * _PyInterpreterState_IDDecref() * _PyInterpreterState_IDIncref() * _PyInterpreterState_IDInitref() * _PyInterpreterState_LookUpID() * _PyWideStringList_AsList() * _PyWideStringList_CheckConsistency() * _PyWideStringList_Clear() * _PyWideStringList_Copy() * _PyWideStringList_Extend() * _Py_ClearArgcArgv() * _Py_DecodeUTF8Ex() * _Py_DecodeUTF8_surrogateescape() * _Py_EncodeLocaleRaw() * _Py_EncodeUTF8Ex() * _Py_GetEnv() * _Py_GetForceASCII() * _Py_GetLocaleEncoding() * _Py_GetLocaleEncodingObject() * _Py_GetLocaleconvNumeric() * _Py_ResetForceASCII() * _Py_device_encoding() * _Py_dg_dtoa() * _Py_dg_freedtoa() * _Py_dg_strtod() * _Py_get_blocking() * _Py_get_env_flag() * _Py_get_inheritable() * _Py_get_osfhandle_noraise() * _Py_get_xoption() * _Py_open() * _Py_open_osfhandle() * _Py_open_osfhandle_noraise() * _Py_read() * _Py_set_blocking() * _Py_str_to_int() * _Py_wfopen() * _Py_wgetcwd() * _Py_wreadlink() * _Py_wrealpath() * _Py_write()
1 parent 2e07449 commit 11306a9

10 files changed

+67
-66
lines changed

Include/internal/pycore_call.h

Lines changed: 5 additions & 5 deletions
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 shared stdlib extensions like the math extension,
26-
// function used via inlined _PyObject_VectorcallTstate() function.
25+
// Export for 'math' shared extension, function used
26+
// via inlined _PyObject_VectorcallTstate() function.
2727
PyAPI_FUNC(PyObject*) _Py_CheckFunctionResult(
2828
PyThreadState *tstate,
2929
PyObject *callable,
@@ -68,7 +68,7 @@ extern PyObject * _PyObject_CallMethodFormat(
6868
const char *format,
6969
...);
7070

71-
// Export for shared stdlib extensions like the array extension
71+
// Export for 'array' shared extension
7272
PyAPI_FUNC(PyObject*) _PyObject_CallMethod(
7373
PyObject *obj,
7474
PyObject *name,
@@ -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 shared stdlib extensions like the math extension,
124-
// function used via inlined _PyObject_VectorcallTstate() function.
123+
// Export for 'math' shared extension, function used
124+
// via inlined _PyObject_VectorcallTstate() function.
125125
PyAPI_FUNC(PyObject*) _PyObject_MakeTpCall(
126126
PyThreadState *tstate,
127127
PyObject *callable,

Include/internal/pycore_code.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ struct _PyCodeConstructor {
203203
// back to a regular function signature. Regardless, this approach
204204
// wouldn't be appropriate if this weren't a strictly internal API.
205205
// (See the comments in https://github.com/python/cpython/pull/26258.)
206-
PyAPI_FUNC(int) _PyCode_Validate(struct _PyCodeConstructor *);
207-
PyAPI_FUNC(PyCodeObject *) _PyCode_New(struct _PyCodeConstructor *);
206+
extern int _PyCode_Validate(struct _PyCodeConstructor *);
207+
extern PyCodeObject* _PyCode_New(struct _PyCodeConstructor *);
208208

209209

210210
/* Private API */
@@ -274,7 +274,7 @@ extern int _PyStaticCode_Init(PyCodeObject *co);
274274
#define EVAL_CALL_STAT_INC_IF_FUNCTION(name, callable) \
275275
do { if (_py_stats && PyFunction_Check(callable)) _py_stats->call_stats.eval_calls[name]++; } while (0)
276276

277-
// Used by the _opcode extension which is built as a shared library
277+
// Export for stdlib '_opcode' shared extension
278278
PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);
279279

280280
#else

Include/internal/pycore_compile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern "C" {
1111
struct _arena; // Type defined in pycore_pyarena.h
1212
struct _mod; // Type defined in pycore_ast.h
1313

14-
// Export the symbol for test_peg_generator (built as a library)
14+
// Export for 'test_peg_generator' shared extension
1515
PyAPI_FUNC(PyCodeObject*) _PyAST_Compile(
1616
struct _mod *mod,
1717
PyObject *filename,
@@ -91,6 +91,7 @@ int _PyCompile_ConstCacheMergeOne(PyObject *const_cache, PyObject **obj);
9191

9292
/* Access compiler internals for unit testing */
9393

94+
// Export for '_testinternalcapi' shared extension
9495
PyAPI_FUNC(PyObject*) _PyCompile_CleanDoc(PyObject *doc);
9596

9697
PyAPI_FUNC(PyObject*) _PyCompile_CodeGen(

Include/internal/pycore_dtoa.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ struct _dtoa_state {
6060
/* These functions are used by modules compiled as C extension like math:
6161
they must be exported. */
6262

63-
PyAPI_FUNC(double) _Py_dg_strtod(const char *str, char **ptr);
64-
PyAPI_FUNC(char *) _Py_dg_dtoa(double d, int mode, int ndigits,
65-
int *decpt, int *sign, char **rve);
66-
PyAPI_FUNC(void) _Py_dg_freedtoa(char *s);
63+
extern double _Py_dg_strtod(const char *str, char **ptr);
64+
extern char* _Py_dg_dtoa(double d, int mode, int ndigits,
65+
int *decpt, int *sign, char **rve);
66+
extern void _Py_dg_freedtoa(char *s);
6767

6868
#endif // _PY_SHORT_FLOAT_REPR == 1
6969

Include/internal/pycore_fileutils.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ PyAPI_FUNC(int) _Py_EncodeLocaleEx(
5252
int current_locale,
5353
_Py_error_handler errors);
5454

55-
PyAPI_FUNC(char*) _Py_EncodeLocaleRaw(
55+
extern char* _Py_EncodeLocaleRaw(
5656
const wchar_t *text,
5757
size_t *error_pos);
5858

59-
PyAPI_FUNC(PyObject *) _Py_device_encoding(int);
59+
extern PyObject* _Py_device_encoding(int);
6060

6161
#if defined(MS_WINDOWS) || defined(__APPLE__)
6262
/* On Windows, the count parameter of read() is an int (bpo-9015, bpo-9611).
@@ -109,24 +109,24 @@ PyAPI_FUNC(int) _Py_stat(
109109
PyObject *path,
110110
struct stat *status);
111111

112-
PyAPI_FUNC(int) _Py_open(
112+
extern int _Py_open(
113113
const char *pathname,
114114
int flags);
115115

116116
PyAPI_FUNC(int) _Py_open_noraise(
117117
const char *pathname,
118118
int flags);
119119

120-
PyAPI_FUNC(FILE *) _Py_wfopen(
120+
extern FILE* _Py_wfopen(
121121
const wchar_t *path,
122122
const wchar_t *mode);
123123

124-
PyAPI_FUNC(Py_ssize_t) _Py_read(
124+
extern Py_ssize_t _Py_read(
125125
int fd,
126126
void *buf,
127127
size_t count);
128128

129-
PyAPI_FUNC(Py_ssize_t) _Py_write(
129+
extern Py_ssize_t _Py_write(
130130
int fd,
131131
const void *buf,
132132
size_t count);
@@ -137,7 +137,7 @@ PyAPI_FUNC(Py_ssize_t) _Py_write_noraise(
137137
size_t count);
138138

139139
#ifdef HAVE_READLINK
140-
PyAPI_FUNC(int) _Py_wreadlink(
140+
extern int _Py_wreadlink(
141141
const wchar_t *path,
142142
wchar_t *buf,
143143
/* Number of characters of 'buf' buffer
@@ -146,21 +146,21 @@ PyAPI_FUNC(int) _Py_wreadlink(
146146
#endif
147147

148148
#ifdef HAVE_REALPATH
149-
PyAPI_FUNC(wchar_t*) _Py_wrealpath(
149+
extern wchar_t* _Py_wrealpath(
150150
const wchar_t *path,
151151
wchar_t *resolved_path,
152152
/* Number of characters of 'resolved_path' buffer
153153
including the trailing NUL character */
154154
size_t resolved_path_len);
155155
#endif
156156

157-
PyAPI_FUNC(wchar_t*) _Py_wgetcwd(
157+
extern wchar_t* _Py_wgetcwd(
158158
wchar_t *buf,
159159
/* Number of characters of 'buf' buffer
160160
including the trailing NUL character */
161161
size_t buflen);
162162

163-
PyAPI_FUNC(int) _Py_get_inheritable(int fd);
163+
extern int _Py_get_inheritable(int fd);
164164

165165
PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable,
166166
int *atomic_flag_works);
@@ -170,18 +170,18 @@ PyAPI_FUNC(int) _Py_set_inheritable_async_safe(int fd, int inheritable,
170170

171171
PyAPI_FUNC(int) _Py_dup(int fd);
172172

173-
PyAPI_FUNC(int) _Py_get_blocking(int fd);
173+
extern int _Py_get_blocking(int fd);
174174

175-
PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking);
175+
extern int _Py_set_blocking(int fd, int blocking);
176176

177177
#ifdef MS_WINDOWS
178-
PyAPI_FUNC(void*) _Py_get_osfhandle_noraise(int fd);
178+
extern void* _Py_get_osfhandle_noraise(int fd);
179179

180180
PyAPI_FUNC(void*) _Py_get_osfhandle(int fd);
181181

182-
PyAPI_FUNC(int) _Py_open_osfhandle_noraise(void *handle, int flags);
182+
extern int _Py_open_osfhandle_noraise(void *handle, int flags);
183183

184-
PyAPI_FUNC(int) _Py_open_osfhandle(void *handle, int flags);
184+
extern int _Py_open_osfhandle(void *handle, int flags);
185185
#endif /* MS_WINDOWS */
186186

187187
// This is used after getting NULL back from Py_DecodeLocale().
@@ -190,51 +190,51 @@ PyAPI_FUNC(int) _Py_open_osfhandle(void *handle, int flags);
190190
? _PyStatus_ERR("cannot decode " NAME) \
191191
: _PyStatus_NO_MEMORY()
192192

193-
PyAPI_DATA(int) _Py_HasFileSystemDefaultEncodeErrors;
193+
extern int _Py_HasFileSystemDefaultEncodeErrors;
194194

195-
PyAPI_FUNC(int) _Py_DecodeUTF8Ex(
195+
extern int _Py_DecodeUTF8Ex(
196196
const char *arg,
197197
Py_ssize_t arglen,
198198
wchar_t **wstr,
199199
size_t *wlen,
200200
const char **reason,
201201
_Py_error_handler errors);
202202

203-
PyAPI_FUNC(int) _Py_EncodeUTF8Ex(
203+
extern int _Py_EncodeUTF8Ex(
204204
const wchar_t *text,
205205
char **str,
206206
size_t *error_pos,
207207
const char **reason,
208208
int raw_malloc,
209209
_Py_error_handler errors);
210210

211-
PyAPI_FUNC(wchar_t*) _Py_DecodeUTF8_surrogateescape(
211+
extern wchar_t* _Py_DecodeUTF8_surrogateescape(
212212
const char *arg,
213213
Py_ssize_t arglen,
214214
size_t *wlen);
215215

216216
extern int
217217
_Py_wstat(const wchar_t *, struct stat *);
218218

219-
PyAPI_FUNC(int) _Py_GetForceASCII(void);
219+
extern int _Py_GetForceASCII(void);
220220

221221
/* Reset "force ASCII" mode (if it was initialized).
222222
223223
This function should be called when Python changes the LC_CTYPE locale,
224224
so the "force ASCII" mode can be detected again on the new locale
225225
encoding. */
226-
PyAPI_FUNC(void) _Py_ResetForceASCII(void);
226+
extern void _Py_ResetForceASCII(void);
227227

228228

229-
PyAPI_FUNC(int) _Py_GetLocaleconvNumeric(
229+
extern int _Py_GetLocaleconvNumeric(
230230
struct lconv *lc,
231231
PyObject **decimal_point,
232232
PyObject **thousands_sep);
233233

234234
PyAPI_FUNC(void) _Py_closerange(int first, int last);
235235

236-
PyAPI_FUNC(wchar_t*) _Py_GetLocaleEncoding(void);
237-
PyAPI_FUNC(PyObject*) _Py_GetLocaleEncodingObject(void);
236+
extern wchar_t* _Py_GetLocaleEncoding(void);
237+
extern PyObject* _Py_GetLocaleEncodingObject(void);
238238

239239
#ifdef HAVE_NON_UNICODE_WCHAR_T_REPRESENTATION
240240
extern int _Py_LocaleUsesNonUnicodeWchar(void);
@@ -253,13 +253,13 @@ extern int _Py_abspath(const wchar_t *path, wchar_t **abspath_p);
253253
#ifdef MS_WINDOWS
254254
extern int _PyOS_getfullpathname(const wchar_t *path, wchar_t **abspath_p);
255255
#endif
256-
extern wchar_t * _Py_join_relfile(const wchar_t *dirname,
257-
const wchar_t *relfile);
256+
extern wchar_t* _Py_join_relfile(const wchar_t *dirname,
257+
const wchar_t *relfile);
258258
extern int _Py_add_relfile(wchar_t *dirname,
259259
const wchar_t *relfile,
260260
size_t bufsize);
261261
extern size_t _Py_find_basename(const wchar_t *filename);
262-
PyAPI_FUNC(wchar_t *) _Py_normpath(wchar_t *path, Py_ssize_t size);
262+
PyAPI_FUNC(wchar_t*) _Py_normpath(wchar_t *path, Py_ssize_t size);
263263

264264
// The Windows Games API family does not provide these functions
265265
// so provide our own implementations. Remove them in case they get added

Include/internal/pycore_floatobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ struct _Py_float_state {
5555
void _PyFloat_ExactDealloc(PyObject *op);
5656

5757

58-
PyAPI_FUNC(void) _PyFloat_DebugMallocStats(FILE* out);
58+
extern void _PyFloat_DebugMallocStats(FILE* out);
5959

6060

6161
/* Format the object based on the format_spec, as defined in PEP 3101
6262
(Advanced String Formatting). */
63-
PyAPI_FUNC(int) _PyFloat_FormatAdvancedWriter(
63+
extern int _PyFloat_FormatAdvancedWriter(
6464
_PyUnicodeWriter *writer,
6565
PyObject *obj,
6666
PyObject *format_spec,

Include/internal/pycore_genobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ extern "C" {
1111
extern PyObject *_PyGen_yf(PyGenObject *);
1212
extern void _PyGen_Finalize(PyObject *self);
1313

14-
// _asyncio shared extensions uses _PyGen_SetStopIterationValue() and
15-
// _PyGen_FetchStopIterationValue()
14+
// Export for '_asyncio' shared extension
1615
PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);
16+
// Export for '_asyncio' shared extension
1717
PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
1818

1919
extern PyObject *_PyCoro_GetAwaitableIter(PyObject *o);

Include/internal/pycore_import.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ extern "C" {
99

1010
extern int _PyImport_IsInitialized(PyInterpreterState *);
1111

12-
PyAPI_FUNC(PyObject *) _PyImport_GetModuleId(_Py_Identifier *name);
12+
extern PyObject* _PyImport_GetModuleId(_Py_Identifier *name);
1313
PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module);
14-
PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module);
14+
extern int _PyImport_SetModuleString(const char *name, PyObject* module);
1515

1616
extern void _PyImport_AcquireLock(PyInterpreterState *interp);
1717
extern int _PyImport_ReleaseLock(PyInterpreterState *interp);
@@ -24,8 +24,8 @@ extern int _PyImport_FixupBuiltin(
2424
extern int _PyImport_FixupExtensionObject(PyObject*, PyObject *,
2525
PyObject *, PyObject *);
2626

27-
PyAPI_FUNC(PyObject *) _PyImport_GetModuleAttr(PyObject *, PyObject *);
28-
PyAPI_FUNC(PyObject *) _PyImport_GetModuleAttrString(const char *, const char *);
27+
PyAPI_FUNC(PyObject*) _PyImport_GetModuleAttr(PyObject *, PyObject *);
28+
PyAPI_FUNC(PyObject*) _PyImport_GetModuleAttrString(const char *, const char *);
2929

3030

3131
struct _import_runtime_state {
@@ -192,12 +192,12 @@ PyAPI_DATA(const struct _frozen *) _PyImport_FrozenStdlib;
192192
PyAPI_DATA(const struct _frozen *) _PyImport_FrozenTest;
193193
extern const struct _module_alias * _PyImport_FrozenAliases;
194194

195-
PyAPI_FUNC(int) _PyImport_CheckSubinterpIncompatibleExtensionAllowed(
195+
extern int _PyImport_CheckSubinterpIncompatibleExtensionAllowed(
196196
const char *name);
197197

198198

199-
// for testing
200-
PyAPI_FUNC(int) _PyImport_ClearExtension(PyObject *name, PyObject *filename);
199+
// Export for '_testinternalcapi' shared extension
200+
PyAPI_DATA(int) _PyImport_ClearExtension(PyObject *name, PyObject *filename);
201201

202202
#ifdef __cplusplus
203203
}

Include/internal/pycore_initconfig.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ struct pyruntimestate;
4949
#define _PyWideStringList_INIT (PyWideStringList){.length = 0, .items = NULL}
5050

5151
#ifndef NDEBUG
52-
PyAPI_FUNC(int) _PyWideStringList_CheckConsistency(const PyWideStringList *list);
52+
extern int _PyWideStringList_CheckConsistency(const PyWideStringList *list);
5353
#endif
54-
PyAPI_FUNC(void) _PyWideStringList_Clear(PyWideStringList *list);
55-
PyAPI_FUNC(int) _PyWideStringList_Copy(PyWideStringList *list,
54+
extern void _PyWideStringList_Clear(PyWideStringList *list);
55+
extern int _PyWideStringList_Copy(PyWideStringList *list,
5656
const PyWideStringList *list2);
57-
PyAPI_FUNC(PyStatus) _PyWideStringList_Extend(PyWideStringList *list,
57+
extern PyStatus _PyWideStringList_Extend(PyWideStringList *list,
5858
const PyWideStringList *list2);
59-
PyAPI_FUNC(PyObject*) _PyWideStringList_AsList(const PyWideStringList *list);
59+
extern PyObject* _PyWideStringList_AsList(const PyWideStringList *list);
6060

6161

6262
/* --- _PyArgv ---------------------------------------------------- */
@@ -68,28 +68,28 @@ typedef struct _PyArgv {
6868
wchar_t * const *wchar_argv;
6969
} _PyArgv;
7070

71-
PyAPI_FUNC(PyStatus) _PyArgv_AsWstrList(const _PyArgv *args,
71+
extern PyStatus _PyArgv_AsWstrList(const _PyArgv *args,
7272
PyWideStringList *list);
7373

7474

7575
/* --- Helper functions ------------------------------------------- */
7676

77-
PyAPI_FUNC(int) _Py_str_to_int(
77+
extern int _Py_str_to_int(
7878
const char *str,
7979
int *result);
80-
PyAPI_FUNC(const wchar_t*) _Py_get_xoption(
80+
extern const wchar_t* _Py_get_xoption(
8181
const PyWideStringList *xoptions,
8282
const wchar_t *name);
83-
PyAPI_FUNC(const char*) _Py_GetEnv(
83+
extern const char* _Py_GetEnv(
8484
int use_environment,
8585
const char *name);
86-
PyAPI_FUNC(void) _Py_get_env_flag(
86+
extern void _Py_get_env_flag(
8787
int use_environment,
8888
int *flag,
8989
const char *name);
9090

9191
/* Py_GetArgcArgv() helper */
92-
PyAPI_FUNC(void) _Py_ClearArgcArgv(void);
92+
extern void _Py_ClearArgcArgv(void);
9393

9494

9595
/* --- _PyPreCmdline ------------------------------------------------- */

Include/internal/pycore_interp.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ struct _xidregitem {
232232
crossinterpdatafunc getdata;
233233
};
234234

235-
PyAPI_FUNC(PyInterpreterState*) _PyInterpreterState_LookUpID(int64_t);
235+
extern PyInterpreterState* _PyInterpreterState_LookUpID(int64_t);
236236

237-
PyAPI_FUNC(int) _PyInterpreterState_IDInitref(PyInterpreterState *);
238-
PyAPI_FUNC(int) _PyInterpreterState_IDIncref(PyInterpreterState *);
239-
PyAPI_FUNC(void) _PyInterpreterState_IDDecref(PyInterpreterState *);
237+
extern int _PyInterpreterState_IDInitref(PyInterpreterState *);
238+
extern int _PyInterpreterState_IDIncref(PyInterpreterState *);
239+
extern void _PyInterpreterState_IDDecref(PyInterpreterState *);
240240

241241
PyAPI_FUNC(PyObject*) _PyInterpreterState_GetMainModule(PyInterpreterState *);
242242

0 commit comments

Comments
 (0)
0