+ /* Iterate through the Python arguments and fill the iovector. */
+ for (i = 0; i < argc; ++i) {
+ PyObject *item = PyTuple_GetItem(args, i);
+ char *stritem;
+ Py_ssize_t length;
+
+ if (PyUnicode_Check(item)) {
+ encoded[i] = PyUnicode_AsEncodedString(item, "utf-8", "strict");
+ if (encoded[i] == NULL)
+ goto out;
+ item = encoded[i];
+ }
+ if (PyBytes_AsStringAndSize(item, &stritem, &length))
+ goto out;
+
+ iov[i].iov_base = stritem;
+ iov[i].iov_len = length;
+ }
+
+ /* Clear errno, because sd_journal_sendv will not set it by
+ itself, unless an error occurs in one of the system calls. */
+ errno = 0;
+
+ /* Send the iovector to the journal. */
+ r = sd_journal_sendv(iov, argc);
+ if (r) {
+ if (errno)
+ PyErr_SetFromErrno(PyExc_IOError);
+ else
+ PyErr_SetString(PyExc_ValueError, "invalid message format");
+ goto out;
+ }
+
+ /* End with success. */
+ Py_INCREF(Py_None);
+ ret = Py_None;