bpo-42972: Fully implement GC protocol for ssl heap types (GH-26370)
This commit is contained in:
parent
6ef5ba391d
commit
dcb8786a98
@ -434,11 +434,11 @@ static PyType_Slot sslerror_type_slots[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static PyType_Spec sslerror_type_spec = {
|
static PyType_Spec sslerror_type_spec = {
|
||||||
"ssl.SSLError",
|
.name = "ssl.SSLError",
|
||||||
sizeof(PyOSErrorObject),
|
.basicsize = sizeof(PyOSErrorObject),
|
||||||
0,
|
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_IMMUTABLETYPE,
|
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
|
||||||
sslerror_type_slots
|
.slots = sslerror_type_slots
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -789,7 +789,8 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
|
|||||||
SSL_CTX *ctx = sslctx->ctx;
|
SSL_CTX *ctx = sslctx->ctx;
|
||||||
_PySSLError err = { 0 };
|
_PySSLError err = { 0 };
|
||||||
|
|
||||||
self = PyObject_New(PySSLSocket, get_state_ctx(sslctx)->PySSLSocket_Type);
|
self = PyObject_GC_New(PySSLSocket,
|
||||||
|
get_state_ctx(sslctx)->PySSLSocket_Type);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -896,6 +897,8 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject_GC_Track(self);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2169,6 +2172,7 @@ PySSL_traverse(PySSLSocket *self, visitproc visit, void *arg)
|
|||||||
Py_VISIT(self->exc_type);
|
Py_VISIT(self->exc_type);
|
||||||
Py_VISIT(self->exc_value);
|
Py_VISIT(self->exc_value);
|
||||||
Py_VISIT(self->exc_tb);
|
Py_VISIT(self->exc_tb);
|
||||||
|
Py_VISIT(Py_TYPE(self));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2185,13 +2189,15 @@ static void
|
|||||||
PySSL_dealloc(PySSLSocket *self)
|
PySSL_dealloc(PySSLSocket *self)
|
||||||
{
|
{
|
||||||
PyTypeObject *tp = Py_TYPE(self);
|
PyTypeObject *tp = Py_TYPE(self);
|
||||||
if (self->ssl)
|
PyObject_GC_UnTrack(self);
|
||||||
|
if (self->ssl) {
|
||||||
SSL_free(self->ssl);
|
SSL_free(self->ssl);
|
||||||
|
}
|
||||||
Py_XDECREF(self->Socket);
|
Py_XDECREF(self->Socket);
|
||||||
Py_XDECREF(self->ctx);
|
Py_XDECREF(self->ctx);
|
||||||
Py_XDECREF(self->server_hostname);
|
Py_XDECREF(self->server_hostname);
|
||||||
Py_XDECREF(self->owner);
|
Py_XDECREF(self->owner);
|
||||||
PyObject_Free(self);
|
PyObject_GC_Del(self);
|
||||||
Py_DECREF(tp);
|
Py_DECREF(tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2903,11 +2909,11 @@ static PyType_Slot PySSLSocket_slots[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static PyType_Spec PySSLSocket_spec = {
|
static PyType_Spec PySSLSocket_spec = {
|
||||||
"_ssl._SSLSocket",
|
.name = "_ssl._SSLSocket",
|
||||||
sizeof(PySSLSocket),
|
.basicsize = sizeof(PySSLSocket),
|
||||||
0,
|
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
|
Py_TPFLAGS_HAVE_GC),
|
||||||
PySSLSocket_slots,
|
.slots = PySSLSocket_slots,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3159,6 +3165,7 @@ context_traverse(PySSLContext *self, visitproc visit, void *arg)
|
|||||||
{
|
{
|
||||||
Py_VISIT(self->set_sni_cb);
|
Py_VISIT(self->set_sni_cb);
|
||||||
Py_VISIT(self->msg_cb);
|
Py_VISIT(self->msg_cb);
|
||||||
|
Py_VISIT(Py_TYPE(self));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4641,11 +4648,11 @@ static PyType_Slot PySSLContext_slots[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static PyType_Spec PySSLContext_spec = {
|
static PyType_Spec PySSLContext_spec = {
|
||||||
"_ssl._SSLContext",
|
.name = "_ssl._SSLContext",
|
||||||
sizeof(PySSLContext),
|
.basicsize = sizeof(PySSLContext),
|
||||||
0,
|
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE,
|
Py_TPFLAGS_IMMUTABLETYPE),
|
||||||
PySSLContext_slots,
|
.slots = PySSLContext_slots,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -4689,10 +4696,18 @@ _ssl_MemoryBIO_impl(PyTypeObject *type)
|
|||||||
return (PyObject *) self;
|
return (PyObject *) self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
memory_bio_traverse(PySSLMemoryBIO *self, visitproc visit, void *arg)
|
||||||
|
{
|
||||||
|
Py_VISIT(Py_TYPE(self));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
memory_bio_dealloc(PySSLMemoryBIO *self)
|
memory_bio_dealloc(PySSLMemoryBIO *self)
|
||||||
{
|
{
|
||||||
PyTypeObject *tp = Py_TYPE(self);
|
PyTypeObject *tp = Py_TYPE(self);
|
||||||
|
PyObject_GC_UnTrack(self);
|
||||||
BIO_free(self->bio);
|
BIO_free(self->bio);
|
||||||
Py_TYPE(self)->tp_free(self);
|
Py_TYPE(self)->tp_free(self);
|
||||||
Py_DECREF(tp);
|
Py_DECREF(tp);
|
||||||
@ -4843,15 +4858,16 @@ static PyType_Slot PySSLMemoryBIO_slots[] = {
|
|||||||
{Py_tp_getset, memory_bio_getsetlist},
|
{Py_tp_getset, memory_bio_getsetlist},
|
||||||
{Py_tp_new, _ssl_MemoryBIO},
|
{Py_tp_new, _ssl_MemoryBIO},
|
||||||
{Py_tp_dealloc, memory_bio_dealloc},
|
{Py_tp_dealloc, memory_bio_dealloc},
|
||||||
|
{Py_tp_traverse, memory_bio_traverse},
|
||||||
{0, 0},
|
{0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
static PyType_Spec PySSLMemoryBIO_spec = {
|
static PyType_Spec PySSLMemoryBIO_spec = {
|
||||||
"_ssl.MemoryBIO",
|
.name = "_ssl.MemoryBIO",
|
||||||
sizeof(PySSLMemoryBIO),
|
.basicsize = sizeof(PySSLMemoryBIO),
|
||||||
0,
|
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
|
Py_TPFLAGS_HAVE_GC),
|
||||||
PySSLMemoryBIO_slots,
|
.slots = PySSLMemoryBIO_slots,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -4934,6 +4950,7 @@ static int
|
|||||||
PySSLSession_traverse(PySSLSession *self, visitproc visit, void *arg)
|
PySSLSession_traverse(PySSLSession *self, visitproc visit, void *arg)
|
||||||
{
|
{
|
||||||
Py_VISIT(self->ctx);
|
Py_VISIT(self->ctx);
|
||||||
|
Py_VISIT(Py_TYPE(self));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5022,11 +5039,11 @@ static PyType_Slot PySSLSession_slots[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static PyType_Spec PySSLSession_spec = {
|
static PyType_Spec PySSLSession_spec = {
|
||||||
"_ssl.SSLSession",
|
.name = "_ssl.SSLSession",
|
||||||
sizeof(PySSLSession),
|
.basicsize = sizeof(PySSLSession),
|
||||||
0,
|
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE,
|
Py_TPFLAGS_IMMUTABLETYPE),
|
||||||
PySSLSession_slots,
|
.slots = PySSLSession_slots,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user