FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.10] bpo-42972: Fully implement GC protocol for ssl heap types (GH-26370) by miss-islington · Pull Request #26399 · python/cpython · GitHub

/ cpython Public
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
73 changes: 45 additions & 28 deletions Modules/_ssl.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,11 @@ static PyType_Slot sslerror_type_slots[] = {
};

static PyType_Spec sslerror_type_spec = {
"ssl.SSLError",
sizeof(PyOSErrorObject),
0,
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_IMMUTABLETYPE,
sslerror_type_slots
.name = "ssl.SSLError",
.basicsize = sizeof(PyOSErrorObject),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
.slots = sslerror_type_slots
};

static void
Expand Down Expand Up @@ -789,7 +789,8 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
SSL_CTX *ctx = sslctx->ctx;
_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)
return NULL;

Expand Down Expand Up @@ -896,6 +897,8 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
return NULL;
}
}

PyObject_GC_Track(self);
return self;
}

Expand Down Expand Up @@ -2169,6 +2172,7 @@ PySSL_traverse(PySSLSocket *self, visitproc visit, void *arg)
Py_VISIT(self->exc_type);
Py_VISIT(self->exc_value);
Py_VISIT(self->exc_tb);
Py_VISIT(Py_TYPE(self));
return 0;
}

Expand All @@ -2185,13 +2189,15 @@ static void
PySSL_dealloc(PySSLSocket *self)
{
PyTypeObject *tp = Py_TYPE(self);
if (self->ssl)
PyObject_GC_UnTrack(self);
if (self->ssl) {
SSL_free(self->ssl);
}
Py_XDECREF(self->Socket);
Py_XDECREF(self->ctx);
Py_XDECREF(self->server_hostname);
Py_XDECREF(self->owner);
PyObject_Free(self);
PyObject_GC_Del(self);
Py_DECREF(tp);
}

Expand Down Expand Up @@ -2903,11 +2909,11 @@ static PyType_Slot PySSLSocket_slots[] = {
};

static PyType_Spec PySSLSocket_spec = {
"_ssl._SSLSocket",
sizeof(PySSLSocket),
0,
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
PySSLSocket_slots,
.name = "_ssl._SSLSocket",
.basicsize = sizeof(PySSLSocket),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
Py_TPFLAGS_HAVE_GC),
.slots = PySSLSocket_slots,
};

/*
Expand Down Expand Up @@ -3159,6 +3165,7 @@ context_traverse(PySSLContext *self, visitproc visit, void *arg)
{
Py_VISIT(self->set_sni_cb);
Py_VISIT(self->msg_cb);
Py_VISIT(Py_TYPE(self));
return 0;
}

Expand Down Expand Up @@ -4641,11 +4648,11 @@ static PyType_Slot PySSLContext_slots[] = {
};

static PyType_Spec PySSLContext_spec = {
"_ssl._SSLContext",
sizeof(PySSLContext),
0,
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE,
PySSLContext_slots,
.name = "_ssl._SSLContext",
.basicsize = sizeof(PySSLContext),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = PySSLContext_slots,
};


Expand Down Expand Up @@ -4689,10 +4696,18 @@ _ssl_MemoryBIO_impl(PyTypeObject *type)
return (PyObject *) self;
}

static int
memory_bio_traverse(PySSLMemoryBIO *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
return 0;
}

static void
memory_bio_dealloc(PySSLMemoryBIO *self)
{
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
BIO_free(self->bio);
Py_TYPE(self)->tp_free(self);
Py_DECREF(tp);
Expand Down Expand Up @@ -4843,15 +4858,16 @@ static PyType_Slot PySSLMemoryBIO_slots[] = {
{Py_tp_getset, memory_bio_getsetlist},
{Py_tp_new, _ssl_MemoryBIO},
{Py_tp_dealloc, memory_bio_dealloc},
{Py_tp_traverse, memory_bio_traverse},
{0, 0},
};

static PyType_Spec PySSLMemoryBIO_spec = {
"_ssl.MemoryBIO",
sizeof(PySSLMemoryBIO),
0,
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
PySSLMemoryBIO_slots,
.name = "_ssl.MemoryBIO",
.basicsize = sizeof(PySSLMemoryBIO),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
Py_TPFLAGS_HAVE_GC),
.slots = PySSLMemoryBIO_slots,
};

/*
Expand Down Expand Up @@ -4934,6 +4950,7 @@ static int
PySSLSession_traverse(PySSLSession *self, visitproc visit, void *arg)
{
Py_VISIT(self->ctx);
Py_VISIT(Py_TYPE(self));
return 0;
}

Expand Down Expand Up @@ -5022,11 +5039,11 @@ static PyType_Slot PySSLSession_slots[] = {
};

static PyType_Spec PySSLSession_spec = {
"_ssl.SSLSession",
sizeof(PySSLSession),
0,
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE,
PySSLSession_slots,
.name = "_ssl.SSLSession",
.basicsize = sizeof(PySSLSession),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = PySSLSession_slots,
};


Expand Down

Back | FazBrowse Home | New Git URL