Skip to content

Commit

Permalink
Only rewind the current container in SdBusMessage.get_contents
Browse files Browse the repository at this point in the history
Otherwise properties break because the actual property set message
consists of tuple of interface and property name and variant of
value. The libsystemd will place the cursor to only read the
value from message but completely rewinding message will point
again to the tuple.
  • Loading branch information
igo95862 committed Oct 28, 2023
1 parent 223c36c commit 65b257d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions 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, 1);
const char* message_signature = sd_bus_message_get_signature(self->message_ref, 0);

if (message_signature == NULL) {
PyErr_SetString(PyExc_TypeError, "Failed to get message signature.");
Expand All @@ -966,7 +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));
CALL_SD_BUS_AND_CHECK(sd_bus_message_rewind(self->message_ref, 0));
_Parse_state read_parser = {
.message = self->message_ref,
.container_char_ptr = message_signature,
Expand Down
5 changes: 4 additions & 1 deletion test/test_read_write_dbus_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,10 @@ def test_reading_multiple_times(self) -> None:
message.seal()

for _ in range(5):
message.get_contents()
self.assertEqual(
message.get_contents(),
"test",
)


if __name__ == "__main__":
Expand Down

0 comments on commit 65b257d

Please sign in to comment.