chiark / gitweb /
ea88840fa7fc7575c58aeb0bc64ac717012fc9b7
[elogind.git] / src / python-systemd / pyutil.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2013 Zbigniew JÄ™drzejewski-Szmek <zbyszek@in.waw.pl>
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #ifndef Py_TYPE
25 /* avoid duplication warnings from errors in Python 2.7 headers */
26 # include <Python.h>
27 #endif
28
29 void cleanup_Py_DECREFp(PyObject **p);
30 PyObject* absolute_timeout(uint64_t t);
31 int set_error(int r, const char* path, const char* invalid_message);
32
33 #define _cleanup_Py_DECREF_ __attribute__((cleanup(cleanup_Py_DECREFp)))
34
35 #if PY_MAJOR_VERSION >=3
36 # define unicode_FromStringAndSize PyUnicode_FromStringAndSize
37 # define unicode_FromString PyUnicode_FromString
38 # define long_FromLong PyLong_FromLong
39 # define long_FromSize_t PyLong_FromSize_t
40 # define long_Check PyLong_Check
41 # define long_AsLong PyLong_AsLong
42 #else
43 /* Python 3 type naming convention is used */
44 # define unicode_FromStringAndSize PyString_FromStringAndSize
45 # define unicode_FromString PyString_FromString
46 # define long_FromLong PyInt_FromLong
47 # define long_FromSize_t PyInt_FromSize_t
48 # define long_Check PyInt_Check
49 # define long_AsLong PyInt_AsLong
50 #endif