Skip to content

Commit 1a66f65

Browse files
committed
gh-107211: No longer export internal variables
No longer export these 5 internal C API variables: * _PyBufferWrapper_Type * _PyImport_FrozenBootstrap * _PyImport_FrozenStdlib * _PyImport_FrozenTest * _Py_SwappedOp Fix definition of these internal functions, replace PyAPI_DATA() with PyAPI_FUNC(): * _PyImport_ClearExtension() * _PyObject_IsFreed() * _PyThreadState_GetCurrent()
1 parent 0d0520a commit 1a66f65

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

Include/internal/pycore_import.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,17 @@ 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+
extern const struct _frozen* _PyImport_FrozenBootstrap;
191+
extern const struct _frozen* _PyImport_FrozenStdlib;
192+
extern const struct _frozen* _PyImport_FrozenTest;
193193
extern const struct _module_alias * _PyImport_FrozenAliases;
194194

195195
extern int _PyImport_CheckSubinterpIncompatibleExtensionAllowed(
196196
const char *name);
197197

198198

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

202202
#ifdef __cplusplus
203203
}

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: 4 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
@@ -468,12 +468,13 @@ extern PyObject* _PyCFunctionWithKeywords_TrampolineCall(
468468
(meth)((self), (args), (kw))
469469
#endif // __EMSCRIPTEN__ && PY_CALL_TRAMPOLINE
470470

471-
// _pickle shared extension uses _PyNone_Type and _PyNotImplemented_Type
471+
// Export for '_pickle' shared extension
472472
PyAPI_DATA(PyTypeObject) _PyNone_Type;
473+
// Export for '_pickle' shared extension
473474
PyAPI_DATA(PyTypeObject) _PyNotImplemented_Type;
474475

475476
/* Maps Py_LT to Py_GT, ..., Py_GE to Py_LE. Defined in Objects/object.c. */
476-
PyAPI_DATA(int) _Py_SwappedOp[];
477+
extern int _Py_SwappedOp[];
477478

478479
#ifdef __cplusplus
479480
}

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)