Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion Lib/test/test_interpreters/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Raise SkipTest if subinterpreters not supported.
_channels = import_helper.import_module('_interpchannels')
from concurrent import interpreters
from test.support import channels
from test.support import channels, force_not_colorized
from .utils import _run_output, TestBase


Expand All @@ -34,6 +34,39 @@ def test_highlevel_reloaded(self):
importlib.reload(channels)
"""));

@force_not_colorized
def test_channel_id_types(self):
# See https://github.com/python/cpython/issues/143376.
code = """\
import _interpchannels
import re
from concurrent import interpreters

class End:
__slots__ = ()
def __new__(cls, chan=None):
return object.__new__(cls)
@property
def _id(self):
return object()

class Send(End): pass
class Recv(End): pass

_interpchannels._register_end_types(Send, Recv)
chan = _interpchannels._channel_id(_interpchannels.create(), _resolve=True)
interp = interpreters.create()
try:
interp.prepare_main(chan=Send(chan))
finally:
interp.close()
"""

out, err = self.assert_python_failure("-c", code)
self.assertEqual(out, '')
errmsg = "TypeError: '_id' attribute must be an _interpchannels.ChannelID object, not object"
self.assertIn(errmsg, err)


class TestChannels(TestBase):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:mod:`concurrent.interpreters`: fix a crash when internal cross-interpreter
channel ends have incorrect channel IDs. Patch by Bénédikt Tran.
11 changes: 11 additions & 0 deletions Modules/_interpchannelsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2634,6 +2634,17 @@ _channelid_from_xid(_PyXIData_t *data)
static int
_channelid_shared(PyThreadState *tstate, PyObject *obj, _PyXIData_t *data)
{
module_state *st = _get_current_module_state();
if (st == NULL) {
return -1;
}
if (!PyObject_IsInstance(obj, (PyObject *)st->ChannelIDType)) {
PyErr_Format(PyExc_TypeError,
"'_id' attribute must be an %N object, not %T",
st->ChannelIDType, obj);
return -1;
}

if (_PyXIData_InitWithSize(
data, tstate->interp, sizeof(struct _channelid_xid), obj,
_channelid_from_xid
Expand Down
Loading