syslog-ng source
python-module.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Balabit
3  * Copyright (c) 2015 Balazs Scheidler <balazs.scheidler@balabit.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * As an additional exemption you are allowed to compile & link against the
20  * OpenSSL libraries as published by the OpenSSL project. See the file
21  * COPYING for details.
22  *
23  */
24 #ifndef PYTHON_MODULE_H_INCLUDED
25 #define PYTHON_MODULE_H_INCLUDED 1
26 
27 /*
28  * There are some Python related things to keep in mind when working on the
29  * Python module. The Python header unfortunately defines a few standard
30  * related conditionals (_POSIX_C_SOURCE and _XOPEN_SOURCE) in Python.h that
31  * it shouldn't, causing two issues potentially:
32  *
33  * 1) warnings, as these defines are usually defined by our configure
34  * script/config.h as well
35  *
36  * 2) triggers POSIX and XOPEN specific interfaces/incompatibilies to be
37  * enabled in system headers. This could cause incompatibilities
38  * between C code that include Python.h and C code that doesn't.
39  * Imagine the case when a new struct member is added based on the
40  * preprocessor defines above. In one part of the code that member
41  * wouldn't exist, in others it would.
42  *
43  * Fortunately this rarely causes issues in practice for a number of reasons:
44  * a) syslog-ng is compiled with the same as _GNU_SOURCE is defined
45  * that implies the other two.<
46  *
47  * b) system libraries are usually designed in a way that struct members
48  * are never removed/added but rather their name is changed (for
49  * example by prefixing them with a pair of underscores)
50  *
51  * Our workaround here is to check whether Python.h inclusion comes first
52  * and if it's not we error out during compilation. Within the Python
53  * module of syslog-ng we should keep the convention to make sure that
54  * python-module.h is the first included file in any C modules.
55  *
56  * python-module.h also makes sure that syslog-ng.h is included (so that
57  * proper ordering happens), so you can omit syslog-ng.h from all
58  * python-module headers.
59  */
60 
61 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
62 #error "_POSIX_C_SOURCE or _XOPEN_SOURCE is already defined, python-module.h should be included first. Check out the comment in python-module.h for more information"
63 #endif
64 
65 #include "compat/compat-python.h"
66 #endif