Skip to content
Closed
Prev Previous commit
Next Next commit
Use single base class feature from bpo-42423
  • Loading branch information
tiran committed Apr 17, 2021
commit 00236fed5d810d37397378510a3413c4541a822d
17 changes: 4 additions & 13 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -5459,39 +5459,30 @@ static PyMethodDef PySSL_methods[] = {
static int
sslmodule_init_types(PyObject *module)
{
PySSLContext_Type = (PyTypeObject *)PyType_FromModuleAndSpec(
PySSLContext_Type = PyModule_AddNewTypeFromSpec(
module, &PySSLContext_spec, NULL
);
if (PySSLContext_Type == NULL)
return -1;

PySSLSocket_Type = (PyTypeObject *)PyType_FromModuleAndSpec(
PySSLSocket_Type = PyModule_AddNewTypeFromSpec(
module, &PySSLSocket_spec, NULL
);
if (PySSLSocket_Type == NULL)
return -1;

PySSLMemoryBIO_Type = (PyTypeObject *)PyType_FromModuleAndSpec(
PySSLMemoryBIO_Type = PyModule_AddNewTypeFromSpec(
module, &PySSLMemoryBIO_spec, NULL
);
if (PySSLMemoryBIO_Type == NULL)
return -1;

PySSLSession_Type = (PyTypeObject *)PyType_FromModuleAndSpec(
PySSLSession_Type = PyModule_AddNewTypeFromSpec(
module, &PySSLSession_spec, NULL
);
if (PySSLSession_Type == NULL)
return -1;

if (PyModule_AddType(module, PySSLContext_Type))
return -1;
if (PyModule_AddType(module, PySSLSocket_Type))
return -1;
if (PyModule_AddType(module, PySSLMemoryBIO_Type))
return -1;
if (PyModule_AddType(module, PySSLSession_Type))
return -1;

return 0;
}

Expand Down
17 changes: 1 addition & 16 deletions Python/modsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,26 +715,11 @@ PyModule_AddType(PyObject *module, PyTypeObject *type)

PyTypeObject *
PyModule_AddNewTypeFromSpec(PyObject *module, PyType_Spec *spec,
PyObject *base)
PyObject *bases)
{
PyTypeObject *type;
PyObject *bases;

/* Support single, optional type like PyErr_NewException() */
if (base == NULL) {
bases = NULL;
}
else if (PyTuple_Check(base)) {
bases = base;
Py_INCREF(bases);
} else {
bases = PyTuple_Pack(1, base);
if (bases == NULL)
return NULL;
}

type = (PyTypeObject *)PyType_FromModuleAndSpec(module, spec, bases);
Py_XDECREF(bases);
if (type == NULL) {
return NULL;
}
Expand Down