Skip to content

Commit 4eba33f

Browse files
iritkatrielwarsaw
authored andcommitted
pythongh-102192: remove redundant exception fields from ssl module socket (python#102466)
1 parent 5c12dcb commit 4eba33f

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

Modules/_ssl.c

+9-19
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,7 @@ typedef struct {
318318
* store exception information on the socket. The handshake, read, write,
319319
* and shutdown methods check for chained exceptions.
320320
*/
321-
PyObject *exc_type;
322-
PyObject *exc_value;
323-
PyObject *exc_tb;
321+
PyObject *exc;
324322
} PySSLSocket;
325323

326324
typedef struct {
@@ -564,13 +562,11 @@ fill_and_set_sslerror(_sslmodulestate *state,
564562

565563
static int
566564
PySSL_ChainExceptions(PySSLSocket *sslsock) {
567-
if (sslsock->exc_type == NULL)
565+
if (sslsock->exc == NULL)
568566
return 0;
569567

570-
_PyErr_ChainExceptions(sslsock->exc_type, sslsock->exc_value, sslsock->exc_tb);
571-
sslsock->exc_type = NULL;
572-
sslsock->exc_value = NULL;
573-
sslsock->exc_tb = NULL;
568+
_PyErr_ChainExceptions1(sslsock->exc);
569+
sslsock->exc = NULL;
574570
return -1;
575571
}
576572

@@ -807,9 +803,7 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
807803
self->owner = NULL;
808804
self->server_hostname = NULL;
809805
self->err = err;
810-
self->exc_type = NULL;
811-
self->exc_value = NULL;
812-
self->exc_tb = NULL;
806+
self->exc = NULL;
813807

814808
/* Make sure the SSL error state is initialized */
815809
ERR_clear_error();
@@ -2179,19 +2173,15 @@ Passed as \"self\" in servername callback.");
21792173
static int
21802174
PySSL_traverse(PySSLSocket *self, visitproc visit, void *arg)
21812175
{
2182-
Py_VISIT(self->exc_type);
2183-
Py_VISIT(self->exc_value);
2184-
Py_VISIT(self->exc_tb);
2176+
Py_VISIT(self->exc);
21852177
Py_VISIT(Py_TYPE(self));
21862178
return 0;
21872179
}
21882180

21892181
static int
21902182
PySSL_clear(PySSLSocket *self)
21912183
{
2192-
Py_CLEAR(self->exc_type);
2193-
Py_CLEAR(self->exc_value);
2194-
Py_CLEAR(self->exc_tb);
2184+
Py_CLEAR(self->exc);
21952185
return 0;
21962186
}
21972187

@@ -2536,7 +2526,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len,
25362526
PySSL_SetError(self, retval, __FILE__, __LINE__);
25372527
goto error;
25382528
}
2539-
if (self->exc_type != NULL)
2529+
if (self->exc != NULL)
25402530
goto error;
25412531

25422532
done:
@@ -2662,7 +2652,7 @@ _ssl__SSLSocket_shutdown_impl(PySSLSocket *self)
26622652
PySSL_SetError(self, ret, __FILE__, __LINE__);
26632653
return NULL;
26642654
}
2665-
if (self->exc_type != NULL)
2655+
if (self->exc != NULL)
26662656
goto error;
26672657
if (sock)
26682658
/* It's already INCREF'ed */

Modules/_ssl/debughelpers.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ _PySSL_msg_callback(int write_p, int version, int content_type,
7474
buf, len
7575
);
7676
if (res == NULL) {
77-
PyErr_Fetch(&ssl_obj->exc_type, &ssl_obj->exc_value, &ssl_obj->exc_tb);
77+
ssl_obj->exc = PyErr_GetRaisedException();
7878
} else {
7979
Py_DECREF(res);
8080
}
@@ -138,8 +138,7 @@ _PySSL_keylog_callback(const SSL *ssl, const char *line)
138138
lock = PyThread_allocate_lock();
139139
if (lock == NULL) {
140140
PyErr_SetString(PyExc_MemoryError, "Unable to allocate lock");
141-
PyErr_Fetch(&ssl_obj->exc_type, &ssl_obj->exc_value,
142-
&ssl_obj->exc_tb);
141+
ssl_obj->exc = PyErr_GetRaisedException();
143142
return;
144143
}
145144
}
@@ -156,7 +155,7 @@ _PySSL_keylog_callback(const SSL *ssl, const char *line)
156155
errno = e;
157156
PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError,
158157
ssl_obj->ctx->keylog_filename);
159-
PyErr_Fetch(&ssl_obj->exc_type, &ssl_obj->exc_value, &ssl_obj->exc_tb);
158+
ssl_obj->exc = PyErr_GetRaisedException();
160159
}
161160
PyGILState_Release(threadstate);
162161
}

0 commit comments

Comments
 (0)