chiark / gitweb /
systemd-python: add support for sd_j_open_files
[elogind.git] / src / python-systemd / pyutil.c
index 42e7ba72cf78d74f403a71a8942014275bb5f62a..722c4f5b5f89f6c11214f003e7afb13969f6ad30 100644 (file)
@@ -58,3 +58,23 @@ int set_error(int r, const char* path, const char* invalid_message) {
         }
         return -1;
 }
+
+#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1
+int Unicode_FSConverter(PyObject* obj, void *_result) {
+        PyObject **result = _result;
+
+        assert(result);
+
+        if (!obj)
+                /* cleanup: we don't return Py_CLEANUP_SUPPORTED, so
+                 * we can assume that it was PyUnicode_FSConverter. */
+                return PyUnicode_FSConverter(obj, result);
+
+        if (obj == Py_None) {
+                *result = NULL;
+                return 1;
+        }
+
+        return PyUnicode_FSConverter(obj, result);
+}
+#endif