forked from M-Labs/artiq
1
0
Fork 0

firmware: Fix kernel RPC handling of zero-size values (e.g. empty arrays)

This commit is contained in:
David Nadlinger 2019-03-31 18:33:44 +01:00
parent b4ddf4c86b
commit cd7a5a3683
2 changed files with 23 additions and 0 deletions

View File

@ -277,6 +277,11 @@ fn process_host_message(io: &Io,
} }
})?; })?;
rpc::recv_return(stream, &tag, slot, &|size| -> Result<_, Error<SchedError>> { rpc::recv_return(stream, &tag, slot, &|size| -> Result<_, Error<SchedError>> {
if size == 0 {
// Don't try to allocate zero-length values, as RpcRecvReply(0) is
// used to terminate the kernel-side receive loop.
return Ok(0 as *mut ())
}
kern_send(io, &kern::RpcRecvReply(Ok(size)))?; kern_send(io, &kern::RpcRecvReply(Ok(size)))?;
Ok(kern_recv(io, |reply| { Ok(kern_recv(io, |reply| {
match reply { match reply {

View File

@ -363,9 +363,27 @@ class _NestedTupleList(EnvExperiment):
if a != self.data: if a != self.data:
raise ValueError raise ValueError
class _EmptyList(EnvExperiment):
def build(self):
self.setattr_device("core")
def get_empty(self) -> TList(TInt32):
return []
@kernel
def run(self):
a = self.get_empty()
if a != []:
raise ValueError
class ListTupleTest(ExperimentCase): class ListTupleTest(ExperimentCase):
def test_list_tuple(self): def test_list_tuple(self):
self.create(_ListTuple).run() self.create(_ListTuple).run()
def test_nested_tuple_list(self): def test_nested_tuple_list(self):
self.create(_NestedTupleList).run() self.create(_NestedTupleList).run()
def test_empty_list(self):
self.create(_EmptyList).run()