From 10d0c6df0091fef892d71ff6ca4e4a5a4861e1b0 Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 7 Aug 2018 06:47:09 +0000 Subject: [PATCH] rpc_proto: serialize keywords correctly. Fixes #1109. --- artiq/firmware/libproto/rpc_proto.rs | 4 ++-- artiq/test/coredevice/test_portability.py | 29 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/artiq/firmware/libproto/rpc_proto.rs b/artiq/firmware/libproto/rpc_proto.rs index 2c040467c..7f421b948 100644 --- a/artiq/firmware/libproto/rpc_proto.rs +++ b/artiq/firmware/libproto/rpc_proto.rs @@ -140,11 +140,11 @@ unsafe fn send_value(writer: &mut Write, tag: Tag, data: &mut *const ()) -> io:: Ok(()) } Tag::Keyword(it) => { - struct Keyword<'a> { name: CSlice<'a, u8>, contents: () }; + struct Keyword<'a> { name: CSlice<'a, u8> }; consume_value!(Keyword, |ptr| { writer.write_string(str::from_utf8((*ptr).name.as_ref()).unwrap())?; let tag = it.clone().next().expect("truncated tag"); - let mut data = &(*ptr).contents as *const (); + let mut data = ptr.offset(1) as *const (); send_value(writer, tag, &mut data) }) // Tag::Keyword never appears in composite types, so we don't have diff --git a/artiq/test/coredevice/test_portability.py b/artiq/test/coredevice/test_portability.py index cd301d29b..2238ea805 100644 --- a/artiq/test/coredevice/test_portability.py +++ b/artiq/test/coredevice/test_portability.py @@ -202,6 +202,20 @@ class _RPCExceptions(EnvExperiment): self.success = True +class _Keywords(EnvExperiment): + def build(self, value, output): + self.setattr_device("core") + self.value = value + self.output = output + + def rpc(self, kw): + self.output.append(kw) + + @kernel + def run(self): + self.rpc(kw=self.value) + + class HostVsDeviceCase(ExperimentCase): def test_primes(self): l_device, l_host = [], [] @@ -245,3 +259,18 @@ class HostVsDeviceCase(ExperimentCase): f(_RPCExceptions, catch=False) uut = self.execute(_RPCExceptions, catch=True) self.assertTrue(uut.success) + + def test_keywords(self): + for f in self.execute, _run_on_host: + output = [] + f(_Keywords, value=0, output=output) + self.assertEqual(output, [0]) + output = [] + f(_Keywords, value=1, output=output) + self.assertEqual(output, [1]) + output = [] + f(_Keywords, value=False, output=output) + self.assertEqual(output, [False]) + output = [] + f(_Keywords, value=True, output=output) + self.assertEqual(output, [True])