Skip to content

Commit e8b6aaa

Browse files
gh-101819: Remove _testcapi dependencies on specific _io symbols (#101918)
1 parent 8a2b7ee commit e8b6aaa

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

Modules/_io/_iomodule.c

+2-10
Original file line numberDiff line numberDiff line change
@@ -720,16 +720,8 @@ PyInit__io(void)
720720
// Add types
721721
for (size_t i=0; i < Py_ARRAY_LENGTH(static_types); i++) {
722722
PyTypeObject *type = static_types[i];
723-
// Private type not exposed in the _io module
724-
if (type == &_PyBytesIOBuffer_Type) {
725-
if (PyType_Ready(type) < 0) {
726-
goto fail;
727-
}
728-
}
729-
else {
730-
if (PyModule_AddType(m, type) < 0) {
731-
goto fail;
732-
}
723+
if (PyModule_AddType(m, type) < 0) {
724+
goto fail;
733725
}
734726
}
735727

Modules/_testcapimodule.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -1448,12 +1448,10 @@ test_from_contiguous(PyObject* self, PyObject *Py_UNUSED(ignored))
14481448
}
14491449

14501450
#if (defined(__linux__) || defined(__FreeBSD__)) && defined(__GNUC__)
1451-
extern PyTypeObject _PyBytesIOBuffer_Type;
14521451

14531452
static PyObject *
14541453
test_pep3118_obsolete_write_locks(PyObject* self, PyObject *Py_UNUSED(ignored))
14551454
{
1456-
PyTypeObject *type = &_PyBytesIOBuffer_Type;
14571455
PyObject *b;
14581456
char *dummy[1];
14591457
int ret, match;
@@ -1466,7 +1464,13 @@ test_pep3118_obsolete_write_locks(PyObject* self, PyObject *Py_UNUSED(ignored))
14661464
goto error;
14671465

14681466
/* bytesiobuf_getbuffer() */
1467+
PyTypeObject *type = (PyTypeObject *)_PyImport_GetModuleAttrString(
1468+
"_io", "_BytesIOBuffer");
1469+
if (type == NULL) {
1470+
return NULL;
1471+
}
14691472
b = type->tp_alloc(type, 0);
1473+
Py_DECREF(type);
14701474
if (b == NULL) {
14711475
return NULL;
14721476
}

0 commit comments

Comments
 (0)