Skip to content
Prev Previous commit
Next Next commit
Fix the channels module (more simply).
  • Loading branch information
ericsnowcurrently committed Feb 15, 2024
commit 6f511d63a66b708a95adcc8b7670d18ca6943709
14 changes: 9 additions & 5 deletions Modules/_xxinterpchannelsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2699,12 +2699,16 @@ set_channelend_types(PyObject *mod, PyTypeObject *send, PyTypeObject *recv)
}
struct xid_class_registry *xid_classes = &state->xid_classes;

if (state->send_channel_type != NULL
|| state->recv_channel_type != NULL)
{
PyErr_SetString(PyExc_TypeError, "already registered");
return -1;
// Clear the old values if the .py module was reloaded.
if (state->send_channel_type != NULL) {
(void)_PyCrossInterpreterData_UnregisterClass(state->send_channel_type);
Py_CLEAR(state->send_channel_type);
}
if (state->recv_channel_type != NULL) {
(void)_PyCrossInterpreterData_UnregisterClass(state->recv_channel_type);
Py_CLEAR(state->recv_channel_type);
}

state->send_channel_type = (PyTypeObject *)Py_NewRef(send);
state->recv_channel_type = (PyTypeObject *)Py_NewRef(recv);

Expand Down