Skip to content

Commit

Permalink
pythongh-105927: _ssl GET_SOCKET() uses _PyWeakref_GET_REF()
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Jun 22, 2023
1 parent ee52158 commit 9c565c2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,20 @@ typedef enum {
#define ERRSTR1(x,y,z) (x ":" y ": " z)
#define ERRSTR(x) ERRSTR1("_ssl.c", Py_STRINGIFY(__LINE__), x)

/* Get the socket from a PySSLSocket, if it has one */
// Get the socket from a PySSLSocket, if it has one.
// Return a borrowed reference.
static inline PySocketSockObject* GET_SOCKET(PySSLSocket *obj) {
if (obj->Socket) {
return (PySocketSockObject *)PyWeakref_GetObject(obj->Socket);
PyObject *sock = _PyWeakref_GET_REF(obj->Socket);
if (sock != NULL) {
// GET_SOCKET() returns a borrowed reference
Py_DECREF(sock);
}
else {
// dead weak reference
sock = Py_None;
}
return (PySocketSockObject *)sock; // borrowed reference
}
else {
return NULL;
Expand Down

0 comments on commit 9c565c2

Please sign in to comment.