8000 gh-107211: No longer export internal variables (#107218) · python/cpython@3b30931 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b30931

Browse files
authored
gh-107211: No longer export internal variables (#107218)
No longer export these 5 internal C API variables: * _PyBufferWrapper_Type * _PyImport_FrozenBootstrap * _PyImport_FrozenStdlib * _PyImport_FrozenTest * _Py_SwappedOp Fix the definition of these internal functions, replace PyAPI_DATA() with PyAPI_FUNC(): * _PyImport_ClearExtension() * _PyObject_IsFreed() * _PyThreadState_GetCurrent()
1 parent c5b13d6 commit 3b30931

File tree

6 files changed

+26
-20
lines changed

6 files changed

+26
-20
lines changed

Include/internal/pycore_import.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,21 @@ struct _module_alias {
187187
const char *orig; /* ASCII encoded string */
188188
};
189189

190-
PyAPI_DATA(const struct _frozen *) _PyImport_FrozenBootstrap;
191-
PyAPI_DATA(const struct _frozen *) _PyImport_FrozenStdlib;
192-
PyAPI_DATA(const struct _frozen *) _PyImport_FrozenTest;
190+
// Export for test_ctypes
191+
PyAPI_DATA(const struct _frozen*) _PyImport_FrozenBootstrap;
192+
// Export for test_ctypes
193+
PyAPI_DATA(const struct _frozen*) _PyImport_FrozenStdlib;
194+
// Export for test_ctypes
195+
PyAPI_DATA(const struct _frozen*) _PyImport_FrozenTest;
196+
193197
extern const struct _module_alias * _PyImport_FrozenAliases;
194198

195199
extern int _PyImport_CheckSubinterpIncompatibleExtensionAllowed(
196200
const char *name);
197201

198202

199203
// Export for '_testinternalcapi' shared extension
200-
PyAPI_DATA(int) _PyImport_ClearExtension(PyObject *name, PyObject *filename);
204+
PyAPI_FUNC(int) _PyImport_ClearExtension(PyObject *name, PyObject *filename);
201205

202206
#ifdef __cplusplus
203207
}

Include/internal/pycore_long.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ 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 Python/mystrtoul.c, _PyBytes_FromHex(),
87-
_PyBytes_DecodeEscape(), etc. */
86+
// Used by _PyBytes_FromHex(), _PyBytes_DecodeEscape(), Python/mystrtoul.c.
87+
// Export for 'binascii' shared extension.
8888
PyAPI_DATA(unsigned char) _PyLong_DigitValue[256];
8989

9090
/* Format the object based on the format_spec, as defined in PEP 3101

Include/internal/pycore_object.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern void _PyDebugAllocatorStats(FILE *out, const char *block_name,
3333
extern void _PyObject_DebugTypeStats(FILE *out);
3434

3535
// Export for shared _testinternalcapi extension
36-
PyAPI_DATA(int) _PyObject_IsFreed(PyObject *);
36+
PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
3737

3838
/* We need to maintain an internal copy of Py{Var}Object_HEAD_INIT to avoid
3939
designated initializer conflicts in C++20. If we use the deinition in
@@ -469,11 +469,14 @@ extern PyObject* _PyCFunctionWithKeywords_TrampolineCall(
469469
(meth)((self), (args), (kw))
470470
#endif // __EMSCRIPTEN__ && PY_CALL_TRAMPOLINE
471471

472-
// _pickle shared extension uses _PyNone_Type and _PyNotImplemented_Type
472+
// Export for '_pickle' shared extension
473473
PyAPI_DATA(PyTypeObject) _PyNone_Type;
474+
// Export for '_pickle' shared extension
474475
PyAPI_DATA(PyTypeObject) _PyNotImplemented_Type;
475476

476-
/* Maps Py_LT to Py_GT, ..., Py_GE to Py_LE. Defined in Objects/object.c. */
477+
// Maps Py_LT to Py_GT, ..., Py_GE to Py_LE.
478+
// Defined in Objects/object.c.
479+
// Export for the stable ABI.
477480
PyAPI_DATA(int) _Py_SwappedOp[];
478481

479482
#ifdef __cplusplus

Include/internal/pycore_pyhash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ typedef union {
7474
} expat;
7575
} _Py_HashSecret_t;
7676

77-
// _elementtree shared extension uses _Py_HashSecret.expat
77+
// Export for '_elementtree' shared extension
7878
PyAPI_DATA(_Py_HashSecret_t) _Py_HashSecret;
7979

8080
#ifdef Py_DEBUG

Include/internal/pycore_pystate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ _Py_ThreadCanHandleSignals(PyInterpreterState *interp)
6666
#if defined(HAVE_THREAD_LOCAL) && !defined(Py_BUILD_CORE_MODULE)
6767
extern _Py_thread_local PyThreadState *_Py_tss_tstate;
6868
#endif
69-
PyAPI_DATA(PyThreadState *) _PyThreadState_GetCurrent(void);
69+
PyAPI_FUNC(PyThreadState *) _PyThreadState_GetCurrent(void);
7070

7171
/* Get the current Python thread state.
7272

Include/internal/pycore_typeobject.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,17 @@ _PyType_IsReady(PyTypeObject *type)
129129
return _PyType_GetDict(type) != NULL;
130130
}
131131

132-
PyObject *
133-
_Py_type_getattro_impl(PyTypeObject *type, PyObject *name, int *suppress_missing_attribute);
134-
PyObject *
135-
_Py_type_getattro(PyTypeObject *type, PyObject *name);
132+
extern PyObject* _Py_type_getattro_impl(PyTypeObject *type, PyObject *name,
133+
int *suppress_missing_attribute);
134+
extern PyObject* _Py_type_getattro(PyTypeObject *type, PyObject *name);
136135

137-
PyObject *_Py_slot_tp_getattro(PyObject *self, PyObject *name);
138-
PyObject *_Py_slot_tp_getattr_hook(PyObject *self, PyObject *name);
136+
extern PyObject* _Py_slot_tp_getattro(PyObject *self, PyObject *name);
137+
extern PyObject* _Py_slot_tp_getattr_hook(PyObject *self, PyObject *name);
139138

140-
PyAPI_DATA(PyTypeObject) _PyBufferWrapper_Type;
139+
extern PyTypeObject _PyBufferWrapper_Type;
141140

142-
PyObject *
143-
_PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *meth_found);
141+
extern PyObject* _PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj,
142+
PyObject *name, int *meth_found);
144143

145144
#ifdef __cplusplus
146145
}

0 commit comments

Comments
 (0)
0