Skip to content

Commit ca602df

Browse files
committed
pythongh-102192: remove redundant excption fields from ssl module socket
1 parent 6716254 commit ca602df

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

Modules/_ssl.c

+8-19
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,7 @@ typedef struct {
314314
* store exception information on the socket. The handshake, read, write,
315315
* and shutdown methods check for chained exceptions.
316316
*/
317-
PyObject *exc_type;
318-
PyObject *exc_value;
319-
PyObject *exc_tb;
317+
PyObject *exc;
320318
} PySSLSocket;
321319

322320
typedef struct {
@@ -560,13 +558,10 @@ fill_and_set_sslerror(_sslmodulestate *state,
560558

561559
static int
562560
PySSL_ChainExceptions(PySSLSocket *sslsock) {
563-
if (sslsock->exc_type == NULL)
561+
if (sslsock->exc == NULL)
564562
return 0;
565563

566-
_PyErr_ChainExceptions(sslsock->exc_type, sslsock->exc_value, sslsock->exc_tb);
567-
sslsock->exc_type = NULL;
568-
sslsock->exc_value = NULL;
569-
sslsock->exc_tb = NULL;
564+
_PyErr_ChainExceptions1(sslsock->exc);
570565
return -1;
571566
}
572567

@@ -803,9 +798,7 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
803798
self->owner = NULL;
804799
self->server_hostname = NULL;
805800
self->err = err;
806-
self->exc_type = NULL;
807-
self->exc_value = NULL;
808-
self->exc_tb = NULL;
801+
self->exc = NULL;
809802

810803
/* Make sure the SSL error state is initialized */
811804
ERR_clear_error();
@@ -2175,19 +2168,15 @@ Passed as \"self\" in servername callback.");
21752168
static int
21762169
PySSL_traverse(PySSLSocket *self, visitproc visit, void *arg)
21772170
{
2178-
Py_VISIT(self->exc_type);
2179-
Py_VISIT(self->exc_value);
2180-
Py_VISIT(self->exc_tb);
2171+
Py_VISIT(self->exc);
21812172
Py_VISIT(Py_TYPE(self));
21822173
return 0;
21832174
}
21842175

21852176
static int
21862177
PySSL_clear(PySSLSocket *self)
21872178
{
2188-
Py_CLEAR(self->exc_type);
2189-
Py_CLEAR(self->exc_value);
2190-
Py_CLEAR(self->exc_tb);
2179+
Py_CLEAR(self->exc);
21912180
return 0;
21922181
}
21932182

@@ -2532,7 +2521,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len,
25322521
PySSL_SetError(self, retval, __FILE__, __LINE__);
25332522
goto error;
25342523
}
2535-
if (self->exc_type != NULL)
2524+
if (self->exc != NULL)
25362525
goto error;
25372526

25382527
done:
@@ -2658,7 +2647,7 @@ _ssl__SSLSocket_shutdown_impl(PySSLSocket *self)
26582647
PySSL_SetError(self, ret, __FILE__, __LINE__);
26592648
return NULL;
26602649
}
2661-
if (self->exc_type != NULL)
2650+
if (self->exc != NULL)
26622651
goto error;
26632652
if (sock)
26642653
/* 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)