Skip to content

Commit

Permalink
Rewind message before parsing it in SdBusMessage.get_contents
Browse files Browse the repository at this point in the history
The same message can be given to multiple handlers for example
in case of multiple tasks awaiting on signals.

This would cause the "Dbus type '\x00' is unknown" errors.
  • Loading branch information
igo95862 committed Oct 28, 2023
1 parent c1d9f2f commit 223c36c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/sdbus/sd_bus_internals_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ static PyObject* iter_tuple_or_single(_Parse_state* parser) {
}

static PyObject* SdBusMessage_get_contents2(SdBusMessageObject* self, PyObject* Py_UNUSED(args)) {
const char* message_signature = sd_bus_message_get_signature(self->message_ref, 0);
const char* message_signature = sd_bus_message_get_signature(self->message_ref, 1);

if (message_signature == NULL) {
PyErr_SetString(PyExc_TypeError, "Failed to get message signature.");
Expand All @@ -966,6 +966,7 @@ static PyObject* SdBusMessage_get_contents2(SdBusMessageObject* self, PyObject*
Py_RETURN_NONE;
}

CALL_SD_BUS_AND_CHECK(sd_bus_message_rewind(self->message_ref, 1));
_Parse_state read_parser = {
.message = self->message_ref,
.container_char_ptr = message_signature,
Expand Down
8 changes: 8 additions & 0 deletions test/test_read_write_dbus_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,14 @@ class TestEnum(str, Enum):

self.assertEqual(message.get_contents(), TestEnum.SOMETHING)

def test_reading_multiple_times(self) -> None:
message = create_message(self.bus)
message.append_data('s', 'test')
message.seal()

for _ in range(5):
message.get_contents()


if __name__ == "__main__":
main()

0 comments on commit 223c36c

Please sign in to comment.