gh-105927: _ssl uses _PyWeakref_GET_REF() (#105965)

This commit is contained in:
Victor Stinner 2023-06-21 16:33:32 +02:00 committed by GitHub
parent c5a722be5f
commit 74da6f7c9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 18 deletions

View file

@ -15,7 +15,6 @@ _PySSL_msg_callback(int write_p, int version, int content_type,
PyGILState_STATE threadstate;
PyObject *res = NULL;
PySSLSocket *ssl_obj = NULL; /* ssl._SSLSocket, borrowed ref */
PyObject *ssl_socket = NULL; /* ssl.SSLSocket or ssl.SSLObject */
int msg_type;
threadstate = PyGILState_Ensure();
@ -27,13 +26,14 @@ _PySSL_msg_callback(int write_p, int version, int content_type,
return;
}
PyObject *ssl_socket; /* ssl.SSLSocket or ssl.SSLObject */
if (ssl_obj->owner)
ssl_socket = PyWeakref_GetObject(ssl_obj->owner);
ssl_socket = _PyWeakref_GET_REF(ssl_obj->owner);
else if (ssl_obj->Socket)
ssl_socket = PyWeakref_GetObject(ssl_obj->Socket);
ssl_socket = _PyWeakref_GET_REF(ssl_obj->Socket);
else
ssl_socket = (PyObject *)ssl_obj;
Py_INCREF(ssl_socket);
ssl_socket = (PyObject *)Py_NewRef(ssl_obj);
assert(ssl_socket != NULL); // _PyWeakref_GET_REF() can return NULL
/* assume that OpenSSL verifies all payload and buf len is of sufficient
length */