Skip to content

Commit 00236fe

Browse files
committed
Use single base class feature from bpo-42423
1 parent 3e50f44 commit 00236fe

File tree

2 files changed

+5
-29
lines changed

2 files changed

+5
-29
lines changed

Modules/_ssl.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5459,39 +5459,30 @@ static PyMethodDef PySSL_methods[] = {
54595459
static int
54605460
sslmodule_init_types(PyObject *module)
54615461
{
5462-
PySSLContext_Type = (PyTypeObject *)PyType_FromModuleAndSpec(
5462+
PySSLContext_Type = PyModule_AddNewTypeFromSpec(
54635463
module, &PySSLContext_spec, NULL
54645464
);
54655465
if (PySSLContext_Type == NULL)
54665466
return -1;
54675467

5468-
PySSLSocket_Type = (PyTypeObject *)PyType_FromModuleAndSpec(
5468+
PySSLSocket_Type = PyModule_AddNewTypeFromSpec(
54695469
module, &PySSLSocket_spec, NULL
54705470
);
54715471
if (PySSLSocket_Type == NULL)
54725472
return -1;
54735473

5474-
PySSLMemoryBIO_Type = (PyTypeObject *)PyType_FromModuleAndSpec(
5474+
PySSLMemoryBIO_Type = PyModule_AddNewTypeFromSpec(
54755475
module, &PySSLMemoryBIO_spec, NULL
54765476
);
54775477
if (PySSLMemoryBIO_Type == NULL)
54785478
return -1;
54795479

5480-
PySSLSession_Type = (PyTypeObject *)PyType_FromModuleAndSpec(
5480+
PySSLSession_Type = PyModule_AddNewTypeFromSpec(
54815481
module, &PySSLSession_spec, NULL
54825482
);
54835483
if (PySSLSession_Type == NULL)
54845484
return -1;
54855485

5486-
if (PyModule_AddType(module, PySSLContext_Type))
5487-
return -1;
5488-
if (PyModule_AddType(module, PySSLSocket_Type))
5489-
return -1;
5490-
if (PyModule_AddType(module, PySSLMemoryBIO_Type))
5491-
return -1;
5492-
if (PyModule_AddType(module, PySSLSession_Type))
5493-
return -1;
5494-
54955486
return 0;
54965487
}
54975488

Python/modsupport.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -715,26 +715,11 @@ PyModule_AddType(PyObject *module, PyTypeObject *type)
715715

716716
PyTypeObject *
717717
PyModule_AddNewTypeFromSpec(PyObject *module, PyType_Spec *spec,
718-
PyObject *base)
718+
PyObject *bases)
719719
{
720720
PyTypeObject *type;
721-
PyObject *bases;
722-
723-
/* Support single, optional type like PyErr_NewException() */
724-
if (base == NULL) {
725-
bases = NULL;
726-
}
727-
else if (PyTuple_Check(base)) {
728-
bases = base;
729-
Py_INCREF(bases);
730-
} else {
731-
bases = PyTuple_Pack(1, base);
732-
if (bases == NULL)
733-
return NULL;
734-
}
735721

736722
type = (PyTypeObject *)PyType_FromModuleAndSpec(module, spec, bases);
737-
Py_XDECREF(bases);
738723
if (type == NULL) {
739724
return NULL;
740725
}

0 commit comments

Comments
 (0)