chiark / gitweb /
5c7ea37cdbaaf927abb8da9b0f8a8fc936eeb00f
[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
32 #define _cleanup_Py_DECREF_ __attribute__((cleanup(cleanup_Py_DECREFp)))
33
34 #if PY_MAJOR_VERSION >=3
35 # define unicode_FromStringAndSize PyUnicode_FromStringAndSize
36 # define unicode_FromString PyUnicode_FromString
37 # define long_FromLong PyLong_FromLong
38 # define long_FromSize_t PyLong_FromSize_t
39 # define long_Check PyLong_Check
40 # define long_AsLong PyLong_AsLong
41 #else
42 /* Python 3 type naming convention is used */
43 # define unicode_FromStringAndSize PyString_FromStringAndSize
44 # define unicode_FromString PyString_FromString
45 # define long_FromLong PyInt_FromLong
46 # define long_FromSize_t PyInt_FromSize_t
47 # define long_Check PyInt_Check
48 # define long_AsLong PyInt_AsLong
49 #endif